Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
ApalinesNews.php
1 <?php
2 
3 /**
4  * This is the model class for table "gportal_apalines_news".
5  *
6  * The followings are the available columns in table 'gportal_apalines_news':
7  * @property integer $id
8  * @property string $title
9  * @property integer $ndate
10  * @property string $channel
11  * @property string $docid
12  * @property integer $background_news
13  * @property integer $related_maindoc_id
14  * @property string $place
15  * @property string $source
16  * @property string $teaser
17  * @property string $content
18  * @property string $filename
19  * @property string $author
20  * @property string $keywords
21  * @property integer $deleted
22  * @property integer $created
23  * @property integer $updated
24  * @property string $xml_filename
25  * @property string $apa_id
26  */
28 {
29  /**
30  * Returns the static model of the specified AR class.
31  * @param string $className active record class name.
32  * @return ApalinesNews 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 'gportal_apalines_news';
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('ndate, background_news, related_maindoc_id, deleted, created, updated', 'numerical', 'integerOnly'=>true),
56  array('title, channel, docid, place, source, author, xml_filename, apa_id', 'length', 'max'=>255),
57  array('filename', 'length', 'max'=>64),
58  array('teaser, content, keywords', 'safe'),
59  // The following rule is used by search().
60  // Please remove those attributes that should not be searched.
61  array('id, title, ndate, channel, docid, background_news, related_maindoc_id, place, source, teaser, content, filename, author, keywords, deleted, created, updated, xml_filename', 'safe', 'on'=>'search'),
62  );
63  }
64 
65  /**
66  * @return array relational rules.
67  */
68  public function relations()
69  {
70  // NOTE: you may need to adjust the relation name and the related
71  // class name for the relations automatically generated below.
72  return array(
73  'bg_news'=>array(self::HAS_MANY, 'ApalinesNews', 'related_maindoc_id'),
74  'multimedia'=>array(self::HAS_MANY, 'ApalinesMM', 'related_maindoc_id'),
75  );
76  }
77 
78  /**
79  * @return array customized attribute labels (name=>label)
80  */
81  public function attributeLabels()
82  {
83  return array(
84  'id' => 'ID',
85  'title' => 'Title',
86  'ndate' => 'Ndate',
87  'channel' => 'Channel',
88  'docid' => 'Docid',
89  'background_news' => 'Background News',
90  'related_maindoc_id' => 'Related Maindoc',
91  'place' => 'Place',
92  'source' => 'Source',
93  'teaser' => 'Teaser',
94  'content' => 'Content',
95  'filename' => 'Filename',
96  'author' => 'Author',
97  'keywords' => 'Keywords',
98  'deleted' => 'Deleted',
99  'created' => 'Created',
100  'updated' => 'Updated',
101  'xml_filename' => 'XML filename',
102  'apa_id' => 'APA id'
103  );
104  }
105 
106  /**
107  * Retrieves a list of models based on the current search/filter conditions.
108  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
109  */
110  public function search()
111  {
112  // Warning: Please modify the following code to remove attributes that
113  // should not be searched.
114 
115  $criteria=new CDbCriteria;
116 
117  $criteria->compare('id',$this->id);
118  $criteria->compare('title',$this->title,true);
119  $criteria->compare('ndate',$this->ndate);
120  $criteria->compare('channel',$this->channel,true);
121  $criteria->compare('docid',$this->docid,true);
122  $criteria->compare('background_news',$this->background_news);
123  $criteria->compare('related_maindoc_id',$this->related_maindoc_id);
124  $criteria->compare('place',$this->place,true);
125  $criteria->compare('source',$this->source,true);
126  $criteria->compare('teaser',$this->teaser,true);
127  $criteria->compare('content',$this->content,true);
128  $criteria->compare('filename',$this->filename,true);
129  $criteria->compare('author',$this->author,true);
130  $criteria->compare('keywords',$this->keywords,true);
131  $criteria->compare('deleted',$this->deleted);
132  $criteria->compare('created',$this->created);
133  $criteria->compare('updated',$this->updated);
134  $criteria->compare('xml_filename',$this->xml_filename, true);
135  $criteria->compare('apa_id',$this->apa_id, true);
136 
137  return new CActiveDataProvider($this, array(
138  'criteria'=>$criteria,
139  ));
140  }
141  /**
142  * Function removes files and files of background news
143  */
144  public function deleteFiles($with_build = false) {
145 
146  if (isset($this->bg_news)) {
147  foreach ($this->bg_news as $bg) {
148  if (isset($bg->multimedia)) {
149  foreach ($bg->multimedia as $mm) {
150  if ($with_build) {
151  $mm->delete();
152  } else {
153  $mm->deleteFiles();
154  }
155  }
156  }
157  }
158  }
159  if (isset($this->multimedia)) {
160  foreach ($this->multimedia as $mm) {
161  if ($with_build) {
162  $mm->delete();
163  } else {
164  $mm->deleteFiles();
165  }
166  }
167  }
168  }
169  /**
170  * Function removes background news before record is deleted
171  */
172  public function beforeDelete() {
173 
174  $this->deleteFiles(true);
175  if (isset($this->bg_news)) {
176  foreach ($this->bg_news as $bg) {
177  $bg->delete();
178  }
179  }
180  return parent::beforeDelete();
181  }
182 }