當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。