public function getProduct($id) { $result['comments'] = $this->comment->getCommentsByProduct($id); $result['categories'] = $this->category->getCategories(); $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin')); $result['isAdmin'] = Auth::isUserInRole(array('admin')); if ($result['isEditor']) { $result['product'] = $this->product->getProductWitnUnavailable($id); } else { $result['product'] = $this->product->getProduct($id); } $all_promotion = $this->promotion->getHighestActivePromotion(); $productPromotion = max($all_promotion['discount'], $result['product']['discount'], $result['product']['category_discount']); if (is_numeric($productPromotion)) { $result['product']['promotion_price'] = $result['product']['price'] - $result['product']['price'] * ($productPromotion / 100); } $result['title'] = 'Shop'; $result['currentCategory'] = $result['product']['category_id']; View::make('product', $result); if (Auth::isAuth()) { View::appendTemplateToLayout('topBar', 'top_bar.user'); } else { View::appendTemplateToLayout('topBar', 'top_bar.guest'); } View::appendTemplateToLayout('header', 'includes.header')->appendTemplateToLayout('footer', 'includes.footer')->appendTemplateToLayout('catMenu', 'side_bar.category_menu')->render(); }
public function delete($id) { if (Auth::isUserInRole(array('admin')) || $this->comment->getComment($id)['user_id'] == Auth::getUserId()) { if ($this->comment->delete($id) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('Done'); Redirect::back(); } Redirect::back(); }
public function createAction() { $resp = new Response(); $request = $this->app->request; $post_id = $request->getPostParam('post_id'); $content = $request->getPostParam('content'); if ($post_id && $content) { $comment = new Comment(array('post_id' => $post_id, 'content' => $content, 'user_id' => $this->app->user->getId())); $comment->save(); } $resp->redirectBack(); return $resp; }
public function comment($section, $newsId) { $comment = Input::get('comment'); $user = User::get(); Comment::Insert(array('newsId' => $newsId, 'userId' => $user->id, 'comment' => $comment)); Response::redirect('/' . $section . '/' . $newsId); }
public function doLoadReplies() { $result = \models\Comment::getReplies(CW::$app->request->get('replyTo'), CW::$app->request->get('last')); CW::$app->db->close(); if (null === $result) { throw new \components\exceptions\BadRequestException(); } return json_encode($result); }
public function show($id) { $flash = $this->app->view()->getData('flash'); $infoComment = ''; $infoCart = ''; if (isset($flash['infoComment'])) { $infoComment = $flash['infoComment']; } if (isset($flash['infoCart'])) { $infoCart = $flash['infoCart']; } parent::routes()->render('show_product.twig', array('app_base' => $this->appBase, 'bugs1' => true, 'carts' => Cart::countCart(), 'comments' => Comment::showComment($id), 'info_comment' => $infoComment, 'info_cart' => $infoCart, 'is_customer' => isset($_SESSION['emailCustomer']) ? sizeof($_SESSION['emailCustomer']) : 0, 'is_order' => Order::countOrder(), 'results' => Product::showProduct($id), 'related_product' => Product::showRelatedProduct(Product::showProductCategory($id), $id), 'title' => Product::showProductName($id))); }
/** @test */ public function it_deletes_all_specified_relations() { $user = User::create([]); $author = Author::create(['user_id' => $user->id]); $post = Post::create(['author_id' => $author->id]); $comment = Comment::create(['post_id' => $post->id]); $user = $user->fresh(); $this->assertEquals($user->author()->count(), 1, 'author'); $this->assertEquals($user->author()->first()->posts()->count(), 1, 'posts'); $this->assertEquals($user->author()->first()->posts()->first()->comments()->count(), 1, 'comments'); $user->delete(); $this->assertEquals(Post::where('author_id', 1)->count(), 0, 'post 0'); $this->assertEquals(Comment::where('post_id', 1)->count(), 0, 'comment 0'); $this->assertEquals(Author::where('user_id', 1)->count(), 0, 'user 0'); }
public function update() { $this->table = $this->fw->get('PARAMS.table'); $this->model = \models\Comment::getInstance($this->table); if (is_null($this->model->getTable())) { $this->fw->error(404); } else { $this->setAJAXLayout(); if ($this->model->update(array('id' => $this->fw->get('POST.id'), $this->fw->get('POST.field') => $this->fw->get('POST.value')))) { if ($this->fw->get('POST.field') != 'moderation') { \helpers\Msg::success('saved'); } } else { \helpers\Msg::error('error'); $this->fw->error(406); } } }
protected function commentValidateOne() { setContentType("json"); $comment = new Comment(); $given = array_keys($_POST); $response["error"] = null; if (count($given) == 1) { if ($given[0] == "text") { $comment->setText($_POST["text"]); } if (!$comment->validate()) { foreach ($comment->getValidationFailures() as $failure) { if ($given[0] == $failure->getPropertyPath()) { $response["error"] = array("name" => $failure->getPropertyPath(), "message" => $failure->getMessage()); } } } $this->viewString(json_encode($response)); } }
/** * Exclude object from result * * @param ChildComment $comment Object to remove from the list of results * * @return $this|ChildCommentQuery The current query, for fluid interface */ public function prune($comment = null) { if ($comment) { $this->addUsingAlias(CommentTableMap::COL_ID, $comment->getId(), Criteria::NOT_EQUAL); } return $this; }
public function nr($id = null) { $is_loged = LoginVal::isLogged(); $http = new Http(); $this->product_m = new \models\Product($id[0]); $name = $this->product_m->getName(); if (empty($name)) { Location::To(URL . 'error'); } $available = $this->product_m->getQuantity(); $promotions = new Promotions($id[0]); $pro = $promotions->getPromotion(); if (!empty($pro)) { $old_price = $this->product_m->getOldPrice($pro->getPercent()); $discount = $pro->getPercent() * 100; } $additionals = $this->product_m->getAdditionals(); $a_images = $this->product_m->getAdditionalImages(); $comments_m = new Comments($id[0]); $pagination = new Pagination(2, $comments_m->getNumberOfComments()); $avg_rating = $comments_m->getAverageRating(); $comments = $comments_m->getComments(2, $pagination->page($id[1])); $next = $pagination->next(); $prev = $pagination->prev(); $num_pages = $pagination->getPages(); $selected = $pagination->getSelected(); $comment = $http->post('comment'); if (!empty($comment) && $is_loged && $http->isActive('send') && !empty($this->product_m)) { $comment = new Comment(); $comment->setComment($http->post('comment')); $comment->setDate(); $comment->setProductId($this->product_m->getId()); $comment->setUserId(Register::get('id')); $comment->setRate($http->post('star')); $comment->writeData(); Location::To(URL . 'product/nr/' . $id[0]); } $comment_tab = array(); if (!empty($comments)) { foreach ($comments as $key => $comment) { if (!empty($comment)) { $comment_tab[$key]['comment'] = $comment->getComment(); $comment_tab[$key]['date'] = $comment->getDate(); $comment_tab[$key]['rate'] = $comment->getRate(); $user = new \models\Users($comment->getUserId()); $login = $user->getLogin(); $comment_tab[$key]['login'] = empty($login) ? 'anonimowy' : $login; } } } $this->render('product', array('categories' => $this->categories, 'd_product' => $this->d_product, 'category' => $this->product_m->getCategory(), 'name' => $this->product_m->getName(), 'description' => $this->product_m->getDescription(), 'image' => $this->product_m->getImage(), 'quantity' => $this->product_m->getQuantity(), 'price' => $this->product_m->getPrice(), 'additionals' => $additionals, 'images' => $a_images, 'comments' => $comment_tab, 'product_nr' => $id[0], 'next' => $next, 'prev' => $prev, 'num_pages' => $num_pages, 'selected' => $selected, 'is_loged' => $is_loged, 'avg_rating' => $avg_rating, 'discount' => $discount, 'old_price' => $old_price, 'available' => $available)); }
public function delete($id) { Comment::deleteComment($id); parent::redirectTo('indexComment'); }
protected function comment($id) { //TODO: check rights $note = NoteQuery::create()->findPK($id); $comment = new Comment(); $comment->setUser($this->params['user']); $comment->setNote($note); $comment->setText($_POST['msg']); $comment->save(); $this->params['comments'] = $note->getComments(); $this->renderType('js.phtml'); }
/** * Возвращает массив с комментариями для записи с заданным id * @param int $id * @return array */ public function getComments($id) { $model = \models\Comment::getInstance($this->table); return $model->getList($id); }
/** * Filter the query by a related \Models\Comment object * * @param \Models\Comment|ObjectCollection $comment the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildUserQuery The current query, for fluid interface */ public function filterByComment($comment, $comparison = null) { if ($comment instanceof \Models\Comment) { return $this->addUsingAlias(UserTableMap::COL_ID, $comment->getUserId(), $comparison); } elseif ($comment instanceof ObjectCollection) { return $this->useCommentQuery()->filterByPrimaryKeys($comment->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByComment() only accepts arguments of type \\Models\\Comment or Collection'); } }
/** * @param ChildComment $comment The ChildComment object to add. */ protected function doAddComment(ChildComment $comment) { $this->collComments[] = $comment; $comment->setNote($this); }
/** * Return all comments * * @see http://codex.wordpress.org/Function_Reference/get_comments */ public function getComments() { $args_comments = ['post_id' => $this->ID, 'orderby' => 'comment_date_gmt', 'status' => static::STATUS_APPROVE]; $comments = []; foreach (get_comments($args_comments, $this->ID) as $c) { $comments[] = Comment::find($c->comment_ID); } return $comments; }
public function comment($name) { $id = explode('-', $name); $id = $id[0]; if (!$this->isLogged()) { $this->addPopup('danger', 'Pro přidání komentáře musíte být přihlášeni.'); redirectTo('/clanek/' . $id); } $comment = new Comment(); $comment->setIdUser($_SESSION["user"]->getId()); $comment->setIdArticle($id); $comment->setContent($_POST["comment_text"]); $comment->save(); $this->addPopup('success', 'Váš komentář byl úspěšně přidán.'); redirectTo('/clanek/' . $id); }
public function addComment(Comment $comment) { $result = $this->db->prepare("\n\t\t\tINSERT INTO comment(comment_date, content, user_id, product_id)\n\t\t\tVALUES(?, ?, ?, ?)\n\t\t"); $result->execute([$comment->getCommentDate(), $comment->getContent(), $comment->getUserId(), $comment->getProductId()]); }