/** * 获取该模型的所有评论 * 这个其实也可以变成一个通用的方法落实在myModel中的 * @return null|\Phalcon\Mvc\Model\ResultsetInterface */ public function comments() { /** @var myModel $this */ return $this->make('comments', function () { return Comments::query()->leftJoin('Users', 'Users.id = Comments.user_id')->where('Comments.commentable_id = :id:')->andWhere('Comments.commentable_type = :type:')->bind(['id' => $this->id, 'type' => get_class($this)])->orderBy('Comments.updated_at Desc')->columns(['Comments.*', 'Users.*'])->execute(); }); }
public function comments() { if (null == $this->comments) { $this->comments = Comments::query()->where('user_id = :user:'******'user' => $this->id])->orderBy('created_at DESC')->execute(); } return $this->comments; }
public function comments() { if ($this->comments == null) { $this->comments = Comments::query()->where('commentable_id = :tag_id:')->andWhere('commentable_type = :type:')->bind(['tag_id' => $this->id, 'type' => get_class($this)])->orderBy('updated_at Desc')->execute(); } return $this->comments; }
/** * Index action */ public function indexAction() { $numberPage = $this->request->getQuery("page", "int", 1); $comments = Comments::query()->order("submitted DESC")->execute(); $paginator = new Paginator(array("data" => $comments, "limit" => 10, "page" => $numberPage)); $this->view->page = $paginator->getPaginate(); }
public function getEpisodesComments() { if ([] == $this->EpisodesComments) { $episodes = $this->getEpisodes(); $ids = []; foreach ($episodes as $episode) { $ids[] = $episode->id; } if (count($ids)) { $this->EpisodesComments = Comments::query()->leftJoin('Episodes', 'Episodes.id = Comments.commentable_id')->where('Comments.commentable_type = :type:', ['type' => 'Episodes'])->inWhere('Comments.commentable_id', $ids)->columns(['Comments.*', 'Episodes.*'])->orderBy('Comments.updated_at DESC')->execute(); } } return $this->EpisodesComments; }
$arr = $torrent->getFiles($params[1]); httpResponse($arr); break; case validateRoute('GET', 'torrents/\\d+/peers'): $torrent = new Torrent($db, $user); list($seeders, $leechers) = $torrent->getPeers((int) $params[1]); httpResponse(array("seeders" => $seeders, "leechers" => $leechers)); break; case validateRoute('GET', 'torrents/\\d+/snatchlog'): $torrent = new Torrent($db, $user); httpResponse($torrent->getSnatchLog((int) $params[1])); break; case validateRoute('GET', 'torrents/\\d+/comments'): $torrent = new Torrent($db, $user); $comments = new Comments($db, $user, $torrent); list($result, $totalCount) = $comments->query((int) $params[1], (int) $_GET["limit"] ?: 10, (int) $_GET["index"] ?: 0); httpResponse($result, $totalCount); break; case validateRoute('POST', 'torrents/\\d+/comments'): $torrent = new Torrent($db); $comments = new Comments($db, $user, $torrent); $comments->add((int) $params[1], $postdata["data"]); httpResponse($result, $totalCount); break; case validateRoute('PATCH', 'torrents/\\d+/comments/\\d+'): $comments = new Comments($db, $user); $comments->update((int) $params[1], (int) $params[3], $postdata["postData"]); httpResponse($result, $totalCount); break; case validateRoute('DELETE', 'torrents/\\d+/comments/\\d+'): $torrent = new Torrent($db, $user);
public function getTaggedFileComments() { /** @var myModel $this */ return $this->make('taggedFileComments', function () { $user = \Phalcon\Di::getDefault()->get('auth'); $comments = Comments::query()->leftJoin('Taggables', 'Comments.commentable_type = "Taggables" AND Comments.commentable_id = t1.id', 't1')->where('t1.tag_id = :tag:', ['tag' => $this->id])->leftJoin('Taggables', 't1.taggable_type = t2.taggable_type AND t1.taggable_id = t2.taggable_id', 't2')->andWhere('t2.user_id = :user:'******'user' => $user->id])->groupBy('Comments.id')->orderBy('Comments.updated_at DESC')->leftJoin('Files', 't1.taggable_type = "Files" AND t1.taggable_id = Files.id')->leftJoin('Users', 'Users.id = Comments.user_id')->columns(['Files.*', 'Comments.*', 'Users.*'])->execute(); return $comments; }); }
/** * @param string $source * @return array */ function getComments($source = 'VuFind') { require_once ROOT_DIR . '/services/MyResearch/lib/Comments.php'; $sql = "SELECT comments.*, CONCAT(LEFT(user.firstname,1), '. ', user.lastname) as fullname, user.displayName as displayName " . "FROM comments RIGHT OUTER JOIN user on comments.user_id = user.id " . "WHERE comments.resource_id = '{$this->id}' ORDER BY comments.created"; //Get a reference to the scope we are in so we can determine how to process the comments. global $library; global $user; //Load all bad words. require_once ROOT_DIR . '/Drivers/marmot_inc/BadWord.php'; $badWords = new BadWord(); $badWordsList = $badWords->getBadWordExpressions(); $commentList = array(); $commentList['user'] = array(); $commentList['staff'] = array(); $comment = new Comments(); $comment->query($sql); if ($comment->N) { while ($comment->fetch()) { $okToAdd = true; if (isset($user) && $user != false && $user->id == $comment->user_id) { //It's always ok to show the user what they wrote } else { //Determine if we should censor bad words or hide the comment completely. $censorWords = true; if (isset($library)) { $censorWords = $library->hideCommentsWithBadWords == 0 ? true : false; } if ($censorWords) { $commentText = $comment->comment; foreach ($badWordsList as $badWord) { $commentText = preg_replace($badWord, '***', $commentText); } $comment->comment = $commentText; } else { //Remove comments with bad words $commentText = trim($comment->comment); foreach ($badWordsList as $badWord) { if (preg_match($badWord, $commentText)) { $okToAdd = false; break; } } } } if ($okToAdd) { //Remove any hashtags that were added to the review. if (preg_match('/#.*/', $comment->comment)) { $comment->comment = preg_replace('/#.*/', '', $comment->comment); $commentList['staff'][] = clone $comment; } else { $commentList['user'][] = clone $comment; } } } } return $commentList; }
$r[$key] = mysqli_real_escape_string($con, $value); } $rarr = array('status' => 0); if ($r['action'] == 'get') { // get a single post // with all the f*****g comments $obj = new Posts($r); $obj->checkInputHas(['postid']); $obj->addSelection("postid = {$r['postid']}"); $result = $obj->query(ERR_NOPOST, true); $postarr = mysqli_fetch_assoc($result); $postarr['vote'] = $obj->getUserVote($r['id'], $r['postid']); // get comments $commentObj = new Comments($r); $commentObj->addSelection("postid=" . $r['postid']); $result = $commentObj->query(); $postarr['comments'] = array(); while ($row = mysqli_fetch_assoc($result)) { unset($row['postid']); $postarr['comments'][] = $row; } $rarr = array_merge($postarr, $rarr); die(json_encode($rarr)); } else { if ($r['action'] == 'set') { // create a new post // send token, userid, content, [groupid, pollid] $postObj = new Posts($r); $postObj->checkTokenValid(); $postObj->checkInputHas(['content']); $postObj->addInsertsFromArray($r, ['id', 'content']);
public function deletePage($minititolo) { return parent::query("DELETE FROM {$this->prefix}pagine WHERE minititolo='{$minititolo}'") ? true : false; }
public function getTaggableComments(Tags $tag = null) { /** @var myModel $this */ return $this->make('taggableComments', function () use($tag) { $query = Comments::query()->leftJoin('Users', 'Comments.user_id = Users.id')->leftJoin('Taggables', 'commentable_type = "Taggables" AND commentable_id = Taggables.id')->leftJoin('Files', 'Taggables.taggable_type = "Files" AND Taggables.taggable_id = Files.id')->leftJoin('Tags', 'Taggables.tag_id = Tags.id')->where('Files.id = :id:', ['id' => $this->id])->orderBy('Comments.updated_at DESC')->columns(['Tags.*', 'Comments.*', 'Users.*']); if ($tag != null) { $query = $query->andWhere('Tags.id = :tag:', ['tag' => $tag->id]); } return $query->execute(); }); }
public function showCommentListAction() { $comments = Comments::query()->orderBy('updated_at Desc')->execute(); foreach ($comments as $c) { echo $c->created_at . ' - ' . $c->content . '<br>'; } die; }