protected function saveGallery($gallery)
 {
     $user = User::model()->findByAttributes(['email' => '*****@*****.**']);
     $album = new MediaAlbum();
     $album->title = $gallery['title'];
     $album->model_id = get_class($user);
     $album->object_id = $user->id;
     $album->source = 'sherdog.com';
     $album->source_id = $gallery['id'];
     $album->status = MediaAlbum::STATUS_ACTIVE;
     if (!$album->save()) {
         throw new CException(json_encode($album->getErrors()));
     }
     $order = 0;
     foreach ($gallery['imgs'] as $img) {
         if (!$img['path']) {
             continue;
         }
         $file = new MediaFile('insert', 'local');
         $file->model_id = get_class($album);
         $file->object_id = $album->id;
         $file->tag = 'files';
         $file->title = $img['title'];
         $file->remote_id = $img['path'];
         $file->order = ++$order;
         $file->getApi()->need_upload = false;
         if (!$file->save()) {
             throw new CException(json_encode($file->getErrors()));
         }
     }
 }
Beispiel #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() . '
                    ']];
    }
 protected function saveGallery($gallery)
 {
     $album = new MediaAlbum();
     $album->title = $gallery['title'];
     $album->model_id = 'sherdog.com';
     $album->object_id = $gallery['id'];
     $album->save(false);
     foreach ($gallery['imgs'] as $img) {
         $file = new MediaFile('create', 'remote');
         $file->model_id = get_class($album);
         $file->object_id = $album->id;
         $file->tag = 'images';
         $file->title = $img['title'];
         $file->remote_id = $img['img'];
         $file->save(false);
     }
 }
 public function actionManage($user_id = null, $q = null)
 {
     if ($user_id) {
         $this->user = User::model()->throw404IfNull()->findByPk($user_id);
         $this->page_title = 'Альбомы пользователя: ' . $this->user->getLink();
     } else {
         $this->user = new User();
         $this->page_title = 'Альбомы';
     }
     $this->render('manage', ['dp' => MediaAlbum::model()->search($this->user, $q), 'is_my' => Yii::app()->user->id && Yii::app()->user->id == $user_id]);
 }
Beispiel #5
0
<?php

$mediaAlbumsDp = function ($positive = true) {
    $album = new MediaAlbum();
    $album->parentModel(Yii::app()->controller->user, $positive);
    return new ActiveDataProvider('MediaAlbum', ['criteria' => $album->parentModel(Yii::app()->controller->user, $positive)->getDbCriteria(), 'pagination' => false]);
};
return [['actions' => ['view'], 'sidebars' => [['type' => 'widget', 'class' => 'media.portlets.AlbumSearch'], ['type' => 'widget', 'class' => 'media.portlets.MediaAlbumList', 'title' => 'Альбомы тогоже пользователя', 'dp' => $mediaAlbumsDp()], ['type' => 'widget', 'class' => 'media.portlets.MediaAlbumList', 'title' => 'Другие альбомы', 'dp' => $mediaAlbumsDp(false)]]], ['actions' => ['manage'], 'sidebars' => [['type' => 'widget', 'class' => 'media.portlets.AlbumSearch']]]];