コード例 #1
0
 public function setapplicationtoadminAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (empty($data["admin_id"]) or empty($data["app_id"])) {
                 throw new Exception($this->_("1An error occurred while saving. Please try again later."));
             }
             $admin = new Admin_Model_Admin();
             $admin->find($data["admin_id"]);
             if (($admin->getId() or $admin->getParentId()) and ($admin->getId() != $this->getAdmin()->getId() and $admin->getParentId() != $this->getAdmin()->getId())) {
                 $this->getSession()->addError("This administrator does not exist");
             }
             $application = new Application_Model_Application();
             $application->find($data["app_id"]);
             if (!$application->getId()) {
                 throw new Exception($this->_("2An error occurred while saving. Please try again later."));
             }
             if (!$application->hasAsAdmin($this->getAdmin()->getId())) {
                 throw new Exception($this->_("3An error occurred while saving. Please try again later."));
             }
             $is_selected = !empty($data["is_selected"]);
             $data = array("success" => 1);
             if ($is_selected) {
                 $data["is_allowed_to_add_pages"] = true;
                 $admin->setIsAllowedToAddPages(true);
                 $application->addAdmin($admin);
             } else {
                 $data["is_allowed_to_add_pages"] = false;
                 $application->removeAdmin($admin);
             }
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }