Пример #1
0
 public function afterUpdate()
 {
     try {
         if ($this->seoText->load(Yii::$app->request->post())) {
             $this->seoText->setAttributes(['_image' => UploadedFile::getInstance($this->seoText, '_image')]);
             // if(!$this->seoText->isEmpty()){
             if ($this->seoText->save()) {
                 if ($this->seoText->_image) {
                     $old = $this->seoText->ogImage;
                     $photo = new Photo();
                     $photo->class = get_class($this->seoText);
                     $photo->item_id = $this->seoText->seotext_id;
                     $photo->image = $this->seoText->_image;
                     if ($photo->image && $photo->validate(['image'])) {
                         $photo->image = Image::upload($photo->image, 'photos', Photo::PHOTO_MAX_WIDTH);
                         if ($photo->image) {
                             if ($photo->save()) {
                                 $old->delete();
                             } else {
                                 @unlink(Yii::getAlias('@webroot') . str_replace(Url::base(true), '', $photo->image));
                             }
                         } else {
                         }
                     }
                 }
             }
         }
     } catch (UnknownMethodException $e) {
     }
 }
Пример #2
0
 public function getPhotos()
 {
     if (!$this->_photos) {
         $this->_photos = [];
         foreach (Photo::find()->where(['class' => NewsModel::className(), 'item_id' => $this->id])->sort()->all() as $model) {
             $this->_photos[] = new PhotoObject($model);
         }
     }
     return $this->_photos;
 }
Пример #3
0
 public function photos($options = [])
 {
     if (!$this->_photos) {
         $this->_photos = [];
         $query = Photo::find()->where(['class' => Category::className(), 'item_id' => $this->id])->sort();
         if (!empty($options['where'])) {
             $query->andFilterWhere($options['where']);
         }
         $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []]);
         foreach ($this->_adp->models as $model) {
             $this->_photos[] = new PhotoObject($model);
         }
     }
     return $this->_photos;
 }
Пример #4
0
 private function findAlbum($id_slug)
 {
     $album = Album::find()->where(['or', 'album_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one();
     if (!$album) {
         return $this->notFound($id_slug);
     }
     if ($album->status != Album::STATUS_ON) {
         return Yii::$app->user->isGuest ? $this->createObject('') : $this->createObject($this->errorText('ALBUM IS OFF'));
     }
     $this->_adp = new ActiveDataProvider(['query' => Photo::find()->where(['model' => Album::className(), 'item_id' => $album->primaryKey])->sort(), 'pagination' => ['pageSize' => $this->_albumOptions['pageSize']]]);
     $albumObject = $this->parseAlbum($album);
     $albumObject->photos = $this->parsePhotos($this->_adp->models);
     $albumObject->seo_h1 = $album->seo_h1;
     $albumObject->seo_title = $album->seo_title;
     $albumObject->seo_keywords = $album->seo_keywords;
     $albumObject->seo_description = $album->seo_description;
     return $albumObject;
 }
Пример #5
0
 public function down()
 {
     $this->dropTable(models\Admin::tableName());
     $this->dropTable(models\LoginForm::tableName());
     $this->dropTable(models\Module::tableName());
     $this->dropTable(models\Photo::tableName());
     $this->dropTable(models\Setting::tableName());
     $this->dropTable(Carousel::tableName());
     $this->dropTable(Category::tableName());
     $this->dropTable(Item::tableName());
     $this->dropTable(Feedback::tableName());
     $this->dropTable(File::tableName());
     $this->dropTable(Album::tableName());
     $this->dropTable(Guestbook::tableName());
     $this->dropTable(News::tableName());
     $this->dropTable(Page::tableName());
     $this->dropTable(Subscriber::tableName());
     $this->dropTable(History::tableName());
     $this->dropTable(Text::tableName());
 }
Пример #6
0
 public function actionDelete($id)
 {
     if ($model = Photo::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii', 'Photo deleted'));
 }
Пример #7
0
 public function getPhotos()
 {
     return $this->hasMany(Photo::className(), ['item_id' => 'item_id'])->where(['class' => self::className()])->sort();
 }
Пример #8
0
 public function run()
 {
     $photos = Photo::find()->where(['model' => get_class($this->model), 'item_id' => $this->model->primaryKey])->sort()->all();
     echo $this->render('photos', ['photos' => $photos]);
 }
Пример #9
0
 public function getPhotos()
 {
     return $this->hasMany(Photo::className(), ['item_id' => 'album_id'])->where(['model' => Album::className()])->sort();
 }
Пример #10
0
 public function api_photo($id)
 {
     $photo = Photo::findOne($id);
     return $photo ? $photo->image : null;
 }
Пример #11
0
 private function findPhoto($id)
 {
     return Photo::findOne($id);
 }
Пример #12
0
 public function getPhotos($index = null)
 {
     if (!$this->_photos) {
         $this->_photos = [];
         foreach (Photo::find()->where(['class' => Item::className(), 'item_id' => $this->id])->sort()->all() as $model) {
             $this->_photos[] = new PhotoObject($model);
         }
     }
     if (is_numeric($index)) {
         if (isset($this->_photos[$index])) {
             return $this->_photos[$index];
         } else {
             return null;
         }
     }
     return $this->_photos;
 }
Пример #13
0
 public function down()
 {
     $this->dropTable(models\Admin::tableName());
     $this->dropTable(models\LoginForm::tableName());
     $this->dropTable(models\Module::tableName());
     $this->dropTable(models\Photo::tableName());
     $this->dropTable(models\Setting::tableName());
     $this->dropTable(Carousel::tableName());
     $this->dropTable(catalog\models\Category::tableName());
     $this->dropTable(catalog\models\Item::tableName());
     $this->dropTable(article\models\Category::tableName());
     $this->dropTable(article\models\Item::tableName());
     $this->dropTable(Feedback::tableName());
     $this->dropTable(File::tableName());
     $this->dropTable(gallery\models\Category::tableName());
     $this->dropTable(Guestbook::tableName());
     $this->dropTable(News::tableName());
     $this->dropTable(Page::tableName());
     $this->dropTable(Subscriber::tableName());
     $this->dropTable(History::tableName());
     $this->dropTable(Text::tableName());
     $this->dropTable(Menu::tableName());
     $this->dropTable(MenuItem::tableName());
 }