contentId = $contentId; $this->ContentClass = $class; //default table.. if ($table === null) $table = 'comments_' . strtolower($this->ContentClass); //just use base comments... if ($objectType === null) $objectType = $this->ContentClass . 'Comment'; //construct parent::__construct($objectType, $table); } /** * get our main page xml. * * we want to display the comment thread for the object * */ function getMainPageXml() { return << XML; } /** * prep our main main page... set content id */ public function initMainPage() { $this->contentId = $this->params('content_id'); } /** * draw our main page, which is the comment table */ public function drawMainPage() { $this->drawCommentTable(); } /** * Creates a new comment of our type... * * @param $data the data to load the class with. */ function factory($data = null) { return new $this->objectType($data, $this->ContentClass); } /** * deletes our comment thread. */ function delete() { $rs = $this->search(array( 'content_id' => $this->contentId ), -1); parent::delete($rs); } /** * gets the count of comments in this thread or multiple threads. * * @param $ids either an id or an array of ids to fetch counts for. * @param if $ids is an array, it will return an associative array of counts * with the key being the content id, otherwise it will return a count for * that content id. */ function getCommentCount($ids = null) { if ($this->count !== null) return $this->count; if (is_array($ids)) { $comRs = dbQuery(" SELECT content_id, count(content_id) AS count FROM {$this->object->tableName} WHERE content_id IN (" . implode(',', $ids) . ") GROUP BY content_id "); while ($comAr = dbFetchAssoc($comRs)) $ret[$comAr['content_id']] = $comAr['count']; return $ret; } else { $comRs = dbQuery(" SELECT id FROM {$this->object->tableName} WHERE content_id = '$this->contentId' "); return dbGetNumRows($comRs); } } /** * draws a summary of the comments... basically how many comments with a * link to view them. wrapped in a span with class of 'commentSummary' */ function drawCommentSummary() { $comCount = $this->getCommentCount(); echo "\n"; $url = $this->getUrl(strtolower($this->ContentClass) . ".view?id=$this->contentId") . "#comments"; echo "$comCount " . Util::pluralize('comment', $comCount) . ""; echo "\n"; } /** * This draws teh comment table. It's wrapped in a div with id of * 'commentContainer' if useRss == true, it will also draw a comment rss * feed link. */ function drawCommentTable() { echo "
\n"; echo "

\n"; $form = $this->object->createReplyForm($this->contentId); $form->drawAll(); echo "

\n"; echo " "; $this->drawComments(); //do we want rss? if ($this->useRss) echo $this->getRssLink(".search?output=rss&content_id=$this->contentId", "Subscribe to comment RSS feed."); echo "\n
\n"; } /** * This gets all the comments for this content id. * * @return an array of comment objects */ function getComments() { return $this->search(array( 'content_id' => $this->contentId ), -1); } /** * this draws all the comments in teh thread. */ function drawComments() { $coms = $this->getComments(); $this->object->drawChildComments($coms, 0); } /** * this initializes teh rss page. */ function initSearchPage() { $this->contentId = $this->params('content_id'); parent::initSearchPage(); } /** * this genearates the rss object. The link goes to the content view page * and the title is the Config::get('site_name') $class Comment Thread */ function generateRss($params = array()) { $rss = parent::generateRss($params); $rss->link = $this->getUrl(strtolower($this->ContentClass) . ".view?id=" . $this->contentId, null, true); $rss->title = Config::get('site_name') . " " . ucfirst($this->ContentClass) . " Comment Thread"; return $rss; } /** * add content id as required parameter. * * this means you can only get comments for an individual object * * @see ObjectManager::getSearchParamXml() */ public function getSearchParamXml() { $xml = ''; $xml .= parent::getSearchParamXml(); return $xml; } } ?>