Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
ApalinesFile.php
1 <?php
2 
3 /**
4  * This is the model class for table "gportal_apalines_file".
5  *
6  * The followings are the available columns in table 'gportal_apalines_file':
7  * @property integer $id
8  * @property string $href
9  * @property integer $size
10  * @property integer $width
11  * @property integer $height
12  * @property string $format
13  * @property integer $parent_id
14  */
15 class ApalinesFile extends CActiveRecord
16 {
17  const THUMBNAIL = 0;
18  const ORIGINAL = 1;
19  const HIRES = 2;
20  /**
21  * Returns the static model of the specified AR class.
22  * @param string $className active record class name.
23  * @return ApalinesFile the static model class
24  */
25  public static function model($className=__CLASS__)
26  {
27  return parent::model($className);
28  }
29 
30  /**
31  * @return string the associated database table name
32  */
33  public function tableName()
34  {
35  return 'gportal_apalines_file';
36  }
37 
38  /**
39  * @return array validation rules for model attributes.
40  */
41  public function rules()
42  {
43  // NOTE: you should only define rules for those attributes that
44  // will receive user inputs.
45  return array(
46  array('parent_id', 'required'),
47  array('size, width, height, parent_id', 'numerical', 'integerOnly'=>true),
48  array('href', 'length' , 'max'=>255),
49  array('format', 'length' , 'max'=>5),
50  // The following rule is used by search().
51  // Please remove those attributes that should not be searched.
52  array('id, href, size, width, height, format, parent_id', 'safe', 'on'=>'search'),
53  );
54  }
55 
56  /**
57  * @return array relational rules.
58  */
59  public function relations()
60  {
61  // NOTE: you may need to adjust the relation name and the related
62  // class name for the relations automatically generated below.
63  return array(
64  );
65  }
66 
67  /**
68  * @return array customized attribute labels (name=>label)
69  */
70  public function attributeLabels()
71  {
72  return array(
73  'id' => 'ID',
74  'href' => 'Href',
75  'size' => 'Size',
76  'width' => 'Width',
77  'height' => 'Height',
78  'format' => 'Format',
79  'parent_id' => 'Parent',
80  );
81  }
82 
83  /**
84  * Retrieves a list of models based on the current search/filter conditions.
85  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
86  */
87  public function search()
88  {
89  // Warning: Please modify the following code to remove attributes that
90  // should not be searched.
91 
92  $criteria=new CDbCriteria;
93 
94  $criteria->compare('id',$this->id);
95  $criteria->compare('href',$this->href,true);
96  $criteria->compare('size',$this->size);
97  $criteria->compare('width',$this->width);
98  $criteria->compare('height',$this->height);
99  $criteria->compare('format',$this->format);
100  $criteria->compare('parent_id',$this->parent_id);
101 
102  return new CActiveDataProvider($this, array(
103  'criteria'=>$criteria,
104  ));
105  }
106  /**
107  * Function removes multimedia files before record is deleted
108  */
109  public function beforeDelete() {
110 
111  $channel = Channel::$instance;
112  $file = $this->href;
113 
114  if (isset($channel)) {
115  if (file_exists($channel->makeImagesPath($file))) {
116  unlink($channel->makeImagesPath($file));
117  Yii::log("{$file} done delete image", 'info');
118  } elseif(file_exists($channel->makeVideosPath($file))) {
119  Yii::log("{$file} done delete video", 'info');
120  unlink($channel->makeVideosPath($file));
121  }
122  }
123  return parent::beforeDelete();
124  }
125 }