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


PHP Tag类代码示例

本文整理汇总了PHP中Tag的典型用法代码示例。如果您正苦于以下问题:PHP Tag类的具体用法?PHP Tag怎么用?PHP Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Tag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upgradeTo02

 /**
  * @return void
  */
 protected function upgradeTo02()
 {
     // Add Tag-column
     /* @var CDbCommand $cmd */
     $cmd = Yii::app()->db->createCommand();
     $cmd->addColumn('Tag', 'userId', 'integer NOT NULL');
     $cmd->addForeignKey('user', 'Tag', 'userId', 'User', 'id', 'CASCADE', 'CASCADE');
     // Refresh DB-Schema
     Yii::app()->db->schema->refresh();
     Tag::model()->refreshMetaData();
     // Set user-IDs
     foreach (Tag::model()->findAll() as $model) {
         // Collect User-IDs
         $userIds = array();
         foreach ($model->entries as $entry) {
             $userIds[$entry->userId] = $entry->userId;
         }
         // Save tag with user relation
         foreach ($userIds as $userId) {
             $tag = new Tag();
             $tag->name = $model->name;
             $tag->userId = $userId;
             $tag->save(false);
         }
         // Remove tag
         $model->delete();
     }
 }
开发者ID:humantech,项目名称:ppma,代码行数:31,代码来源:UpgradeController.php

示例2: recordTags

 public static function recordTags($phrase, $model, $obj)
 {
     $tags = TagTools::splitPhrase($phrase);
     foreach ($tags as $settag) {
         $tag = new Tag();
         if ($model == "etime") {
             $modelTag = new EtimeTag();
         } else {
             $modelTag = new EventTag();
         }
         $tag->setTag($settag);
         $c = new Criteria();
         $c->add(TagPeer::NORMALIZED_TAG, $tag->getNormalizedTag());
         $tag_exists = TagPeer::doSelectOne($c);
         if (!$tag_exists) {
             $tag->save();
         } else {
             $tag = $tag_exists;
         }
         if ($model == "etime") {
             $modelTag->setEtime($obj);
         } else {
             $modelTag->setEvent($obj);
         }
         $modelTag->setTag($tag);
         $modelTag->save();
     }
     return true;
 }
开发者ID:soon0009,项目名称:EMS,代码行数:29,代码来源:TagTools.class.php

示例3: setTags

 /**
  * @param array $tags
  */
 public function setTags(array $tags)
 {
     foreach ($tags as $tag) {
         $tag = new Tag($tag);
         $this->tags[$tag->getName()] = $tag;
     }
 }
开发者ID:freyr,项目名称:gallery,代码行数:10,代码来源:Photo.php

示例4: newTag

 /**
  * @param sfGuardUser $user
  * @param integer $element_id
  * @param string $name
  * @param string $type
  */
 public static function newTag($user, $element_id, $name, $type)
 {
     $tag = TagTable::getInstance()->findOneByNameAndUserId($name, $user->id);
     if (!$tag) {
         $tag = new Tag();
         $tag->setName(substr($name, 0, self::MAX_LENGTH));
         $tag->setUserId($user->id);
         $tag->save();
     }
     if ($type == 'decision') {
         $tagDecision = new TagDecision();
         $tagDecision->setDecisionId($element_id);
         $tagDecision->setTagId($tag->id);
         $tagDecision->save();
     } else {
         if ($type == 'release') {
             $tagRelease = new TagRelease();
             $tagRelease->setReleaseId($element_id);
             $tagRelease->setTagId($tag->id);
             $tagRelease->save();
         } else {
             $tagAlternative = new TagAlternative();
             $tagAlternative->setAlternativeId($element_id);
             $tagAlternative->setTagId($tag->id);
             $tagAlternative->save();
             Doctrine_Query::create()->delete('Graph')->where('decision_id = ?', $tagAlternative->Alternative->decision_id)->execute();
         }
     }
     return;
 }
开发者ID:sensorsix,项目名称:app,代码行数:36,代码来源:Tag.class.php

示例5: createAndSaveRawModelWithManyToManyRelation

 public static function createAndSaveRawModelWithManyToManyRelation()
 {
     include_once __DIR__ . '/../scripts/tested_models.php';
     $car = new \Car();
     $car->nameCar = 'AcmeCar';
     $car->noteCar = '10';
     $car->idBrand = 1;
     $car->save();
     $tags = array();
     $tag1 = new \Tag();
     $tag1->libTag = 'Sport';
     $tag1->save();
     $tag2 = new \Tag();
     $tag2->libTag = 'Family';
     $tag2->save();
     $tag3 = new \Tag();
     $tag3->libTag = 'Crossover';
     $tag3->save();
     $tags[] = $tag1;
     $tags[] = $tag2;
     $tags[] = $tag3;
     $car->setTag($tags);
     $car->save();
     // create test
     $req = \PicORM\Model::getDataSource()->prepare('SELECT count(*) as nb FROM car_have_tag WHERE idCar = ?');
     $req->execute(array($car->idCar));
     $resultBDD = $req->fetch(\PDO::FETCH_ASSOC);
     return array(array($car, $tags, $resultBDD));
 }
