本文整理匯總了PHP中Tags::normalizeTags方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tags::normalizeTags方法的具體用法?PHP Tags::normalizeTags怎麽用?PHP Tags::normalizeTags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tags
的用法示例。
在下文中一共展示了Tags::normalizeTags方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testNormalizeTags
public function testNormalizeTags()
{
$tags = array('test', '#test', '#test,', '##test,');
$normalizedTags = array('#test', '#test', '#test', '##test');
$normalizedTagsSuppressedHash = array('test', 'test', 'test', '#test');
$this->assertEquals($normalizedTags, Tags::normalizeTags($tags, false));
$this->assertEquals($normalizedTagsSuppressedHash, Tags::normalizeTags($tags, true));
}
示例2: testHasTag
public function testHasTag()
{
$contact = $this->contacts('testAnyone');
$contact->clearTags();
$tags = array('test', 'test2', 'test3');
foreach ($tags as $tag) {
$this->assertFalse($contact->hasTag($tag, null, true));
}
$contact->addTags($tags);
$contactTags = $contact->getTags(true);
$this->assertEquals(Tags::normalizeTags($tags), ArrayUtil::sort($contactTags));
foreach ($tags as $tag) {
$this->assertTrue($contact->hasTag($tag, null, true));
}
}
示例3: removeTags
/**
* Removes the specified tag(s) from the owner model
* @param mixed $tags a string or array of strings containing tags
* @return boolean whether or not at least one tag was deleted successfully
*/
public function removeTags($tags)
{
$result = false;
$removedTags = array();
$tags = Tags::normalizeTags((array) $tags);
foreach ((array) $tags as $tag) {
if (empty($tag)) {
continue;
}
$attributes = array('type' => get_class($this->getOwner()), 'itemId' => $this->getOwner()->id, 'tag' => $tag);
if ($this->hasTag($tag) && CActiveRecord::model('Tags')->deleteAllByAttributes($attributes) > 0) {
if (false !== ($offset = array_search($tag, $this->_tags))) {
unset($this->_tags[$offset]);
}
// update tag cache
$removedTags[] = $tag;
$result = true;
}
}
if ($this->flowTriggersEnabled) {
X2Flow::trigger('RecordTagRemoveTrigger', array('model' => $this->getOwner(), 'tags' => $removedTags));
}
return $result;
}