Esempio n. 1
0
 public function install()
 {
     $bdd = Bdd::getInstance();
     $filename = DATA_DIR . "/data.json";
     Cli::pinfo("Import {$filename} in database");
     $data = json_decode(file_get_contents($filename));
     $bdd->import($data);
 }
Esempio n. 2
0
 public function persist()
 {
     try {
         $bdd = Bdd::getInstance()->getConnexion();
         for ($i = 0; $i < sizeof($this->products); $i++) {
             $req = $bdd->prepare("INSERT INTO product SET name=:name, \n                                                    description=:description, \n                                                    image=:image, \n                                                    keyword=:keyword, \n                                                    height=:height,\n                                                    width=:width, \n                                                    nb_pakage=:nb_package, \n                                                    category=:category, \n                                                    weight=:weight");
             $data = array('name' => $this->products[$i]->getName(), 'description' => $this->products[$i]->getDescription(), 'image' => $this->products[$i]->getImage(), 'keyword' => $this->products[$i]->getKeyword(), 'height' => $this->products[$i]->getHeight(), 'width' => $this->products[$i]->getWidth(), 'nb_package' => $this->products[$i]->getNbPackage(), 'category' => $this->products[$i]->getCategory(), 'weight' => $this->products[$i]->getWeight());
             $req->execute($data);
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Esempio n. 3
0
 public function dologin($login, $password)
 {
     $bdd = Bdd::getInstance();
     $user = $this->simpleSelect(array($bdd->quoteIdent(self::USERNAME) . "=:login"), array("login" => $login));
     if ($user->isEmpty()) {
         Logger::debug("User {$login} not found");
         return false;
     }
     $hash = $user->get(self::PASSWORD);
     $pwd = new Password();
     if (!$pwd->check($password, $hash)) {
         Logger::debug("Invalid password for {$login}");
         return false;
     }
     Logger::debug("User {$login} authenticated");
     return $user->getId();
 }
Esempio n. 4
0
 public function install()
 {
     Cli::pinfo(" * Create database structure");
     $bdd = Bdd::getInstance();
     if (is_dir(self::MODEL_DIR)) {
         if ($dh = opendir(self::MODEL_DIR)) {
             while (($file = readdir($dh)) !== false) {
                 if (substr($file, -15) == "Model.class.php" && substr($file, 0, 4) != "Base") {
                     $class = __NAMESPACE__ . "\\" . substr($file, 0, -10);
                     $model = new $class();
                     $bdd->dropTable($model->getTableName());
                     $model->createTable();
                 }
             }
             closedir($dh);
         }
     }
 }
Esempio n. 5
0
 public function whereEq($name, $value)
 {
     $bdd = Bdd::getInstance();
     if (is_string($value)) {
         $this->where[] = $name . "=" . $bdd->quote($value);
     } elseif ($value === null) {
         $this->where[] = $name . " IS NULL";
     } elseif ($value === true) {
         $this->where[] = $name . "=1";
     } elseif ($value === false) {
         $this->where[] = $name . "=0";
     } else {
         $this->where[] = $name . "=" . $value;
     }
     return $this;
 }
Esempio n. 6
0
 /**
  * Efface les tables de WP
  */
 public function wp_clean_sql()
 {
     $bdd = Bdd::getInstance();
     $sql = $bdd->dbh->prepare("SHOW TABLES LIKE '" . $this->_table_prefix . "%'");
     $sql->execute();
     $tables = $sql->fetchAll();
     foreach ($tables as $table) {
         $table_name = $table[0];
         // To rename the table
         $sql1 = $bdd->dbh->prepare("DROP TABLE `{$table_name}`");
         $sql1->execute();
     }
     return TRUE;
 }