public function findAllAttaches()
 {
     $model = $this->getOwner();
     $object_id = $model->isNewRecord ? $this->_tmpPrefix() : $model->id;
     MediaFile::model()->findAllByAttributes(array('object_id' => $object_id, 'model_id' => get_class($model)));
     return MediaFile::model()->findAllByAttributes(array('object_id' => $object_id, 'model_id' => get_class($model)));
 }
Example #2
0
    public function getSearchInfo()
    {
        return ['video' => ['sql' => '
                    SELECT
                        media_files.id,
                        media_files.id as object_id, "MediaFile" as model_id,
                        media_files.title, media_files.descr

                        FROM  ' . MediaFile::model()->tableName() . '
                        WHERE media_files.type="video"
                    '], 'audio' => ['sql' => '
                    SELECT
                        media_files.id,
                        media_files.id as object_id, "MediaFile" as model_id,
                        media_files.title, media_files.descr

                        FROM  ' . MediaFile::model()->tableName() . '
                        WHERE media_files.type="audio"
                    '], 'albums' => ['sql' => '
                    SELECT
                        media_albums.id,
                        media_albums.id as object_id, "MediaAlbum" as model_id,
                        media_albums.title, media_albums.descr

                        FROM  ' . MediaAlbum::model()->tableName() . '
                    ']];
    }
 public function actionExistFiles($model_id, $object_id, $tag)
 {
     if ($object_id == 0) {
         $object_id = 'tmp_' . Yii::app()->user->id;
     }
     $existFiles = MediaFile::model()->parent($model_id, $object_id)->tag($tag)->findAll();
     $this->sendFilesAsJson($existFiles);
 }
 public function actionDownloadFile($hash)
 {
     list($hash, $id) = explode('x', $hash);
     $model = MediaFile::model()->findByPk(intval($id));
     if (!$model || $model->getHash() != $hash || !$model->getIsFileExist()) {
         $this->pageNotFound();
     }
     if ($this->x_send_file_enabled) {
         Yii::app()->request->xSendFile($model->server_path, ['saveName' => $model->name, 'terminate' => false]);
     } else {
         $this->request->sendFile($model->name, $model->content);
     }
 }
 public function actionView($id)
 {
     $model = MediaAlbum::model()->throw404IfNull()->findByPk($id);
     $this->user = $model->getParentModel();
     $this->page_title = 'Альбом: ' . $model->title;
     $form = new Form('Media.UploadFilesForm', $model);
     $dp = MediaFile::model()->getDataProvider($model, 'files');
     $dp->getPagination()->pageSize = 18;
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('view', ['model' => $model, 'form' => $form, 'dp' => $dp]);
     } else {
         $this->render('view', ['model' => $model, 'form' => $form, 'dp' => $dp]);
     }
 }
 protected function parseVideo($db)
 {
     $collection = $db->sherdog_video;
     foreach ($collection->find() as $video) {
         $model = MediaFile::model()->findByAttributes(['source' => 'sherdog.com', 'source_id' => $video['id']]);
         if ($model) {
             continue;
         }
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $this->saveVideo($video);
             $transaction->commit();
             $video['status'] = 'parsed';
             $collection->update(['id' => $video['id']], $video);
         } catch (Exception $e) {
             $transaction->rollback();
             $collection->remove(['id' => $video['id']]);
             Yii::log($e, CLogger::LEVEL_ERROR);
         }
     }
 }
 public function actionView($id)
 {
     $file = MediaFile::model()->throw404IfNull()->findByPk($id);
     $this->setMetaTags($file);
     $this->render('view', ['model' => $file]);
 }
 public function actionLocalToRemote($id, $api)
 {
     $file = MediaFile::model()->findByPk($id);
     $file->target_api = $api;
     $file->save();
 }
Example #9
0
 public function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             $model = MediaFile::model()->parent($this->model_id, $this->object_id)->tag($this->tag)->find();
             $this->order || ($this->order = $model ? $model->order + 1 : 1);
         }
         return true;
     }
     return false;
 }