array( self::INTERVAL_ANNUAL => 'Annually', self::INTERVAL_SEMESTER => 'Twice a year', self::INTERVAL_MONTHLY => 'Monthly', self::INTERVAL_WEEKLY => 'Weekly', ), ); if (isset($code)) return isset($_items[$type][$code]) ? $_items[$type][$code] : false; else return isset($_items[$type]) ? $_items[$type] : false; } /** * Returns the static model of the specified AR class. * @param string $className active record class name. * @return Quota 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 'quota'; } /** * @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(' sales_agent_id, amount, interval, status, commission_forumula_id', 'required'), array('id, sales_agent_id, interval, status, commission_forumula_id', 'numerical', 'integerOnly' => true), array('amount', 'length', 'max' => 8), array('implemented_at','date','format' => 'MM/dd/yyyy'), array('comments, commission_formula_parameters', 'safe'), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, sales_agent_id, amount, implemented_at, interval, comments, status, commission_forumula_id, commission_formula_parameters', '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( 'commissionFormula' => array(self::BELONGS_TO, 'CommissionFormula', 'commission_forumula_id'), 'salesAgent' => array(self::BELONGS_TO, 'User', 'sales_agent_id'), 'assignedBy' => array(self::BELONGS_TO, 'User', 'assigned_by') ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'sales_agent_id' => 'Sales Agent', 'amount' => 'Amount', 'implemented_at' => 'Implemented At', 'interval' => 'Interval', 'comments' => 'Comments', 'status' => 'Status', 'commission_forumula_id' => 'Commission Forumula', 'commission_formula_parameters' => 'Commission Formula Parameters', ); } /** * 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); $criteria->compare('sales_agent_id', $this->sales_agent_id); $criteria->compare('amount', $this->amount, true); $criteria->compare('implemented_at', $this->implemented_at, true); $criteria->compare('interval', $this->interval); $criteria->compare('comments', $this->comments, true); $criteria->compare('status', $this->status); $criteria->compare('commission_forumula_id', $this->commission_forumula_id); $criteria->compare('commission_formula_parameters', $this->commission_formula_parameters, true); return new CActiveDataProvider($this, array( 'criteria' => $criteria, )); } public function behaviors() { return array( 'active-record-relation' => array( 'class' => 'ext.activerecord-relation.EActiveRecordRelationBehavior', ), 'morray' => array( 'class' => 'ext.restfullyii.components.MorrayBehavior', ), 'related-search' => array( 'class' => 'RelatedSearchBehavior', 'relations' => array( 'salesAgentName' => 'itemHeader.item_code', 'assignedByName' => 'itemHeader.branch_id' ), ), ); } public function beforeSave() { if ($this->implemented_at != null) $this->implemented_at = date('Y-m-d', strtotime($this->implemented_at)); else { $this->implemented_at = null; } return parent::beforeSave(); } public function afterFind() { if ($this->implemented_at != null) $this->implemented_at = date('m/d/Y', strtotime($this->implemented_at)); return parent::afterFind(); } }