本文整理汇总了PHP中Topic::getSubtopics方法的典型用法代码示例。如果您正苦于以下问题:PHP Topic::getSubtopics方法的具体用法?PHP Topic::getSubtopics怎么用?PHP Topic::getSubtopics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topic
的用法示例。
在下文中一共展示了Topic::getSubtopics方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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']);
//.........这里部分代码省略.........
示例2: array
$f_topic_delete_id = Input::Get('f_topic_delete_id', 'int', 0);
$errorMsgs = array();
$doDelete = true;
$deleteTopic = new Topic($f_topic_delete_id);
if ($deleteTopic->hasSubtopics()) {
$doDelete = false;
$errorMsgs[] = getGS('This topic has subtopics, therefore it cannot be deleted.');
}
$numArticles = count(ArticleTopic::GetArticlesWithTopic($f_topic_delete_id));
if ($numArticles > 0) {
$doDelete = false;
$errorMsgs[] = getGS('There are $1 articles using the topic.', $numArticles);
}
if ($f_confirmed == 1) {
// get a list of subtopics
$deleteTopics = $deleteTopic->getSubtopics();
// detach all subtopics from all articles
foreach ($deleteTopics as $topic) {
ArticleTopic::RemoveTopicFromArticles($topic->getTopicId());
}
// delete all subtopics
foreach ($deleteTopics as $topic) {
$topic->delete($f_topic_language_id);
}
$doDelete = true;
}
if ($doDelete) {
ArticleTopic::RemoveTopicFromArticles($deleteTopic->getTopicId());
$deleted = $deleteTopic->delete($f_topic_language_id);
if ($deleted) {
camp_html_add_msg(getGS("Topic was deleted."), "ok");
示例3: UpdateOrder
/**
* Update order for all items in tree.
*
* @param array $order
* $parent => array(
* $order => $topicId
* );
* @return bool
*/
public static function UpdateOrder(array $p_order)
{
global $g_ado_db;
$orderChanged = false;
foreach ($p_order as $parentId => $order) {
list(, $parentId) = explode('_', $parentId);
$parentTopic = new Topic((int) $parentId);
$subtopics = $parentTopic->getSubtopics(true);
if (count($subtopics) != count($order)) {
return false;
}
foreach ($order as $newTopicOrder => $topicId) {
list(, $topicId) = explode('_', $topicId);
if ($subtopics[$newTopicOrder] != $topicId) {
$oldTopicOrder = array_search($topicId, $subtopics);
self::SwitchTopics($subtopics[$newTopicOrder], $topicId, $parentTopic);
$subtopics[$oldTopicOrder] = $subtopics[$newTopicOrder];
$subtopics[$newTopicOrder] = $topicId;
$orderChanged = true;
}
}
}
if ($orderChanged) {
CampCache::singleton()->clear('user');
}
return TRUE;
}
示例4: testCreate
public function testCreate()
{
// test create(), fetch(), getLeft(), getRight(), getName()
$this->createAndTest(1, array('names'=>array(1=>'Sports', 2=>'Sport')), 1, 2);
$this->createAndTest(3, array('names'=>array(1=>'Electronics', 2=>'Electronice')), 1, 2);
$this->createAndTest(2, array('names'=>array(1=>'Education', 2=>'Educație')), 1, 2);
$this->createAndTest(27, array('names'=>array(1=>'Health', 2=>'Sănătate')), 1, 2);
$this->createAndTest(4, array('parent_id'=>3, 'names'=>array(1=>'Televisions', 2=>'Televizoare')), 6, 7);
$this->createAndTest(9, array('parent_id'=>3, 'names'=>array(1=>'Portable Electronics', 2=>'Electronice portabile')), 6, 7);
$this->createAndTest(14, array('parent_id'=>2, 'names'=>array(1=>'Culture', 2=>'Cultură')), 4, 5);
$this->createAndTest(15, array('parent_id'=>2, 'names'=>array(1=>'Science', 2=>'Știință')), 4, 5);
$this->createAndTest(26, array('parent_id'=>2, 'names'=>array(1=>'Religion', 2=>'Religie')), 4, 5);
$this->createAndTest(16, array('parent_id'=>14, 'names'=>array(1=>'Music', 2=>'Muzică')), 9, 10);
$this->createAndTest(19, array('parent_id'=>14, 'names'=>array(1=>'Film', 2=>'Film')), 9, 10);
$this->createAndTest(22, array('parent_id'=>14, 'names'=>array(1=>'Books', 2=>'Cărți')), 9, 10);
$this->createAndTest(17, array('parent_id'=>16, 'names'=>array(1=>'Classical', 2=>'Clasică')), 14, 15);
$this->createAndTest(18, array('parent_id'=>16, 'names'=>array(1=>'Jazz', 2=>'Jazz')), 14, 15);
$this->createAndTest(24, array('parent_id'=>15, 'names'=>array(1=>'Physics', 2=>'Fizică')), 7, 8);
$this->createAndTest(25, array('parent_id'=>15, 'names'=>array(1=>'Mathematics', 2=>'Matematică')), 7, 8);
// test constructor and GetByFullName()
$topic = new Topic('Physics:en');
// test other get methods
$this->assertEquals(24, $topic->getTopicId());
$this->assertEquals(15, $topic->getParentId());
$this->assertEquals(2, $topic->getNumTranslations());
$translations = array(1=>new TopicName(24, 1), 2=>new TopicName(24, 2));
$this->assertEquals($translations, $topic->getTranslations());
$path = array(2=>new Topic(2), 15=>new Topic(15), 24=>new Topic(24));
$pathIds = array(2=>2, 15=>15, 24=>24);
$this->assertEquals($path, $topic->getPath());
$this->assertEquals($pathIds, $topic->getPath(true));
$this->assertFalse($topic->hasSubtopics());
$this->assertFalse($topic->isRoot());
$this->assertEquals(1, $topic->getWidth());
$this->assertEquals(array(), $topic->getSubtopics());
$topic = new Topic('Educație:ro');
$this->assertTrue($topic->isRoot());
$this->assertTrue($topic->hasSubtopics());
$this->assertEquals(21, $topic->getWidth());
$this->assertEquals(null, $topic->getParentId());
$this->assertEquals(array(2=>new Topic(2)), $topic->getPath());
$subtopicsDepth1 = array(new Topic(26), new Topic(15), new Topic(14));
$subtopicsDepth1Ids = array(26, 15, 14);
$this->assertEquals($subtopicsDepth1, $topic->getSubtopics());
$this->assertEquals($subtopicsDepth1Ids, $topic->getSubtopics(true));
$subtopicsDepth2 = array(new Topic(26), new Topic(15), new Topic(25), new Topic(24),
new Topic(14), new Topic(22), new Topic(19), new Topic(16));
$this->assertEquals($subtopicsDepth2, $topic->getSubtopics(false, 2));
$subtopicsAll = array(new Topic(26), new Topic(15), new Topic(25), new Topic(24),
new Topic(14), new Topic(22), new Topic(19), new Topic(16), new Topic(18), new Topic(17));
$this->assertEquals($subtopicsAll, $topic->getSubtopics(false, 0));
$topics = array(new Topic(2));
$this->assertEquals($topics, Topic::GetTopics(2));
$this->assertEquals($topics, Topic::GetTopics(null, 1, 'Education'));
$this->assertEquals($subtopicsDepth1, Topic::GetTopics(null, null, null, 2));
$this->assertEquals($subtopicsAll, Topic::GetTopics(null, null, null, 2, 0));
$subtopicsDepth1Name = array(new Topic(14), new Topic(26), new Topic(15));
$this->assertEquals($subtopicsDepth1Name, Topic::GetTopics(null, 1, null, 2, 1,
null, array(array('field'=>'byname', 'dir'=>'asc'))));
$tree = array(
array(27=>new Topic(27)),
array(2=>new Topic(2)),
array(2=>new Topic(2), 26=>new Topic(26)),
array(2=>new Topic(2), 15=>new Topic(15)),
array(2=>new Topic(2), 15=>new Topic(15), 25=>new Topic(25)),
array(2=>new Topic(2), 15=>new Topic(15), 24=>new Topic(24)),
array(2=>new Topic(2), 14=>new Topic(14)),
array(2=>new Topic(2), 14=>new Topic(14), 22=>new Topic(22)),
array(2=>new Topic(2), 14=>new Topic(14), 19=>new Topic(19)),
array(2=>new Topic(2), 14=>new Topic(14), 16=>new Topic(16)),
array(2=>new Topic(2), 14=>new Topic(14), 16=>new Topic(16), 18=>new Topic(18)),
array(2=>new Topic(2), 14=>new Topic(14), 16=>new Topic(16), 17=>new Topic(17)),
array(3=>new Topic(3)),
array(3=>new Topic(3), 9=>new Topic(9)),
array(3=>new Topic(3), 4=>new Topic(4)),
array(1=>new Topic(1))
//.........这里部分代码省略.........
示例5: 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');
}
//.........这里部分代码省略.........