Example #1
0
 public function actionShow($id)
 {
     $club = AdminClub::getInfo($id);
     $categories = Category::getAllCategory();
     $countDiscussions = AdminClub::getCountDiscussions($id);
     return $this->render('show', ['club' => $club, 'categories' => $categories, 'countDiscussions' => $countDiscussions]);
 }
Example #2
0
 public function actionArticle_edit($article_id)
 {
     $model = Blog::findOne($article_id);
     $categories = Category::getAllCategory();
     $marks = AdminBlog::getArticlesMarks($article_id);
     $comments = AdminCommon::getComments('blog', $article_id, 0, 5);
     $content = ['content_type' => 'blog', 'content_id' => $article_id];
     if (Yii::$app->request->post() && $model->validate()) {
         $model['id_level_1'] = $_POST['Blog']['id_level_1'];
         $model->save();
         $this->redirect('/admin/blog?page=1');
     }
     return $this->render('article_edit', ['model' => $model, 'categories' => $categories, 'marks' => $marks, 'comments' => $comments, 'content' => $content]);
 }
 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]);
 }
Example #4
0
 /**
  * виводить список всіх клубів, також фільтрує за категорією
  */
 public function actionList($filter)
 {
     $request = Yii::$app->request;
     $contentId = $request->post('contentId');
     if ($filter == 'all') {
         $clubs = Club::getAllClubs(20, $contentId);
     } else {
         $clubs = Club::getCategoryClubs(20, $filter, $contentId);
     }
     if ($request->isAjax) {
         echo json_encode(['content' => $clubs]);
         return;
     }
     $categories = Category::getAllCategory();
     return $this->render('list', ['clubs' => $clubs, 'categories' => $categories]);
 }
Example #5
0
 public function actionPost($slug)
 {
     $model = new CommentsBlog();
     //витягнення статті
     $post = Blog::getPostByUrl($slug);
     //якщо немає 404
     if (!$post['article_id']) {
         throw new \yii\web\HttpException(404);
     }
     //якщо стаття закрита адміністратором, то редірект на всі статті
     if (!$post['article_id'] || time() < $post['time_closed']) {
         return $this->redirect('/blog/all');
     }
     View::viewArticle($post['article_id'], $post['views']);
     //перевірка чи користувач лайкнув
     if (!Yii::$app->user->isGuest) {
         $post['islike'] = Blog::isLikeArticle($post['article_id'], Yii::$app->user->getId());
     } else {
         $post['islike'] = false;
     }
     $i_blocked = User::checkIfIInBlaclList($post['id_author']);
     $user_id = $post['user_id'];
     $marks = Marks::getArticleMarks(20);
     $categories = Category::getAllCategory();
     //інші статті автора
     $other_articles = Blog::getOtherArticle($user_id, 0, 2, $post['article_id']);
     foreach ($other_articles as &$article) {
         $article['text'] = substr($article['text'], 0, 350) . '...';
     }
     ////        КОМЕНТАРІ         ////
     //витягуємо всі коменті до статті
     $from = "comments_blog";
     //отримання всіх коментарів до фотографії
     $comments = Comments::getCommentsNew($post['article_id'], $from);
     $request = Yii::$app->request;
     if ($request->isAjax && $model->load($request->post()) && $model->validate()) {
         if (!Yii::$app->user->isGuest) {
             $author_id = Blog::getIdAuthorArticle($model['id_article']);
             if (!User::checkIfIInBlaclList($author_id)) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 $model->date_time = date('Y-m-d H:i:s');
                 $model->id_user = Yii::$app->user->getId();
                 $model->text = htmlspecialchars($model->text);
                 //визначення чи це простий комент чи це ре-комент
                 $text = explode(":", $model->text);
                 //перевіряємо чи введено коректне ім'я користувача якому дана відповідь
                 $true_name = 0;
                 foreach ($comment as $key) {
                     if ($key['name'] == $text[0]) {
                         $true_name = 1;
                     }
                 }
                 if (!$true_name) {
                     $model->answer_id = 0;
                 }
                 if ($model->save()) {
                     Blog::updateComments($post['article_id'], 1);
                     $latest_id = $model->id;
                     $user = User::find()->select('avatar, name')->where(["id" => $model->id_user])->one();
                     echo json_encode(['text' => $model->text, 'id_user' => $model->id_user, 'name' => $user['name'], 'avatar' => $user['avatar'], 'sex' => $user['sex'], 'id_comment' => $latest_id]);
                     die;
                 } else {
                     echo 0;
                 }
             } else {
                 return json_encode('error');
             }
         }
         ////        КОМЕНТАРІ         ////
     } else {
         return $this->render('post', ['post' => $post, 'other_articles' => $other_articles, 'marks' => $marks, 'categories' => $categories, 'user_id' => $user_id, 'model' => $model, 'comments' => $comments, 'i_blocked' => $i_blocked]);
     }
 }
