Skip to content

Instantly share code, notes, and snippets.

@yaoquan
Created August 27, 2011 14:58
Show Gist options
  • Select an option

  • Save yaoquan/1175480 to your computer and use it in GitHub Desktop.

Select an option

Save yaoquan/1175480 to your computer and use it in GitHub Desktop.
<?php
/**
* This is the model class for table "groups".
*
* The followings are the available columns in table 'groups':
* @property string $id
* @property integer $parentId
* @property string $path
* @property string $name
* @property string $description
* @property integer $isTeam
* @property string $avatar
* @property string $dateCreated
* @property string $dateLastUpdated
* @property integer $lastUpdatedBy
* @property string $status
*/
class Groups extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @return Groups the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'groups';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('isTeam, created', 'required'),
array('parentId, isTeam, lastUpdatedBy', 'numerical', 'integerOnly'=>true),
array('path', 'length', 'max'=>500),
array('name', 'length', 'max'=>50),
array('description', 'length', 'max'=>200),
array('avatar', 'length', 'max'=>100),
array('status', 'length', 'max'=>10),
array('updated', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, parentId, path, name, description, isTeam, avatar, created, updated, updatedBy, status', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'createdBy' => array(self::BELONGS_TO, 'User', 'createdBy'),
'groupMembers' => array(self::HAS_MANY, 'GroupMember', 'groupId'),
'parentGroup' => array(self::BELONGS_TO, 'GROUP', 'parentId'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'parentId' => 'Parent',
'path' => 'Path',
'name' => 'Name',
'description' => 'Description',
'isTeam' => 'Is Team',
'avatar' => 'Avatar',
'createdBy' => 'Created By',
'created' => 'Date Created',
'updated' => 'Date Last Updated',
'status' => 'Status',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('parentId',$this->parentId);
$criteria->compare('path',$this->path,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('description',$this->description,true);
$criteria->compare('isTeam',$this->isTeam);
$criteria->compare('avatar',$this->avatar,true);
$criteria->compare('createdBy',$this->createdBy,true);
$criteria->compare('created',$this->created,true);
$criteria->compare('updated',$this->updated,true);
$criteria->compare('status',$this->status,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
protected function beforeValidate()
{
if(parent::beforeValidate())
{
if($this->isNewRecord)
{
$this->created=$this->updated=date("Y-m-d H:i:s");
}
else
$this->updated=date("Y-m-d H:i:s");
return true;
}
else
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment