本文整理汇总了PHP中Tag类的典型用法代码示例。如果您正苦于以下问题:PHP Tag类的具体用法?PHP Tag怎么用?PHP Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tag类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: add
public static function add($id, $meta)
{
$desc = Description::create(['id' => $id, 'name' => $meta->name, 'market_name' => $meta->market_name ?: $meta->name, 'icon_url' => $meta->icon_url, 'icon_url_large' => isset($meta->icon_url_large) ? $meta->icon_url_large : '', 'name_color' => $meta->name_color ?: '000000']);
if (!empty($meta->actions)) {
foreach ($meta->actions as $idx => $action) {
if ($action->name == 'Inspect in Game...') {
$desc->inspect_url_template = $action->link;
$desc->save();
break;
}
}
}
foreach ($meta->tags as $idx => $tag_data) {
$tag = Tag::find('all', array('conditions' => array('category = ? AND category_name = ? AND internal_name = ? AND name = ?', $tag_data->category, $tag_data->category_name, $tag_data->internal_name, $tag_data->name)));
if (empty($tag)) {
$tag = new Tag(['category' => $tag_data->category, 'category_name' => $tag_data->category_name, 'internal_name' => $tag_data->internal_name, 'name' => $tag_data->name]);
if (!$tag->is_valid()) {
$desc->delete();
return null;
} else {
$tag->save();
}
} else {
$tag = $tag[0];
}
if ($tag_data->category == 'Rarity') {
$desc->name_color = $tag_data->color;
$desc->save();
}
Descriptiontag::create(['description_id' => $desc->id, 'tag_id' => $tag->id]);
}
return $desc;
}
开发者ID:puttyplayer,项目名称:CSGOShop,代码行数:33,代码来源:Description.php
示例17: cascadeInvalidationTo
public function cascadeInvalidationTo(Tag $tag)
{
$this->cascade[] = $tag;
if ($this->invalid) {
$tag->invalidate();
}
}
开发者ID:redstarxz,项目名称:flarumone,代码行数:7,代码来源:Tag.php
示例18: XML_Read
function XML_Read($Object, $Level = 1)
{
#-----------------------------------------------------------------------------
static $Index = 1;
#-----------------------------------------------------------------------------
$Md5 = Md5($Index++);
#-----------------------------------------------------------------------------
$Attribs = $Object->Attribs;
#-----------------------------------------------------------------------------
$Name = isset($Attribs['comment']) ? $Attribs['comment'] : $Object->Name;
#-----------------------------------------------------------------------------
$P = new Tag('P', array('class' => 'NodeName', 'onclick' => SPrintF("TreeSwitch('%s');", $Md5)), new Tag('IMG', array('align' => 'left', 'src' => 'SRC:{Images/Icons/Node.gif}')), new Tag('SPAN', $Name));
#-----------------------------------------------------------------------------
$Node = new Tag('DIV', array('class' => 'Node'), $P);
#-----------------------------------------------------------------------------
if (Count($Attribs)) {
#---------------------------------------------------------------------------
foreach (Array_Keys($Attribs) as $AttribID) {
$Node->AddChild(new Tag('P', array('class' => 'NodeParam'), new Tag('SPAN', SPrintF('%s: ', $AttribID)), new Tag('SPAN', array('class' => 'NodeParam'), $Attribs[$AttribID])));
}
}
#-----------------------------------------------------------------------------
if (Count($Childs = $Object->Childs)) {
#---------------------------------------------------------------------------
$Content = new Tag('DIV', array('style' => 'display:none;'), array('id' => $Md5));
#---------------------------------------------------------------------------
foreach ($Childs as $Child) {
$Content->AddChild(XML_Read($Child, $Level + 1));
}
#---------------------------------------------------------------------------
$Node->AddChild($Content);
}
#-----------------------------------------------------------------------------
return $Node;
}
开发者ID:carriercomm,项目名称:jbs,代码行数:35,代码来源:Repository.comp.php
示例19: registerUser
/**
* This function will create a new user object and return the newly created user object.
*
* @param array $userInfo This should have the properties: username, firstname, lastname, password, ui_language
*
* @return mixed
*/
public function registerUser(array $userInfo, $userLanguage)
{
$user = \User::create($userInfo);
//make the first user an admin
if (\User::all()->count() <= 1) {
$user->is_admin = 1;
}
// Trim trailing whitespace from user first and last name.
$user->firstname = trim($user->firstname);
$user->lastname = trim($user->lastname);
$user->save();
\Setting::create(['ui_language' => $userLanguage, 'user_id' => $user->id]);
/* Add welcome note to user - create notebook, tag and note */
//$notebookCreate = Notebook::create(array('title' => Lang::get('notebooks.welcome_notebook_title')));
$notebookCreate = new \Notebook();
$notebookCreate->title = Lang::get('notebooks.welcome_notebook_title');
$notebookCreate->save();
$notebookCreate->users()->attach($user->id, ['umask' => \PaperworkHelpers::UMASK_OWNER]);
//$tagCreate = Tag::create(array('title' => Lang::get('notebooks.welcome_note_tag'), 'visibility' => 0));
$tagCreate = new \Tag();
$tagCreate->title = Lang::get('notebooks.welcome_note_tag');
$tagCreate->visibility = 0;
$tagCreate->user_id = $user->id;
$tagCreate->save();
//$tagCreate->users()->attach($user->id);
$noteCreate = new \Note();
$versionCreate = new \Version(['title' => Lang::get('notebooks.welcome_note_title'), 'content' => Lang::get('notebooks.welcome_note_content'), 'content_preview' => mb_substr(strip_tags(Lang::get('notebooks.welcome_note_content')), 0, 255), 'user_id' => $user->id]);
$versionCreate->save();
$noteCreate->version()->associate($versionCreate);
$noteCreate->notebook_id = $notebookCreate->id;
$noteCreate->save();
$noteCreate->users()->attach($user->id, ['umask' => \PaperworkHelpers::UMASK_OWNER]);
$noteCreate->tags()->sync([$tagCreate->id]);
return $user;
}
开发者ID:jinchen891021,项目名称:paperwork,代码行数:42,代码来源:UserRegistrator.php
示例20: setTagsArray
public function setTagsArray(array $data)
{
// reset dei tag per semplificare lo script
ProductTag::model()->deleteAll('product=:p', array(':p' => $this->id));
// data attuale
$now = new DateTime();
$timestamp = $now->format('Y-m-d H-i-s');
// ricerca dei tag e creazione dei link
foreach ($data as $tagName) {
$tag = Tag::model()->find('name=:nm', array(':nm' => $tagName));
/** @var Tag $tag */
if ($tag == null) {
$tag = new Tag();
$tag->name = $tagName;
$tag->description = ucwords($tagName);
$tag->timestamp = $timestamp;
$tag->insert();
}
$productTag = ProductTag::model()->find('product=:p AND tag=:t', array(':p' => $this->id, ':t' => $tag->id));
/** @var ProductTag $productTag */
if ($productTag == null) {
$productTag = new ProductTag();
$productTag->product = $this->id;
$productTag->tag = $tag->id;
$productTag->insert();
}
}
}
开发者ID:KuRLiC,项目名称:PHPTest,代码行数:28,代码来源:Product.php
注:本文中的Tag类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论