public function actionShow($id)
 {
     $model = Photo::findOne($id);
     $marks = AdminPhoto::getMarks($id);
     $comments = AdminCommon::getComments('photo', $id, 0, 5);
     $content = ['content_type' => 'photo', 'content_id' => $id];
     $categories = Category::getAllCategory();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->save();
     }
     $photo = AdminPhoto::getPhotoInfo($id);
     if (!isset($photo['photo_id'])) {
         return $this->render('error.404.php');
     }
     return $this->render('show', ['photo' => $photo, 'marks' => $marks, 'comments' => $comments, 'model' => $model, 'categories' => $categories, 'content' => $content]);
 }
 public function actionConfirm()
 {
     if (!Yii::$app->request->post() or !Yii::$app->request->isAjax) {
         throw new BadRequestHttpException('Only POST Ajax requests');
     }
     $checkedPhotosId = Yii::$app->request->post('checkedPhotos');
     if (!$checkedPhotosId or $checkedPhotosId == []) {
         throw new \HttpInvalidParamException('No photos');
     }
     /** @var Users $user */
     $user = Yii::$app->session->get('user');
     if (!$user) {
         throw new UnauthorizedHttpException('Need login');
     }
     $checkedPhotosNames = [];
     // Mark selected photos
     foreach ($checkedPhotosId as $checkedPhotoId) {
         /** @var Photo $photoModel */
         $photoModel = Photo::findOne($checkedPhotoId);
         if (!$photoModel) {
             throw new NotFoundHttpException('Photo ' . $checkedPhotoId . ' not found');
         }
         if ($photoModel->project_id !== $user->project_id) {
             throw new HttpException(403);
         }
         if ($photoModel->selected === true) {
             continue;
         }
         $photoModel->selected = true;
         $photoModel->save();
         $checkedPhotosNames[] = '#' . $photoModel->id . ' - ' . $photoModel->filename;
     }
     // Deselect not checked photos
     $checkedPhotos = Photo::findAll(['user_id' => $user->id, 'selected' => true]);
     foreach ($checkedPhotos as $checkedPhoto) {
         if (!in_array($checkedPhoto->id, $checkedPhotosId)) {
             $checkedPhoto->selected = false;
             $checkedPhoto->save();
         }
     }
     // Notify by email
     try {
         Yii::$app->mailer->compose('checked', ['checkedPhotosNames' => $checkedPhotosNames, 'user' => $user])->setFrom([Yii::$app->params['siteEmail'] => 'Fotoboom.net'])->setTo(Yii::$app->params['adminEmail'])->setSubject('Пользователь ' . $user->name . ' выбрал фото')->send();
     } catch (\Exception $e) {
     }
     return json_encode(['success' => true, 'message' => 'Выбранные фото успешно отправлены фотографу. Теперь вы можете просто закрыть страницу.']);
 }
