本文整理汇总了PHP中Tag::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::find方法的具体用法?PHP Tag::find怎么用?PHP Tag::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tag
的用法示例。
在下文中一共展示了Tag::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_should_bind_sql_bind_in_using_active_records
public function test_should_bind_sql_bind_in_using_active_records()
{
$Tag = new Tag();
$Tag->create(array('name' => 'Tag 1'));
$Tag->create(array('name' => 'Tag 2'));
$this->assertTrue($Tags = $Tag->find(array('conditions' => array('name IN (?)', $Tag->find()))));
$this->assertEqual($Tags[0]->name, 'Tag 1');
$this->assertEqual($Tags[1]->name, 'Tag 2');
}
示例2: 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;
}
示例3: 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;
}
示例4: tags
public function tags($id)
{
$tag = Tag::find($id);
$posts = $tag->posts()->get();
$tags = Tag::with('posts')->paginate(8);
return View::make('search', compact('posts', 'tags'));
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// get POST data
$input = Input::all();
// set validation rules
$rules = array('title' => 'required', 'text' => 'required', 'image' => 'required');
// validate input
$validation = Validator::make($input, $rules);
// if validation fails, return the user to the form w/ validation errors
if ($validation->fails()) {
return Redirect::back()->withErrors($validation)->withInput();
} else {
// create new Post instance
$post = Post::create(array('title' => $input['title']));
// create Text instance w/ text body
$text = Text::create(array('text' => $input['text']));
// save new Text and associate w/ new post
$post->text()->save($text);
// create the new Image
$image = Image::create(array('url' => $input['image']));
// save new Text and associate w/ new post
$post->image()->save($image);
if (isset($input['tags'])) {
foreach ($input['tags'] as $tagId) {
$tag = Tag::find($tagId);
$post->tags()->save($tag);
}
}
// associate the post with the current user
$post->author()->associate(Auth::user())->save();
// redirect to newly created post page
return Redirect::route('post.show', array($post->id));
}
}
示例6: alias_name
public function alias_name()
{
if ($this->alias_name === null) {
$this->alias_name = Tag::find($this->alias_id)->name;
}
return $this->alias_name;
}
示例7: getPostByTag
public static function getPostByTag($tag_id)
{
$tagData = Tag::find($tag_id);
if ($tagData) {
$data = DB::select(" SELECT * FROM posts WHERE id IN (SELECT post_id FROM post_tags WHERE tag_id = {$tag_id}) ");
}
return $data;
}
示例8: dataExist
/**
* Verify if exist
*/
private function dataExist($id)
{
$data = Tag::find($id);
if (!$data) {
return Redirect::route('tag_list')->with('mError', 'Ce tag est introuvable !');
} else {
return $data;
}
}
示例9: createPostAction
public function createPostAction()
{
if ($this->request->isPost()) {
$post = new Post();
$post->topic = $this->request->getPost('title');
$post->content = str_replace('</div>', '\\n', str_replace('<div>', '', $this->request->getPost('post')));
$post->is_service = $this->request->getPost('is_service');
$post->created_at = date('d.m.Y, h:i');
if ($post->save()) {
$tt = explode(',', $this->request->getPost('tags'));
foreach ($tt as $t) {
$tag = Tag::findFirst(array('conditions' => 'name = ?1', 'bind' => array(1 => $t)));
if ($tag) {
$tag_post = new PostTag();
$tag_post->post_id = $post->id;
$tag_post->tag_id = $tag->id;
if (!$tag_post->save()) {
message($this, 'd', 'Ошибка привязки категории к посту');
return $this->response->redirect();
}
} else {
$tag = new Tag();
$tag->name = $t;
if ($tag->save()) {
$tag_post = new PostTag();
$tag_post->post_id = $post->id;
$tag_post->tag_id = $tag->id;
if (!$tag_post->save()) {
message($this, 'd', 'Ошибка привязки категории к посту');
return $this->response->redirect();
}
} else {
message($this, 'd', 'Ошибка сохранения новой категории');
return $this->response->redirect();
}
}
}
message($this, 's', 'Новость успешно добавлена');
return $this->response->redirect();
} else {
foreach ($post->getMessages() as $message) {
message($this, "d", "Ошибка: " . $message->getMessage() . " в поле " . $message->getField() . ". Тип: " . $message->getType());
}
return $this->response->redirect();
}
} else {
$this->assets->collection('headerJs')->addJs("js/jquery-ui.min.js");
$this->assets->collection('headerCss')->addCss("css/jquery-ui.min.css")->addCss("css/jquery-ui.structure.min.css");
$tt = Tag::find();
$tags = "";
foreach ($tt as $tag) {
$tags .= '"' . $tag->name . '", ';
}
$tags = substr($tags, 0, -2);
$this->view->setParamToView('tags', $tags);
}
}
示例10: destroy
public function destroy($id)
{
$tag = Tag::find($id);
$tag->delete();
if ($tag == null) {
return $this->statusResponse(['error' => 'No Tag found']);
}
return $this->statusResponse(['notice' => 'Tag deleted', 'tag' => $tag]);
}
示例11: approve
function approve($user_id, $ip_addr)
{
DB::update("tag_implications SET is_pending = FALSE WHERE id = {$this->id}");
$t = Tag::find($this->predicate_id);
$implied_tags = implode(' ', self::with_implied(array($t->name)));
foreach (Post::find('all', array('conditions' => array("id IN (SELECT pt.post_id FROM posts_tags pt WHERE pt.tag_id = ?)", $t->id))) as $post) {
$post->update_attributes(array('tags' => $post->tags . " " . $implied_tags, 'updater_user_id' => $user_id, 'updater_ip_addr' => $ip_addr));
}
}
示例12: approve
public function approve($user_id, $ip_addr)
{
self::connection()->executeSql("UPDATE tag_implications SET is_pending = FALSE WHERE id = " . $this->id);
$t = Tag::find($this->predicate_id);
$implied_tags = implode(' ', self::with_implied(array($t->name)));
foreach (Post::where("id IN (SELECT pt.post_id FROM posts_tags pt WHERE pt.tag_id = ?)", $t->id)->take() as $post) {
$post->updateAttributes(array('tags' => $post->cached_tags . " " . $implied_tags, 'updater_user_id' => $user_id, 'updater_ip_addr' => $ip_addr));
}
}
示例13: Tag
function test_should_store_zero_strings_as_intergers()
{
$Tag = new Tag(array('name' => 'Ticket #21'));
$this->assertTrue($Tag->save());
$this->assertEqual($Tag->get('score'), 100);
$Tag->setAttributes(array('score' => '0'));
$this->assertTrue($Tag->save());
$Tag =& $Tag->find($Tag->id);
$this->assertIdentical($Tag->get('score'), 0);
}
示例14: tag_links
function tag_links($tags, $options = array())
{
if (!$tags) {
return null;
}
$prefix = !empty($options['prefix']) ? $options['prefix'] : '';
if (is_string($tags)) {
$tags = explode(' ', $tags);
$tags = Tag::find(array('conditions' => array('name in (??)', $tags), 'select' => 'name, tag_type, post_count'));
} elseif (is_array($tags)) {
if (is_indexed_arr($tags) && count(current($tags)) == 2) {
# We're getting a tag's cached_related tags. We need to find the tag type.
$i = 0;
$t = array();
foreach ($tags as $tag) {
$t[] = array('name' => current($tag), 'type' => Tag::type_name_helper(current($tag)), 'post_count' => end($tag));
}
} else {
# We're getting a post's cached_tags. We need to find the count for each tag.
$names = array_keys($tags);
# We may have a misstyped metatag. Better return.
if (!isset($names[0]) || !is_string($names[0])) {
return;
}
$count = Tag::find_post_count_and_name('all', array('conditions' => array('name in (??)', $names), 'order' => 'name', 'return_array' => true));
// vde($count);
$i = 0;
# There's a possibility a tag was deleted and cached_tags wasn't updated.
# This will cause errors, so we'll just skip tags that weren't found.
$t = array();
foreach ($count as $tag) {
$t[] = array('name' => $tag['name'], 'type' => $tags[$tag['name']], 'post_count' => $tag['post_count']);
}
}
$tags = $t;
unset($t);
} elseif (is_a($tags, 'Tag')) {
//
}
$tag_query = !empty(Request::$params->tags) ? Request::$params->tags : null;
$html = '';
foreach ($tags as $tag) {
list($name, $type, $count) = array_values($tag);
if (ctype_digit($type)) {
$type = Tag::type_name($type);
}
$html .= '<li class="tag-type-' . $type . '"><a href="/tag?name=' . $name . '">?</a>';
if (User::is('>=30')) {
$html .= ' <a href="/post?tags=' . $name . '+' . $tag_query . '">+</a> <a href="/post?tags=-' . $name . $tag_query . '">–</a>';
}
$hover = !empty($options['with_hover_highlight']) ? " onmouseover='Post.highlight_posts_with_tag(\"{$name}\")' onmouseout='Post.highlight_posts_with_tag(null)'" : '';
$html .= ' <a href="/post?tags=' . $name . '"' . $hover . '>' . str_replace('_', ' ', $name) . '</a> <span class="post-count">' . $count . '</span></li>';
}
return $html;
}
示例15: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$this->tag = Tag::find($id);
$this->tag->fill(Input::all());
if (!$this->tag->valid()) {
return Redirect::back()->withInput()->with('errors', $this->tag->errors);
} else {
$this->tag->update();
return Redirect::route('projects.index');
}
}