public function actionDeleteComment() { $contentType = Yii::$app->request->post('contentType'); $contentId = Yii::$app->request->post('contentId'); AdminCommon::deleteComment($contentType, $contentId); echo json_encode(['status' => 1]); }
public static function getArchivePhoto($type, $filter, $sort, $limit, $offset, $count = false) { ///////////////////////////////////SELECT////////////////////////////////////// if ($count) { $query = (new Query())->select('COUNT(1)'); } else { $query = (new Query())->select(['p.id AS photo_id', 'p.src AS photo_src', 'p.name AS photo_name', 'u.id AS user_id', 'u.name AS user_name', 'l1.name AS photo_category', 'l2.name AS photo_subcategory', 'p.date AS photo_date']); if ($type == "photo_day") { $query->addSelect('bp.date AS glory'); } elseif ($type == "photo_week") { $query->addSelect(['bp.week_num AS week_num', 'bp.year AS year']); } elseif ($type == "photo_month") { $query->addSelect(['bp.month_num AS month_num', 'bp.year AS year']); } elseif ($type == "photo_year") { $query->addSelect('bp.year_num AS year'); } } ///////////////////////////////////FROM////////////////////////////////////// $query = self::getFromToQuery($type, $query); ///////////////////////////////////JOIN////////////////////////////////////// $query->innerJoin('photos p', 'bp.id_photo=p.id')->innerJoin('user u', 'p.id_author=u.id')->innerJoin('level_1 l1', 'p.id_level_1=l1.id')->leftJoin('level_2 l2', 'p.id_level_2=l2.id'); ///////////////////////////////////WHERE////////////////////////////////////// if ($filter) { $query->filterWhere(['=', 'p.id', $filter['photo_id']])->AndFilterWhere(['like', 'p.name', $filter['photo_name']])->AndFilterWhere(['like', 'u.name', $filter['user_name']])->AndFilterWhere(['like', 'l1.name', $filter['photo_category']])->AndFilterWhere(['like', 'l2.name', $filter['photo_subcategory']])->AndFilterWhere(['>=', 'p.date', $filter['date_min']])->AndFilterWhere(['<=', 'p.date', $filter['date_max']]); $query = self::getFilterGlory($filter['glory_min'], $filter['glory_max'], $type, $query); } ///////////////////////////////////LIMIT, OFFSET////////////////////////////////////// if (!$count) { if ($limit) { $query->limit($limit)->offset($offset); } ///////////////////////////////////ORDER BY////////////////////////////////////// if ($sort) { if ($sort == 'glory' || $sort == '-glory') { $sort = self::getSortGlory($sort, $type); $query->orderBy($sort); } else { $query = AdminCommon::getSortQuery($query, $sort); } } $photos = $query->all(); foreach ($photos as &$photo) { $photo['photo_src'] = '/img/photos/' . str_replace('-', '/', explode(' ', $photo['photo_date'])[0]) . '/s_' . $photo['photo_src']; $photo['photo_date'] = explode(" ", $photo['photo_date'])[0]; if ($photo['photo_subcategory'] == "") { $photo['photo_subcategory'] = "Немає підкатегорії"; } $photo['glory'] = self::generatePhotoGlory($photo, $type); } return $photos; } else { return $query->scalar(); } }
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 static function generateSortTh($th_array, $sort) { $tr = "<tr>"; foreach ($th_array as $th) { if ($th[0] == false) { $tr .= "<th class='text-center'>" . $th[1] . "</th>"; } else { $sort_href = AdminCommon::getSortHref($th[0], $sort); $arrow_sort = AdminCommon::getArrowToSort($th[0], $sort); $tr .= "<th class='text-center'><a href='{$sort_href}'>{$th['1']} {$arrow_sort}</a></th>"; } } $tr .= "</tr>"; return $tr; }
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 static function getPhotos($id) { $photos = (new Query())->select(['cp.id as photo_id', 'cp.name as photo_name', 'u.id as user_id', 'u.name as user_name', 'cp.views as photo_views', 'cp.likes as photo_likes', 'cp.date as photo_date', 'cp.src as photo_src', 'cp.comments as photo_comments'])->from('club_photo cp')->innerJoin('user u', 'u.id=cp.id_author')->where(['cp.club_id' => $id])->indexBy('photo_id')->all(); $ids = []; foreach ($photos as $k => &$photo) { $ids[] = $k; $date = explode(' ', $photo['photo_date']); $date = explode('-', $date[0]); $photo['photo_src'] = '/img/club/photos/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/l_' . $photo['photo_src']; $photo['comment'] = []; } $comments = AdminCommon::getComments('club', $ids, 0, 5); foreach ($comments as $comment) { $photos[$comment['ct_id']]['comments'][] = $comment; } return $photos; }
public static function getArticles($filter, $sort, $offset, $limit) { $query = (new Query())->select(' a.id AS article_id, a.name AS article_name, a.date AS article_date, a.thumbnail AS article_cover, a.rating_all AS article_rating, a.id AS article_id, u.id AS user_id, u.name AS user_name, l1.name AS category_name, ')->from('articles a')->innerJoin('user u', 'a.id_author=u.id')->innerJoin('level_1 l1', 'a.id_level_1=l1.id'); if ($filter) { self::getFilterArticles($filter, $query); } if ($sort) { AdminCommon::getSortQuery($query, $sort); } $articles = $query->limit($limit)->offset($offset)->all(); return $articles; }
<aside class="main-sidebar"> <section class="sidebar"> <!-- Sidebar user panel --> <?php $count_messages = \app\models\AdminCommon::getCountFeedback(); if ($count_messages) { $template = '<a href="{url}" > <i class="fa fa-envelope" style="margin-right: 4px;"></i>{label} <small class="label pull-right bg-yellow">' . $count_messages . '</small> </a>'; } else { $template = '<a href="{url}" ><i class="fa fa-envelope" style="margin-right: 4px;"></i>{label}</a>'; } ?> <?php echo dmstr\widgets\Menu::widget(['options' => ['class' => 'sidebar-menu'], 'items' => [['label' => 'ГОЛОВНЕ МЕНЮ', 'options' => ['class' => 'header']], ['label' => 'Повідомлення', 'icon' => 'fa fa-envelope', 'url' => ['/admin/messages'], 'small' => 12, 'template' => $template], ['label' => 'Статті', 'icon' => 'fa fa-edit', 'url' => ['/admin/blog?page=1']], ['label' => 'Найкращі фотографії', 'icon' => 'fa fa-bar-chart', 'url' => ['/admin/best-photo?page=1']], ['label' => 'Клуби', 'icon' => 'fa fa-group', 'url' => ['/admin/club?page=1']], ['label' => 'Користувачі', 'icon' => 'fa fa-user', 'url' => ['/admin/user?page=1']], ['label' => 'Фото', 'icon' => 'fa fa-photo', 'url' => ['/admin/photo?page=1']]]]); ?> </section> </aside>
public function actionUserSendMessage() { $post = Yii::$app->request->post(); AdminCommon::sendMessage($post['user_id'], $post['message']); }
>Фото місяця </option> <option value="photo_year" <?php echo $type == 'photo_year' ? 'selected' : ""; ?> >Фото року </option> </select> </div> </div> <div class="box-body table-responsive with-border"> <table class="table table-hover table-filter"> <tbody> <!-- Заголовок таблиці --> <?php echo \app\models\AdminCommon::generateSortTh($th_array, $sort); ?> <!--Пошук для таблиці --> <tr class="filters"> <?php $form = \yii\widgets\ActiveForm::begin(['action' => ['/admin/best-photo/' . $type . '?page=1'], 'method' => 'get', 'fieldConfig' => ['template' => '{input}{error}']]); ?> <td><?php echo $form->field($model, 'photo_id')->textInput(['class' => '']); ?> </td> <td></td> <td><?php echo $form->field($model, 'photo_name')->textInput(['class' => '']); ?> </td>