Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Item.php
1 <?php
2 
3 /**
4  * Gentics Portal.Node PHP
5  * Author & Copyright (c) by Gentics Software GmbH
6  * sales@gentics.com
7  * http://www.gentics.com
8  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
9  * You must not use this software without a valid license agreement.
10  *
11  * This is the model class for table "{{item}}".
12  *
13  * The followings are the available columns in table '{{item}}':
14  * @property string $id
15  * @property double $price
16  * @property string $admin_email
17  * @property string $page_id
18  * @property string $title
19  * @property string $item_id
20  * @property string $order_id
21  * @property string $quantity
22  * @property string $referrer
23  * @property string $ip_address
24  * @property string $ordered_at
25  * @property string $item_referrer
26  */
27 class Item extends CActiveRecord
28 {
29  /**
30  * Returns the static model of the specified AR class.
31  * @param string $className active record class name.
32  * @return Item the static model class
33  */
34  public static function model($className=__CLASS__)
35  {
36  return parent::model($className);
37  }
38 
39  /**
40  * @return string the associated database table name
41  */
42  public function tableName()
43  {
44  return '{{item}}';
45  }
46 
47  /**
48  * @return array validation rules for model attributes.
49  */
50  public function rules()
51  {
52  // NOTE: you should only define rules for those attributes that
53  // will receive user inputs.
54  return array(
55  array('admin_email, title, referrer, ip_address, page_id, item_id', 'required'),
56  array('page_id, item_id','numerical', 'integerOnly' => true),
57  array('price, quantity', 'numerical'),
58  array('quantity','compare','operator'=>'>','compareValue'=>(-1)),
59  array('price','compare','operator'=>'>','compareValue'=>(-1)),
60  array('admin_email, title, referrer, item_referrer', 'length', 'max'=>255),
61  array('page_id, item_id, order_id, quantity', 'length', 'max'=>10),
62  array('ip_address', 'length', 'max'=>16),
63  array('ordered_at', 'safe'),
64  array('admin_email','email'),
65  // The following rule is used by search().
66  // Please remove those attributes that should not be searched.
67  array('id, price, admin_email, page_id, title, item_id, order_id, quantity, referrer, ip_address, ordered_at', 'safe', 'on'=>'search'),
68  );
69  }
70 
71  /**
72  * @return array relational rules.
73  */
74  public function relations()
75  {
76  // NOTE: you may need to adjust the relation name and the related
77  // class name for the relations automatically generated below.
78  return array(
79  'order' => array(self::BELONGS_TO, 'Order', 'order_id'),
80  );
81  }
82 
83  /**
84  * @return array customized attribute labels (name=>label)
85  */
86  public function attributeLabels()
87  {
88  return array(
89  'id' => ShoppingcartModule::t('ID'),
90  'price' => ShoppingcartModule::t('Price'),
91  'admin_email' => ShoppingcartModule::t('Admin Email'),
92  'page_id' => ShoppingcartModule::t('Page'),
93  'title' => ShoppingcartModule::t('Title'),
94  'item_id' => ShoppingcartModule::t('Item'),
95  'order_id' => ShoppingcartModule::t('Order'),
96  'quantity' => ShoppingcartModule::t('Quantity'),
97  'referrer' => ShoppingcartModule::t('Referrer'),
98  'ip_address' => ShoppingcartModule::t('Ip Address'),
99  'ordered_at' => ShoppingcartModule::t('Ordered At'),
100  );
101  }
102 
103  /**
104  * Retrieves a list of models based on the current search/filter conditions.
105  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106  */
107  public function search()
108  {
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,true);
115  $criteria->compare('price',$this->price);
116  $criteria->compare('admin_email',$this->admin_email,true);
117  $criteria->compare('page_id',$this->page_id,true);
118  $criteria->compare('title',$this->title,true);
119  $criteria->compare('item_id',$this->item_id,true);
120  $criteria->compare('order_id',$this->order_id,true);
121  $criteria->compare('quantity',$this->quantity,true);
122  $criteria->compare('referrer',$this->referrer,true);
123  $criteria->compare('ip_address',$this->ip_adsress,true);
124  $criteria->compare('ordered_at',$this->ordered_at,true);
125 
126  return new CActiveDataProvider($this, array(
127  'criteria'=>$criteria,
128  ));
129  }
130  /**
131  * Returns the price with currency in the correct local format
132  *
133  * @param string $price the price that you want to attach currency
134  *
135  * @return string price with currency
136  */
137  public static function addCurrency($price){
138  $currency = Yii::app()->getModule('shoppingcart')->currency;
139  return Yii::app()->numberFormatter->formatCurrency($price, $currency);
140  }
141 
142  /**
143  * Function to get checksum of fields
144  *
145  * @param object $model instance of Item class
146  * @param boolean $encrypted flag that shows when fields of instance are encrypted
147  *
148  * @return checksum of fields
149  */
150  public function getItemChecksum($encrypted = false){
151  $fields = array('item_id','title','price','page_id','admin_email');
152  $str= '';
153  foreach($fields as $field){
154  $str.= $encrypted? EncryptHelper::decrypt($this->$field):$this->$field;
155  }
156  return md5($str);
157  }
158 }