示例#1
0
 public function run()
 {
     if (User::hasPermission('viewMedia')) {
         $recent = MediaModel::find()->orderBy(['id' => SORT_DESC])->limit($this->recentLimit)->all();
         return $this->render('media', ['height' => $this->height, 'width' => $this->width, 'position' => $this->position, 'recent' => $recent]);
     }
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params = [])
 {
     $query = Media::find()->joinWith('translations');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['album_id' => $this->album_id, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['>=', 'created_at', strtotime($this->created_at)])->andFilterWhere(['<=', 'created_at', strtotime($this->created_at . ' 23:59:59')]);
     return $dataProvider;
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMedia()
 {
     return $this->hasMany(Media::className(), ['album_id' => 'id']);
 }
 /**
  * @param array $value the value of the attribute
  */
 public function setUploadValue($value)
 {
     $this->newUploads = [];
     foreach ($value as $media_id) {
         if (ctype_digit($media_id) && !in_array($media_id, $this->newUploads)) {
             $media = Media::findOne([Media::tableName() . '.' . Media::primaryKey()[0] => $media_id]);
             //Disallow to add images uploaded by other users
             if (!$media || $media->created_by !== Yii::$app->user->id) {
                 continue;
             }
             $this->newUploads[] = (int) $media_id;
         }
     }
 }
 /**
  * Delete model with medias
  * @param $id
  * @return array
  */
 public function actionDelete($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (Yii::$app->user->isGuest) {
         return ['error' => 'Please, authorise to delete files.'];
     }
     $tableName = Media::tableName();
     /**
      * @var yeesoft\media\models\Media
      */
     $model = Media::findOne(["{$tableName}.id" => $id, "{$tableName}.created_by" => Yii::$app->user->identity->id]);
     if (!$model) {
         return ['error' => Yii::t('yii', 'You are not allowed to perform this action.')];
     }
     if ($model->isImage()) {
         $model->deleteThumbs($this->routes);
     }
     $model->deleteFile($this->routes);
     $model->delete();
     return ['success' => 'true'];
 }
 /** Render model info
  * @param int $id
  * @param string $strictThumb only this thumb will be selected
  * @return string
  */
 public function actionInfo($id, $strictThumb = null)
 {
     $tableName = Media::tableName();
     /**
      * @var yeesoft\media\models\Media
      */
     $model = Media::findOne(["{$tableName}.id" => $id]);
     return $this->renderPartial('info', ['model' => $model, 'strictThumb' => $strictThumb]);
 }