当前位置: 首页>>代码示例>>PHP>>正文


PHP Tags::normalizeTag方法代码示例

本文整理汇总了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'));
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:24,代码来源:TagsTest.php

示例2: normalizeTags

 public static function normalizeTags(array $tags, $suppressHash = false)
 {
     foreach ($tags as &$tag) {
         $tag = Tags::normalizeTag($tag, $suppressHash);
     }
     return $tags;
 }
开发者ID:shayanyi,项目名称:CRM,代码行数:7,代码来源:Tags.php

示例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;
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:38,代码来源:TagBehavior.php


注:本文中的Tags::normalizeTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。