Create() public static method

Create an array of DatabaseObjects.
public static Create ( string $p_className, string $p_queryStr ) : array
$p_className string The type of objects to create. The class must be a decendant of DatabaseObject and have a constructor that can take no parameters.
$p_queryStr string The database query string that will fetch the rows from the database.
return array
Example #1
0
 /**
  * @return array
  */
 public static function GetEvents()
 {
     $tmpEvent = new Event();
     $columns = implode(',', $tmpEvent->getColumnNames(true));
     $queryStr = "SELECT {$columns} FROM Events ORDER BY Id";
     $events = DbObjectArray::Create('Event', $queryStr);
     return $events;
 }
Example #2
0
 /**
  * Return an array of all time units.
  * @return array
  */
 public static function GetTimeUnits($p_languageCode)
 {
     $queryStr = "SELECT TimeUnits.Unit, TimeUnits.Name " . " FROM TimeUnits, Languages " . " WHERE TimeUnits.IdLanguage = Languages.Id " . " AND Languages.Code = '{$p_languageCode}'" . " ORDER BY TimeUnits.Unit ASC";
     $timeUnits = DbObjectArray::Create('TimeUnit', $queryStr);
     if (count($timeUnits) == 0) {
         $queryStr = "SELECT TimeUnits.Unit, TimeUnits.Name " . " FROM TimeUnits, Languages " . " WHERE TimeUnits.IdLanguage = Languages.Id " . " AND Languages.Code = 'en'" . " ORDER BY TimeUnits.Unit ASC";
         $timeUnits = DbObjectArray::Create('TimeUnit', $queryStr);
     }
     return $timeUnits;
 }
Example #3
0
 /**
  * Get all the actions that currently need to be performed.
  * @return array
  */
 public static function GetPendingActions()
 {
     $datetime = strftime("%Y-%m-%d %H:%M:00");
     $queryStr = "SELECT * FROM IssuePublish " . " WHERE time_action <= '{$datetime}'" . " AND is_completed != 'Y'" . " ORDER BY time_action ASC";
     $result = DbObjectArray::Create('IssuePublish', $queryStr);
     return $result;
 }
Example #4
0
 /**
  * @param array $p_sqlOptions
  * @param boolean $p_update
  * @param boolean $p_useFilter
  *		filter templates matching setting in SystemPrefs
  * @param boolean $p_strict
  *      if true, retrieves only template (tpl) files
  *
  * @return array
  */
 public static function GetAllTemplates($p_sqlOptions = null, $p_update = true, $p_useFilter = false, $p_strict = false)
 {
     if ($p_update) {
         self::UpdateStatus();
     }
     $queryStr = 'SELECT * FROM Templates';
     if ($p_strict) {
         $queryStr .= ' WHERE Type < 5';
     }
     if ($p_useFilter && ($rexeg = self::GetTemplateFilterRegex(true))) {
         $queryStr .= $p_strict == false ? ' WHERE ' : ' AND ';
         $queryStr .= 'Name NOT REGEXP "' . self::GetTemplateFilterRegex(true) . '"';
     }
     if (!is_null($p_sqlOptions)) {
         $queryStr = DatabaseObject::ProcessOptions($queryStr, $p_sqlOptions);
     } else {
         $queryStr .= ' ORDER BY Level ASC, Name ASC';
     }
     $templates = DbObjectArray::Create('Template', $queryStr);
     return $templates;
 }
Example #5
0
 /**
  * Return an array of Language objects based on the given contraints.
  *
  * @param int $p_id
  * @param string $p_languageCode
  * @param string $p_name
  * @param array $p_excludedLanguages
  * @param array $p_order
  * @return array
  */
 public static function GetLanguages($p_id = null, $p_languageCode = null, $p_name = null, array $p_excludedLanguages = array(), array $p_order = array(), $p_skipCache = false)
 {
     global $g_ado_db;
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $paramsArray['id'] = is_null($p_id) ? 'null' : $p_id;
         $paramsArray['language_code'] = is_null($p_languageCode) ? 'null' : $p_languageCode;
         $paramsArray['name'] = is_null($p_name) ? 'null' : $p_name;
         $paramsArray['excluded_languages'] = $p_excludedLanguages;
         $paramsArray['order'] = $p_order;
         $cacheListObj = new CampCacheList($paramsArray, __METHOD__);
         $languages = $cacheListObj->fetchFromCache();
         if ($languages !== false && is_array($languages)) {
             return $languages;
         }
     }
     $selectClauseObj = new SQLSelectClause();
     $tmpLanguage = new Language();
     $selectClauseObj->setTable($tmpLanguage->getDbTableName());
     if (!is_null($p_id)) {
         $selectClauseObj->addWhere($g_ado_db->escapeKeyVal('Id', (int) $p_id));
     }
     if (!is_null($p_languageCode)) {
         $selectClauseObj->addWhere($g_ado_db->escapeKeyVal('Code', $p_languageCode));
     }
     if (!is_null($p_name)) {
         $selectClauseObj->addWhere($g_ado_db->escapeKeyVal('Name', $p_name));
     }
     if (count($p_excludedLanguages) > 0) {
         $excludedLanguages = array();
         foreach ($p_excludedLanguages as $excludedLanguage) {
             $excludedLanguages[] = (int) $excludedLanguage;
         }
         $selectClauseObj->addWhere("Id NOT IN (" . implode(', ', $excludedLanguages) . ")");
     }
     $order = Language::ProcessLanguageListOrder($p_order);
     foreach ($order as $orderDesc) {
         $selectClauseObj->addOrderBy($orderDesc['field'] . ' ' . $orderDesc['dir']);
     }
     $selectClause = $selectClauseObj->buildQuery();
     $languages = DbObjectArray::Create('Language', $selectClause);
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $cacheListObj->storeInCache($languages);
     }
     return $languages;
 }
Example #6
0
	/**
	 * Get an array of users who have uploaded images.
	 * @return array
	 */
	public static function GetUploadUsers()
	{
		$tmpUser = new User();
		$columnNames = $tmpUser->getColumnNames();
		$queryColumnNames = array();
		foreach ($columnNames as $columnName) {
			$queryColumnNames[] = 'liveuser_users.'.$columnName;
		}
		$queryColumnNames = implode(",", $queryColumnNames);
		$queryStr = 'SELECT DISTINCT liveuser_users.Id, '.$queryColumnNames
					.' FROM Images, liveuser_users '
                    .' WHERE Images.UploadedByUser = liveuser_users.Id';
		$users = DbObjectArray::Create('User', $queryStr);
		return $users;
	} // fn GetUploadUsers
Example #7
0
    /**
     * Get all users matching the given parameters.
     *
     * @param boolean $p_onlyAdmin
     * @param string $p_userType
     *
     * @return array
     */
    public static function GetUsers($p_onlyAdmin = true, $p_userType = null)
    {
        global $g_ado_db;

        $constraints = array();
        if ($p_onlyAdmin) {
            $constraints[] = "Reader='N'";
        }
        if (!is_null($p_userType)) {
            $constraints[] = "fk_user_type='".$p_userType."'";
        }
        if (count($constraints) > 0) {
            $whereStr = " WHERE ".implode(" AND ", $constraints);
        }
        $sql = "SELECT * FROM liveuser_users " . $whereStr;
        return DbObjectArray::Create("User", $sql);
    } // fn GetUsers
Example #8
0
 /**
  * Do a simple search.
  *
  * @param array $p_columns
  *		Array of arrays of two strings: column name and search value.
  * @param array $p_sqlOptions
  *		See ProcessOptions().
  *
  * @return array
  */
 public static function Search($p_className, $p_columns = null, $p_sqlOptions = null)
 {
     global $g_ado_db;
     if (!class_exists($p_className)) {
         return array();
     }
     $tmpObj = new $p_className();
     $queryStr = "SELECT * FROM " . $tmpObj->m_dbTableName;
     if (is_array($p_columns) && count($p_columns) > 0) {
         $contraints = array();
         foreach ($p_columns as $item) {
             if (count($item) == 2) {
                 list($columnName, $value) = $item;
                 $contraints[] = $g_ado_db->escapeKeyVal($columnName, $value);
             }
         }
         $queryStr .= " WHERE " . implode(" AND ", $contraints);
     }
     $queryStr = DatabaseObject::ProcessOptions($queryStr, $p_sqlOptions);
     $dbObjects = DbObjectArray::Create($p_className, $queryStr);
     return $dbObjects;
 }
