コード例 #1
0
 public function indexAction()
 {
     if (isset($_SESSION['msg'])) {
         $this->view->msg = $_SESSION['msg'];
         unset($_SESSION['msg']);
     }
     $userNs = new Zend_Session_Namespace('members');
     $userId = $userNs->userId;
     $form = new Album_Form_Album();
     $objModelAlbum = new Album_Model_Album();
     $objModelGapperLocation = new Application_Model_GapperLocation();
     /*------------- GET GAPPER LOCATION ---------------*/
     $yesterday = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"));
     $whereGapperLocation = "user_id='{$userId}' and latest=1 AND addedon >= '{$yesterday}'";
     $arrGapperLocation = $objModelGapperLocation->fetchAll($whereGapperLocation);
     if (!empty($arrGapperLocation)) {
         $this->view->myLatitude = $arrGapperLocation[0]->latitude;
         $this->view->myLongitude = $arrGapperLocation[0]->longitude;
     } else {
         $this->view->myLatitude = "";
         $this->view->myLongitude = "";
     }
     /*-------------------------------------------------*/
     $elements = $form->getElements();
     $form->clearDecorators();
     foreach ($elements as $element) {
         $element->removeDecorator('label');
     }
     /*---------------------- GET USED PHOTO SIZE OF USER --------------------------*/
     $arrAlbumCapacity = $objModelAlbum->albumCapacity($userId);
     $this->view->capacityImage = $arrAlbumCapacity[0];
     $this->view->capacityPercent = $arrAlbumCapacity[1];
     $request = $this->getRequest();
     // Get posted value
     if ($request->isPost()) {
         $params = $request->getParams();
         // Get all posted value
         if ($form->isValid($params)) {
             $option['userId'] = $userId;
             // LoggedIn UserId
             $arrLatLang = explode(",", $params['latlang']);
             $latitude = substr($arrLatLang[0], 1, strlen($arrLatLang[0]));
             // Longitude of location
             $longitude = substr($arrLatLang[1], 0, -1);
             //	Latitude of location
             $option['name'] = $params['name'];
             $option['description'] = $params['description'];
             $option['location'] = $params['address'];
             $option['permission'] = $params['permissions'];
             $option['longitude'] = $longitude;
             $option['latitude'] = $latitude;
             $option['status'] = 1;
             $albumM = new Album_Model_Album($option);
             $album_id = $albumM->save();
             if ($album_id > 0) {
                 /*----- start tags--------*/
                 if ($params['tags'] != "" && $params['tags'] != 'Separate Tags by a comma. For example: \' Holiday, London, Travel\'') {
                     $arrTags = explode(",", $params['tags']);
                     foreach ($arrTags as $_tag) {
                         $_tag = trim($_tag);
                         $tagsM = new Application_Model_Tags();
                         $tag = $tagsM->fetchRow("tag='{$_tag}'");
                         if (false === $tag) {
                             $tagsM->setTag($_tag);
                             $tag_id = $tagsM->save();
                         } else {
                             $tag_id = $tag->getId();
                         }
                         $albumTagM = new Album_Model_AlbumTag();
                         $albumTagM->setAlbumId($album_id);
                         $albumTagM->setTagId($tag_id);
                         $albumTagM->save();
                     }
                 }
                 $redirectUrl = "/album/my-photos/album-photos/id/" . $album_id;
                 /*---------- end tags-------*/
                 //$this->_helper->redirector('index','create-album',"album");
                 $_SESSION['msg'] = "Album created successfully.";
                 $this->_redirect($redirectUrl);
                 $form->reset();
             } else {
                 $_SESSION['msg'] = "Faild to create Album. Please try again.";
                 $this->_redirect('/album/create-album');
             }
         }
     }
     $objModelUserPermission = new Application_Model_UserPermission();
     $whereUserPermission = "permission_id='5' AND user_id='{$userId}'";
     $arrUserPermission = $objModelUserPermission->fetchRow($whereUserPermission);
     $form->getElement('permissions')->setValue($arrUserPermission->friendGroupId);
     $this->view->form = $form;
 }