Example #1
0
 private function newArticleList()
 {
     $latest = Cacher::get(LATEST_ARTICLE_ID_KEY);
     if (!$latest) {
         $article = ArticleEntry::orderBy('article_id', 'DESC')->first();
         if ($article) {
             $latest = $article->article_id;
             Cacher::set(LATEST_ARTICLE_ID_KEY, $latest);
         }
     }
     $newList = array();
     $check = $latest;
     $fail = 0;
     while (true) {
         $check += 2;
         $article = new Article($check);
         try {
             $article->fetch();
             $newList[] = $article->data;
             mlog('Found: ' . $article->data['id'] . ' ' . $article->data['title'] . ' ' . $article->data['date']);
         } catch (Exception $ex) {
             $fail++;
             mlog('NotFound: ' . $check . ' Exception: ' . $ex->getMessage());
             if ($fail >= 3) {
                 break;
             }
         }
     }
     mlog('Found ' . count($newList) . ' new article(s)');
     return $newList;
 }
$issuePublishEvent->dumpToHtml();

echo "Executing pending events:<br>";
$events = IssuePublish::GetPendingActions();
foreach ($events as $event) {
    $event->doAction();
    $event->dumpToHtml();
}

// Check if issues are published
echo "Is the issue published?<br>";
$issue->fetch();
$issue->dumpToHtml();

// Are the articles published?
echo "Are the articles published?<br>";
$article1->fetch();
$article1->dumpToHtml();
$article2->fetch();
$article2->dumpToHtml();

echo "Number of remaining events (should be zero): ".count(IssuePublish::GetPendingActions())."<br>";

echo "Deleting objects.<br>";
$issue->delete();
$article1->delete();
$article2->delete();
$issuePublishEvent->delete();

echo "done.<br>";
?>
Example #3
0
    /**
     * 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
Example #4
0
 /**
  * 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;
 }
Example #5
0
    /**
     * 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