public function set_primary_photoAction($id = null, $business_id = null)
 {
     $this->view->disable();
     $photos = BusinessImages::findFirst($id);
     $userSession = $this->session->get('userSession');
     if (!$photos) {
         // if(!$photos || $userSession['id'] != $photos->member_id) {
         return $this->response->redirect('business/photos/' . $business_id);
     } else {
         $currentPhotos = BusinessImages::find('business_id = "' . $business_id . '"');
         foreach ($currentPhotos as $key => $currentPhoto) {
             $currentPhoto->primary_pic = 'No';
             $currentPhoto->update();
         }
         $photos->modified = date('Y-m-d H:i:s');
         $photos->primary_pic = 'Yes';
         if ($photos->update()) {
             $userSession['primary_pic'] = $photos->file_path . $photos->filename;
             $this->session->set('userSession', $userSession);
             $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>Photo has been set as primary.');
             return $this->response->redirect('business/view/' . $business_id);
         } else {
             $this->view->disable();
             echo "failed to modified data. ";
         }
     }
 }
 public function photosAction($id = null)
 {
     $business = array();
     if (isset($_GET["page"])) {
         $currentPage = (int) $_GET["page"];
     } else {
         $currentPage = 1;
     }
     $business = Business::findFirstById($id);
     $businessImages = BusinessImages::find(array('business_id = "' . $id . '"', "order" => "id DESC"));
     if (!$business) {
         return $this->response->redirect('review/search_business');
     }
     $this->view->setVar('business', $business);
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $businessImages, "limit" => 10, "page" => $currentPage));
     $page = $paginator->getPaginate();
     $this->view->setVar('businessImages', $page);
     $businessFirstImg = BusinessImages::findFirst(array('business_id = "' . $id . '"', "order" => "id DESC"));
     $this->view->setVar('businessFirstImg', $businessFirstImg);
     // $businessLastImg = BusinessImages::findFirst(array('business_id = "'.$id.'"', "order" => "id DESC"));
     // $this->view->setVar('businessLastImg', $businessLastImg);
 }