function delete() { // delete all contacts and comments linked with this client as well $db = new db_alloc(); $query = prepare("SELECT * FROM clientContact WHERE clientID=%d", $this->get_id()); $db->query($query); while ($db->next_record()) { $clientContact = new clientContact(); $clientContact->read_db_record($db); $clientContact->delete(); } $query = prepare("SELECT * FROM comment WHERE commentType = 'client' and commentLinkID=%d", $this->get_id()); $db->query($query); while ($db->next_record()) { $comment = new comment(); $comment->read_db_record($db); $comment->delete(); } return parent::delete(); }
<?php // Create a search index for Comments. This patch may take a long time to apply. ini_set('max_execution_time', 180000); ini_set('memory_limit', "256M"); $index = Zend_Search_Lucene::create(ATTACHMENTS_DIR . 'search/comment'); $db = new db_alloc(); $q = prepare("SELECT * FROM comment"); $db->query($q); while ($db->row()) { $comment = new comment(); $comment->read_db_record($db); $comment->update_search_index_doc($index); } $index->commit();
function comment_stats() { // date from which a comment is counted as being new. if monday then date back to friday, else the previous day $days = date("w") == 1 ? 3 : 1; $date = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $days, date("Y"))); $query = "SELECT * FROM comment"; $db = new db_alloc(); $db->query($query); while ($db->next_record()) { $comment = new comment(); $comment->read_db_record($db); $this->comments["total"][$comment->get_value("commentModifiedUser")]++; $this->comments["total"]["total"]++; if ($comment->get_value("commentModifiedTime") != "") { if (!isset($this->comments["all"][$comment->get_value("commentModifiedUser")])) { $this->comments["all"][$comment->get_value("commentModifiedUser")] = array(); } $this->comments["all"][$comment->get_value("commentModifiedUser")][date("Y-m-d", strtotime($comment->get_value("commentModifiedTime")))]++; $this->comments["all"][$comment->get_value("commentModifiedUser")]["total"]++; $this->comments["all"]["total"][date("Y-m-d", strtotime($comment->get_value("commentModifiedTime")))]++; if (strcmp($date, $comment->get_value("commentModifiedTime")) <= 0) { if (!isset($this->comments["new"][$comment->get_value("commentModifiedUser")])) { $this->comments["new"][$comment->get_value("commentModifiedUser")] = array(); } $this->comments["new"][$comment->get_value("commentModifiedUser")][date("Y-m-d", strtotime($comment->get_value("commentModifiedTime")))]++; $this->comments["new"][$comment->get_value("commentModifiedUser")]["total"]++; $this->comments["new"]["total"][date("Y-m-d", strtotime($comment->get_value("commentModifiedTime")))]++; } } } return $this->comments; }