public function store(Request $request) { $tag = new Tag(); $tag->fill($request->all()); $tag->save(); return $tag; }
public function actionInit() { $imageList = Image::find()->asArray()->all(); foreach ($imageList as $image) { $rawFilePath = $image['rawFilePath']; $match = []; if (preg_match('/\\/homeNASDownloads\\/photo_[0-9\\-]+\\/?(.*)/', dirname($rawFilePath), $match)) { $tagName = $match[1]; if (empty($tagName)) { continue; } $tag = Tag::find()->where(['tagName' => $tagName])->one(); if ($tag === null) { $tag = new Tag(); $tag->tagName = $tagName; $tag->isDelete = false; $now = date('Y-m-d H:i:s'); $tag->createTime = $now; $tag->updateTime = $now; $tag->save(); } $imageTag = ImageTag::find()->where(['imageId' => $image['id'], 'tagId' => $tag->id])->one(); if ($imageTag == null) { $imageTag = new ImageTag(); $imageTag->imageId = $image['id']; $imageTag->tagId = $tag->id; $imageTag->isDelete = false; $imageTag->createTime = $now; $imageTag->updateTime = $now; $imageTag->save(); } } } }
public static function setTags($entryId, $tags) { if (!$tags) { return; } // Write new tags to Tag table try { foreach ($tags as $k => $t) { // Add new tag if id is not exist if (!isset($t['id'])) { $tag = new Tag(); $tag->text = $t['text']; $tag->save(); $tags[$k]['id'] = $tag->id; } } } catch (Exception $e) { return $e->getMessage(); } // Update tags for current entry //TODO: rewrite with junction table relations try { EntryTag::deleteAll(['entry_id' => (int) $entryId]); foreach ($tags as $t) { $e = new EntryTag(); $e->tag_id = $t['id']; $e->entry_id = $entryId; $e->save(); } } catch (Exception $e) { return $e->getMessage(); } }
public static function addTags($tags_str, $id) { $tags = self::string2array($tags_str); foreach ($tags as $one) { $tag_exists = Tag::find()->where("name = '" . $one . "'")->one(); //var_dump($tag_exists); exit; if ($tag_exists == null) { $tag = new Tag(); $tag->name = $one; $tag->frequency = 1; $tag->items .= $id; $tag->save(); } else { if (array_search($id, self::string2array($tag_exists->items)) === false || array_search($id, self::string2array($tag_exists->items)) < 0) { //var_dump($id); //var_dump(self::string2array($tag_exists->items)); //var_dump(array_search($id, self::string2array($tag_exists->items)) === false); //var_dump(array_search($id, self::string2array($tag_exists->items)) < 0); exit; $tag_exists->frequency++; $tag_exists->items .= "," . $id; $tag_exists->update(); } } } }
/** * Get tag by id. * * @param $id * @return mixed */ public function getById($id) { $tag = $this->model->find($id); if (!is_null($tag)) { $tag->hot++; $tag->update(); } return $tag; }
/** * Run the database seeds. * * @return void */ public function run() { // Seeds the tag table foreach (range(1, 1000) as $t) { $tag = new Tag(); $tag->tag_name = str_shuffle('abcdefghijklmnopqrstuvwxyz'); $tag->save(); } }
public function saved($model) { foreach ($model->tags as $tag) { $new_tag = Tag::where('type', '=', $tag->type)->where('tag', '=', $tag->tag)->first(); if (!$new_tag) { $new_tag = new Tag(['type' => $tag->type, 'tag' => $tag->tag]); $new_tag->save(); } } }
public function init() { parent::init(); $tag = new Tag(); $tags = $tag->findTagWeights($this->max); foreach ($tags as $tag => $weight) { $link = Html::a(Html::encode($tag), ['post/index', 'tag' => $tag]); echo Html::tag('span', $link, ['class' => 'tag', 'style' => "font-size:{$weight}pt"]) . "\n"; } }
/** * Display the home page. * * @return Response */ public function index() { $url = config('medias.image-host'); $film_url = config('medias.film-host'); //hien thi film hot, sap xep moi nhat len tren $filmCondition = ['publish' => 1, 'isHot' => 1]; $films = $this->film->where($filmCondition)->orderBy('created_at', 'desc')->get(); //$banners = $this->getBanner(); $cond = ['publish' => 1, 'sub_cat_id' => 5]; $banners = Banner::where($cond)->get(); return view('front.index', compact('films', 'url', 'film_url', 'banners')); }
public function addTags($tags = []) { $rowTagsName = Tag::all(['name'])->toArray(); $rowTagsName = array_flatten($rowTagsName); foreach ($tags as $key => $tag) { if (in_array($tag, $rowTagsName)) { } else { $tag = new Tag(); $tag->name = $tag; $tag->save(); } } }
public function edit($id) { $article = Article::findOrFail($id); //Calls for tag list $tags = Tag::lists('name', 'id'); return view('articles.edit', compact('article', 'tags')); }
public function postUpload(Request $request) { $input = $request->all(); $rules = array('image' => 'image|max:204800'); $validation = \Validator::make($input, $rules); if ($validation->fails()) { return \Response::json([$validation->errors->first()], 400); } if ($media = $this->handleMediaUpload($request, 'image')) { $tagIDs = []; if ($request->has('tags')) { $tagList = explode(',', $request->input('tags')); foreach ($tagList as $tag) { $tag = trim($tag); $tagORM = \App\Models\Tag::where('name', $tag)->first() ?: new \App\Models\Tag(); $tagORM->name = $tag; if (empty($tagORM->slug)) { $tagORM->slug = \App\Helpers\Text::slugify($tagORM->name); } $tagORM->save(); $tagIDs[] = $tagORM->id; } if (count($tagIDs)) { $media->tags()->sync($tagIDs); } } return \Response::json('success', 200); } else { return \Response::json('error', 400); } }
/** * Generate or regenerate popular Discover Cache items * * @param SearchHandlerInterface $searchHandler * @param CacheHandlerInterface $cacheHandler */ public function generatePopular(SearchHandlerInterface $searchHandler, CacheHandlerInterface $cacheHandler) { $tags = Tag::all()->groupBy('name')->orderBy('created_at')->take(20)->get(); foreach ($tags as $tag) { $this->generate($tag, $cacheHandler, $searchHandler); } }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { \App\Models\Tag::create(['name' => $faker->word]); } }
public function delete() { $user = $this->auth(); $tag = Tag::find(Input::get('tagId')); $tag->delete(); return $this->output(new \stdClass()); }
public static function getTagWeights($limit = 20) { $models = Tag::find()->with('posts')->orderBy('name')->all(); $minFrequency = 0; $maxFrequency = 0; foreach ($models as $model) { $weight = count($model->posts); $minFrequency = $minFrequency > $weight ? $weight : $minFrequency; $maxFrequency = $maxFrequency < $weight ? $weight : $maxFrequency; } $sizeRange = self::MAX_FONT_SIZE - self::MIN_FONT_SIZE; $minCount = log($minFrequency + 1); $maxCount = log($maxFrequency + 1); if ($maxCount != $minCount) { $countRange = $maxCount - $minCount; } else { $countRange = 1; } $tags = []; foreach ($models as $model) { $tags[$model->name] = round(self::MIN_FONT_SIZE + (log(count($model->posts) + 1) - $minCount) * ($sizeRange / $countRange)); } arsort($tags); return $tags; }
/** * Compose the sidebar. */ private function composeSidebar() { view()->composer('partials.sidebar', function ($view) { $view->with('latest', Article::published()->orderBy('id', 'desc')->take(5)->get()); $view->with('tags', Tag::all()); }); }
public function getIndex() { // Get all the tags, in alphabetical order $tags = Tag::orderBy('name', 'asc')->get(); // Return the view to the user with the tags return view('tags.list', ['tags' => $tags]); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update($id) { $tag = Tag::findOrfail($id); $tag->name = Input::get('name'); $tag->save(); return redirect()->route('admin.tag.index'); }
function index(Request $request) { ///////////////// // Load Filter // ///////////////// $filters = $this->request->only('type', 'tag', 'skip', 'take', 'group', 'with_count'); /////////// // Query // /////////// if (!$filters['take']) { $filters['take'] = 500; } else { $filters['take'] = min($filters['take'] * 1, 500); } $filters['skip'] = $filters['skip'] * 1; $q = Model::name($filters['name'])->type($filters['type']); if ($filters['group']) { $q = $q->groupby('tag'); } if ($filters['with_count']) { $count = $q->count(); } $data = $q->skip($filters['skip'])->take($filters['take'])->orderBy('tag')->select(['type', 'tag'])->get(); ////////////// // Response // ////////////// return response()->json(JSend::success(['count' => $count, 'data' => $data->toArray()])->asArray())->setCallback($this->request->input('callback')); }
public function category($subject, $type) { $type = new TagType($type); $categories = Tag::withType($type)->get()->lists('name', 'name')->toArray(); $subjectCategory = $subject->tagsWithType($type)->first(); return $this->select($type . '_tags[]', $categories, $subjectCategory ? $subjectCategory->name : null); }
public static function boot() { parent::boot(); Tag::creating(function (Tag $tag) { $tag->generateSlug(); }); }
/** * Store a newly created resource in storage. * * @param Request $request * @param URI int $fact_id * @return Response */ public function store(Request $request, $user_id = null, $fact_id = null) { if (!$request->input('tag_name')) { return $this->respondUnprocessed(); } $fact = Fact::find($fact_id); if ($user_id) { $authUser = Auth::ID(); if ($authUser != $user_id) { return $this->respondForbidden("Unauthorized: Must be logged to access endpoint"); } if ($fact->user_id != $user_id) { return $this->respondForbidden("Unauthorized: Verify you still have access to resource"); } } if (!$fact) { return $this->respondNotFound("Fact Not found"); } else { $tag_name = $request->input('tag_name'); $tag = Tag::firstOrCreate(['tag_name' => $tag_name]); if ($tag) { TaggedFact::create(['fact_id' => $fact_id, 'tag_id' => $tag->id]); $metadata = ['tag_id' => $tag->id]; return $this->respondCreated("Request Successful", $metadata); } else { return $this->respondUnprocessed("Unable to tag the fact"); } } }
/** * Creates a new Artist model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Artist(); $photos = []; if (Yii::$app->request->isPost) { for ($i = 0; $i < count(Yii::$app->request->post('Photo', [])); $i++) { $photos[] = new Photo(); } $data = Yii::$app->request->post(); $data['Artist']['user_id'] = Yii::$app->user->id; } else { $data = null; } if ($model->load($data) && $model->save()) { Photo::loadMultiple($photos, Yii::$app->request->post()); foreach ($photos as $photo) { $photo->artist_id = $model->id; } if (Photo::validateMultiple($photos)) { foreach ($photos as $photo) { $model->link('photos', $photo); } } $tags = Yii::$app->request->post('Artist', ''); $tags = Tag::find()->where(['in', 'id', explode(',', $tags['tags'])])->all(); foreach ($tags as $tag) { $model->link('tags', $tag); } return $this->redirect(['release/index', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'photos' => $photos]); } }
/** * Lists all Partner models. * @return mixed */ public function actionIndex() { $searchModel = new PartnerSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); // $this->ajaxAssign('tags', Tag::find()->asArray()->publicTags()->all()); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'tags' => [__('Public tags') => Tag::find()->publicTags()->all(), __('Personal tags') => Tag::find()->personalTags()->all()]]); }
/** * Display a listing of the resource with its problems connected; * * @return \Illuminate\Http\Response */ public function problems($id) { $tag = Tag::findOrFail($id); $tags = TagService::getTagWithProblem($tag->id); $title = '문제 목록 - ' . $tag->name . ' - ' . $tags->currentPage() . ' 페이지'; $resultAccCode = Result::acceptCode; return view('tags.problems', compact('tag', 'tags', 'title', 'resultAccCode')); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('tags')->truncate(); $faker = Faker\Factory::create(); for ($i = 0; $i < 30; $i++) { Tag::create(['name' => $faker->unique()->word]); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $tags = Tag::lists("name", "id"); $article = Article::with("tags")->find($id); $categories = Category::lists("name", "id"); // dd($article->tags->lists("id")); return view("dashboard.articles.edit", compact("article", "categories", "tags")); }
/** * Get a tag JSON by a given tag_id * method: get * route: api/tags/<tag_id> * @param int $tag_id * @return json {"success": true or false, "data": {"tag": tag}}; */ public function show($tag_id) { $tag = Tag::find($tag_id); if ($tag == NULL) { return \Response::json(array("success" => false)); } return \Response::json(["success" => true, "data" => array("tag" => $tag)]); }
/** * Finds the Tag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tag::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }