EliteConf
 All Data Structures Namespaces Files Functions Variables Pages
Paper.php
Go to the documentation of this file.
1 <?php
2 
14 class Paper extends CActiveRecord {
15 
22  public $file;
23 
24  public static function model($className = __CLASS__) {
25  return parent::model($className);
26  }
27 
31  public function tableName() {
32  return 'paper';
33  }
34 
38  public function rules() {
39  // NOTE: you should only define rules for those attributes that
40  // will receive user inputs.
41  return array(
42  array('paper_name', 'length', 'max' => 60),
43  array('paper_size', 'length', 'max' => 10),
44  array('author_id', 'length', 'max' => 6),
45  array('author_name', 'length', 'max' => 20),
46  array('rating', 'length', 'max' => 2),
47  //Yükleme kuralları, sadece pdf dosyalar yüklenecek.
48  array('file', 'file', 'types' => 'pdf'),
49  // The following rule is used by search().
50  // Please remove those attributes that should not be searched.
51  array('id, paper_name, paper_size, author_id, author_name, rating', 'safe', 'on' => 'search'),
52  );
53  }
54 
58  public function relations() {
59  // NOTE: you may need to adjust the relation name and the related
60  // class name for the relations automatically generated below.
61  return array(
62  );
63  }
64 
68  public function attributeLabels() {
69  return array(
70  'id' => 'ID',
71  'paper_name' => 'Paper Name',
72  'paper_size' => 'Paper Size',
73  'author_id' => 'Author',
74  'author_name' => 'Author Name',
75  'rating' => 'Rating',
76  );
77  }
78 
83  public function search() {
84  // Warning: Please modify the following code to remove attributes that
85  // should not be searched.
86 
87  $criteria = new CDbCriteria;
88 
89  $criteria->compare('id', $this->id, true);
90  $criteria->compare('paper_name', $this->paper_name, true);
91  $criteria->compare('paper_size', $this->paper_size, true);
92  $criteria->compare('author_id', $this->author_id, true);
93  $criteria->compare('author_name', $this->author_name, true);
94  $criteria->compare('rating', $this->rating, true);
95 
96  return new CActiveDataProvider($this, array(
97  'criteria' => $criteria,
98  ));
99  }
100 
101  public function beforeSave() {
102  if ($file = CUploadedFile::getInstance($this, 'file')) {
103  $this->paper_name = $file->name;
104  $this->paper_size = $file->size;
105  $this->author_id = Yii::app()->user->id;
106  $this->author_name = Yii::app()->user->name;
107  }
108 
109  return parent::beforeSave();
110  }
111 
112 }