コード例 #1
0
ファイル: class.BaseModel.php プロジェクト: arno06/Savely
 /**
  *
  */
 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;
 }
コード例 #2
0
ファイル: class.Query.php プロジェクト: arno06/Savely
 /**
  * @Author Alain LEE - alee@cbi-multimedia.com
  * @param string $pHandler
  * @return array|resource
  */
 public function explain($pHandler = "default")
 {
     $query = $this->get();
     $result = Query::execute("EXPLAIN " . $query, $pHandler);
     $useKey = true;
     $useTemporary = false;
     $useFileSort = false;
     $tableWithNoIndex = array();
     $errors = array();
     if (is_array($result)) {
         foreach ($result as $row) {
             if (!empty($row['type']) && $row['type'] == "ALL" && $row['select_type'] != "UNION RESULT") {
                 $tableWithNoIndex[] = $row['table'];
                 $useKey = false;
             }
             if (!empty($row['Extra'])) {
                 if (stripos($row['Extra'], "Using temporary") !== false) {
                     $useTemporary = true;
                 }
                 if (stripos($row['Extra'], "Using filesort") !== false) {
                     $useFileSort = true;
                 }
             }
         }
     }
     if ((sizeof($result) > 1 || stripos($query, " WHERE ") !== false) && !$useKey) {
         foreach ($tableWithNoIndex as $t) {
             $errors[] = "La table <b>" . $t . "</b> n'utilise pas d'index";
         }
     }
     if ($useTemporary) {
         $errors[] = "Utilisation d'une table temporaire";
     }
     if ($useFileSort) {
         $errors[] = "Un tri nécessite un deuxi&egrave;me passage dans les résultats et peut ralentir la requête";
     }
     if (!empty($errors)) {
         $displayError = "La requête \"<b>" . $query . "</b>\" peut présenter des lenteurs :";
         foreach ($errors as $e) {
             $displayError .= "<br/>- " . $e;
         }
         trigger_error($displayError, E_USER_WARNING);
     }
     return $result;
 }
コード例 #3
0
ファイル: model.ModelLink.php プロジェクト: arno06/Savely
 private function decorateLink(&$pData)
 {
     $s = Query::select('*', 'sil_states')->andWhere('id_link', Query::EQUAL, $pData['id_link'])->andWhere('price_state', Query::UPPER, '0')->order('date_state', 'DESC')->limit('0', '1')->execute($this->handler);
     $pData['last_state'] = $s[0];
     $s = Query::execute("SELECT MIN(ROUND(price_state, 2)) as previous_price FROM sil_states WHERE id_link = '" . $pData['id_link'] . "' AND ROUND(price_state, 2) > '" . $pData['last_state']['price_state'] . "' AND price_state > 0 AND date_state BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() ORDER BY date_state;", $this->handler);
     $pData['previous_price'] = null;
     if (!empty($s)) {
         $pData['previous_price'] = round($s[0]['previous_price'], 2);
         if ($pData['previous_price'] == $pData['last_state']['price_state']) {
             $pData['previous_price'] = null;
         }
     }
 }