Example #1
0
 public function delete($id = null)
 {
     if (!$this->loaded()) {
         $this->find($id);
     }
     //remove all comment logs for this comment type: comment, comment approved, comment received
     $site = Helper_Game::getSite();
     $gameCommentId = $site->getEvent(Helper_Game::COMMENT)->id;
     $gameCommentApprovedId = $site->getEvent(Helper_Game::COMMENT_APPROVED)->id;
     $gameCommentReceivedId = $site->getEvent(Helper_Game::COMMENT_RECEIVED)->id;
     $infos = ORM::factory("Game_LogInfo")->and_where_open()->where("name", "like", "comment")->or_where("name", "like", "comment_id")->and_where_close()->and_where_open()->where("data", "=", $this->id)->or_where("data", "like", $this->comment)->and_where_close()->find_all();
     foreach ($infos as $info) {
         $log = $info->_eventLog;
         switch ($log->event_id) {
             case $gameCommentId:
             case $gameCommentReceivedId:
                 if ($log->data->comment == $this->id) {
                     $log->delete();
                 }
                 break;
             case $gameCommentApprovedId:
                 if (empty($log->data->comment_id) && $log->item->item_id == $this->photo->id) {
                     $log->delete();
                 }
                 if (!empty($log->data->comment_id) && $log->data->comment_id == $this->id) {
                     $log->delete();
                 }
                 break;
             default:
                 //do nothing
                 break;
         }
     }
     parent::delete($id);
 }
Example #2
0
 public function action_index()
 {
     $site = Helper_Game::getSite();
     $this->template->content = View::factory("trophy/index");
     $this->template->content->awards = Helper_Game::alphebetizeHonors($site->awards);
     $this->template->content->badges = Helper_Game::alphebetizeHonors($site->badges);
     $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar());
 }
Example #3
0
 public function action_preview($id)
 {
     $id = filter_var($id, FILTER_SANITIZE_NUMBER_INT);
     $homeSpot = ORM::factory("homespot", $id);
     if (!$homeSpot->loaded()) {
         Message::set(Message::ERROR, "Sorry, that could not be found.");
         $this->request->redirect("admin/home/create");
         return;
     }
     $this->template->title = 'Share Your Photos - National Geographic Kids My Shot Community';
     $this->template->scripts = array('public/js/vendor/jquery.jcarousel.js', 'public/js/categories/slideshow.js', 'public/js/home/home.js');
     $awards = array();
     $badges = array();
     $events = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Model_Game_Site::HONOR_GIVEN))->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all();
     foreach ($events as $event) {
         $eventUser = ORM::factory('user', $event->user->user_id);
         if ($eventUser->id) {
             if ($event->data->type == "game_Badge") {
                 $obj = new stdClass();
                 $obj->data = $event->data;
                 $obj->honor = ORM::factory($event->data->type, $event->data->honor_id);
                 $obj->user = ORM::factory('user', $event->user->user_id);
                 $badges[] = $obj;
             }
         }
         if (count($badges) >= $this->maxBadges) {
             break;
         }
     }
     if (count($awards) < $this->maxAwards) {
         $aevents = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Helper_Game::AWARD_GIVEN)->id)->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all();
         foreach ($aevents as $event) {
             $obj = new stdClass();
             $obj->data = $event->data;
             $obj->honor = ORM::factory($event->data->type, $event->data->honor_id);
             $obj->user = ORM::factory('user', $event->user->user_id);
             $obj->photo = ORM::factory('photo', $event->item->item_id);
             $awards[] = $obj;
             if (count($awards) >= $this->maxAwards) {
                 break;
             }
         }
     }
     $honors = array_merge($awards, $badges);
     if (count($honors) == 0) {
         $honors = false;
     }
     $slider = Model_DLSliderGroup::getCurrentSlider();
     if ($slider) {
         $this->template->top = View::factory("home/slider");
         $this->template->top->slider = $slider;
     }
     $this->template->content = View::factory('home/index');
     $this->template->content->set(array('user' => $this->user, 'recently_added' => Reel_More::factory(ORM::factory('photo')->order_by('created', 'desc')), 'top_rated' => Reel_More::factory(Helper_Photos::get_top_rated()), 'honors' => $honors, 'potd' => Model_DailyPhoto::todaysPhoto(), 'homeSpot' => $homeSpot, 'homeSpotEditLink' => HTML::anchor("admin/home/edit/{$homeSpot->id}", "Edit")));
     $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar());
 }
