/**
  * Finds the File model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return File the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = File::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
 /**
  * @return bool
  */
 public function delete()
 {
     if (parent::delete() === false) {
         return false;
     }
     $this->deleteThumbnails();
     return true;
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = File::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'material_id' => $this->material_id, 'material_type' => $this->material_type, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'file_name', $this->file_name]);
     return $dataProvider;
 }
Example #4
0
 /**
  * @param $materialId
  * @param $materialType
  * @param $materialBlock
  * @return array|\yii\db\ActiveRecord[]
  */
 public static function getFilesByMaterialIdAndTypeAndBlock($materialId, $materialType, $materialBlock)
 {
     return File::find()->where(['material_id' => $materialId, 'material_type' => $materialType, 'block' => $materialBlock])->all();
 }
Example #5
0
 public function getImages()
 {
     return File::getFilesByMaterialAndType($this->id, File::TYPE_DOCUMENT);
 }