开发者ID:peacq,项目名称:picorm,代码行数:29,代码来源:Model.php

示例6: savePostTags

 public static function savePostTags($postid, $tags)
 {
     $postid = (int) $postid;
     if (0 === $postid || empty($tags)) {
         return false;
     }
     if (is_string($tags)) {
         $tags = self::filterTagsArray($tags);
     }
     $count = 0;
     foreach ((array) $tags as $v) {
         $model = self::model()->findByAttributes(array('name' => $v));
         if ($model === null) {
             $model = new Tag();
             $model->name = $v;
             if ($model->save()) {
                 $count++;
             }
         }
         $row = app()->getDb()->createCommand()->select('id')->from(TABLE_POST_TAG)->where(array('and', 'post_id = :postid', 'tag_id = :tagid'), array(':postid' => $postid, ':tagid' => $model->id))->queryScalar();
         if ($row === false) {
             $columns = array('post_id' => $postid, 'tag_id' => $model->id);
             $count = app()->getDb()->createCommand()->insert(TABLE_POST_TAG, $columns);
             if ($count > 0) {
                 $model->post_nums = $model->post_nums + 1;
                 $model->save(true, array('post_nums'));
             }
         }
         unset($model);
     }
     return $count;
 }
开发者ID:rainsongsky,项目名称:24beta,代码行数:32,代码来源:Tag.php

示例7: afterSave

    public function afterSave()
    {
        $this->_deleteRels();

        $model_id = get_class($this->owner);

        if (isset($_POST[$model_id]['tags']))
        {
            foreach (explode(',', $_POST[$model_id]['tags']) as $tag_name)
            {
                $tag = Tag::model()->find("name = '{$tag_name}'");
                if (!$tag)
                {
                    $tag = new Tag();
                    $tag->name = $tag_name;
                    $tag->save();
                }

                $tag_rel = new TagRel();
                $tag_rel->tag_id    = $tag->id;
                $tag_rel->object_id = $this->owner->id;
                $tag_rel->model_id  = $model_id;
            }
        }
    }
开发者ID:nizsheanez,项目名称:kur.ru,代码行数:25,代码来源:TagBehavior.php

示例8: json

 /**
  * The function returns JSON responses for different methods.
  * 
  * @access public
  * @param string $method THe method.
  * @return string The JSON response.
  */
 public function json($method = null)
 {
     $response = array();
     switch ($method) {
         case 'tags':
             $Tag = new Tag();
             $params = array();
             $params[] = $Tag->getParam('search', Request::get('term'));
             foreach ($Tag->findList($params, 'Name asc', 0, 20) as $Tag) {
                 $response[] = $Tag->Name;
             }
             break;
         case 'ref':
             $Object = null;
             $params = array();
             if (Request::get('field') == 'Reference[Page]') {
                 $Object = new Content_Page();
             } else {
                 if (Request::get('field') == 'Reference[Product]') {
                     $Object = new Product();
                 }
             }
             if ($Object) {
                 $params[] = $Object->getParam('search', Request::get('term'));
                 foreach ($Object->findShortList($params, 'Name asc', 0, 10) as $Object) {
                     printf("%d|%s\n", $Object->Id, $Object->Name);
                 }
             }
             exit;
             break;
     }
     return $this->outputJSON($response);
 }
开发者ID:vosaan,项目名称:ankor.local,代码行数:40,代码来源:articles.php

示例9: insertNewTag

 public static function insertNewTag($app_id, $name, PDO $con = null)
 {
     $row = array('app_id' => $app_id, 'name' => $name);
     $tag = new Tag($row);
     $tag->insert($con);
     return $tag;
 }
开发者ID:kzfk,项目名称:emlauncher,代码行数:7,代码来源:Tag.php

