/** * Get the articles that have no publication/issue/section. * * @param int $p_start * @param int $p_maxRows * @return array * An array of two elements: * An array of articles and the total number of articles. */ public static function GetUnplacedArticles($p_start = 0, $p_maxRows = 20) { global $g_ado_db; $tmpArticle = new Article(); $columnNames = $tmpArticle->getColumnNames(true); $queryStr = 'SELECT '.implode(", ", $columnNames) .' FROM Articles ' ." WHERE IdPublication=0 AND NrIssue=0 AND NrSection=0 " .' ORDER BY Number DESC, IdLanguage ' ." LIMIT $p_start, $p_maxRows"; $query = $g_ado_db->Execute($queryStr); $articles = array(); if ($query != false) { while ($row = $query->FetchRow()) { $tmpArticle = new Article(); $tmpArticle->fetch($row); $articles[] = $tmpArticle; } } $queryStr = 'SELECT COUNT(*) FROM Articles' ." WHERE IdPublication=0 AND NrIssue=0 AND NrSection=0 "; $totalArticles = $g_ado_db->GetOne($queryStr); return array($articles, $totalArticles); } // fn GetUnplacedArticles
/** * Return an array of Article objects, all the articles * which use this image. * * @return array */ public static function GetArticlesThatUseImage($p_imageId) { global $g_ado_db; $article = new Article(); $columnNames = $article->getColumnNames(); $columnQuery = array(); foreach ($columnNames as $columnName) { $columnQuery[] = 'Articles.' . $columnName; } $columnQuery = implode(',', $columnQuery); $queryStr = 'SELECT ' . $columnQuery . ' FROM Articles, ArticleImages ' . ' WHERE ArticleImages.IdImage=' . $p_imageId . ' AND ArticleImages.NrArticle=Articles.Number' . ' ORDER BY Articles.Number, Articles.IdLanguage'; $rows = $g_ado_db->GetAll($queryStr); $articles = array(); if (is_array($rows)) { foreach ($rows as $row) { $tmpArticle = new Article(); $tmpArticle->fetch($row); $articles[] = $tmpArticle; } } return $articles; }
/** * Get the Articles that have the given Topic. * @param int $p_topicId * @return array */ public static function GetArticlesWithTopic($p_topicId) { global $g_ado_db; $articleIds = array(); $queryStr = "SELECT NrArticle FROM ArticleTopics WHERE Topicid = {$p_topicId}"; $rows = $g_ado_db->GetAll($queryStr); if (is_array($rows)) { foreach ($rows as $row) { $articleIds[] = $row['NrArticle']; } } $queryStr = 'SELECT DISTINCT(ArticleType) FROM TopicFields'; $rows = $g_ado_db->GetAll($queryStr); foreach ($rows as $row) { $queryStr = "SELECT FieldName FROM TopicFields WHERE ArticleType = '" . $row['ArticleType'] . "'"; $rows2 = $g_ado_db->GetAll($queryStr); if (!is_array($rows2) || sizeof($rows2) == 0) { continue; } $columns = ''; foreach ($rows2 as $row2) { $columns .= " OR F" . $row2['FieldName'] . " = {$p_topicId}"; } $columns = substr($columns, 3); $queryStr = "SELECT DISTINCT(NrArticle) FROM X" . $row['ArticleType'] . " WHERE {$columns}"; $rows2 = $g_ado_db->GetAll($queryStr); if (!is_array($rows2)) { continue; } foreach ($rows2 as $row2) { foreach ($row2 as $fieldName => $value) { $articleIds[] = $value; } } } if (sizeof($articleIds) == 0) { return null; } $articleIds = array_unique($articleIds); $tmpArticle = new Article(); $columnNames = implode(',', $tmpArticle->getColumnNames(true)); $queryStr = "SELECT {$columnNames} FROM Articles WHERE Number IN (" . implode(', ', $articleIds) . ")"; return DbObjectArray::Create('Article', $queryStr); }
/** * For now, this is mostly a hack to get the home page working. * The raw array is returned. * * @param int $p_limit * @return array */ public static function GetFutureActions($p_limit) { global $g_ado_db; $datetime = strftime("%Y-%m-%d %H:%M:00"); $dummyArticle = new Article(); $columnNames = $dummyArticle->getColumnNames(true); $queryStr = "SELECT id, time_action, publish_action, publish_on_front_page, publish_on_section_page," . implode(",", $columnNames). " FROM Articles, ArticlePublish " . " WHERE ArticlePublish.time_action >= '" . $datetime . "'" . " AND ArticlePublish.is_completed != 'Y'" . " AND Articles.Published != 'N'" . " AND Articles.Number=ArticlePublish.fk_article_number " . " AND Articles.IdLanguage=ArticlePublish.fk_language_id " . " ORDER BY time_action DESC" . " LIMIT $p_limit"; $rows = $g_ado_db->GetAll($queryStr); $addKeys = array(); if ($rows && (count($rows) > 0)) { foreach ($rows as $row) { $row["ObjectType"] = "article"; $addKeys[$row['time_action']] = $row; } } return $addKeys; } // fn GetFutureActions