public function init() { parent::init(); if ($this->article_id != null) { $this->comments = Comments::find()->where('article_content_id =' . $this->article_id)->orderBy(['id' => SORT_DESC])->all(); } }
/** * Shows user's profile. * @param integer $id * @return \yii\web\Response * @throws \yii\web\NotFoundHttpException */ public function actionShow($id) { $this->enableCsrfValidation = false; $profile = $this->finder->findProfileById($id); if ($profile === null) { throw new NotFoundHttpException(); } $query = Comments::find()->where(['deleted' => Comments::NO_DELETED, 'user_id' => $id])->orderBy('created_at'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $comments = $query->offset($pages->offset)->limit($pages->limit)->all(); $model = new Comments(); $this->performAjaxValidation($model); $user = User::findOne(Yii::$app->user->getId()); if ($model->load(Yii::$app->request->post())) { $model->created_at = time(); $model->user_id = $profile->user->getId(); $model->sender_id = Yii::$app->user->getId(); $model->save(); return $this->refresh(); } else { return $this->render('show', ['profile' => $profile, 'model' => $model, 'user' => $user, 'comments' => $comments, 'pages' => $pages]); } return $this->render('show', ['profile' => $profile]); }
public function searchItemComments($itemId) { $query = Comments::find(); $query->andFilterWhere(['id_item' => $itemId]); $dataProvider = new ActiveDataProvider(['query' => $query]); return $dataProvider; }
public function actionComments() { $comments = Comments::find(); $pagination = new Pagination(['defaultPageSize' => 2, 'totalCount' => $comments->count()]); $comments = $comments->offset($pagination->offset)->limit($pagination->limit)->all(); $cookies = Yii::$app->request->cookies; return $this->render('comments', ['comments' => $comments, 'pagination' => $pagination, 'name' => $cookies->getValue('name'), 'boldCookie' => $cookies->getValue('bold'), 'bold' => Yii::$app->session->get('bold')]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comments::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['CommentID' => $this->CommentID, 'AttachmentTypeID' => $this->AttachmentTypeID, 'UserID' => $this->UserID, 'PostID' => $this->PostID, 'Like' => $this->Like, 'TimeStamp' => $this->TimeStamp]); $query->andFilterWhere(['like', 'CommentContent', $this->CommentContent])->andFilterWhere(['like', 'Attachment', $this->Attachment]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function findReplies($params) { $query = Comments::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query = Comments::find()->andFilterWhere(['api' => $this->api, 'object' => $this->object, 'property' => $this->property]); $query->andFilterWhere(['not', ['reply_to_comment' => null]]); $dataProvider = new ActiveDataProvider(['query' => $query]); return $dataProvider; }
protected function getComments(&$comments, $postId = 0) { $validates = array(); $comments = array(); if ($postId != 0 || $postId == 0 && Auth::check('default')) { if ($postId != 0) { $validates['post_id'] = $postId; } $comments = Comments::find('all', array('conditions' => $validates)); } return count($comments); }
/** * Displays a single Post model. * Also added functionality of adding comments, related to particular Post model. * @param integer $id * @return mixed */ public function actionView($id) { $comments = Comments::find()->where(['post_id' => $id])->all(); $newComment = new Comments(); if ($newComment->load(Yii::$app->request->post()) && $newComment->validate()) { $newComment->created_at = time(); $newComment->post_id = $id; $newComment->save(); return $this->redirect(['view', 'id' => $id]); } else { return $this->render('view', ['model' => $this->findModel($id), 'comments' => $comments, 'newComment' => $newComment]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comments::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'wine_id' => $this->wine_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
public function actionAddComment() { $comment = Yii::$app->request->post(); $model = new Comments(); $model->article_id = $comment['article']; $model->user_id = $comment['user']; $model->comment = $comment['comment']; $model->enable = 1; $model->save(); $user = Comments::find()->with('user')->where(['id' => $model->id])->one(); $array = array('comment' => $model->comment, 'user' => $user->user->name_fml); echo json_encode($array); // print_r($user->user->name_fml); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comments::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'product_id' => $this->product_id, 'moder' => $this->moder]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comments::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'post_id' => $this->post_id, 'active' => $this->active, 'parent_id' => $this->parent_id, 'image_id' => $this->image_id, 'ip' => $this->ip]); $query->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'agent', $this->agent]); return $dataProvider; }
public function actionProduct($id = null) { $product = Products::find()->where(['id' => $id])->one(); $sec = Sections::find(['title'])->where(['id' => $product->section_id])->one(); $others = Products::find()->orderBy(['date' => SORT_DESC])->where(['section_id' => $product->section_id])->andWhere(['not in', 'id', [$id]])->limit(4)->all(); $comments = Comments::find()->where(['product_id' => $id])->orderBy(['id' => SORT_DESC])->all(); $model = new CommentForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $com = new Comments(); $com->product_id = $id; $com->login = Yii::$app->session->get('login'); $com->comment = $model->comment; $com->save(); return $this->redirect(Yii::$app->request->referrer); } return $this->render('product', ['product' => $product, 'section_title' => $sec, 'others' => $others, 'model' => $model, 'comments' => $comments]); }
public function actionView($id, $ajax = false) { $login = new login(); $comment = new Comments(); $getComments = Comments::find()->where(['id_new' => $id]); $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $getComments->count()]); $getComments = $getComments->offset($pagination->offset)->limit($pagination->limit)->all(); if ($comment->load(Yii::$app->request->post()) && $comment->create($id)) { return $this->redirect(['view', 'id' => $id]); } else { if ($ajax == true) { return $this->renderAjax('ajaxComment', ['login' => $login, 'comment' => $comment, 'getComments' => $getComments, 'pagination' => $pagination]); } else { return $this->render('view', ['login' => $login, 'model' => $this->findModel($id), 'comment' => $comment, 'getComments' => $getComments, 'pagination' => $pagination]); } } }
/** * Устанавливает коды стран отправителей исходя из IP адресов * @throws \Exception */ function actionIndex() { if (!extension_loaded('geoip')) { throw new \Exception(Console::ansiFormat('Расширение GeoIP недоступно')); } $comments = Comments::find()->where(['country_code' => null])->all(); $geoip = new GeoIP(); foreach ($comments as $item) { if (!$item->country_code) { $ip = long2ip($item->ip); try { $geoip->setHost($ip); $code = $geoip->getCountryCode(); $item->country_code = $code; $item->save(); echo Console::ansiFormat($item->id . ': ' . $ip . ' - ' . $code, [Console::FG_GREEN]) . PHP_EOL; } catch (\Exception $e) { echo Console::ansiFormat($item->id . ': ' . $ip . ' - ' . 'host не обнаружен!', [Console::FG_RED]) . PHP_EOL; } } } }
/** * Displays a User model. * @param integer $id * @param boolean $followed * @return mixed */ public function actionView($id, $followed = null) { // If I'm trying to view myself then redirect to index $myId = \Yii::$app->user->id; if ($myId == $id) { return $this->redirect(['index']); } $model = $this->findModel($id); $votedUpAPIsArray = array_filter(explode(',', $model->votes_up_apis)); $votedUpAPIsArrayInt = array_map('intval', $votedUpAPIsArray); $votedUpAPIsQuery = Apis::find()->where(['id' => $votedUpAPIsArrayInt]); $votedUpAPIsDataProvider = new ActiveDataProvider(['query' => $votedUpAPIsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedDownAPIsArray = array_filter(explode(',', $model->votes_down_apis)); $votedDownAPIsArrayInt = array_map('intval', $votedDownAPIsArray); $votedDownAPIsQuery = Apis::find()->where(['id' => $votedDownAPIsArrayInt]); $votedDownAPIsDataProvider = new ActiveDataProvider(['query' => $votedDownAPIsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedUpObjectsArray = array_filter(explode(',', $model->votes_up_objects)); $votedUpObjectsArrayInt = array_map('intval', $votedUpObjectsArray); $votedUpObjectsQuery = Objects::find()->where(['id' => $votedUpObjectsArrayInt]); $votedUpObjectsDataProvider = new ActiveDataProvider(['query' => $votedUpObjectsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedDownObjectsArray = array_filter(explode(',', $model->votes_down_objects)); $votedDownObjectsArrayInt = array_map('intval', $votedDownObjectsArray); $votedDownObjectsQuery = Objects::find()->where(['id' => $votedDownObjectsArrayInt]); $votedDownObjectsDataProvider = new ActiveDataProvider(['query' => $votedDownObjectsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedUpCommentsArray = array_filter(explode(',', $model->votes_up_comments)); $votedUpCommentsArrayInt = array_map('intval', $votedUpCommentsArray); $votedUpCommentsQuery = Comments::find()->where(['id' => $votedUpCommentsArrayInt]); $votedUpCommentsDataProvider = new ActiveDataProvider(['query' => $votedUpCommentsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedDownCommentsArray = array_filter(explode(',', $model->votes_down_comments)); $votedDownCommentsArrayInt = array_map('intval', $votedDownCommentsArray); $votedDownCommentsQuery = Comments::find()->where(['id' => $votedDownCommentsArrayInt]); $votedDownCommentsDataProvider = new ActiveDataProvider(['query' => $votedDownCommentsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $followedUsers = $model->getFollowees(); $followedUsersDataProvider = new ActiveDataProvider(['query' => $followedUsers, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $followedApis = $model->getFollowingApis(); $followedApisDataProvider = new ActiveDataProvider(['query' => $followedApis, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $followUserUser = FollowUserUser::findOne(['follower' => $myId, 'followee' => $id]); $doIFollow = false; if ($followUserUser != null) { $doIFollow = true; $followUserUser->last_seen = date("Y-m-d H:i:s"); $followUserUser->changed_photo = false; $followUserUser->changed_linkedin = false; $followUserUser->changed_github = false; $followUserUser->created_api = null; $followUserUser->changed_upvotes_apis = null; $followUserUser->changed_downvotes_apis = null; $followUserUser->save(); } $followers = FollowUserUser::find(['followee' => $id])->count(); $this->view->params['followed'] = $followed; return $this->render('view', ['model' => $model, 'votedUpAPIsDataProvider' => $votedUpAPIsDataProvider, 'votedDownAPIsDataProvider' => $votedDownAPIsDataProvider, 'votedUpObjectsDataProvider' => $votedUpObjectsDataProvider, 'votedDownObjectsDataProvider' => $votedDownObjectsDataProvider, 'votedUpCommentsDataProvider' => $votedUpCommentsDataProvider, 'votedDownCommentsDataProvider' => $votedDownCommentsDataProvider, 'followedUsersDataProvider' => $followedUsersDataProvider, 'followedApisDataProvider' => $followedApisDataProvider, 'doIFollow' => $doIFollow, 'followers' => $followers]); }
/** * Lists all Comments models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Comments::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $comment = Comments::find($id); $comment->delete(); return response()->json($comment); }
<?php } } ?> <h3><?php echo $article['title']; ?> </h3> <ul> <li>Author by <?php echo $userName[$i]['name_fml']; ?> /</li> <li>Stat /</li> <li><?php echo Comments::find()->where(['article_id' => $article['id']])->count('comment'); ?> comments /</li> <li><?php $months = array('Янваль', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'); $sub = substr($article['create_at'], 0, 10); $replace = str_replace('-', ' ', $sub); $subWeek = substr($replace, 5, 2); echo substr($article['create_at'], 0, 4) . ' '; echo $months[$subWeek - 1] . ' '; echo substr($sub, 8, 8); ?> </li> <br><br> </ul> <br><br>
public function actionCatalog($item = '') { @session_start(); $_SESSION['current_str'] = 'catalog'; $url = parse_url(Yii::$app->request->url); $url = explode('/', $url['path']); if (strrpos($item, '/')) { $item = trim(substr($item, strrpos($item, '/') + 1, strlen($item) - strrpos($item, '/'))); } else { $item = trim($item); } $result = ModArendaTree::findOne(['url' => $item]); //���� �� ������� ���������, �������������� ��� �����, ����� ������ ������ if (!$result) { $kroshka = []; foreach ($url as $key => $value) { if (!empty($value) && $value !== 'catalog') { if ($key != count($url) - 1) { $cat = ModArendaTree::findOne(['url' => $value]); if ($cat) { $kroshka['cats'][] = $cat; } } else { $id = trim(substr($value, strrpos($value, '-') + 1, strlen($value) - strrpos($value, '-'))); $tovar = Products::findOne(['id' => $id]); $kroshka['tovars'][] = $tovar; } } } if (strrpos($item, '-')) { $id = trim(substr($item, strrpos($item, '-') + 1, strlen($item) - strrpos($item, '-'))); $tovar = Products::findOne(['id' => $id]); $characteristics = CharacteristicsProducts::find()->select(['characteristics_products.*', 'characteristics.name AS characteristic_name'])->where(['product_id' => $id])->leftJoin('characteristics', 'characteristics_products.character_id=characteristics.id')->asArray()->all(); $comments = Comments::find()->where(['product_id' => $id])->andWhere(['moder' => 1])->asArray()->all(); $pohozhie = Products::find()->where(['cat_id' => $tovar->cat_id])->andWhere('id<>' . $tovar->id)->orderBy(['id' => SORT_DESC])->asArray()->all(); return $this->render('tovar', ['data' => $tovar, 'characteristics' => $characteristics, 'kroshka' => $kroshka, 'comments' => $comments, 'pohozhie' => $pohozhie]); } else { return $this->render('main_cats'); } } $kroshka = []; foreach ($url as $key => $value) { if (!empty($value) && $value !== 'catalog') { $cat = ModArendaTree::findOne(['url' => $value]); if ($cat) { $kroshka['cats'][] = $cat; } } } $result_parent = ModArendaTree::find()->select(['mod_arenda_tree.*', 'images_for_cats.url AS image'])->leftJoin('images_for_cats', 'images_for_cats.cat_id=mod_arenda_tree.id')->groupBy('mod_arenda_tree.id')->where(['parent_id' => $result->id])->asArray()->all(); if ($result_parent) { return $this->render('cats', ['data' => $result_parent, 'kroshka' => $kroshka]); } else { $cat = ModArendaTree::findOne(['url' => $item]); $char_for_cats = CharacteristicsForCats::find()->select(['characteristics_for_cats.*', 'characteristics.name AS char_name'])->where(['cat_id' => $cat->id])->leftJoin('characteristics', 'characteristics.id=characteristics_for_cats.character_id')->orderBy(['character_id' => SORT_ASC])->asArray()->all(); if (empty($char_for_cats)) { while ($cat->parent_id != 0) { $char_for_cats = CharacteristicsForCats::find()->select(['characteristics_for_cats.*', 'characteristics.name AS char_name'])->where(['cat_id' => $cat->parent_id])->leftJoin('characteristics', 'characteristics.id=characteristics_for_cats.character_id')->orderBy(['character_id' => SORT_ASC])->asArray()->all(); $cat = ModArendaTree::findOne(['id' => $cat->parent_id]); } } if ($char_for_cats) { //тут будет код если все охуенно } if (Yii::$app->request->post()) { $post = Yii::$app->request->post(); unset($post['_csrf']); $q = ''; foreach ($post as $key => $value) { if ($value == 'all') { continue; } if (is_array($value)) { if (empty($value[0]) || empty($value[1])) { continue; } $chid = substr($key, 3); // возвращает "bcdef" $q .= 'INNER JOIN characteristics_products AS ' . $key . ' ON (' . $key . '.product_id=P.id AND (' . $key . '.character_id=' . $chid . ' AND (' . $key . '.value>=' . $value[0] . ' AND ' . $key . '.value<=' . $value[1] . ' )))'; } else { $chid = substr($key, 3); // возвращает "bcdef" $q .= 'INNER JOIN characteristics_products AS ' . $key . ' ON (' . $key . '.product_id=P.id AND (' . $key . '.character_id=' . $chid . ' AND ' . $key . '.value="' . $value . '"))'; } } $tovars = Yii::$app->db->createCommand(' SELECT P.* FROM products AS P ' . $q . ' WHERE cat_id=' . $result->id . ' ')->queryAll(); } else { $tovars = Yii::$app->db->createCommand(' SELECT P.* FROM products AS P WHERE cat_id=' . $result->id . ' ')->queryAll(); } foreach ($tovars as $key => $value) { $chars = CharacteristicsProducts::find()->where(['product_id' => $value['id']])->orderBy(['character_id' => SORT_ASC])->asArray()->all(); $tovars[$key]['chars'] = $chars; } //ЗАПРО ДЛЯ ФИЛЬТРА $tovars1 = Yii::$app->db->createCommand(' SELECT P.* FROM products AS P WHERE cat_id=' . $result->id . ' ')->queryAll(); foreach ($tovars1 as $key => $value) { $chars = CharacteristicsProducts::find()->where(['product_id' => $value['id']])->orderBy(['character_id' => SORT_ASC])->asArray()->all(); $tovars1[$key]['chars'] = $chars; } //ЗАПРО ДЛЯ ФИЛЬТРА //делаем проверку на типы фильтров $CHARACTERISTICS = []; foreach ($tovars1 as $key => $value) { foreach ($value['chars'] as $key1 => $value1) { if (isset($CHARACTERISTICS[$key1])) { if (!in_array(strtolower($value1['value']), $CHARACTERISTICS[$key1]) && $value1['value'] != 'none') { $CHARACTERISTICS[$key1][] = mb_strtolower($value1['value']); } } else { if ($value1['value'] != 'none') { $CHARACTERISTICS[$key1][] = is_numeric($value1['value']) ? $value1['value'] : mb_strtolower($value1['value']); } } if (!isset($CHARACTER[$key1])) { $CHARACTER[$key1] = 'number'; } if (!is_numeric($value1['value'])) { $CHARACTER[$key1] = 'string'; } } } foreach ($CHARACTERISTICS as $key3 => $value3) { $CHARACTERISTICS[$key3]['type'] = $CHARACTER[$key3]; } foreach ($char_for_cats as $key3 => $value3) { if (!isset($CHARACTERISTICS[$key3])) { unset($char_for_cats[$key3]); } else { $char_for_cats[$key3]['chars'] = $CHARACTERISTICS[$key3]; } } return $this->render('tovars', ['data' => $tovars, 'kroshka' => $kroshka, 'chars' => $char_for_cats]); } }