/** * Imports board tags. * * @return void */ public function importInfinityBoardTags() { # THEIR TABLES $tTagsTable = $this->tcon->table("board_tags"); # BEGIN USER IMPORT $this->info("\tImporting Tags ..."); $tTagsTable->chunk(100, function ($tags) { $this->line("\t\tImporting 100 tags."); $boardTags = []; $tagModels = []; foreach ($tags as $tag) { $tagTxt = substr((string) $tag->tag, 0, 32); if (!isset($boardTags[$tag->uri])) { $boardTags[$tag->uri] = []; } if (!isset($tagModels[$tagTxt])) { $tagModels[$tagTxt] = BoardTag::firstOrCreate(['tag' => $tagTxt]); } $boardTags[$tag->uri] = $tagModels[$tagTxt]; } foreach ($boardTags as $board_uri => $tags) { $board = Board::find($board_uri); if ($board) { $board->tags()->attach($tags); } else { $this->warn("\t\t\tBoard \"{$board_uri}\" could not be found to add tags to."); } } unset($tag, $tagModel, $tagModels, $boardTags); }); }
protected function boardListTags() { $tags = BoardTag::distinct('tag')->with(['boards', 'boards.stats', 'boards.stats.uniques'])->limit(50)->get(); $tagWeight = []; foreach ($tags as $tag) { $tagWeight[$tag->tag] = $tag->getWeight(3); if ($tag->getWeight() > 0) { } } return $tagWeight; }
/** * Put tags. * * @return Response */ public function putTags(Board $board) { if (!$board->canEditConfig($this->user)) { return abort(403); } $input = Input::all(); $rules = ['boardTags' => ["array", "min:0", "max:5"]]; if (isset($input['boardTags']) && is_array($input['boardTags'])) { $input['boardTags'] = array_filter($input['boardTags']); } $validator = Validator::make($input, $rules); $validator->each('boardTags', ['string', 'alpha_dash', 'max:24']); if (!$validator->passes()) { return redirect()->back()->withErrors($validator->errors()); } $tags = []; $tagArray = []; foreach ($input['boardTags'] as $boardTag) { $boardTag = (string) $boardTag; if (strlen($boardTag) && !isset($tagArray[$boardTag])) { // Add the tag to the list of set tags to prevent duplicates. $tagArray[$boardTag] = true; // Find or create the board tag. $tags[] = BoardTag::firstorCreate(['tag' => $boardTag]); } } $board->tags()->detach(); if (count($tags)) { $tags = $board->tags()->saveMany($tags); } Event::fire(new BoardWasModified($board)); return $this->view(static::VIEW_TAGS, ['board' => $board, 'tags' => array_keys($tagArray), 'tab' => "tags"]); }