本文整理汇总了PHP中Tags::normalizeTag方法的典型用法代码示例。如果您正苦于以下问题:PHP Tags::normalizeTag方法的具体用法?PHP Tags::normalizeTag怎么用?PHP Tags::normalizeTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tags
的用法示例。
在下文中一共展示了Tags::normalizeTag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testValidation
public function testValidation()
{
$contact = $this->contacts('testAnyone');
$tag = new Tags();
$tag->setAttributes(array('itemId' => $contact->id, 'type' => get_class($contact), 'itemName' => $contact->name, 'tag' => 'test', 'taggedBy' => 'testuser'));
$this->assertSaves($tag);
// ensure that normalization was performed upon validation
$this->assertEquals(Tags::normalizeTag('test'), $tag->tag);
// ensure that tag must be unique
$tag = new Tags();
$tag->setAttributes(array('itemId' => $contact->id, 'type' => get_class($contact), 'itemName' => $contact->name, 'tag' => 'test', 'taggedBy' => 'testuser'));
$tag->validate();
$this->assertTrue($tag->hasErrors('tag'));
// ensure that tag must be unique
$tag = new Tags();
$tag->setAttributes(array('itemId' => $contact->id, 'type' => get_class($contact), 'itemName' => $contact->name, 'tag' => '#test', 'taggedBy' => 'testuser'));
$tag->validate();
$this->assertTrue($tag->hasErrors('tag'));
// ensure that tag must be unique
$tag = new Tags();
$tag->setAttributes(array('itemId' => $contact->id, 'type' => get_class($contact), 'itemName' => $contact->name, 'tag' => '#test,', 'taggedBy' => 'testuser'));
$tag->validate();
$this->assertTrue($tag->hasErrors('tag'));
}
示例2: normalizeTags
public static function normalizeTags(array $tags, $suppressHash = false)
{
foreach ($tags as &$tag) {
$tag = Tags::normalizeTag($tag, $suppressHash);
}
return $tags;
}
示例3: addTags
/**
* Adds the specified tag(s) to the owner model, but not
* if the tag has already been added.
* @param mixed $tags a string or array of strings containing tags
* @return boolean whether or not at least one tag was added successfully
*/
public function addTags($tags)
{
$result = false;
$addedTags = array();
foreach ((array) $tags as $tagName) {
if (empty($tagName)) {
continue;
}
if (!$this->hasTag($tagName)) {
// check for duplicate tag
$tag = new Tags();
$tag->tag = Tags::normalizeTag($tagName);
$tag->itemId = $this->getOwner()->id;
$tag->type = get_class($this->getOwner());
$tag->taggedBy = Yii::app()->getSuName();
$tag->timestamp = time();
$tag->itemName = $this->getOwner()->name;
if ($tag->save()) {
$this->_tags[] = $tag->tag;
// update tag cache
$addedTags[] = $tagName;
$result = true;
} else {
throw new CHttpException(422, 'Failed saving tag due to errors: ' . json_encode($tag->errors));
}
}
}
if ($this->flowTriggersEnabled) {
X2Flow::trigger('RecordTagAddTrigger', array('model' => $this->getOwner(), 'tags' => $addedTags));
}
return $result;
}