Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
RememberedPage.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 model is ActiveRecord which represents single remembered page in database.
11  *
12  * The followings are the available columns in table '{{remembered_pages}}':
13  * @property integer $id
14  * @property string $collection_id
15  * @property string $page_id
16  * @property string $url
17  * @property array $additional
18  * @property string $image
19  * @property string $title
20  * @property string $created
21  */
22 
23 class RememberedPage extends CActiveRecord
24 {
25 
26  /**
27  * Returns the static model of the specified AR class.
28  *
29  * @param string $className active record class name
30  *
31  * @return array|CActiveRecord
32  */
33  public static function model($className = __CLASS__)
34  {
35  return parent::model($className);
36  }
37 
38  /**
39  * Returns the name of the associated database table.
40  * By default this method returns the class name as the table name.
41  * You may override this method if the table is not named after this convention.
42  *
43  * @return string the table name
44  */
45  public function tableName()
46  {
47  return '{{remembered_pages}}';
48  }
49 
50  /**
51  * Returns the validation rules for attributes.
52  *
53  * @return array
54  */
55  public function rules()
56  {
57  return array(
58  array('created', 'default', 'value' => AppHelper::mysqlDate()),
59  array('url, title, page_id, collection_id','required'),
60  array('page_id, title','length', 'max'=>255),
61  array('additional', 'safe'),
62  array('created', 'type', 'type'=>'datetime', 'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss'),
63  array('id, url, title, page_id, collection_id, created','safe', 'on'=>'search'),
64  );
65  }
66 
67 
68  public function getAttributeLabel($name)
69  {
70  return RememberModule::t(parent::getAttributeLabel($name));
71  }
72 
73  protected function beforeSave()
74  {
75  if($this->additional !== null) {
76  $this->additional = serialize($this->additional);
77  }
78  return parent::beforeSave();
79  }
80 
81  protected function afterSave()
82  {
83  if($this->additional !== null) {
84  $this->additional = unserialize($this->additional);
85  }
86  }
87 
88  protected function afterFind()
89  {
90  if($this->additional !== null) {
91  $this->additional = unserialize($this->additional);
92  }
93  }
94 
95  public function getFbSharerUrl(){
96  $shareUrl = "http://www.facebook.com/sharer.php?s=100&p[title]=%title%&p[url]=%url%&p[summary]=%summary%&p[images][0]=%image%";
97  return str_replace(
98  array('%title%', '%url%', '%summary%', '%image%'),
99  array($this->title, $this->url, $this->title, $this->image), $shareUrl);
100  }
101  /**
102  * Search
103  *
104  * @return CActiveDataProvider
105  */
106  public function search($pageSize = 10, $collection_id = null)
107  {
108  // Warning: Please modify the following code to remove attributes that
109  // should not be searched.
110 
111  $criteria = new CDbCriteria;
112 
113  $criteria->compare('id', $this->id, true);
114  $criteria->compare('page_id', $this->page_id, true);
115  $criteria->compare('url', $this->url, true);
116  $criteria->compare('title', $this->title, true);
117  $criteria->compare('created', $this->created, true);
118  $criteria->compare('collection_id', $collection_id);
119 
120  $pagination = new CPagination($this->count($criteria));
121  $pagination->applyLimit($criteria);
122  $pagination->setPageSize($pageSize);
123 
124  return new CActiveDataProvider($this, array('criteria' => $criteria,'pagination' => $pagination));
125  }
126 }