/** * @return void */ public function autocomplete() { $datas = null; $response = array("error" => ""); if (!isset($_GET["form_name"]) || empty($_GET["form_name"])) { $response["error"] = '$_GET["form_name"] require'; } if (!isset($_GET["input_name"]) || empty($_GET["input_name"])) { $response["error"] = '$_GET["input_name"] require'; } if (empty($response["error"])) { $path_to_form = "includes/applications/" . $_GET["application"] . "/modules/"; if ($_GET["module"]) { $path_to_form .= $_GET["module"] . "/"; } else { $path_to_form .= "front/"; } $path_to_form .= "forms/form." . $_GET["form_name"] . ".json"; try { $datas = SimpleJSON::import($path_to_form); } catch (Exception $e) { $response["error"] = "Formulaire introuvable " . $path_to_form; $this->response($response); } if (!is_array($datas[$_GET["input_name"]])) { $response["error"] = "Champs ciblé introuvable"; $this->response($response); } $input = $datas[$_GET["input_name"]]; if ($input["tag"] != Form::TAG_INPUT || $input["attributes"]["type"] != "text") { $response["error"] = "Champs ciblé n'est pas un input type 'text'"; $this->response($response); } if (!$input["autoComplete"] || !is_array($input["autoComplete"])) { $response["error"] = "Les éléments de bases ne sont pas renseignés"; $this->response($response); } $model = new $input["autoComplete"]["model"](); $cond = Query::condition()->andWhere($input["autoComplete"]["value"], Query::LIKE, "%" . $_GET["q"] . "%"); if (isset($input["autoComplete"]["condition"]) && is_array($input["autoComplete"]["condition"]) && count($input["autoComplete"]["condition"])) { foreach ($input["autoComplete"]["condition"] as $m => $p) { call_user_func_array(array($cond, $m), $p); } } if (isset($_GET["replies"]) && Form::isNumeric($_GET["replies"])) { $result = $model->{$input}["autoComplete"]["method"]($_GET["replies"]); } else { $result = $model->{$input}["autoComplete"]["method"]($cond, $input["autoComplete"]["value"]); } $response["responses"] = array(); foreach ($result as $r) { $d = array("value" => $r[$input["autoComplete"]["value"]]); if (isset($input["autoComplete"]["raw"]) && is_array($input["autoComplete"]["raw"])) { foreach ($input["autoComplete"]["raw"] as $v) { $d[$v] = $r[$v]; } } $response["responses"][] = $d; } } $this->response($response); }
private static function upload($pName, $pId, $pData, $pRequire = "") { self::$ct_upload++; $file = $style = $value = ""; $server_url = Configuration::$server_url; /** * @todo concaténer la valeur du relative path de l'application en cours à $server_url ? */ $disabled = isset($pData["attributes"]["disabled"]) && $pData["attributes"]["disabled"] == "disabled" ? "disabled" : ""; if (isset($pData["attributes"]["value"]) && !empty($pData["attributes"]["value"])) { $value = $pData["attributes"]["value"]; $file = $server_url; /** @var ModelUpload $m */ $m = isset($pData["model"]) && !empty($pData["model"]) ? $pData["model"] : "core\\models\\ModelUpload"; if (Form::isNumeric($value)) { $file .= Application::getInstance()->getPathPart() . $m::getPathById($value); } else { $file .= $value; } } $deleteFileAction = ""; if (isset($pData['deleteFileAction']) && !empty($pData['deleteFileAction'])) { if ($value && Form::isNumeric($value)) { $action = preg_replace('/\\{id\\}/', $value, $pData['deleteFileAction']); } else { $action = $pData['deleteFileAction']; } $deleteFileAction = 'data-delete_file_action="' . $action . '"'; } $comp = "<input " . $disabled . " type='file' name='" . $pName . "_input' data-form_name='" . $pData["form_name"] . "' data-input_name='" . $pData["field_name"] . "' data-application='" . Core::$application . "' data-value='" . $value . "' data-file='" . $file . "' data-module='" . Core::$module . "'" . $deleteFileAction . ">"; $input = self::getLabel($pData["label"] . $pRequire, $pId); $input .= self::getComponent($comp, 'upload'); return $input; }