Exemple #3
0
 public function run()
 {
     if (strpos(\Yii::$app->request->url, "view-post")) {
         $post = Post::findOne(\Yii::$app->request->get('id'));
         $current_page = $post->page;
     } else {
         if (strpos(\Yii::$app->request->url, "view-album")) {
             $photo = Photo::findOne(\Yii::$app->request->get('id'));
             $current_page = $photo->page;
         } else {
             $slug = \Yii::$app->request->get('slug');
             $current_page = Page::find()->where(['slug' => $slug])->one();
         }
     }
     $parent = $current_page->parent_id == 0 ? null : Page::findOne($current_page->parent_id);
     return $this->render('breadCrumb', ['parent' => $parent, 'current_page' => $current_page]);
 }
 /**
  * Finds the Photo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Photo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Photo::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #5
0
 public function actionViewAlbum($id)
 {
     if (Yii::$app->deviceDetect->isMobile()) {
         $this->layout = "//mobile";
         $mobile = 'mobile/';
     } else {
         $this->layout = "//inner";
         $mobile = '';
     }
     $album = Photo::findOne($id);
     $next_album = Photo::find()->where(['page_id' => $album->page_id, 'parent_id' => 0])->andWhere(['>', 'id', $album->id])->orderBy(['create_date' => SORT_DESC])->one();
     $prev_album = Photo::find()->where(['page_id' => $album->page_id, 'parent_id' => 0])->andWhere(['<', 'id', $album->id])->orderBy(['create_date' => SORT_DESC])->one();
     $page = $album->page;
     if ($page->parent_id == 0) {
         $menu = Page::find()->where(['parent_id' => $page->id])->all();
     } else {
         $menu = Page::find()->where(['parent_id' => $page->parent_id])->all();
     }
     $photos = Photo::find()->where(['parent_id' => $id])->orderBy(['order' => SORT_ASC])->all();
     return $this->render($mobile . 'template/album', ['menu' => $menu, 'album' => $album, 'next_album' => $next_album, 'prev_album' => $prev_album, 'photos' => $photos]);
 }
 public function actionPhoto()
 {
     $model = Photo::findOne(Yii::$app->request->post('pk', ''));
     $ownerId = $model->file->user_id;
     return self::update($model, $ownerId);
 }
 /**
  * Finds the Photo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Photo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Photo::findOne($id)) !== null) {
         if ($model->file->user_id != Yii::$app->user->id) {
             throw new \yii\web\ForbiddenHttpException();
         }
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionPhotoEdit($id)
 {
     $model = Photo::findOne(['id' => $id]);
     $tmpI = $model->src;
     $tmpD = $model->date;
     if ($model->id_author != Yii::$app->user->getId()) {
         return $this->redirect('/');
     }
     if (!$model) {
         throw new \yii\web\HttpException(404);
     }
     $all_categories = Category::getAllTranslatedCategory();
     $all_subcategories = Category::getAllTranslatedSubCategoryByCategory($model->id_level_1);
     $this->redirectOnHomepageIfGuest($user, $isMyProfile);
     $marksNames = Marks::getNamesByIdPhoto($id);
     $date = explode(' ', $model->date);
     $date = explode('-', $date[0]);
     $photoSrc = '/img/photos/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/original_' . $model->src;
     $request = Yii::$app->request;
     if ($request->isAjax && $model->load($request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load($request->post()) && $model->validate()) {
         $model->src = $tmpI;
         if (!Category::isSetCategory($model->id_level_1) || !SubCategoryController::isValidCategory($model->id_level_1, $model->id_level_2) && Category::hasSubCategory($model->id_level_1) || !User::checkAlbum($model->id_album)) {
             return $this->redirect("/");
         }
         Yii::$app->db->createCommand("DELETE FROM marks_photo WHERE id_photo={$id}")->execute();
         if ($request->post('mark')) {
             $marks_arr_new = $request->post('mark');
         } else {
             $marks_arr_new = [];
         }
         if ($model->id_marks) {
             $marks_arr_new[$model->id_marks] = '';
         }
         $marks_arr_new = \app\components\Marks::format($marks_arr_new);
         $marks_tmp = [];
         foreach ($marks_arr_new as $k => $v) {
             $marks_tmp[] = $k;
         }
         //список тих що в базі даних
         $marks_tmp = Marks::getMarksByNames($marks_tmp);
         //масив id тих що в бд
         $marks_tmp_id = [];
         foreach ($marks_tmp as $v) {
             $marks_tmp_id[] = $v['id'];
         }
         //обновилення coununter тих о в бд
         if ($marks_tmp_id) {
             Marks::updateCountMarks($marks_tmp_id);
         }
         //позначаємо ті що є в бд
         foreach ($marks_tmp as $k => $v) {
             $marks_arr_new[$k] = true;
         }
         //список тих що нема в бд
         $marks_tmp = [];
         foreach ($marks_arr_new as $k => $v) {
             if (!$v) {
                 $marks_tmp[] = $k;
             }
         }
         if ($marks_tmp) {
             Marks::insertMarks($marks_tmp);
         }
         $marks_tmp = Marks::getMarksByNames($marks_tmp);
         foreach ($marks_tmp as $v) {
             $marks_tmp_id[] = $v['id'];
         }
         //зберігаємо данні в БД
         $model->date = date('Y-m-d H:i:s');
         $model->id_author = Yii::$app->user->getId();
         $model->views = 1;
         $model->rating_all = 1;
         if (Album::isPrivacyAlbum($model->id_album)) {
             $model->is_closed = 1;
         }
         if (isset($_POST['private'])) {
             $model->erotic = 1;
         } else {
             $model->erotic = 0;
         }
         $model->date = $tmpD;
         $model->save();
         if ($marks_tmp_id) {
             Marks::addMarksToPhoto($marks_tmp_id, $model->id);
         }
         // Якщо це перше фото в альбомі, то встановлюємо його як обкладинку альбому
         if (Photo::thisFirstAlbumPhoto($model->id_album) == 1) {
             Photo::setPhotoToCover($model->id, $model->id_album);
         }
         //формуємо повідомлення про вдале додання нової фотографії
         // @todo перекласти
         \Yii::$app->getSession()->setFlash('notify', 'Фотографія успішно редагована!');
         return $this->redirect("/photo" . $model->id);
     }
     $model->id_marks = '';
     return $this->render('photo_edit', ['model' => $model, 'all_categories' => $all_categories, 'all_subcategories' => $all_subcategories, 'user' => $user, 'isMyProfile' => $isMyProfile, 'marksNames' => $marksNames, 'photoSrc' => $photoSrc]);
 }