/** * Get the messages that match the given conditions. * The conditions are AND'ed together. * * @param array $p_match * An array of (column name => value to match) * @param string $p_method * The way to combine the statements: can be * "AND", "OR", or "RAW". RAW is for cases when * you want to type an SQL condition directly in * $p_match, for example: * Phorum_message::GetMessages("status > 0 AND author LIKE %foo%", "RAW"); * * @return array */ public static function GetMessages($p_match, $p_method = "AND") { global $PHORUM; global $g_ado_db; if (!is_array($p_match)) { return null; } $p_method = strtoupper(trim($p_method)); if (!in_array($p_method, array("AND", "OR", "RAW"))) { return null; } if ($p_method != "RAW") { foreach ($p_match as $columnName => $value) { $parts[] = '`'.$columnName."`='".mysql_real_escape_string($value)."'"; } $whereClause = implode(" $p_method ", $parts); } else { $whereClause = $p_match; } $sql = "SELECT * FROM ".$PHORUM['message_table'] ." WHERE $whereClause" ." ORDER BY message_id"; $result = $g_ado_db->GetAll($sql); $returnArray = array(); if (count($result) > 0){ foreach ($result as $row) { $tmpMessage = new Phorum_message(); $tmpMessage->fetch($row); $returnArray[$row['message_id']] = $tmpMessage; } } return $returnArray; } // fn GetMessages
function testUpdateThreadInfo() { // Create thread start. $message = new Phorum_message(); $message->create(1, 'delete me'); $messageId = $message->getMessageId(); // add message to the thread. $message2 = new Phorum_message(); $message2->create(1, "delete me", "wow", $messageId, $messageId); $message->fetch(); $threadCount = $message->getNumMessagesInThread(); $message2->delete(); $message->fetch(); $threadCount2 = $message->getNumMessagesInThread(); if ($threadCount != ($threadCount2 + 1)) { $this->fail("Thread stats not updated correctly."); } }
/** * Get the comments and their associated articles. * * @param string $p_status * Can be 'approved' or 'unapproved'. * @param boolean $p_getTotal * If TRUE, return the number of comments that match the search * criteria and not the actual records. * @param string $p_searchString * A string to search for. * @param array $p_sqlOptions * See DatabaseObject::ProcessOptions(). * @return array */ public static function GetComments($p_status = 'approved', $p_getTotal = false, $p_searchString = '', $p_sqlOptions = null) { global $PHORUM; global $g_ado_db; $messageTable = $PHORUM['message_table']; $selectClause = "*"; if ($p_getTotal) { $selectClause = "COUNT(*)"; } $baseQuery = "SELECT $selectClause FROM ($messageTable" ." LEFT JOIN ArticleComments " ." ON $messageTable". ".thread=ArticleComments.fk_comment_id)" ." LEFT JOIN Articles ON ArticleComments.fk_article_number=Articles.Number" ." AND ArticleComments.fk_language_id=Articles.IdLanguage"; $whereQuery = "$messageTable.message_id != $messageTable.thread"; if ($p_status == 'approved') { $whereQuery .= " AND status > 0"; } elseif ($p_status == 'unapproved') { $whereQuery .= " AND status < 0"; } if (!empty($p_searchString)) { $p_searchString = mysql_real_escape_string($p_searchString); if (!empty($whereQuery)) { $whereQuery .= " AND "; } $search_columns = array( 'subject', 'body', 'email', 'author', 'ip', 'Name', ); $whereAry = array(); foreach ($search_columns as $column) { $whereAry[] = $column . " LIKE '%$p_searchString%'"; } $whereQuery .= '(' . implode(' OR ', $whereAry) . ')'; } if (!empty($whereQuery)) { $baseQuery .= " WHERE ".$whereQuery; } // Default ORDER BY clause if (is_null($p_sqlOptions) || !isset($p_sqlOptions['ORDER BY'])) { $baseQuery .= " ORDER BY ".$PHORUM['message_table'].".message_id"; } //echo $baseQuery."<br><br>"; if ($p_getTotal) { $numComments = $g_ado_db->GetOne($baseQuery); return $numComments; } else { $queryStr = DatabaseObject::ProcessOptions($baseQuery, $p_sqlOptions); $rows = $g_ado_db->GetAll($queryStr); $returnArray = array(); if (is_array($rows)) { foreach ($rows as $row) { $comment = new Phorum_message(); $comment->fetch($row); $article = new Article(); $article->fetch($row); $returnArray[] = array("comment" => $comment, "article" => $article); } } return $returnArray; } } // fn GetComments