Example #4
0
 /**
  * View the homepage.
  *
  * @return void
  * @author Merrick Christensen
  */
 public function action_index()
 {
     $this->template->title = 'Share Your Photos - National Geographic Kids My Shot Community';
     $this->template->scripts = array('public/js/vendor/jquery.jcarousel.js', 'public/js/categories/slideshow.js', 'public/js/home/home.js');
     $awards = array();
     $badges = array();
     $events = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Model_Game_Site::HONOR_GIVEN))->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all();
     foreach ($events as $event) {
         $eventUser = ORM::factory('user', $event->user->user_id);
         if ($eventUser->id) {
             if ($event->data->type == "game_Badge") {
                 $obj = new stdClass();
                 $obj->data = $event->data;
                 $obj->honor = ORM::factory($event->data->type, $event->data->honor_id);
                 $obj->user = ORM::factory('user', $event->user->user_id);
                 $badges[] = $obj;
             }
         }
         if (count($badges) >= $this->maxBadges) {
             break;
         }
     }
     if (count($awards) < $this->maxAwards) {
         $aevents = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Helper_Game::AWARD_GIVEN)->id)->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all();
         foreach ($aevents as $event) {
             $obj = new stdClass();
             $obj->data = $event->data;
             $obj->honor = ORM::factory($event->data->type, $event->data->honor_id);
             $obj->user = ORM::factory('user', $event->user->user_id);
             $obj->photo = ORM::factory('photo', $event->item->item_id);
             $awards[] = $obj;
             if (count($awards) >= $this->maxAwards) {
                 break;
             }
         }
     }
     $honors = array_merge($awards, $badges);
     if (count($honors) == 0) {
         $honors = false;
     }
     $slider = Model_DLSliderGroup::getCurrentSlider();
     if ($slider) {
         $this->template->top = View::factory("home/slider");
         $this->template->top->slider = $slider;
     }
     $this->template->content = View::factory('home/index');
     $this->template->content->set(array('user' => $this->user, 'recently_added' => Reel_More::factory(ORM::factory('photo')->order_by('created', 'desc')), 'top_rated' => Reel_More::factory(Helper_Photos::get_top_rated()), 'honors' => $honors, 'potd' => Model_DailyPhoto::todaysPhoto(), 'homeSpot' => Model_Homespot::getCurrent()));
     $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar());
 }
Example #5
0
 public function action_flipfavorite($photo_id)
 {
     $photo = ORM::factory('photo')->where('id', '=', $photo_id)->find();
     if ($this->user->id && $photo->loaded()) {
         if ($this->user->isFavorite($photo_id)) {
             $this->user->removeFavorite($photo_id);
             Message::set(Message::SUCCESS, 'You removed "' . $photo->name . '" as a favorite!');
         } else {
             $this->user->addFavorite($photo_id);
             $favLogs = Helper_Game::getUser($this->user->id)->getLogsforEvent(Helper_Game::getSite()->getEvent(Helper_Game::FAVORITE));
             $addLog = true;
             foreach ($favLogs as $log) {
                 if ($log->data->photo_id == $photo_id) {
                     $addLog = false;
                     break;
                 }
             }
             $event = $addLog ? Helper_Game::logEvent(Helper_Game::FAVORITE, $this->user->id, array('photo_id' => $photo_id)) : false;
             $event2 = $addLog ? Helper_Game::logEvent(Helper_Game::FAVORITED, $photo->user->id, $photo->id, array('photo_id' => $photo_id, 'user_id' => $this->user->id)) : false;
             Message::set(Message::SUCCESS, 'You added "' . $photo->name . '" as a favorite!');
         }
         Request::instance()->redirect('/photos/view/' . $photo_id);
     } else {
         Request::instance()->redirect('/');
     }
 }
Example #6
0
 public function before()
 {
     parent::before();
     $this->template->title = $this->active ? 'Error' : 'Complete';
     $this->site = Helper_Game::getSite();
 }
Example #7
0
 public function delete($id = null)
 {
     //delete all comments
     foreach ($this->comments->find_all() as $comment) {
         $comment->delete();
     }
     //delete all photos
     foreach ($this->photos->find_all() as $photo) {
         $photo->delete();
     }
     //delete avatar
     if ($this->avatar->loaded()) {
         $this->avatar->delete();
     }
     //delete all logs that refer to this user
     $logInfos = ORM::factory("Game_LogInfo")->or_where_open()->where("name", "=", "user")->or_where("name", "=", "user_id")->or_where_close()->where("data", "=", $this->id)->find_all();
     foreach ($logInfos as $logInfo) {
         $logInfo->_eventLog->delete();
     }
     //delete the user in gamification DB
     $site = Helper_Game::getSite();
     $gUser = $site->getUser($this->id);
     $gUser->delete();
     parent::delete($id);
 }
Example #8
0
 public function before()
 {
     parent::before();
     $this->site = Helper_Game::getSite();
 }