public function action_index($id) { $gallery = Model_Gallery::getBySlug($id, false); if (!$gallery || !$gallery->isPublished() && !Helper_Account::is_admin(Auth::instance()->get_user())) { $this->template->content = View::factory("errors/index"); return; } $this->template->content = View::factory("gallery/index")->set("gallery", $gallery); $this->template->content->reel = Reel::factory($gallery->photos); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
/** * View the tag page. * * @return void * @author Merrick Christensen */ public function action_view($id = NULL) { $tag = ORM::factory('tag')->where('id', '=', $id)->find(); $this->template->title = 'View Photos Tagged ' . $tag->name . ' - National Geographic Kids My Shot'; $this->template->content = View::factory('tags/index'); if ($tag->loaded()) { $this->template->content->set(array('tag' => $tag, 'reel' => Reel::factory($tag->photos->order_by("photos.created", "desc")))); } else { Message::set(Message::NOTICE, "This tag does not exist."); Request::instance()->redirect('/'); } $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
/** * View the category page. * * @return void * @author Merrick Christensen */ public function action_index($id = NULL) { $category = ORM::factory('category')->where('id', '=', $id)->find(); $this->template->title = 'View ' . $category->name . ' Photos - National Geographic Kids My Shot'; $this->template->scripts = array('public/js/categories/slideshow.js'); $this->template->content = View::factory('categories/index'); // Take a deep breath! $featured = DB::query(Database::SELECT, 'SELECT * FROM (SELECT `photos`.`id` AS `id`, `ratings`.`id` AS `rating_id`, `photos`.`moderation_status_id`, `photos`.`category_id`, `photos`.`user_id`, `photos`.`name`, `photos`.`caption`, `photos`.`thumbnail`, `photos`.`small`, `photos`.`medium`, `photos`.`large`, `photos`.`original`, `photos`.`file_type`, `photos`.`order`, `photos`.`created`, Avg(`rating`) AS `rating` FROM `ratings` JOIN `photos` ON ( `photos`.`id` = `ratings`.`photo_id` ) WHERE `category_id` = ' . $id . ' GROUP BY `photo_id` ORDER BY `rating` DESC LIMIT 20) AS top_rated ORDER BY Rand() LIMIT 5')->as_object('Model_Photo'); // Did you make it? if ($category->loaded()) { $this->template->content->set(array('category' => $category, 'reel' => Reel::factory(ORM::factory('photo')->where('category_id', '=', $id)->order_by('created', 'desc')), 'featured_photos' => $featured->execute())); } else { Message::set(Message::NOTICE, "This category does not exist."); Request::instance()->redirect('/'); } $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
public function action_index() { $searchBase = ORM::factory("photo"); $qTerms = (object) filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); if (!empty($qTerms->catid)) { $cat = ORM::factory("category", $qTerms->catid); $searchBase = $cat->photos; } if (!empty($qTerms->query)) { $searchBase->where("name", "LIKE", "%{$qTerms->query}%"); $qParts = explode(" ", $qTerms->query); if (count($qParts) > 0) { foreach ($qParts as $q) { $searchBase->or_where("name", "LIKE", "%{$q}%"); } } } $this->template->content = View::factory("admin/allphotos/index"); $this->template->content->reel = Reel::factory($searchBase->order_by("created", "desc")); }
public function action_favorites($user = null) { if ($user === NULL) { Message::set(Message::NOTICE, 'User does not exist!'); Request::instance()->redirect('/'); } else { if (is_numeric($user)) { $account = ORM::factory('user')->where('id', '=', $user)->find(); } else { $account = ORM::factory('user')->where('vanity_url', '=', $user)->find(); } if ($account->loaded()) { if (!Helper_Account::is_approved($account)) { Message::set(Message::NOTICE, 'User has not been approved!'); Request::instance()->redirect('/'); } } else { Message::set(Message::NOTICE, 'User does not exist!'); Request::instance()->redirect('/'); } } if (!isset($account)) { Message::set(Message::NOTICE, 'User does not exist!'); Request::instance()->redirect('/'); } $this->template->content = View::factory("profile/favorites"); $this->template->content->user = $account; $this->template->content->reel = Reel::factory($account->favorite_photos); $this->template->top = View::factory('profile/topper'); $this->template->top->user = $account; $this->template->top->owner = $this->user; $this->template->top->photos = $account->viewablePhotos()->order_by(DB::expr('RAND()'))->limit(30)->find_all(); }
public function action_popular() { $date_before = date('Y-m-j G:i:s', strtotime('-7 day' . date('Y-m-j G:i:s'))); $this->template->title = 'Most Popular Photos - National Geographic Kids My Shot'; $this->template->content->set(array('name' => 'Most Popular', 'reel' => Reel::factory(DB::select('*')->from('popular_photos')->order_by('views', 'DESC')->as_object('Model_Photo')))); }