コード例 #1
0
 public function indexAction()
 {
     //Load Townhall Resource Page
     if ($topicName = $this->getRequest()->getParam('topic', FALSE)) {
         $topicName = strtolower($topicName);
         $topicService = new Service_Topic();
         if (is_array($topics = $topicService->fetchUrlList())) {
             if ($topic = array_search($topicName, $topics)) {
                 $this->_helper->layout->setLayout('topmenu');
                 $resourceService = new Service_Resource();
                 if (is_array($resources = $resourceService->fetchByTopic($topic))) {
                     for ($i = 0; $i < $resources['total']; $i++) {
                         $bookmarked = false;
                         if (count($resources['resources'][$i]['Bookmarkers'])) {
                             foreach ($resources['resources'][$i]['Bookmarkers'] as $bookmarker) {
                                 if ($this->_user->id == $bookmarker['id']) {
                                     $bookmarked = true;
                                     break;
                                 }
                             }
                         }
                         $resources['resources'][$i]['bookmarked'] = $bookmarked;
                     }
                     $this->view->title = ucfirst($topicName);
                     $this->view->resources = $resources['resources'];
                     $this->view->resourceCount = $resources['total'];
                     return $this->render('topicResources');
                 } else {
                     return $this->_redirect("/resources/error");
                 }
             } else {
                 $this->view->error = $topics;
                 return $this->render();
                 return $this->_redirect("/resources/error");
             }
         } else {
             return $this->_redirect("/error");
         }
         //Modify for Error Response Page
     } else {
         $this->_helper->layout->setLayout('topmenu');
         $resourceService = new Service_Resource();
         $newestResources = $resourceService->fetchNewest();
         for ($i = 0; $i < count($newestResources); $i++) {
             $bookmarked = false;
             if (count($newestResources[$i]['Bookmarkers'])) {
                 foreach ($newestResources[$i]['Bookmarkers'] as $bookmarker) {
                     if ($this->_user->id == $bookmarker['id']) {
                         $bookmarked = true;
                         break;
                     }
                 }
             }
             $newestResources[$i]['bookmarked'] = $bookmarked;
         }
         $this->view->newestResources = $newestResources;
         $locationResources = $resourceService->fetchByState($this->_user->stateprovid);
         for ($i = 0; $i < $locationResources['total']; $i++) {
             $bookmarked = false;
             if (count($locationResources['resources'][$i]['Bookmarkers'])) {
                 foreach ($locationResources['resources'][$i]['Bookmarkers'] as $bookmarker) {
                     if ($this->_user->id == $bookmarker['id']) {
                         $bookmarked = true;
                         break;
                     }
                 }
             }
             $locationResources['resources'][$i]['bookmarked'] = $bookmarked;
         }
         $this->view->localResources = $locationResources;
         return $this->render();
     }
 }