Example #9
0
 /**
  * Return all publications as an array of Publication objects.
  *
  * @param string $p_name
  * @param int $p_aliasId
  * @param array $p_sqlOptions
  *
  * @return array
  */
 public static function GetPublications($p_name = null, $p_aliasId = null, $p_sqlOptions = null)
 {
     global $g_ado_db;
     if (is_null($p_sqlOptions)) {
         $p_sqlOptions = array();
     }
     if (!isset($p_sqlOptions["ORDER BY"])) {
         $p_sqlOptions["ORDER BY"] = array("Name" => "ASC");
     }
     $tmpPub = new Publication();
     $columns = $tmpPub->getColumnNames(true);
     $queryStr = 'SELECT ' . implode(',', $columns) . ', Aliases.Name as Alias' . ', URLTypes.Name as URLType' . ', Languages.OrigName as NativeName' . ' FROM Publications, Languages, Aliases, URLTypes' . ' WHERE Publications.IdDefaultAlias = Aliases.Id ' . ' AND Publications.IdURLType = URLTypes.Id ' . ' AND Publications.IdDefaultLanguage = Languages.Id ';
     if (is_string($p_name)) {
         $queryStr .= " AND Publications.Name=" . $g_ado_db->escape($p_name);
     }
     if (is_numeric($p_aliasId)) {
         $queryStr .= " AND Publications.IdDefaultAlias={$p_aliasId}";
     }
     $queryStr = DatabaseObject::ProcessOptions($queryStr, $p_sqlOptions);
     $publications = DbObjectArray::Create('Publication', $queryStr);
     return $publications;
 }
Example #10
0
	/**
	 * Get all the languages to which this issue has been translated.
	 *
	 * @param boolean $p_getUnusedLanguagesOnly
	 * 		Reverses the search and finds only those languages which this
	 * 		issue has not been translated into.
	 * @param boolean $p_excludeCurrent
	 *      If true, exclude the current language from the list.
	 * @param array $p_order
     *      The array of order directives in the format:
     *      array('field'=>field_name, 'dir'=>order_direction)
     *      field_name can take one of the following values:
     *        bynumber, byname, byenglish_name, bycode
     *      order_direction can take one of the following values:
     *        asc, desc
	 * @param boolean $p_allIssues
	 *      If true return all the languages in which all issues of the
	 *      publication were translated.
	 * @return array
	 * 		Return an array of Language objects.
	 */
	public function getLanguages($p_getUnusedLanguagesOnly = false,
	$p_excludeCurrent = false, array $p_order = array(), $p_allIssues = false,
	$p_published = false)
	{
		$tmpLanguage = new Language();
		$columnNames = $tmpLanguage->getColumnNames(true);
		if ($p_getUnusedLanguagesOnly) {
			$queryStr = "SELECT ".implode(',', $columnNames)
						." FROM Languages LEFT JOIN Issues "
						." ON Issues.IdPublication = ".$this->m_data['IdPublication'];
            if (!$p_allIssues) {
                $queryStr .= " AND Issues.Number = ".$this->m_data['Number'];
            }
            if ($p_published) {
                $queryStr .= " AND Issues.Published = 'Y'";
            }
            $queryStr .= " AND Issues.IdLanguage = Languages.Id "
                      ." WHERE Issues.IdPublication IS NULL";
		} else {
			$queryStr = "SELECT ".implode(',', $columnNames)
						." FROM Languages, Issues "
						." WHERE Issues.IdPublication = ".$this->m_data['IdPublication'];
            if (!$p_allIssues) {
                $queryStr .= " AND Issues.Number = ".$this->m_data['Number'];
            }
            $queryStr .= " AND Issues.IdLanguage = Languages.Id ";
            if ($p_excludeCurrent) {
                $queryStr .= " AND Languages.Id != " . $this->m_data['IdLanguage'];
            }
            if ($p_published) {
                $queryStr .= " AND Issues.Published = 'Y'";
            }
		}
		list($languagesKey) = $tmpLanguage->getKeyColumnNames();
		$queryStr .= " GROUP BY $languagesKey";
        $order = Issue::ProcessLanguageListOrder($p_order);
		foreach ($order as $orderDesc) {
            $sqlOrder[] = $orderDesc['field'] . ' ' . $orderDesc['dir'];
        }
        if (count($sqlOrder) > 0) {
            $queryStr .= ' ORDER BY ' . implode(', ', $sqlOrder);
        }
		$languages = DbObjectArray::Create('Language', $queryStr);
		return $languages;
	} // fn getLanguages
