/** * Creates a new ModelField. The example below creates a ModelField which * lists client accounts for selection. * * @code * $clients = new ModelField("brokerage.setup.clients.client_id", "account"); * @endcode * @param $path The full path to the field in the module which is to be returned by this field. * @param $value The name of the field from the model whose value should be displayed in the list. */ public function __construct($path, $value) { global $redirectedPackage; $this->info = Model::resolvePath($path); $this->model = Model::load((substr($this->info["model"], 0, 1) == "." ? $redirectedPackage : "") . $this->info["model"]); $this->valueField = $value; $field = $this->model->getFields(array($value)); $this->setLabel($field[0]["label"]); $this->setDescription($field[0]["description"]); $this->setName($this->info["field"]); $params = array("fields" => array($this->info["field"], $this->valueField), "sort_field" => $this->valueField); if ($this->conditions != '') { $params['conditions'] = $this->conditions; } $data = $this->model->get($params, Model::MODE_ARRAY); $this->addOption("Add new " . Utils::singular($this->model->getEntity()), 'NEW'); foreach ($data as $datum) { if ($datum[1] == "") { $this->addOption($datum[0]); } else { $this->addOption($datum[1], $datum[0]); } } $modelPath = str_replace('.', '/', $this->model->package); $this->addAttribute('onchange', "fapiAddModelItem('{$modelPath}', this, '{$value}')"); }
/** * 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); } }