Ejemplo n.º 1
0
 public function all($pCond = null, $pFields = "*")
 {
     $all = parent::all($pCond, $pFields);
     foreach ($all as &$post) {
         $post['categories'] = Query::select('b.*', 'post_category a')->join('main_category b', Query::JOIN_INNER, 'a.id_category=b.id_category')->andWhere('a.id_post', Query::EQUAL, $post['id_post'])->execute();
     }
     return $all;
 }
Ejemplo n.º 2
0
 public function __construct()
 {
     /** @var AuthenticationHandler $auth */
     $auth = Application::getInstance()->authenticationHandler;
     $auth::getInstance();
     $this->addContent('user_data', AuthenticationHandler::$data);
     $m = new ModelCategory();
     $this->addContent('categories', $m->all(Query::condition()->order('name_category', 'ASC')));
 }
Ejemplo n.º 3
0
 public static function isUser($pLogin, $pMdp)
 {
     if (empty($pLogin) || empty($pMdp)) {
         return false;
     }
     $instance = self::getInstance();
     if ($result = $instance->one(Query::condition()->andWhere(Configuration::$authentication_fieldLogin, Query::EQUAL, $pLogin))) {
         if ($result[configuration::$authentication_fieldPassword] == $pMdp) {
             self::$data = $result;
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 public function prepareCategories($pTags)
 {
     if (empty($pTags)) {
         return array();
     }
     $ids = array();
     foreach ($pTags as $t) {
         if (Query::count($this->table, Query::condition()->andWhere('name_category', Query::EQUAL, $t))) {
             continue;
         }
         $permalink = RoutingHandler::sanitize($t);
         $this->insert(array('name_category' => $t, 'permalink_category' => $permalink));
         $ids[] = $this->getInsertId();
     }
     return $ids;
 }
Ejemplo n.º 5
0
 public function update()
 {
     if (!Core::checkRequiredGetVars('permalink_list', 'prop_list') || !isset($_POST) || empty($_POST) || !isset($_POST['value']) || empty($_POST['value'])) {
         Go::to404();
     }
     $m = new ModelList();
     $list = $m->one(Query::condition()->andWhere('permalink_list', Query::EQUAL, $_GET['permalink_list']));
     if (!$list) {
         Go::to404();
     }
     $name = $_GET['prop_list'];
     if ($m->updateById($list['id_list'], array($name => $_POST['value']))) {
         $response = array("message" => "ok");
     } else {
         $response = array("error", "Unable to perform an update on field '" . $name . "'");
     }
     $response = SimpleJSON::encode($response);
     Core::performResponse($response, 'json');
 }
Ejemplo n.º 6
0
 public static function isUser($pLogin, $pMdp, $pHash = false)
 {
     if (empty($pLogin) || empty($pMdp)) {
         return false;
     }
     /** @var BaseModel $instance */
     $instance = self::getInstance();
     if ($result = $instance->one(Query::condition()->andWhere(Configuration::$authentication_fieldLogin, Query::EQUAL, $pLogin))) {
         $salt = $result[Configuration::$authentication_fieldSalt];
         $value = $pMdp;
         if (!$pHash) {
             $value = self::computePasswordHash($pMdp, $salt);
         }
         if ($result[configuration::$authentication_fieldPassword] == $value) {
             self::$data = $result;
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 7
0
 /**
  * @return QueryCondition
  */
 public function getConditionLimit()
 {
     return Query::condition()->limit($this->first, $this->number);
 }
Ejemplo n.º 8
0
 /**
  * Méthode de définition des champs à mettre-à-jour
  * @param array $pValues
  * @param bool $pEscape
  * @return QueryUpdate
  */
 public function values($pValues, $pEscape = true)
 {
     foreach ($pValues as $field => $value) {
         array_push($this->values, $field . "=" . Query::escapeValue($value, $pEscape));
     }
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * @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);
 }
Ejemplo n.º 10
0
 /**
  * Méthode de pré-traitement du formulaire avant envoi à la vue (parsing des libellés, des types de balises, définition des js/css requis)
  * @return void
  */
 public function prepareToView()
 {
     $this->cleanData();
     if (isset($this->post)) {
         $this->injectValues($this->post);
     }
     Autoload::addScript("Form");
     $this->countMendatory = 0;
     foreach ($this->data as $name => &$data) {
         switch ($data["tag"]) {
             case self::TAG_RICHEDITOR:
                 /** @ todo **/
                 trace("you must handle richeditor");
                 Autoload::addScript("ckeditor/ckeditor.js");
                 break;
             case self::TAG_UPLOAD:
                 Autoload::addComponent("Uploader");
                 Autoload::addScript("M4Tween");
                 $this->hasUpload = true;
                 break;
             case self::TAG_INPUT:
                 if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "checkbox") {
                     unset($data["attributes"]["valueOff"]);
                 }
                 if (isset($data["autoComplete"])) {
                     Autoload::addComponent('Autocomplete');
                 }
                 if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "file") {
                     Autoload::addComponent("Uploader");
                     Autoload::addScript("M4Tween");
                     $this->hasUpload = true;
                 } else {
                     if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "submit" && Application::getInstance()->multiLanguage) {
                         $data["attributes"]["value"] = Dictionary::term($data["attributes"]["value"]);
                     }
                 }
                 break;
             case self::TAG_DATEPICKER:
                 Autoload::addComponent("Pikaday");
                 $this->hasDatePicker = true;
                 break;
             case self::TAG_COLORPICKER:
                 Autoload::addScript("jscolor/jscolor.js");
                 $this->hasColorPicker = true;
                 break;
             case self::TAG_RADIOGROUP:
             case self::TAG_CHECKBOXGROUP:
             case self::TAG_SELECT:
                 if (isset($data["fromModel"]) && is_array($data["fromModel"])) {
                     $condition = null;
                     $fm = $data["fromModel"];
                     if (isset($fm["condition"]) && is_array($fm["condition"])) {
                         $condition = Query::condition();
                         foreach ($fm["condition"] as $method => $parameters) {
                             call_user_func_array(array($condition, $method), $parameters);
                         }
                     }
                     $model = method_exists($fm["model"], "getInstance") ? $fm["model"]::getInstance() : new $fm["model"]();
                     $datas = $model->{$fm}["method"]($condition);
                     $options = array();
                     $defaultChecked = isset($data["attributes"]["checked"]) && !isset($this->post);
                     foreach ($datas as $donnees) {
                         if (is_object($donnees)) {
                             $donnees_name = $donnees->{$fm}["name"];
                             $donnees_value = $donnees->{$fm}["value"];
                         } else {
                             $donnees_name = isset($donnees[$fm['name']]) ? $donnees[$fm["name"]] : '';
                             $donnees_value = isset($donnees[$fm['value']]) ? $donnees[$fm["value"]] : '';
                         }
                         $options[] = array("name" => $donnees_name, "label" => $donnees_name, "value" => $donnees_value, "checked" => $defaultChecked);
                     }
                     if (!isset($data["options"])) {
                         $data["options"] = $options;
                     } else {
                         $data["options"] = array_merge($data["options"], $options);
                     }
                 }
                 if (isset($data["chosen"]) && $data["chosen"] == true) {
                     Autoload::addScript("chosen/chosen.min.js");
                     /** @todo componentify this */
                     Autoload::addStyle(Core::$path_to_components . "/chosen/style/chosen.css");
                 }
                 break;
         }
         if ($data["require"]) {
             $this->countMendatory++;
         }
         if (isset($data["attributes"]["valueGet"])) {
             if (isset($_GET[$data["attributes"]["valueGet"]])) {
                 $data["attributes"]["value"] = $_GET[$data["attributes"]["valueGet"]];
                 unset($this->data[$name]["attributes"]["valueGet"]);
             } else {
                 if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "hidden") {
                     unset($this->data[$name]);
                 }
             }
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * Méthode static de création de la table d'upload
  * @param String $pApplication [optional] Nom de l'application sur laquelle on souhaite ajouter la table
  * @return resource
  */
 public static function create($pApplication = "main")
 {
     return Query::create($pApplication . "_upload", "MyISAM")->addField("id_upload", "int", "11", "", false, true)->addField("path_upload", "varchar", "255")->execute();
 }
Ejemplo n.º 12
0
 /**
  * Méthode permettant de lister toutes les entrées du model
  * Gestion automatique du ORDER BY
  * @param String $pCondition		Condition souhaitée pour la requête SQL
  * @return void
  */
 public function listing($pCondition = null)
 {
     if (!$this->actions->isEnabled("listing")) {
         Go::to404();
     }
     $this->setTitle($this->titles->get('listing'));
     $this->setTemplate("default", "listing");
     $this->addContent("titles", $this->listTitle);
     $this->addContent("id", $this->model->id);
     if (!$pCondition) {
         $pCondition = Query::condition();
     }
     $pConditionCount = clone $pCondition;
     for ($i = 0, $max = count($this->listTitle); $i < $max; $i++) {
         if (isset($_GET["order"]) && in_array($_GET["order"], $this->listTitle[$i])) {
             $pCondition->order($_GET["order"], isset($_GET["by"]) ? $_GET["by"] : "ASC");
             $i = $max;
         }
     }
     if ($this->usePaginationOnList) {
         $nbDatas = $this->model->count($pConditionCount);
         $currentPage = isset($_GET["page"]) ? $_GET["page"] : 1;
         $pagination = new PaginationHandler($currentPage, $this->nbItemsByPage, $nbDatas);
         $pCondition->limit($pagination->first, $pagination->number);
         $data = $this->model->all($pCondition);
         $this->addContent("paginationInfo", $pagination->getPaginationInfo());
     } else {
         $data = $this->model->all($pCondition);
     }
     $this->addContent("liste", $data);
     $this->addContent("h1", $this->h1->get('listing'));
 }
Ejemplo n.º 13
0
 public static function debugger()
 {
     trace("premiere action trace");
     trigger_error("Une notice trigger par le code", E_USER_NOTICE);
     for ($i = 0; $i < 20; $i++) {
         trigger_error("Un warning trigger &agrave; chaque itération", E_USER_WARNING);
         if ($i % 3 == 0) {
             trace("i : " . $i);
         }
     }
     trace("before sleep 10 secondes");
     sleep(10);
     trace("after sleep 10 secondes");
     trace("derni&egrave;re action trace");
     Query::select("*", "ma_table")->join("mon_autre_table")->andWhere("un_champ", Query::EQUAL, "une valeur")->limit(0, 1)->groupBy("some_id")->execute();
 }
Ejemplo n.º 14
0
 public function retrieveByUser($pIdUser, $pCount = 10)
 {
     return $this->all(Query::condition()->andWhere('id_user', Query::EQUAL, $pIdUser)->order('name_list')->limit(0, $pCount));
 }
Ejemplo n.º 15
0
 /**
  *
  */
 public function generateInputsFromDescribe()
 {
     $result = Query::execute('DESCRIBE ' . $this->table, $this->handler);
     $inputs = array();
     foreach ($result as &$field) {
         $name = $field['Field'];
         switch ($field['Type']) {
             case "date":
                 $input = array('tag' => 'datepicker', 'attributes');
                 break;
             case "text":
                 $input = array('tag' => 'textarea');
                 break;
             default:
                 $input = array('tag' => 'input', 'attributes' => array('type' => 'text'));
                 break;
         }
         $input['label'] = $name;
         $inputs[$name] = $input;
     }
     $inputs['submit'] = array('label' => '', 'tag' => 'input', 'attributes' => array('type' => 'submit', 'value' => 'Valider', 'class' => 'button'));
     return $inputs;
 }
Ejemplo n.º 16
0
 public function updatePriceLinks()
 {
     $links = $this->all();
     foreach ($links as &$l) {
         $this->decorateLink($l);
         Query::update($this->table)->values(array('weekly_price_link' => $l['previous_price']))->andWhere('id_link', Query::EQUAL, $l['id_link'])->execute($this->handler);
     }
 }