public function contents($model_id = 0, $slug = '') { $network = $this->network; $theme = $network->theme; $theme = check_for_tour_theme($theme); Theme::setActive($theme); $data = $this->data; $model = Model::find($model_id); if ($model) { $contents = $model->contents()->published()->ofNetwork($this->network->id)->orderBy('id', 'desc')->get(); $data['page_title'] = $model->name . ' Contents'; $data['model'] = $model; $data['contents'] = $contents; $content_views = 0; foreach ($contents as $content) { $content_views = $content_views + $content->fake_views; } $data['content_views'] = $content_views; $username = \Request::server('PHP_AUTH_USER', 'sampleuser'); $data['is_favorite'] = $username && Favorite::ofUsername($username)->hasFavorite('Model', $model->id)->count() ? 1 : 0; $this->breadcrumbs->addCrumb('Popular Models', url('models')); $this->breadcrumbs->addCrumb($model->name . ' Contents'); return Theme::view('model.contents', $data); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $username = \Request::server('PHP_AUTH_USER', 'sampleuser'); $response = []; $type = $request->input('type', ''); $id = $request->input('id', ''); $model = null; switch ($type) { case 'Content': $model = Content::find($request->input('id')); break; case 'Dvd': $model = Dvd::find($request->input('id')); break; case 'Dvdseries': $model = Dvdseries::find($request->input('id')); break; case 'Model': $model = Model::find($request->input('id')); break; } if ($username && $id && $model) { if (Favorite::ofUsername($username)->hasFavorite($type, $id)->count()) { $response['success'] = false; $response['message'] = 'Already in your favorites.'; } else { $fav = new Favorite(); $fav->username = $username; $model->favorites()->save($fav); $response['success'] = true; $response['message'] = 'Successfully added to your favorites.'; } } return \Response::json($response); }
/** * Bind data to the view. * * @param View $view * @return void */ public function compose(View $view) { $network_id = config('yppmembers.network_id'); $network = Network::find($network_id); $network_sites = $network->sites()->withcontent()->orderBy('name', 'asc')->get(); $most_used_tags_in_network = Tag::ofNetwork($network->id)->mostUsedInNetwork($network->id)->take(20)->get(); $most_used_models_in_network = Model::ofNetwork($network->id)->mostUsedInNetwork($network->id)->take(20)->get(); $view->with('network_sites', $network_sites); $view->with('most_used_tags_in_network', $most_used_tags_in_network); $view->with('most_used_models_in_network', $most_used_models_in_network); }
public function xhrSearch(Request $request) { $q = Request::input('q', ''); $q = strip_tags(str_replace("'", " ", $q)); $response = []; if (!empty($q)) { $contents = Content::ofNetwork($this->network->id)->published()->search($q)->paginate(10); $models = Model::ofNetwork($this->network->id)->where('name', 'LIKE', "%{$q}%")->paginate(10); $tags = Tag::ofNetwork($this->network->id)->where('name', 'LIKE', "%{$q}%")->paginate(10); $items = $contents->merge($models)->merge($tags); foreach ($items as $item) { $response[] = ['title' => $item->getAttribute('title') ? $item->title : $item->name, 'url' => $item->link, 'thumb' => $item->thumb, 'type' => class_basename(get_class($item))]; } $this->dispatch(new UpdateSearchKeywords($q)); } return \Response::json($response); }
public function __construct() { $network_id = config('yppmembers.network_id'); $network = Network::find($network_id); if (!$network) { echo 'Invalid Network'; exit; } $this->network = $network; $this->breadcrumbs = new \Creitive\Breadcrumbs\Breadcrumbs(); $this->breadcrumbs->setListElement('ol'); $this->breadcrumbs->setDivider(null); $this->breadcrumbs->setCssClasses('breadcrumb'); $this->breadcrumbs->addCrumb($network->name, url()); $data['breadcrumbs'] = $this->breadcrumbs; $data['network'] = $network; $data['support_url'] = config('yppmembers.support_url'); $data['network_sites'] = $network->sites()->withcontent()->orderBy('name', 'asc')->get(); $data['most_used_tags_in_network'] = Tag::ofNetwork($network->id)->mostUsedInNetwork($network->id)->take(20)->get(); $data['most_used_models_in_network'] = Model::ofNetwork($network->id)->mostUsedInNetwork($network->id)->take(20)->get(); $data['show_network_header'] = true; $data['piwik_tracker_ids'] = config('yppmembers.use_piwik') && $network->piwik_id != 0 ? [$network->piwik_id] : []; $this->data = $data; }