View file vkclone-0.0.1/protected/models/Profile.php

File size: 2.66Kb
<?php
/**
 * This is the model class for table "{{profiles}}".
 *
 * The followings are the available columns in table '{{profiles}}':
 * @property string $id
 * @property string $type
 * @property string $avatar_id
 * @property string $alias
 *
 * The followings are the available model relations:
 * @property Groups $groups
 * @property GalleryPhotos $avatar
 * @property Users $users
 */
class Profile extends CActiveRecord {

	/**
	 * @return string the associated database table name
	 */
	public function tableName() {
		return '{{profiles}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		return array(
			array('type', 'required'),
			array('type', 'in', 'range' => array('user', 'group', 'public')),
			array('avatar_id', 'length', 'max' => 10),
			array('alias', 'length', 'max' => 255),
			// The following rule is used by search().
			array('id, type, avatar_id, alias', 'safe', 'on' => 'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations() {
		return array(
			'avatar' => array(self::BELONGS_TO, 'GalleryPhoto', 'avatar_id'),
			'group' => array(self::HAS_ONE, 'Group', 'id'),
			'user' => array(self::HAS_ONE, 'User', 'id'),
			'public' => array(self::HAS_ONE, 'CPublic', 'id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array(
			'id' => 'ID',
			'type' => 'Type',
			'avatar_id' => 'Avatar',
			'alias' => 'Alias',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search() {
		$criteria = new CDbCriteria;

		$criteria->compare('id', $this->id, true);
		$criteria->compare('type', $this->type, true);
		$criteria->compare('avatar_id', $this->avatar_id, true);
		$criteria->compare('alias', $this->alias, true);

		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Profile the static model class
	 */
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
}