Advertisement
fernandezekiel

Quota Model

May 19th, 2013
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.96 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This is the model class for table "quota".
  5.  *
  6.  * The followings are the available columns in table 'quota':
  7.  * @property integer $id
  8.  * @property integer $sales_agent_id
  9.  * @property string $amount
  10.  * @property string $implemented_at
  11.  * @property integer $interval
  12.  * @property string $comments
  13.  * @property integer $status
  14.  * @property integer $commission_forumula_id
  15.  * @property string $commission_formula_parameters
  16.  */
  17. class Quota extends CActiveRecord {
  18.  
  19.     public $commission_formula_parameters = "{}";
  20.     const INTERVAL_ANNUAL = 1;
  21.     const INTERVAL_SEMESTER = 2;
  22.     const INTERVAL_MONTHLY = 3;
  23.     const INTERVAL_WEEKLY = 4;
  24.  
  25.     public static function itemAlias($type, $code = NULL) {
  26.         $_items = array(
  27.             'interval' => array(
  28.                 self::INTERVAL_ANNUAL => 'Annually',
  29.                 self::INTERVAL_SEMESTER => 'Twice a year',
  30.                 self::INTERVAL_MONTHLY => 'Monthly',
  31.                 self::INTERVAL_WEEKLY => 'Weekly',
  32.             ),
  33.         );
  34.         if (isset($code))
  35.             return isset($_items[$type][$code]) ? $_items[$type][$code] : false;
  36.         else
  37.             return isset($_items[$type]) ? $_items[$type] : false;
  38.     }
  39.  
  40.     /**
  41.      * Returns the static model of the specified AR class.
  42.      * @param string $className active record class name.
  43.      * @return Quota the static model class
  44.      */
  45.     public static function model($className = __CLASS__) {
  46.         return parent::model($className);
  47.     }
  48.  
  49.     /**
  50.      * @return string the associated database table name
  51.      */
  52.     public function tableName() {
  53.         return 'quota';
  54.     }
  55.  
  56.     /**
  57.      * @return array validation rules for model attributes.
  58.      */
  59.     public function rules() {
  60.         // NOTE: you should only define rules for those attributes that
  61.         // will receive user inputs.
  62.         return array(
  63.             array(' sales_agent_id, amount, interval, status, commission_forumula_id', 'required'),
  64.             array('id, sales_agent_id, interval, status, commission_forumula_id', 'numerical', 'integerOnly' => true),
  65.             array('amount', 'length', 'max' => 8),
  66.              array('implemented_at','date','format' => 'MM/dd/yyyy'),
  67.             array('comments, commission_formula_parameters', 'safe'),
  68.             // The following rule is used by search().
  69.             // Please remove those attributes that should not be searched.
  70.             array('id, sales_agent_id, amount, implemented_at, interval, comments, status, commission_forumula_id, commission_formula_parameters', 'safe', 'on' => 'search'),
  71.         );
  72.     }
  73.  
  74.     /**
  75.      * @return array relational rules.
  76.      */
  77.     public function relations() {
  78.         // NOTE: you may need to adjust the relation name and the related
  79.         // class name for the relations automatically generated below.
  80.         return array(
  81.             'commissionFormula' => array(self::BELONGS_TO, 'CommissionFormula', 'commission_forumula_id'),
  82.             'salesAgent' => array(self::BELONGS_TO, 'User', 'sales_agent_id'),
  83.             'assignedBy' => array(self::BELONGS_TO, 'User', 'assigned_by')
  84.         );
  85.     }
  86.  
  87.     /**
  88.      * @return array customized attribute labels (name=>label)
  89.      */
  90.     public function attributeLabels() {
  91.         return array(
  92.             'id' => 'ID',
  93.             'sales_agent_id' => 'Sales Agent',
  94.             'amount' => 'Amount',
  95.             'implemented_at' => 'Implemented At',
  96.             'interval' => 'Interval',
  97.             'comments' => 'Comments',
  98.             'status' => 'Status',
  99.             'commission_forumula_id' => 'Commission Forumula',
  100.             'commission_formula_parameters' => 'Commission Formula Parameters',
  101.         );
  102.     }
  103.  
  104.     /**
  105.      * Retrieves a list of models based on the current search/filter conditions.
  106.      * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  107.      */
  108.     public function search() {
  109.         // Warning: Please modify the following code to remove attributes that
  110.         // should not be searched.
  111.  
  112.         $criteria = new CDbCriteria;
  113.  
  114.         $criteria->compare('id', $this->id);
  115.         $criteria->compare('sales_agent_id', $this->sales_agent_id);
  116.         $criteria->compare('amount', $this->amount, true);
  117.         $criteria->compare('implemented_at', $this->implemented_at, true);
  118.         $criteria->compare('interval', $this->interval);
  119.         $criteria->compare('comments', $this->comments, true);
  120.         $criteria->compare('status', $this->status);
  121.         $criteria->compare('commission_forumula_id', $this->commission_forumula_id);
  122.         $criteria->compare('commission_formula_parameters', $this->commission_formula_parameters, true);
  123.  
  124.         return new CActiveDataProvider($this, array(
  125.             'criteria' => $criteria,
  126.         ));
  127.     }
  128.  
  129.  
  130.     public function behaviors() {
  131.         return array(
  132.             'active-record-relation' => array(
  133.                 'class' => 'ext.activerecord-relation.EActiveRecordRelationBehavior',
  134.             ),
  135.             'morray' => array(
  136.                 'class' => 'ext.restfullyii.components.MorrayBehavior',
  137.             ),
  138.             'related-search' => array(
  139.                 'class' => 'RelatedSearchBehavior',
  140.                 'relations' => array(
  141.                     'salesAgentName' => 'itemHeader.item_code',
  142.                     'assignedByName' => 'itemHeader.branch_id'
  143.                 ),
  144.             ),
  145.         );
  146.     }
  147.     public function beforeSave() {
  148.  
  149.         if ($this->implemented_at != null)
  150.             $this->implemented_at = date('Y-m-d', strtotime($this->implemented_at));
  151.         else {
  152.             $this->implemented_at = null;
  153.         }
  154.  
  155.         return parent::beforeSave();
  156.     }
  157.  
  158.     public function afterFind() {
  159.  
  160.         if ($this->implemented_at != null)
  161.             $this->implemented_at = date('m/d/Y', strtotime($this->implemented_at));
  162.  
  163.         return parent::afterFind();
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement