本文整理汇总了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;
}