private function delete_record()
 {
     $record_id = isset($_POST['pk']) ? $_POST['pk'] : NULL;
     // if(!$this->verify_record_can_be_deleted($record_id))
     // {
     // return array('success' => FALSE, 'error' => 'access_error', 'msg' => 'Record was not found or cannot be deleted');
     // }
     $obj = ModelManager::find($this->model_name, $record_id);
     if (!$obj) {
         return array('success' => FALSE, 'error' => 'access_error', 'msg' => 'Record was not found or cannot be deleted');
     }
     if (isset($this->form_options['callbacks']['pre_deletion']) && is_callable($this->form_options['callbacks']['pre_deletion'])) {
         $result = call_user_func($this->form_options['callbacks']['pre_deletion'], array('object' => &$obj));
         if (!$result['success']) {
             return array('success' => FALSE, 'msg' => $result['msg']);
         }
     }
     if (!$obj->delete()) {
         return array('success' => FALSE, 'msg' => 'Unable to deleted the record');
     }
     if (isset($this->form_options['callbacks']['post_delete']) && is_callable($this->form_options['callbacks']['post_delete'])) {
         $result = call_user_func($this->form_options['callbacks']['post_delete'], array('object' => &$obj));
         if (!$result['success']) {
             return array('success' => FALSE, 'error' => 'post_save_error', 'msg' => $result['msg']);
         }
     }
     return array('success' => TRUE);
 }
示例#2
0
 /**
  * @return null
  */
 protected function getReference()
 {
     if ($this->connection && !$this->reference) {
         $reference = null;
         // create reference
         if ($model_name = ModelManager::find($this->connection->getTargetName())) {
             $model = new $model_name();
             $column_name = $this->connection->getTargetColumn();
             if ($model && $model->isExists($column_name)) {
                 $column = $model->getColumn($column_name);
                 $reference = new ModelReference($model, $column);
                 if ($this->connection->getDelete()) {
                     $reference->setDelete($this->connection->getDelete());
                 }
                 if ($this->connection->getUpdate()) {
                     $reference->setUpdate($this->connection->getUpdate());
                 }
                 $this->reference = $reference;
             } else {
                 throw new \Exception('not found connection target paramater.column name is "' . $this->connection->getTargetName() . '"');
             }
         } else {
             throw new \Exception('not found connection target paramater.column name is "' . $this->connection->getTargetName() . '"');
         }
     }
     return $this->reference;
 }