Example #11
0
 /**
  * Get the logs.
  *
  * @param int $p_eventId
  * @param array $p_sqlOptions
  *
  * @return array
  */
 public static function GetLogs($p_eventId = null, $p_sqlOptions = null)
 {
     if (is_null($p_sqlOptions) || !isset($p_sqlOptions['ORDER BY'])) {
         $p_sqlOptions['ORDER BY'] = array('time_created' => 'DESC');
     }
     $tmpLog = new Log();
     $columns = $tmpLog->getColumnNames(true);
     $queryStr = "SELECT " . implode(", ", $columns) . ", INET_NTOA(Log.user_ip) AS user_ip_addr" . ", liveuser_users.Name as full_name" . ", liveuser_users.UName as user_name" . " FROM Log" . " LEFT JOIN liveuser_users" . " ON Log.fk_user_id = liveuser_users.Id";
     if (!is_null($p_eventId)) {
         $queryStr .= " WHERE Log.fk_event_id={$p_eventId}";
     }
     $queryStr = DatabaseObject::ProcessOptions($queryStr, $p_sqlOptions);
     $logLines = DbObjectArray::Create('Log', $queryStr);
     return $logLines;
 }
Example #12
0
    /**
     * Get all comments associated with the given article.
     *
     * @param int $p_articleNumber
     * @param int $p_languageId
     * @param string $p_status
     *      This can be NULL if you dont care about the status,
     *      "approved" or "unapproved".
     * @param boolean $p_countOnly
     * @return array
     */
    public static function GetArticleComments($p_articleNumber, $p_languageId,
                                              $p_status = null, $p_countOnly = false,
                                              $p_skipCache = true)
    {
        global $PHORUM, $g_ado_db;

        if (CampCache::IsEnabled() && !$p_skipCache) {
        	$cacheKey = __METHOD__ . '_' . (int)$p_articleNumber . '_'
        	. (int)$p_languageId . '_' . $p_status . '_' . (int)$p_count_only;
        	$result = CampCache::singleton()->fetch($cacheKey);
            if ($result !== false) {
                return $result;
            }
        }

        $threadId = ArticleComment::GetCommentThreadId($p_articleNumber, $p_languageId);
        if (!$threadId) {
            $result = $p_countOnly ? 0 : null;
        	if (CampCache::IsEnabled()) {
        		CampCache::singleton()->store($cacheKey, $result);
        	}
        	return $result;
        }

        // Are we counting or getting the comments?
        $selectClause = "*";
        if ($p_countOnly) {
            $selectClause = "COUNT(*)";
        }

        // Only getting comments with a specific status?
        $whereClause = "";
        if (!is_null($p_status)) {
            if ($p_status == "approved") {
                $whereClause = " AND status=".PHORUM_STATUS_APPROVED;
            } elseif ($p_status == "unapproved") {
                $whereClause = " AND status=".PHORUM_STATUS_HIDDEN;
            }
        }
        $queryStr = "SELECT $selectClause "
                    ." FROM ".$PHORUM['message_table']
                    ." WHERE thread=$threadId"
                    ." AND message_id != thread"
                    . $whereClause
                    ." ORDER BY message_id";
        if ($p_countOnly) {
        	$result = $g_ado_db->GetOne($queryStr);
        } else {
	        $result = DbObjectArray::Create("Phorum_message", $queryStr);
        }
        if (CampCache::IsEnabled() && !$p_skipCache) {
        	CampCache::singleton()->store($cacheKey, $result, self::DEFAULT_TTL);
        }
        return $result;
    } // fn GetArticleComments
Example #13
0
 /**
  * Return an array of all URL types.
  * @return array
  */
 public static function GetUrlTypes()
 {
     $queryStr = 'SELECT * FROM URLTypes';
     $urlTypes = DbObjectArray::Create('UrlType', $queryStr);
     return $urlTypes;
 }
