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