private function addData() { $validated = $this->modelInstance->setData($this->modelData); if ($validated === true) { $this->modelInstance->save(); $this->added++; return 'Added'; } else { return $validated; } }
public function setData(array $data) { foreach ($data as $key => $value) { if ($key === 'password') { $data[$key] = md5($value); } } parent::setData($data); }
/** * Delete a particular item from the model. * @param $params * @return unknown_type */ public function delete($params) { if (User::getPermission($this->permissionPrefix . "_can_delete")) { $data = $this->model->getWithField($this->model->getKeyField(), $params[0]); $this->model->delete($this->model->getKeyField(), $params[0]); $this->model->setData($data[0]); Application::queueNotification($this->getDeleteNotificationMessage(Utils::singular($this->model->getEntity()), $this->model)); Application::redirect($this->urlPath); } }
/** * Controller action method for adding new items to the model database. * @return String */ public function add() { if ($this->apiMode === true) { $return = $this->model->setData($_REQUEST); if ($return === true) { $id = $this->model->save(); return json_encode(array("success" => true, "data" => $id)); } else { return json_encode(array("success" => false, "data" => $return)); } } else { $form = $this->getForm(); $this->label = "New " . $this->label; $form->setCallback($this->callbackMethod, array("action" => "add", "instance" => $this, "success_message" => "Added new " . $this->model->name, "form" => $form)); return $form->render(); } }