Example #14
0
    /**
	 * Get the Blogs that have the given Topic.
	 * @param int $p_fk_topic_id
	 * @return array
	 */
	public static function XXGetBlogsWithTopic($p_fk_topic_id)
	{
		global $g_ado_db;

		$blogIds = array();
		$queryStr = "SELECT fk_blog_id FROM BlogTopics WHERE fk_topic_id = $p_fk_topic_id";
		$rows = $g_ado_db->GetAll($queryStr);
		if (is_array($rows)) {
			foreach ($rows as $row) {
				$blogIds[] = $row['fk_blog_id'];
			}
		}

		$queryStr = 'SELECT DISTINCT(BlogType) FROM TopicFields';
		$rows = $g_ado_db->GetAll($queryStr);
		foreach ($rows as $row) {
			$queryStr = "SELECT FieldName FROM TopicFields WHERE BlogType = '"
						. $row['BlogType'] . "'";
			$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_fk_topic_id";
			}
			$columns = substr($columns, 3);
			$queryStr = "SELECT DISTINCT(fk_blog_id) FROM X" . $row['BlogType']
						. " WHERE $columns";
			$rows2 = $g_ado_db->GetAll($queryStr);
			if (!is_array($rows2)) {
				continue;
			}
			foreach ($rows2 as $row2) {
				foreach ($row2 as $fieldName=>$value) {
					$blogIds[] = $value;
				}
			}
		}

		if (sizeof($blogIds) == 0) {
			return null;
		}

		$blogIds = array_unique($blogIds);
		$tmpBlog = new Blog();
		$columnNames = implode(',', $tmpBlog->getColumnNames(true));
		$queryStr = "SELECT $columnNames FROM Blogs WHERE Number IN ("
					. implode(', ', $blogIds) . ")";
    	return DbObjectArray::Create('Blog', $queryStr);
	} // fn GetBlogsWithTopic
Example #15
0
 /**
  * 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);
 }
Example #16
0
 /**
  * Get the $p_max number of the most recently modified articles.
  * @param int $p_max
  * @return array
  */
 public static function GetRecentlyModifiedArticles($p_max)
 {
     $queryStr = "SELECT * FROM Articles "
                ." ORDER BY time_updated DESC"
                ." LIMIT $p_max";
     $result = DbObjectArray::Create('Article', $queryStr);
     return $result;
 } // fn GetRecentlyModifiedArticles
Example #17
0
 /**
  * @return array
  */
 public static function GetAuthors()
 {
     $tmpAuthor = new Author();
     $columns = implode(',', $tmpAuthor->getColumnNames(true));
     $queryStr = "SELECT {$columns}\n            FROM " . self::TABLE . '
         ORDER BY first_name';
     $authors = DbObjectArray::Create('Author', $queryStr);
     return $authors;
 }
 /**
  * Return an array of SubscriptionSection objects matching the
  * search criteria.
  *
  * @param int $p_subscriptionId
  * @param int $p_sectionId
  * @param int $p_languageId
  * @return array
  */
 public static function GetSubscriptionSections($p_subscriptionId, $p_sectionId = null, $p_languageId = null)
 {
     $queryStr = "SELECT SubsSections.*, Sections.Name, Subscriptions.Type, " . "Languages.Name as LangName, Languages.OrigName as LangOrigName" . " FROM Subscriptions, Sections, SubsSections LEFT JOIN Languages " . " ON SubsSections.IdLanguage = Languages.Id " . " WHERE Subscriptions.Id = {$p_subscriptionId} " . " AND Subscriptions.Id = SubsSections.IdSubscription " . " AND Subscriptions.IdPublication = Sections.IdPublication " . " AND SubsSections.SectionNumber = Sections.Number ";
     if (!is_null($p_sectionId)) {
         $queryStr .= " AND SubsSections.SectionNumber = {$p_sectionId}";
     }
     if (!is_null($p_languageId)) {
         $queryStr .= " AND SubsSections.IdLanguage = {$p_languageId}";
     }
     $queryStr .= " GROUP BY SectionNumber, IdLanguage ORDER BY SectionNumber, LangName";
     $sections = DbObjectArray::Create('SubscriptionSection', $queryStr);
     return $sections;
 }
Example #19
0
	/**
	 * Get all the actions that currently need to be performed.
	 * @return array
	 */
	public static function GetPendingActions()
	{
	    $datetime = strftime("%Y-%m-%d %H:%M:00");
        $queryStr = "SELECT * FROM ArticlePublish, Articles "
        			. " WHERE ArticlePublish.fk_article_number=Articles.Number"
                    . " AND ArticlePublish.time_action <= '$datetime'"
                    . " AND ArticlePublish.is_completed != 'Y'"
                    . " AND Articles.Published != 'N'"
                    . " ORDER BY ArticlePublish.time_action ASC";
        $result = DbObjectArray::Create('ArticlePublish', $queryStr);
        return $result;
	} // fn GetPendingActions