本文整理汇总了PHP中Topic::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Topic::exists方法的具体用法?PHP Topic::exists怎么用?PHP Topic::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topic
的用法示例。
在下文中一共展示了Topic::exists方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transfer_topics_3_5
function transfer_topics_3_5($p_parentId = 0)
{
global $g_ado_db;
$sql = 'SELECT * FROM TopicsOld';
if (!is_null($p_parentId)) {
$sql .= " WHERE ParentId = {$p_parentId}";
}
$sql .= ' ORDER BY TopicOrder DESC, LanguageId ASC';
$rows = $g_ado_db->GetAll($sql);
foreach ($rows as $row) {
$topic = new Topic($row['Id']);
if ($topic->exists()) {
$topic->setName($row['LanguageId'], $row['Name']);
} else {
$topic->create(array('parent_id' => $p_parentId, 'names' => array($row['LanguageId'] => $row['Name'])));
transfer_topics_3_5($topic->getTopicId());
}
}
}
示例2: GetList
/**
* Returns an articles list based on the given parameters.
*
* @param array $p_parameters
* An array of ComparisonOperation objects
* @param string $p_order
* An array of columns and directions to order by
* @param integer $p_start
* The record number to start the list
* @param integer $p_limit
* The offset. How many records from $p_start will be retrieved.
* @param integer $p_count
* The total count of the elements; this count is computed without
* applying the start ($p_start) and limit parameters ($p_limit)
*
* @return array $articlesList
* An array of Article objects
*/
public static function GetList(array $p_parameters, $p_order = null,
$p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false)
{
global $g_ado_db;
if (!$p_skipCache && CampCache::IsEnabled()) {
$paramsArray['parameters'] = serialize($p_parameters);
$paramsArray['order'] = (is_null($p_order)) ? 'null' : $p_order;
$paramsArray['start'] = $p_start;
$paramsArray['limit'] = $p_limit;
$cacheListObj = new CampCacheList($paramsArray, __METHOD__);
$articlesList = $cacheListObj->fetchFromCache();
if ($articlesList !== false && is_array($articlesList)) {
return $articlesList;
}
}
$matchAllTopics = false;
$hasTopics = array();
$hasNotTopics = array();
$selectClauseObj = new SQLSelectClause();
$otherTables = array();
// sets the name of the table for the this database object
$tmpArticle = new Article();
$articleTable = $tmpArticle->getDbTableName();
$selectClauseObj->setTable($articleTable);
unset($tmpArticle);
$languageId = null;
// parses the given parameters in order to build the WHERE part of
// the SQL SELECT sentence
foreach ($p_parameters as $param) {
$comparisonOperation = self::ProcessListParameters($param, $otherTables);
$leftOperand = strtolower($comparisonOperation['left']);
if ($leftOperand == 'idlanguage' && $comparisonOperation['symbol'] == '=') {
$languageId = $comparisonOperation['right'];
}
if (array_key_exists($leftOperand, Article::$s_regularParameters)) {
// regular article field, having a direct correspondent in the
// Article table fields
$whereCondition = Article::$s_regularParameters[$leftOperand]
. ' ' . $comparisonOperation['symbol']
. " '" . $g_ado_db->escape($comparisonOperation['right']) . "' ";
if ($leftOperand == 'reads'
&& strstr($comparisonOperation['symbol'], '=') !== false
&& $comparisonOperation['right'] == 0) {
$selectClauseObj->addConditionalWhere($whereCondition);
$isNullCond = Article::$s_regularParameters[$leftOperand]
. ' IS NULL';
$selectClauseObj->addConditionalWhere($isNullCond);
} elseif ($leftOperand == 'type' && $comparisonOperation['symbol'] == '=' ) {
$selectClauseObj->addConditionalWhere($whereCondition);
} else {
$selectClauseObj->addWhere($whereCondition);
}
} elseif ($leftOperand == 'matchalltopics') {
// set the matchAllTopics flag
$matchAllTopics = true;
} elseif ($leftOperand == 'topic') {
// add the topic to the list of match/do not match topics depending
// on the operator
$topic = new Topic($comparisonOperation['right']);
if ($topic->exists()) {
$topicIds = $topic->getSubtopics(true, 0);
$topicIds[] = $comparisonOperation['right'];
if ($comparisonOperation['symbol'] == '=') {
$hasTopics[] = $topicIds;
} else {
$hasNotTopics[] = $topicIds;
}
}
} elseif ($leftOperand == 'author') {
$otherTables['ArticleAuthors'] = array('__JOIN' => ',');
$author = Author::ReadName($comparisonOperation['right']);
$symbol = $comparisonOperation['symbol'];
$valModifier = strtolower($symbol) == 'like' ? '%' : '';
$firstName = $g_ado_db->escape($author['first_name']);
$lastName = $g_ado_db->escape($author['last_name']);
//.........这里部分代码省略.........
示例3: has_topic
public function has_topic($p_topicName) {
$topic = new Topic($p_topicName);
if (!$topic->exists()) {
$this->trigger_invalid_value_error('has_topic', $p_topicName);
return null;
}
$articleTopics = $this->getContentCache('article_topics');
if (is_null($articleTopics)) {
$articleTopics = ArticleTopic::GetArticleTopics($this->m_dbObject->getArticleNumber());
$this->setContentCache('article_topics', $articleTopics);
}
foreach ($articleTopics as $articleTopic) {
if ($articleTopic->getTopicId() == $topic->getTopicId()) {
return (int)true;
}
}
return (int)false;
}
示例4: unset
}
// delete
foreach ($articleTopics as $topic) {
if (!in_array($topic->getTopicId(), $f_topic_ids)) {
ArticleTopic::RemoveTopicFromArticle($topic->getTopicId(), $f_article_number);
} else {
unset($f_topic_ids[array_search($topic->getTopicId(), $f_topic_ids)]);
}
}
// insert rest
foreach ($f_topic_ids as $topicIdString) {
// Verify topic exists
$tmpTopic = new Topic($topicIdString);
if ($tmpTopic->exists()) {
ArticleTopic::AddTopicToArticle($topicIdString, $f_article_number);
}
}
?>
<script type="text/javascript">
<?php if (!is_null($f_topic_ids)) { ?>
try {
parent.$.fancybox.reload = true;
parent.$.fancybox.message = '<?php putGS('Topics updated.'); ?>';
} catch (e) {}
<?php } ?>
parent.$.fancybox.close();
</script>
示例5: ProcessConstraints
/**
* Processes list constraints passed in an array.
*
* @param array $p_constraints
* @return array
*/
protected function ProcessConstraints(array $p_constraints)
{
$parameters = array();
$state = 1;
$attribute = null;
$articleTypeName = null;
$operator = null;
$value = null;
$context = CampTemplate::singleton()->context();
foreach ($p_constraints as $index=>$word) {
switch ($state) {
case self::CONSTRAINT_ATTRIBUTE_NAME: // reading the parameter name
$attribute = strtolower($word);
if (!array_key_exists($attribute, ArticlesList::$s_parameters)) {
// not a static field; is it a article type name?
self::ReadArticleTypes();
if (array_key_exists($attribute, self::$s_articleTypes)) {
$articleTypeName = self::$s_articleTypes[$attribute];
$state = self::CONSTRAINT_DYNAMIC_FIELD;
break;
}
// not an article type name; is it a dynamic field name?
$dynamicFields = self::GetDynamicFields($articleTypeName, $attribute);
if (count($dynamicFields) > 0) {
if (count($dynamicFields) == 1) {
$type = $dynamicFields[0]->getGenericType();
} else {
$type = 'string';
}
$state = self::CONSTRAINT_OPERATOR;
break;
}
// unknown attribute
CampTemplate::singleton()->trigger_error("invalid attribute $word in statement list_articles, constraints parameter");
return false;
} else {
$type = ArticlesList::$s_parameters[$attribute]['type'];
}
if ($attribute == 'keyword') {
$operator = new Operator('is', 'string');
$state = self::CONSTRAINT_VALUE;
} elseif ($attribute == 'matchalltopics' || $attribute == 'matchanytopic') {
if ($attribute == 'matchalltopics') {
$operator = new Operator('is', 'boolean');
$comparisonOperation = new ComparisonOperation($attribute, $operator, 'true');
$parameters[] = $comparisonOperation;
}
$state = self::CONSTRAINT_ATTRIBUTE_NAME;
} else {
$state = self::CONSTRAINT_OPERATOR;
}
$this->m_ignoreIssue = $this->m_ignoreIssue || $attribute == 'issue';
$this->m_ignoreSection = $this->m_ignoreSection || $attribute == 'section';
if ($attribute == 'onfrontpage' || $attribute == 'onsection') {
if (($index + 1) < count($p_constraints)) {
try {
$operator = new Operator($p_constraints[$index+1], 'switch');
}
catch (InvalidOperatorException $e) {
$operator = new Operator('is', 'switch');
$comparisonOperation = new ComparisonOperation($attribute, $operator, 'on');
$parameters[] = $comparisonOperation;
$state = self::CONSTRAINT_ATTRIBUTE_NAME;
}
} else {
$operator = new Operator('is', 'switch');
$comparisonOperation = new ComparisonOperation($attribute, $operator, 'on');
$parameters[] = $comparisonOperation;
$state = self::CONSTRAINT_ATTRIBUTE_NAME;
}
}
break;
case self::CONSTRAINT_DYNAMIC_FIELD:
$attribute = strtolower($word);
$dynamicFields = self::GetDynamicFields($articleTypeName, $attribute);
if (count($dynamicFields) > 0) {
$type = $dynamicFields[0]->getGenericType();
$state = self::CONSTRAINT_OPERATOR;
break;
}
CampTemplate::singleton()->trigger_error("invalid dynamic field $word in statement list_articles, constraints parameter");
return false;
case self::CONSTRAINT_OPERATOR: // reading the operator
try {
$operator = new Operator($word, $type);
}
catch (InvalidOperatorException $e) {
CampTemplate::singleton()->trigger_error("invalid operator $word of parameter constraints.$attribute in statement list_articles");
return false;
}
$state = self::CONSTRAINT_VALUE;
//.........这里部分代码省略.........
示例6: createAndTest
private function createAndTest($p_topicId, $p_data, $p_left, $p_right)
{
$topic = new Topic($p_topicId);
$topic->create($p_data);
unset($topic);
$topic = new Topic($p_topicId);
$this->assertTrue($topic->exists());
foreach ($p_data['names'] as $languageId=>$name) {
$this->assertEquals($name, $topic->getName($languageId));
}
$this->assertEquals($p_left, $topic->getLeft());
$this->assertEquals($p_right, $topic->getRight());
}
示例7: create
/**
* Create a new topic.
*
* The values array may have the following keys:
* - parent_id - parent topic identifier
* - id - topic identifier; if not supplied generated automatically
* - node_left
* - node_right
* - names - array of topic translations of the form: language_id => name
*
* @param array $p_values
* @return boolean
*/
public function create($p_values = null, $p_allNamesRequired = false)
{
global $g_ado_db;
if (!isset($p_values['names']) || !is_array($p_values['names'])) {
return false;
}
$names_available = array();
$names_occupied = array();
foreach ($p_values['names'] as $check_lang_id => $check_topic_name) {
$check_name_obj = new \TopicName($check_topic_name, $check_lang_id);
if ($check_name_obj->exists()) {
$names_occupied[$check_lang_id] = $check_topic_name;
} else {
$names_available[$check_lang_id] = $check_topic_name;
}
unset($check_name_obj);
}
if (empty($names_available)) {
return false;
}
if ($p_allNamesRequired) {
if (!empty($names_occupied)) {
return false;
}
}
$p_values['names'] = $names_available;
$g_ado_db->Execute("LOCK TABLE Topics WRITE, TopicNames WRITE");
if (isset($p_values['parent_id']) && !empty($p_values['parent_id'])) {
$parent = new Topic($p_values['parent_id']);
if (!$parent->exists()) {
$g_ado_db->Execute("UNLOCK TABLES");
return false;
}
$parentLeft = (int) $parent->getLeft();
} else {
$parentLeft = 0;
}
$g_ado_db->Execute("UPDATE Topics SET node_left = node_left + 2 WHERE node_left > {$parentLeft}");
$g_ado_db->Execute("UPDATE Topics SET node_right = node_right + 2 WHERE node_right > {$parentLeft}");
$this->m_data['node_left'] = $parentLeft + 1;
$this->m_data['node_right'] = $parentLeft + 2;
$some_name_set = false;
$some_name_not_set = false;
// create node
if ($success = parent::create($p_values)) {
// create topic names
foreach ($p_values['names'] as $languageId => $name) {
$topicName = new TopicName($this->getTopicId(), $languageId);
$res = $topicName->create(array('name' => $name));
if ($res) {
$some_name_set = true;
$this->m_names[$languageId] = $topicName;
} else {
$some_name_not_set = true;
}
}
if ($p_allNamesRequired && $some_name_not_set) {
\TopicName::DeleteTopicNames($this->getTopicId());
$success = false;
}
if (!$some_name_set) {
$success = false;
}
if (!$success) {
$g_ado_db->Execute("DELETE FROM Topics WHERE id = " . $this->getTopicId());
}
}
if (!$success) {
$g_ado_db->Execute("UPDATE Topics SET node_left = node_left - 2 WHERE node_left > ({$parentLeft} + 2)");
$g_ado_db->Execute("UPDATE Topics SET node_right = node_right - 2 WHERE node_right > ({$parentLeft} + 2)");
}
$g_ado_db->Execute("UNLOCK TABLES");
if ($success) {
$this->m_exists = true;
}
CampCache::singleton()->clear('user');
return $success;
}
示例8: GetList
/**
* Returns an blog topics list based on the given parameters.
*
* @param array $p_parameters
* An array of ComparisonOperation objects
* @param string $p_order
* An array of columns and directions to order by
* @param integer $p_start
* The record number to start the list
* @param integer $p_limit
* The offset. How many records from $p_start will be retrieved.
* @param integer $p_count
* The total count of the elements; this count is computed without
* applying the start ($p_start) and limit parameters ($p_limit)
*
* @return array $blogTopicsList
* An array of Topic objects
*/
public static function GetList(array $p_parameters, $p_order = null,
$p_start = 0, $p_limit = 0, &$p_count)
{
global $g_ado_db;
$selectClauseObj = new SQLSelectClause();
$countClauseObj = new SQLSelectClause();
// processes the parameters
foreach ($p_parameters as $parameter) {
$comparisonOperation = self::ProcessListParameters($parameter);
if (sizeof($comparisonOperation) < 1) {
break;
}
if (strpos($comparisonOperation['left'], 'fk_entry_id') !== false) {
$hasBlogentryId = true;
}
$whereCondition = $comparisonOperation['left'] . ' '
. $comparisonOperation['symbol'] . " '"
. $g_ado_db->escape($comparisonOperation['right']) . "' ";
$selectClauseObj->addWhere($whereCondition);
$countClauseObj->addWhere($whereCondition);
}
// validates whether blog number was given
if ($hasBlogentryId == false) {
CampTemplate::singleton()->trigger_error("missed parameter Blogentry Number in statement list_blog_topics");
return array();
}
// sets the main table and columns to be fetched
$tmpBlogentryTopic = new BlogentryTopic();
$selectClauseObj->setTable($tmpBlogentryTopic->getDbTableName());
$selectClauseObj->addColumn('fk_topic_id');
$countClauseObj->setTable($tmpBlogentryTopic->getDbTableName());
$countClauseObj->addColumn('COUNT(*)');
unset($tmpBlogTopic);
if (!is_array($p_order)) {
$p_order = array();
}
// sets the order condition if any
foreach ($p_order as $orderColumn => $orderDirection) {
$selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
}
// sets the limit
$selectClauseObj->setLimit($p_start, $p_limit);
// builds the query and executes it
$selectQuery = $selectClauseObj->buildQuery();
$topics = $g_ado_db->GetAll($selectQuery);
if (!is_array($topics)) {
return array();
}
$countQuery = $countClauseObj->buildQuery();
$p_count = $g_ado_db->GetOne($countQuery);
// builds the array of topic objects
$blogentryTopicsList = array();
foreach ($topics as $topic) {
$topObj = new Topic($topic['fk_topic_id']);
if ($topObj->exists()) {
$blogentryTopicsList[] = $topObj;
}
}
return $blogentryTopicsList;
} // fn GetList
示例9: GetList
//.........这里部分代码省略.........
{
global $g_ado_db;
if (!$p_skipCache && CampCache::IsEnabled()) {
$paramsArray['parameters'] = serialize($p_parameters);
$paramsArray['order'] = (is_null($p_order)) ? 'null' : $p_order;
$paramsArray['start'] = $p_start;
$paramsArray['limit'] = $p_limit;
$cacheListObj = new CampCacheList($paramsArray, __METHOD__);
$articleTopicsList = $cacheListObj->fetchFromCache();
if ($articleTopicsList !== false
&& is_array($articleTopicsList)) {
return $articleTopicsList;
}
}
$selectClauseObj = new SQLSelectClause();
$countClauseObj = new SQLSelectClause();
$rootTopicIds = array();
// processes the parameters
foreach ($p_parameters as $parameter) {
$comparisonOperation = self::ProcessListParameters($parameter);
if (sizeof($comparisonOperation) < 1) {
break;
}
if (strpos($comparisonOperation['left'], 'NrArticle') !== false) {
$hasArticleNr = true;
}
if (strpos($comparisonOperation['left'], 'RootTopic') !== false) {
$rootTopicIds[] = (int)$comparisonOperation['right'];
continue;
}
$whereCondition = $comparisonOperation['left'] . ' '
. $comparisonOperation['symbol'] . " '"
. $g_ado_db->escape($comparisonOperation['right']) . "' ";
$selectClauseObj->addWhere($whereCondition);
$countClauseObj->addWhere($whereCondition);
}
// validates whether article number was given
if ($hasArticleNr === false) {
CampTemplate::singleton()->trigger_error("missed parameter Article Number in statement list_article_topics");
return array();
}
if(count($rootTopicIds) > 0) {
$subtopicsQuery = Topic::BuildSubtopicsQueryWithoutDepth($rootTopicIds);
$whereCondition = 'TopicId IN ('.$subtopicsQuery->buildQuery().')';
$selectClauseObj->addWhere($whereCondition);
$countClauseObj->addWhere($whereCondition);
}
// sets the main table and columns to be fetched
$tmpArticleTopic = new ArticleTopic();
$selectClauseObj->setTable($tmpArticleTopic->getDbTableName());
$selectClauseObj->addColumn('TopicId');
$countClauseObj->setTable($tmpArticleTopic->getDbTableName());
$countClauseObj->addColumn('COUNT(*)');
unset($tmpArticleTopic);
if (!is_array($p_order)) {
$p_order = array();
}
// sets the order condition if any
foreach ($p_order as $orderColumn => $orderDirection) {
$selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
}
// sets the limit
$selectClauseObj->setLimit($p_start, $p_limit);
// builds the query and executes it
$selectQuery = $selectClauseObj->buildQuery();
$topics = $g_ado_db->GetAll($selectQuery);
if (is_array($topics)) {
$countQuery = $countClauseObj->buildQuery();
$p_count = $g_ado_db->GetOne($countQuery);
// builds the array of topic objects
$articleTopicsList = array();
foreach ($topics as $topic) {
$topObj = new Topic($topic['TopicId']);
if ($topObj->exists()) {
$articleTopicsList[] = $topObj;
}
}
} else {
$articleTopicsList = array();
$p_count = 0;
}
if (!$p_skipCache && CampCache::IsEnabled()) {
$cacheListObj->storeInCache($articleTopicsList);
}
return $articleTopicsList;
} // fn GetList
示例10: Article
camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()), null, true);
exit;
}
if (!$g_user->hasPermission('AttachTopicToArticle')) {
camp_html_display_error(getGS("You do not have the right to detach topics from articles."), null, true);
exit;
}
$articleObj = new Article($f_language_selected, $f_article_number);
if (!$articleObj->exists()) {
camp_html_display_error(getGS('Article does not exist.'), null, true);
exit;
}
$topicObj = new Topic($f_topic_id);
if (!$topicObj->exists()) {
camp_html_display_error(getGS('Topic does not exist.'), null, true);
exit;
}
ArticleTopic::RemoveTopicFromArticle($f_topic_id, $f_article_number);
$topicName = $topicObj->getName($f_language_selected);
if (empty($topicName)) {
$topicName = $topicObj->getName(1);
}
camp_html_add_msg(getGS("The topic '$1' has been removed from article.", $topicName), "ok");
$url = camp_html_article_url($articleObj, $f_language_id, "edit.php");
camp_html_goto_page($url);
?>
示例11: ProcessConstraints
/**
* Processes list constraints passed in an array.
*
* @param array $p_constraints
* @return array
*/
protected function ProcessConstraints(array $p_constraints)
{
$parameters = array();
$state = 1;
$attribute = null;
$operator = null;
$value = null;
foreach ($p_constraints as $index=>$word) {
switch ($state) {
case 1: // reading the parameter name
$attribute = strtolower($word);
if (!array_key_exists($attribute, self::$s_parameters)) {
CampTemplate::singleton()->trigger_error("invalid attribute $word in statement list_blogentries, constraints parameter");
return false;
}
if ($attribute == 'keyword') {
$operator = new Operator('is', 'string');
$state = 3;
} elseif ($attribute == 'matchalltopics' || $attribute == 'matchanytopic') {
if ($attribute == 'matchalltopics') {
$operator = new Operator('is', 'boolean');
$comparisonOperation = new ComparisonOperation($attribute, $operator, 'true');
$parameters[] = $comparisonOperation;
}
$state = 1;
} else {
$state = 2;
}
if ($attribute == 'onfrontpage' || $attribute == 'onsection') {
if (($index + 1) < count($p_constraints)) {
try {
$operator = new Operator($p_constraints[$index+1], 'switch');
}
catch (InvalidOperatorException $e) {
$operator = new Operator('is', 'switch');
$comparisonOperation = new ComparisonOperation($attribute, $operator, 'on');
$parameters[] = $comparisonOperation;
$state = 1;
}
} else {
$operator = new Operator('is', 'switch');
$comparisonOperation = new ComparisonOperation($attribute, $operator, 'on');
$parameters[] = $comparisonOperation;
$state = 1;
}
}
break;
case 2: // reading the operator
$type = self::$s_parameters[$attribute]['type'];
try {
$operator = new Operator($word, $type);
}
catch (InvalidOperatorException $e) {
CampTemplate::singleton()->trigger_error("invalid operator $word of parameter constraints.$attribute in statement list_blogentries");
return false;
}
$state = 3;
break;
case 3: // reading the value to compare against
$type = self::$s_parameters[$attribute]['type'];
$metaClassName = 'Meta'.ucfirst($type);
try {
$valueObj = new $metaClassName($word);
} catch (InvalidValueException $e) {
CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_blogentries");
return false;
}
if ($attribute == 'type') {
$word = trim($word);
$blogType = new BlogType($word);
if (!$blogType->exists()) {
CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_blogentries");
return false;
}
$value = $word;
} elseif ($attribute == 'topic') {
$topicObj = new Topic($word);
if (!$topicObj->exists()) {
CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_blogentries");
return false;
} else {
$value = $topicObj->getTopicId();
}
} elseif ($attribute == 'author') {
if (strtolower($word) == '__current') {
$context = CampTemplate::singleton()->context();
$value = $context->blog->author->name;
} else {
$value = $word;
}
} else {
$value = $word;
}
$comparisonOperation = new ComparisonOperation($attribute, $operator, $value);
//.........这里部分代码省略.........
示例12: GetList
/**
* Returns an articles list based on the given parameters.
*
* @param array $p_parameters
* An array of ComparisonOperation objects
* @param string $p_order
* An array of columns and directions to order by
* @param integer $p_start
* The record number to start the list
* @param integer $p_limit
* The offset. How many records from $p_start will be retrieved.
* @param integer $p_count
* The total count of the elements; this count is computed without
* applying the start ($p_start) and limit parameters ($p_limit)
*
* @return array $articlesList
* An array of Article objects
*/
public static function GetList(array $p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false, $returnObjs = true)
{
global $g_ado_db;
if (!$p_skipCache && CampCache::IsEnabled()) {
$paramsArray['parameters'] = serialize($p_parameters);
$paramsArray['order'] = is_null($p_order) ? 'null' : $p_order;
$paramsArray['start'] = $p_start;
$paramsArray['limit'] = $p_limit;
$cacheListObj = new CampCacheList($paramsArray, __METHOD__);
$articlesList = $cacheListObj->fetchFromCache();
if ($articlesList !== false && is_array($articlesList)) {
return $articlesList;
}
}
$matchAllTopics = false;
$hasTopics = array();
$hasNotTopics = array();
$selectClauseObj = new SQLSelectClause();
$otherTables = array();
// sets the name of the table for the this database object
$tmpArticle = new Article();
$articleTable = $tmpArticle->getDbTableName();
$selectClauseObj->setTable($articleTable);
unset($tmpArticle);
$languageId = null;
// parses the given parameters in order to build the WHERE part of
// the SQL SELECT sentence
foreach ($p_parameters as $param) {
$comparisonOperation = self::ProcessListParameters($param, $otherTables);
$leftOperand = strtolower($comparisonOperation['left']);
if ($leftOperand == 'idlanguage' && $comparisonOperation['symbol'] == '=') {
$languageId = $comparisonOperation['right'];
}
if (array_key_exists($leftOperand, Article::$s_regularParameters)) {
// regular article field, having a direct correspondent in the
// Article table fields
$whereCondition = Article::$s_regularParameters[$leftOperand] . ' ' . $comparisonOperation['symbol'] . " " . $g_ado_db->escape($comparisonOperation['right']) . " ";
if ($leftOperand == 'reads' && strstr($comparisonOperation['symbol'], '=') !== false && $comparisonOperation['right'] == 0) {
$selectClauseObj->addConditionalWhere($whereCondition);
$isNullCond = Article::$s_regularParameters[$leftOperand] . ' IS NULL';
$selectClauseObj->addConditionalWhere($isNullCond);
} elseif ($leftOperand == 'type' && $comparisonOperation['symbol'] == '=') {
$selectClauseObj->addConditionalWhere($whereCondition);
} elseif ($leftOperand == 'workflow_status' && isset($comparisonOperation['pending'])) {
$selectClauseObj->addConditionalWhere('Articles.NrIssue = 0');
$selectClauseObj->addConditionalWhere('Articles.NrSection = 0');
$selectClauseObj->addWhere($whereCondition);
} else {
$selectClauseObj->addWhere($whereCondition);
}
} elseif ($leftOperand == 'matchalltopics') {
// set the matchAllTopics flag
$matchAllTopics = true;
} elseif ($leftOperand == 'topic') {
// add the topic to the list of match/do not match topics depending
// on the operator
$topic = new Topic($comparisonOperation['right']);
if ($topic->exists()) {
$topicIds = $topic->getSubtopics(true, 0);
$topicIds[] = $comparisonOperation['right'];
if ($comparisonOperation['symbol'] == '=') {
$hasTopics[] = $topicIds;
} else {
$hasNotTopics[] = $topicIds;
}
}
} elseif ($leftOperand == 'author') {
$otherTables['ArticleAuthors'] = array('__JOIN' => ',');
$author = Author::ReadName($comparisonOperation['right']);
$symbol = $comparisonOperation['symbol'];
$valModifier = strtolower($symbol) == 'like' ? '%' : '';
$firstName = trim($g_ado_db->escape($author['first_name']), "'");
$lastName = trim($g_ado_db->escape($author['last_name']), "'");
$whereCondition = "ArticleAuthors.fk_author_id IN\n (SELECT Authors.id\n FROM Authors\n WHERE CONCAT(Authors.first_name, ' ', Authors.last_name) {$symbol}\n '{$valModifier}{$firstName} {$lastName}{$valModifier}')";
$selectClauseObj->addWhere($whereCondition);
$selectClauseObj->addWhere('Articles.Number = ArticleAuthors.fk_article_number');
$selectClauseObj->addWhere('Articles.IdLanguage = ArticleAuthors.fk_language_id');
} elseif ($leftOperand == 'search_phrase') {
$searchQuery = ArticleIndex::SearchQuery($comparisonOperation['right'], $comparisonOperation['symbol']);
if (!empty($searchQuery)) {
$otherTables["({$searchQuery})"] = array('__TABLE_ALIAS' => 'search', '__JOIN' => 'INNER JOIN', 'Number' => 'NrArticle', 'IdLanguage' => 'IdLanguage');
}
//.........这里部分代码省略.........
示例13: create
/**
* Create a new topic.
*
* The values array may have the following keys:
* - parent_id - parent topic identifier
* - id - topic identifier; if not supplied generated automatically
* - node_left
* - node_right
* - names - array of topic translations of the form: language_id => name
*
* @param array $p_values
* @return boolean
*/
public function create($p_values = null)
{
global $g_ado_db;
if (!isset($p_values['names'])) {
return false;
}
$g_ado_db->Execute("LOCK TABLE Topics WRITE, TopicNames WRITE");
if (isset($p_values['parent_id']) && !empty($p_values['parent_id'])) {
$parent = new Topic($p_values['parent_id']);
if (!$parent->exists()) {
$g_ado_db->Execute("UNLOCK TABLES");
return false;
}
$parentLeft = (int)$parent->getLeft();
} else {
$parentLeft = 0;
}
$g_ado_db->Execute("UPDATE Topics SET node_left = node_left + 2 WHERE node_left > $parentLeft");
$g_ado_db->Execute("UPDATE Topics SET node_right = node_right + 2 WHERE node_right > $parentLeft");
$this->m_data['node_left'] = $parentLeft + 1;
$this->m_data['node_right'] = $parentLeft + 2;
// create node
if ($success = parent::create($p_values)) {
// create topic names
foreach ($p_values['names'] as $languageId=>$name) {
$topicName = new TopicName($this->getTopicId(), $languageId);
$topicName->create(array('name'=>$name));
$this->m_names[$languageId] = $topicName;
}
}
$g_ado_db->Execute("UNLOCK TABLES");
if ($success) {
$this->m_exists = true;
if (function_exists("camp_load_translation_strings")) {
camp_load_translation_strings("api");
}
$logtext = getGS('Topic "$1" ($2) added', implode(', ', $this->m_names), $this->m_data['id']);
Log::Message($logtext, null, 141);
}
CampCache::singleton()->clear('user');
return $success;
} // fn create