Пример #1
0
 /**
  * Action - locationsmanage
  * management geographic coordinates
  *
  * Access to the action is possible in the following paths:
  * - /blogmanager/locationsmanage
  *
  * @return void
  */
 public function locationsmanageAction()
 {
     $request = $this->getRequest();
     $action = $request->getPost('action');
     $post_id = $request->getPost('post_id');
     if ($request->getPost('user_id')) {
         $user_id = $request->getPost('user_id');
     } else {
         $user_id = $this->_identity->user_id;
     }
     $ret = array('post_id' => 0);
     $post = new Default_Model_DbTable_BlogPost($this->db);
     if ($post->loadForUser($user_id, $post_id)) {
         $ret['post_id'] = $post->getId();
         switch ($action) {
             case 'get':
                 $ret['locations'] = array();
                 foreach ($post->locations as $location) {
                     $location_id = $location->getId();
                     $details_url = $this->getUrl('details', 'blogmanager') . "?post_id={$post_id}&location_id={$location_id}";
                     $ret['locations'][] = array('location_id' => $location_id, 'latitude' => $location->latitude, 'longitude' => $location->longitude, 'description' => $location->description, 'content' => $location->content, 'correction' => $location->correction, 'details' => $location->details ? $details_url : '');
                 }
                 break;
             case 'description':
                 //correction
                 $formBlogPostLocation = new Default_Form_BlogPostLocation();
                 // Проверяем на валидность поля формы
                 $allParams = $this->_getAllParams();
                 $result = $formBlogPostLocation->isValid($allParams);
                 if ($result) {
                     $location_id = $request->getPost('location_id');
                     $location = new Default_Model_DbTable_BlogPostLocation($this->db);
                     if ($location->loadForPost($post->getId(), $location_id)) {
                         $location->description = $formBlogPostLocation->getValue('description');
                         $location->save();
                         $location_id = $location->getId();
                         $ret['location_id'] = $location_id;
                         $ret['latitude'] = $location->latitude;
                         $ret['longitude'] = $location->longitude;
                         $ret['description'] = $location->description;
                         $ret['content'] = $location->content;
                         $ret['correction'] = $location->correction;
                         if ($location->details) {
                             $ret['details'] = $this->getUrl('details', 'blogmanager') . "?post_id={$post_id}&location_id={$location_id}";
                         }
                     }
                 } else {
                     $ret['location_id'] = 0;
                 }
                 break;
             case 'content':
                 $formBlogPostLocation = new Default_Form_BlogPostLocation();
                 // Проверяем на валидность поля формы
                 $allParams = $this->_getAllParams();
                 $result = $formBlogPostLocation->isValid($allParams);
                 if ($result) {
                     $location_id = $request->getPost('location_id');
                     $location = new Default_Model_DbTable_BlogPostLocation($this->db);
                     if ($location->loadForPost($post->getId(), $location_id)) {
                         $content = $formBlogPostLocation->getValue('content');
                         $location->content = $content;
                         $location->save();
                         $location_id = $location->getId();
                         $ret['location_id'] = $location_id;
                         $ret['latitude'] = $location->latitude;
                         $ret['longitude'] = $location->longitude;
                         $ret['description'] = $location->description;
                         $ret['content'] = $location->content;
                         $ret['correction'] = $location->correction;
                         if ($location->details) {
                             $ret['details'] = $this->getUrl('details', 'blogmanager') . "?post_id={$post_id}&location_id={$location_id}";
                         }
                     }
                 } else {
                     $ret['location_id'] = 0;
                 }
                 break;
             case 'get_details':
                 $location_id = $request->getPost('location_id');
                 $location = new Default_Model_DbTable_BlogPostLocation($this->db);
                 if ($location->loadForPost($post->getId(), $location_id)) {
                     $location_id = $location->getId();
                     $ret['location_id'] = $location_id;
                     $ret['details'] = $location->details;
                 } else {
                     $ret['location_id'] = 0;
                     $ret['error'] = $this->Translate('Ошибка получения подробной информации по географической координате');
                 }
                 break;
             case 'set_details':
                 $formBlogPostLocation = new Default_Form_BlogPostLocation();
                 // Проверяем на валидность поля формы
                 $allParams = $this->_getAllParams();
                 $result = $formBlogPostLocation->isValid($allParams);
                 if ($result) {
                     $location_id = $request->getPost('location_id');
                     $location = new Default_Model_DbTable_BlogPostLocation($this->db);
                     if ($location->loadForPost($post->getId(), $location_id)) {
                         $details = $formBlogPostLocation->getValue('details');
                         $location->details = $details;
                         $location->save();
                         $location_id = $location->getId();
                         $ret['location_id'] = $location_id;
                         $ret['latitude'] = $location->latitude;
                         $ret['longitude'] = $location->longitude;
                         $ret['description'] = $location->description;
                         $ret['content'] = $location->content;
                         $ret['correction'] = $location->correction;
                         if ($location->details) {
                             $ret['details'] = $this->getUrl('details', 'blogmanager') . "?post_id={$post_id}&location_id={$location_id}";
                         }
                     }
                 } else {
                     $ret['location_id'] = 0;
                     $ret['error'] = $this->Translate('Ошибка записи подробной информации по географической координате');
                 }
                 break;
             case 'correction':
                 $formBlogPostLocation = new Default_Form_BlogPostLocation();
                 // Проверяем на валидность поля формы
                 $allParams = $this->_getAllParams();
                 $result = $formBlogPostLocation->isValid($allParams);
                 if ($result) {
                     $location_id = $request->getPost('location_id');
                     $location = new Default_Model_DbTable_BlogPostLocation($this->db);
                     if ($location->loadForPost($post->getId(), $location_id)) {
                         $location->correction = $formBlogPostLocation->getValue('correction');
                         $location->save();
                         $location_id = $location->getId();
                         $ret['location_id'] = $location_id;
                         $ret['latitude'] = $location->latitude;
                         $ret['longitude'] = $location->longitude;
                         $ret['description'] = $location->description;
                         $ret['content'] = $location->content;
                         $ret['correction'] = $location->correction;
                         if ($location->details) {
                             $ret['details'] = $this->getUrl('details', 'blogmanager') . "?post_id={$post_id}&location_id={$location_id}";
                         }
                     }
                 } else {
                     $ret['location_id'] = 0;
                 }
                 break;
             case 'add':
                 $formBlogPostLocation = new Default_Form_BlogPostLocation();
                 // Проверяем на валидность поля формы
                 $allParams = $this->_getAllParams();
                 $result = $formBlogPostLocation->isValid($allParams);
                 if ($result) {
                     $location = new Default_Model_DbTable_BlogPostLocation($this->db);
                     $location->post_id = $post->getId();
                     $location->description = $formBlogPostLocation->getValue('description');
                     $location->longitude = $formBlogPostLocation->getValue('longitude');
                     $location->latitude = $formBlogPostLocation->getValue('latitude');
                     if ($request->getPost('content')) {
                         $location->content = $formBlogPostLocation->getValue('content');
                     }
                     $location->save();
                     $ret['location_id'] = $location->getId();
                     $ret['latitude'] = $location->latitude;
                     $ret['longitude'] = $location->longitude;
                     $ret['description'] = $location->description;
                     $ret['content'] = $location->content;
                     $ret['correction'] = $location->correction;
                 } else {
                     $ret['location_id'] = 0;
                 }
                 break;
             case 'delete':
                 $location_id = $request->getPost('location_id');
                 $location = new Default_Model_DbTable_BlogPostLocation($this->db);
                 if ($location->loadForPost($post->getId(), $location_id)) {
                     $ret['location_id'] = $location->getId();
                     $location->delete();
                 }
                 break;
             case 'move':
                 $formBlogPostLocation = new Default_Form_BlogPostLocation();
                 // Проверяем на валидность поля формы
                 $allParams = $this->_getAllParams();
                 $result = $formBlogPostLocation->isValid($allParams);
                 if ($result) {
                     $location_id = $request->getPost('location_id');
                     $location = new Default_Model_DbTable_BlogPostLocation($this->db);
                     if ($location->loadForPost($post->getId(), $location_id)) {
                         if ($request->getPost('description')) {
                             $location->description = $formBlogPostLocation->getValue('description');
                         }
                         $location->longitude = $formBlogPostLocation->getValue('longitude');
                         $location->latitude = $formBlogPostLocation->getValue('latitude');
                         $location->save();
                         $location_id = $location->getId();
                         $ret['location_id'] = $location_id;
                         $ret['latitude'] = $location->latitude;
                         $ret['longitude'] = $location->longitude;
                         $ret['description'] = $location->description;
                         $ret['content'] = $location->content;
                         $ret['correction'] = $location->correction;
                         if ($location->details) {
                             $ret['details'] = $this->getUrl('details', 'blogmanager') . "?post_id={$post_id}&location_id={$location_id}";
                         }
                     } else {
                         $ret['location_id'] = 0;
                     }
                 } else {
                     $ret['location_id'] = 0;
                 }
                 break;
         }
     }
     $this->sendJson($ret);
 }