Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
TmpUser.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  * This is the model class for table "{{tmp_user}}".
11  *
12  * The followings are the available columns in table '{{tmp_user}}':
13  * @property int $id
14  * @property string $salutation
15  * @property string $firstname
16  * @property string $lastname
17  * @property string $company
18  * @property string $birthday
19  * @property string $street
20  * @property string $zip_code
21  * @property string $city
22  * @property string $country
23  * @property string $telephone
24  * @property string $email
25  * @property string $memberNo
26  */
27 class TmpUser extends CActiveRecord
28 {
29  /**
30  * Returns the static model of the specified AR class.
31  * @param string $className active record class name.
32  * @return TmpUser 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 '{{tmp_user}}';
45  }
46 
47  protected function afterFind()
48  {
49  $format = Yii::app()->locale->getDateFormat();
50  $oldDate = $this->birthday;
51  $this->birthday = Yii::app()->dateFormatter->format($format, $oldDate);
52  parent::afterFind();
53  }
54 
55  protected function beforeSave()
56  {
57  if(parent::beforeSave()) {
58 
59  $dateFormat = Yii::app()->locale->getDateFormat();
60  $dateFormat = ($dateFormat == 'MMM d, y')?'MMM d, yyyy':$dateFormat;
61 
62  $this->birthday = date('Y-m-d',
63  CDateTimeParser::parse($this->birthday,
64  $dateFormat));
65  return true;
66  } else {
67  return false;
68  }
69  }
70 
71  /**
72  protected function beforeSave()
73  {
74  if(parent::beforeSave())
75  {
76  // Format dates based on the locale
77  foreach($this->metadata->tableSchema->columns as $columnName => $column)
78  {
79  if ($column->dbType == 'date')
80  {
81  $this->$columnName = date('Y-m-d',
82  CDateTimeParser::parse($this->$columnName,
83  Yii::app()->locale->getDateFormat('short')));
84  }
85  elseif ($column->dbType == 'datetime')
86  {
87  $this->$columnName = date('Y-m-d H:i:s',
88  CDateTimeParser::parse($this->$columnName,
89  Yii::app()->locale->getDateTimeFormat('short')));
90  }
91  }
92  return true;
93  }
94  else
95  return false;
96  }
97  protected function afterFind()
98  {
99  // Format dates based on the locale
100  foreach($this->metadata->tableSchema->columns as $columnName => $column)
101  {
102  if (!strlen($this->$columnName)) continue;
103 
104  if ($column->dbType == 'date')
105  {
106  $this->$columnName = Yii::app()->dateFormatter->formatDateTime(
107  CDateTimeParser::parse(
108  $this->$columnName,
109  'yyyy-MM-dd'
110  ),
111  'short',null
112  );
113  }
114  elseif ($column->dbType == 'datetime' || $column->dbType == 'timestamp')
115  {
116  $this->$columnName = Yii::app()->dateFormatter->formatDateTime(
117  CDateTimeParser::parse(
118  $this->$columnName,
119  'yyyy-MM-dd hh:mm:ss'
120  ),
121  'short','short'
122  );
123  }
124  }
125  return parent::afterFind();
126  }
127  **/
128  /**
129  * @return array validation rules for model attributes.
130  */
131  public function rules()
132  {
133  // NOTE: you should only define rules for those attributes that
134  // will receive user inputs.
135  $dateFormat = Yii::app()->locale->getDateFormat();
136  $dateFormat = ($dateFormat == 'MMM d, y')?'MMM d, yyyy':$dateFormat;
137 
138  return array(
139  array('salutation, firstname, lastname, street, zip_code, city, country, email', 'required'),
140  array('salutation, firstname, lastname, company, street, zip_code, city, country, telephone, email', 'length', 'max'=>255),
141  array('email','email'),
142  array('birthday','date','format' => $dateFormat), //'dd.MM.yyyy'
143  array('birthday', 'safe'),
144  // The following rule is used by search().
145  // Please remove those attributes that should not be searched.
146  array('id, salutation, firstname, lastname, company, birthday, street, zip_code, city, country, telephone, email', 'safe', 'on'=>'search'),
147  array('salutation, firstname, lastname, street, zip_code, city, country, email, birthday, telephone, company','filter', 'filter'=>array($obj=new CHtmlPurifier(),'purify')),
148  );
149  }
150 
151  /**
152  * @return array relational rules.
153  */
154  public function relations()
155  {
156  // NOTE: you may need to adjust the relation name and the related
157  // class name for the relations automatically generated below.
158  return array(
159  'order' => array(self::HAS_ONE, 'Order', 'user_id'),
160  );
161  }
162 
163  /*
164  * The method return registered user model that connect with order
165  * @return object
166  */
167  public function getExistUser()
168  {
169  return Profile::model()->findByPk($this->parent_user_id);
170  }
171 
172  /**
173  * @return array customized attribute labels (name=>label)
174  */
175 
176  public function attributeLabels()
177  {
178  return array(
179  'id' => ShoppingcartModule::t('ID'),
180  'salutation' => ShoppingcartModule::t('Salutation'),
181  'firstname' => ShoppingcartModule::t('First Name'),
182  'lastname' => ShoppingcartModule::t('Last Name'),
183  'company' => ShoppingcartModule::t('Company'),
184  'birthday' => ShoppingcartModule::t('Date Of Birth'),
185  'street' => ShoppingcartModule::t('Street'),
186  'zip_code' => ShoppingcartModule::t('Zip Code'),
187  'city' => ShoppingcartModule::t('City'),
188  'country' => ShoppingcartModule::t('Country'),
189  'telephone' => ShoppingcartModule::t('Telephone'),
190  'email' => ShoppingcartModule::t('Email'),
191  );
192  }
193  /*
194  * The method implement fields from registered profile
195  * @return object
196  */
197  public function implementFromSession(){
198 
199  if(isset($this->parent_user_id)){
200  $user = Profile::model()->findByPk($this->parent_user_id);
201  if(isset($user)){
202  foreach($this->attributes as $fieldName => $value){
203  if(isset($user->$fieldName) && empty($this->$fieldName)){
204  $this->$fieldName = $user->$fieldName;
205  }
206  }
207  }
208  }
209 
210  return $this;
211  }
212  /*
213  * The method unset fields that exists in registered profile
214  * @return object
215  */
216  public function unsetExistFields(){
217 
218  if(isset($this->parent_user_id)){
219  $user = Profile::model()->findByPk($this->parent_user_id);
220  if(isset($user)){
221  foreach($this->attributes as $fieldName => $value){
222  if(isset($user->$fieldName) && isset($this->$fieldName)
223  && $user->$fieldName==$this->$fieldName){
224  unset($this->$fieldName);
225  }
226  }
227  }
228  }
229 
230  return $this;
231  }
232 
233  /**
234  * Retrieves a list of models based on the current search/filter conditions.
235  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
236  */
237  public function search()
238  {
239  // Warning: Please modify the following code to remove attributes that
240  // should not be searched.
241 
242  $criteria=new CDbCriteria;
243 
244  $criteria->compare('id',$this->id,true);
245  $criteria->compare('salutation',$this->salutation,true);
246  $criteria->compare('first_name',$this->first_name,true);
247  $criteria->compare('last_name',$this->last_name,true);
248  $criteria->compare('company',$this->company,true);
249  $criteria->compare('date_of_birth',$this->date_of_birth,true);
250  $criteria->compare('street',$this->street,true);
251  $criteria->compare('zip_code',$this->zip_code,true);
252  $criteria->compare('city',$this->city,true);
253  $criteria->compare('svnr',$this->svnr,true);
254  $criteria->compare('memberNo',$this->memberNo,true);
255  $criteria->compare('country',$this->country,true);
256  $criteria->compare('telephone',$this->telephone,true);
257  $criteria->compare('email',$this->email,true);
258 
259  return new CActiveDataProvider($this, array(
260  'criteria'=>$criteria,
261  ));
262  }
263 
264 }