コード例 #1
0
 public function savepostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $application = new Application_Model_Application();
         try {
             if (!empty($datas['app_id'])) {
                 $application->find($datas['app_id']);
                 if (!$application->getId()) {
                     throw new Exception($this->_('An error occurred while saving the application. Please try again later.'));
                 }
             }
             if (empty($datas['bundle_id'])) {
                 throw new Exception($this->_('The Bundle Id is required'));
             }
             $application->addData($datas)->save();
             $this->getSession()->addSuccess($this->_('The application has been successfully saved'));
             $this->_redirect('application/backoffice/list');
         } catch (Exception $e) {
             $this->getSession()->addError($e->getMessage());
             if ($application->getId()) {
                 $this->_redirect('application/backoffice/edit', array('app_id' => $application->getId()));
             } else {
                 $this->_redirect('application/backoffice/new');
             }
         }
     }
 }
コード例 #2
0
 public function savedeviceAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data["app_id"]) or !is_array($data["devices"]) or empty($data["devices"])) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $application = new Application_Model_Application();
             $application->find($data["app_id"]);
             $data_app_to_save = array("banner_title" => $data["banner_title"], "banner_author" => $data["banner_author"], "banner_button_label" => $data["banner_button_label"]);
             $application->addData($data_app_to_save)->save();
             if (!$application->getId()) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             foreach ($data["devices"] as $device_data) {
                 if (!empty($device_data["store_url"])) {
                     if (stripos($device_data["store_url"], "http") === false) {
                         $device_data["store_url"] = "http://" . $device_data["store_url"];
                     }
                     if (!Zend_Uri::check($device_data["store_url"])) {
                         throw new Exception($this->_("Please enter a correct URL for the %s store", $device_data["name"]));
                     }
                 } else {
                     $device_data["store_url"] = null;
                 }
                 $device = $application->getDevice($device_data["type_id"]);
                 $device->addData($device_data)->save();
             }
             $data = array("success" => 1, "message" => $this->_("Info successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }