コード例 #1
0
ファイル: Registration.php プロジェクト: adrpar/daiquiri
 /**
  * Deletes a registration entry.
  * @param int $id id of registration entry
  * @param array $formParams
  * @return array $response
  */
 public function delete($id, array $formParams = array())
 {
     // create the form object
     $form = new Daiquiri_Form_Danger(array('submit' => 'Delete registration entry'));
     // valiadate the form if POST
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             // get the form values
             $values = $form->getValues();
             // delete the user and redirect
             $this->getResource()->deleteRegistration($id);
             return array('status' => 'ok');
         } else {
             return $this->getModelHelper('CRUD')->validationErrorResponse($form);
         }
     }
     return array('form' => $form, 'status' => 'form');
 }
コード例 #2
0
ファイル: Sessions.php プロジェクト: vrtulka23/daiquiri
 /**
  * Destroys a given session
  * @param string $session
  * @param array $formParams
  * @return array $response
  */
 public function destroy($session, array $formParams = array())
 {
     // create the form object
     $form = new Daiquiri_Form_Danger(array('submit' => 'Destroy session'));
     // valiadate the form if POST
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             $this->getResource()->deleteRow($session);
             return array('status' => 'ok');
         } else {
             return $this->getModelHelper('CRUD')->validationErrorResponse($form);
         }
     }
     return array('form' => $form, 'status' => 'form');
 }
コード例 #3
0
ファイル: Details.php プロジェクト: vrtulka23/daiquiri
 /**
  * Deletes a user detail.
  * @param int $userId id of the user
  * @param string $key key of the detail
  * @param array $formParams
  * @return array $response
  */
 public function delete($userId, $key, array $formParams = array())
 {
     if (empty($userId) || empty($key)) {
         throw new Daiquiri_Exception_BadRequest('id and/or key arguments are missing. ');
     }
     // check if the key is there
     if ($this->getResource()->fetchValue($userId, $key) === false) {
         return array('status' => 'error', 'error' => 'Key not found');
     } else {
         if (in_array($key, Daiquiri_Auth::getInstance()->getDetailKeys())) {
             return array('status' => 'error', 'error' => 'Key is protected');
         }
     }
     // create the form object
     $form = new Daiquiri_Form_Danger(array('submit' => 'Delete detail'));
     // valiadate the form if POST
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             $this->getResource()->deleteValue($userId, $key);
             return array('status' => 'ok');
         } else {
             return $this->getModelHelper('CRUD')->validationErrorResponse($form);
         }
     }
     return array('form' => $form, 'status' => 'form');
 }
コード例 #4
0
ファイル: Jobs.php プロジェクト: vrtulka23/daiquiri
 /**
  * Remove a job.
  * @param type $id id of the job
  * @return array $response
  */
 public function remove($id, array $formParams = array())
 {
     // create the form object
     $form = new Daiquiri_Form_Danger(array('submit' => 'Remove job'));
     // valiadate the form if POST
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             $this->getResource()->removeJob($id);
             return array('status' => 'ok');
         } else {
             return $this->getModelHelper('CRUD')->validationErrorResponse($form);
         }
     }
     return array('form' => $form, 'status' => 'form');
 }
コード例 #5
0
ファイル: User.php プロジェクト: vrtulka23/daiquiri
 /**
  * Deletes an existing user.
  * @param int $id id of the user
  * @param array $formParams
  * @return array $response
  */
 public function delete($id, array $formParams = array())
 {
     // create the form object
     $form = new Daiquiri_Form_Danger(array('submit' => 'Delete user'));
     // valiadate the form if POST
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             // get the form values
             $values = $form->getValues();
             // delete the user and redirect
             $this->getResource()->deleteRow($id);
             // invalidate the session of the user
             $resource = new Auth_Model_Resource_Sessions();
             foreach ($resource->fetchAuthSessionsByUserId($id) as $session) {
                 $resource->deleteRow($session);
             }
             // log the event and return
             Daiquiri_Log::getInstance()->notice("user deleted by admin (user_id: {$id})");
             return array('status' => 'ok');
         } else {
             return $this->getModelHelper('CRUD')->validationErrorResponse($form);
         }
     }
     return array('form' => $form, 'status' => 'form');
 }
コード例 #6
0
ファイル: Account.php プロジェクト: vrtulka23/daiquiri
 /**
  * Removes a job.
  * @param type $id job id
  * @param array $formParams
  * @return array $response
  */
 public function removeJob($id, array $formParams = array())
 {
     // set job resource
     $this->setResource(Query_Model_Resource_AbstractQuery::factory());
     // get job and check permissions
     $row = $this->getResource()->fetchRow($id);
     if (empty($row) || $row['user_id'] !== Daiquiri_Auth::getInstance()->getCurrentId()) {
         throw new Daiquiri_Exception_NotFound();
     }
     // create the form object
     $form = new Daiquiri_Form_Danger(array('submit' => 'Remove job'));
     // valiadate the form if POST
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             try {
                 $this->getResource()->removeJob($id);
                 return array('status' => 'ok');
             } catch (Exception $e) {
                 return $this->getModelHelper('CRUD')->validationErrorResponse($form, $e->getMessage());
             }
         } else {
             return $this->getModelHelper('CRUD')->validationErrorResponse($form);
         }
     }
     return array('form' => $form, 'status' => 'form');
 }