示例10: setOptions

 /**
  * Set the options available for this input.
  *
  * @param array[] $options Array of menu options in the format
  *   `array( 'data' => …, 'label' => … )`
  * @chainable
  */
 public function setOptions($options)
 {
     $value = $this->getValue();
     $isValueAvailable = false;
     $this->options = array();
     // Rebuild the dropdown menu
     $this->input->clearContent();
     foreach ($options as $opt) {
         $optValue = $this->cleanUpValue($opt['data']);
         $option = new Tag('option');
         $option->setAttributes(array('value' => $optValue));
         $option->appendContent(isset($opt['label']) ? $opt['label'] : $optValue);
         if ($value === $optValue) {
             $isValueAvailable = true;
         }
         $this->options[] = $option;
         $this->input->appendContent($option);
     }
     // Restore the previous value, or reset to something sensible
     if ($isValueAvailable) {
         // Previous value is still available
         $this->setValue($value);
     } else {
         // No longer valid, reset
         if (count($options)) {
             $this->setValue($options[0]['data']);
         }
     }
     return $this;
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:37,代码来源:DropdownInputWidget.php

示例11: viewAction

 public function viewAction()
 {
     $label = $this->_getParam('label');
     if ($label === null) {
         throw new Zend_Exception('No label specified in TagsController::viewAction()');
     }
     $tagManager = new Tag();
     $tag = $tagManager->fetchRow(array('label = ?' => $label));
     if ($tag === null) {
         throw new Zend_Exception('Tag not found in TagsController::viewAction()');
     }
     $this->view->tag = $tag;
     // get posts
     $page = array_key_exists('p', $_GET) ? $_GET['p'] : 1;
     $page = $page < 1 ? 1 : $page;
     $this->view->page = $page;
     $postManager = new Post();
     $postCount = $postManager->fetchAll(array('id IN (SELECT post_id FROM posts_tags WHERE tag_id = ?)' => $tag->id, 'is_active = ?' => 1))->count();
     $this->view->pageCount = ceil($postCount / 10);
     $this->view->posts = $postManager->fetchAll(array('id IN (SELECT post_id FROM posts_tags WHERE tag_id = ?)' => $tag->id, 'is_active = ?' => 1), 'posted_at DESC', 10, ($page - 1) * 10);
     $this->view->paginationBase = '/tags/' . $tag->label;
     // description
     $this->view->metaDescription = 'Read my posts tagged with \'' . $tag->title . '\'.';
     // set title
     $this->_title('Posts tagged with \'' . $tag->title . '\'');
     $this->_forward('listing', 'posts');
 }
开发者ID:neilgarb,项目名称:codecaine,代码行数:27,代码来源:TagsController.php

示例12: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $user_id = Auth::id();
     $comment = Input::get('comment');
     $tags = Input::get('tagged_uid');
     $rating = Input::get('rating');
     $type = Input::get('media_type');
     $imdb_id = Input::get('imdb_id');
     $post = new Post();
     $post->user_id = $user_id;
     $post->type = $type;
     $post->imdb_id = $imdb_id;
     $post->rating = $rating;
     $post->comment = $comment;
     $post->save();
     if (sizeof($tags) > 0) {
         foreach ($tags as $tagged_uid) {
             $tag = new Tag();
             $tag->post_id = $post->id;
             $tag->user_tagging = $user_id;
             $tag->user_tagged = $tagged_uid;
             $tag->save();
         }
     }
     return Redirect::to('/media/' . $imdb_id);
 }
开发者ID:jcanver,项目名称:seenjump,代码行数:31,代码来源:PostController.php

示例13: executeSaveTag

 public function executeSaveTag()
 {
     try {
         $parameters = $this->getRequest()->getParameterHolder()->getAll();
         if ($parameters['id']) {
             $obj = Document::getDocumentInstance($parameters['id']);
             $parent = Document::getParentOf($parameters['id']);
         } else {
             $obj = new Tag();
             $parent = Document::getDocumentInstance($parameters['parent']);
         }
         foreach ($parameters as $key => $value) {
             if (!(strpos($key, 'attr') === false)) {
                 $function = 'set' . str_replace('attr', '', $key);
                 $obj->{$function}($value);
             }
         }
         if (!$parameters['attrExclusive']) {
             $obj->setExclusive(0);
         }
         $obj->save(null, $parent);
         UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error");
     }
     PanelService::redirect('tag');
     exit;
 }
开发者ID:kotow,项目名称:work,代码行数:28,代码来源:actions.class.php

示例14: set_tags

 /**
  * set and add new tags to the post entity
  * @param string $val
  * @return array
  */
 public function set_tags($val)
 {
     if (!empty($val)) {
         $tagsArr = \Base::instance()->split($val);
         $tag_res = new Tag();
         $tags = array();
         // find IDs of known Tags
         $known_tags = $tag_res->find(array('title IN ?', $tagsArr));
         if ($known_tags) {
             foreach ($known_tags as $tag) {
                 $tags[$tag->_id] = $tag->title;
             }
             $newTags = array_diff($tagsArr, array_values($tags));
         } else {
             $newTags = $tagsArr;
         }
         // create remaining new Tags
         foreach ($newTags as $tag) {
             $tag_res->reset();
             $tag_res->title = $tag;
             $out = $tag_res->save();
             $tags[$out->_id] = $out->title;
         }
         // set array of IDs to current Post
         $val = array_keys($tags);
     }
     return $val;
 }
开发者ID:xfra35,项目名称:fabulog,代码行数:33,代码来源:post.php

示例15: cmpTags

 function cmpTags(Tag $a, Tag $b)
 {
     if ($a->SizeRelatedContext() == $b->SizeRelatedContent()) {
         return 0;
     }
     return $a->SizeRelatedContent() < $b->SizeRelatedContent() ? -1 : 1;
 }
开发者ID:basti92,项目名称:Qorum,代码行数:7,代码来源:DefaultController.php


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