Example #6
0
 public function actionAlbum_edit($album_id)
 {
     $this->redirectOnHomepageIfGuest($user, $isMyProfile);
     $request = Yii::$app->request;
     $model = Album::findOne($album_id);
     if ($model->id_user != Yii::$app->user->getId()) {
         return $this->redirect('/id' . Yii::$app->user->getId() . '/albums');
     }
     $images = Photo::getAlbumPhotos($album_id, 20, Yii::$app->request->post('contentId'));
     $has_subalbum = Album::hasSubalbum($album_id);
     $model->scenario = 'album_add_edit';
     $level_1 = Category::getAllCategory();
     $level_2 = Category::getAllSubcategory();
     if ($request->isAjax && $request->post('contentId')) {
         foreach ($images as &$image) {
             $image['photo_list_subcat'] = [];
             foreach ($level_2 as $l) {
                 if ($image['photo_id_level_1'] == $l['subcategory_id_level_1']) {
                     $image['photo_list_subcat'][] = $l;
                 }
             }
         }
         echo json_encode(['content' => $images, 'coverId' => $model->cover_id]);
         return;
     }
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         if ($_POST['Album']['parent_id'] == "") {
             $_POST['Album']['parent_id'] = 0;
             $model->parent_id = $_POST['Album']['parent_id'];
         }
         // Якшо прийшов батьківський альбом в альбом, який і так є батьківським
         if ($_POST['Album']['parent_id'] != 0 && $has_subalbum) {
             $this->redirect('/albums');
         }
         // Приховуємо фотографії з альбома, якщо користувач міняє налаштування приватності
         if (($model->OldAttributes['friends_group_id'] != $model->friends_group_id || $model->OldAttributes['password'] != $model->password) && ($model->friends_group_id != 0 || $model->password != "")) {
             Album::hidePrivacyPhoto($model->id);
         }
         // Якщо користувач знімає налаштування приватності, то робимо всі фото в альбомі відкриті
         if (($model->OldAttributes['friends_group_id'] != 0 || $model->OldAttributes['password'] != "") && ($model->friends_group_id == 0 && $model->password == "")) {
             Album::showPrivacyPhoto($model->id);
         }
         // Якщо міняємо налаштування приватності батьківського альбома, то змінюємо і в дочірніх
         if ($has_subalbum && ($model->oldAttributes['password'] != $model['password'] || $model['friends_group_id'] != $model->oldAttributes['friends_group_id'])) {
             Album::setSubalbumPrivacy($album_id, $model['password'], $model['friends_group_id']);
         }
         // Зберігаємо доданий альбом
         if ($_POST['Album']['parent_id'] != 0 && Album::checkParentAlbum($_POST['Album']['parent_id'])) {
             $model->parent_id = $_POST['Album']['parent_id'];
             Album::childAlbumSetParentPrivacy($model);
         }
         $model->save();
         // @todo перекласти
         \Yii::$app->session->setFlash('notify', 'Альбом успішно редагований!');
         $this->redirect('/id' . \Yii::$app->user->getId() . '/albums');
     }
     $thumbnail = Album::getThumbnail($model->cover_id);
     return $this->render('album_edit', ['model' => $model, 'album_id' => $album_id, 'images' => $images, 'level_1' => $level_1, 'level_2' => $level_2, 'cover_id' => $model->cover_id, 'user' => $user, 'isMyProfile' => $isMyProfile, 'has_subalbum' => $has_subalbum, 'thumbnail' => $thumbnail]);
 }