コード例 #1
0
ファイル: WXDBAuthenticate.php プロジェクト: phpwax/phpwax
 public function verify($username, $password)
 {
     $object = WXInflections::camelize($this->db_table, true);
     $user = new $object();
     $method = "find_by_" . $this->user_field . "_and_" . $this->password_field;
     if ($this->encrypt) {
         $password = $this->encrypt($password);
     }
     $result = $user->{$method}($username, $password);
     if ($result) {
         $this->user_object = $result;
         $this->user_id = $result->id;
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: WXSearch.php プロジェクト: phpwax/phpwax
 public function get_results($limit = false)
 {
     $setups = array();
     foreach (self::$search_array as $search) {
         if (is_array($search['field'])) {
             try {
                 WXActiveRecord::getDefaultPDO()->query("ALTER TABLE " . $search['table'] . " ADD FULLTEXT " . $search['field'] . " (" . implode(",", $search['field']) . ");");
             } catch (Exception $e) {
             }
         } else {
             try {
                 WXActiveRecord::getDefaultPDO()->query("ALTER TABLE " . $search['table'] . " ADD FULLTEXT " . $search['field'] . " (" . $search['field'] . ");");
             } catch (Exception $e) {
             }
         }
         if (is_array($search['field'])) {
             $query = "SELECT *, MATCH(";
             $query .= implode(",", $search['field']);
             $query .= ") AGAINST('" . $this->search_phrase . "') AS score FROM " . $search['table'];
             $query .= " WHERE MATCH(" . implode(",", $search['field']) . ") AGAINST('" . $this->search_phrase . "')";
             if ($search['order'] != "") {
                 $query .= "ORDER BY " . $search['order'];
             }
         } else {
             $query = "SELECT *, MATCH(" . $search['field'] . ") AGAINST('" . $this->search_phrase . "') AS score FROM " . $search['table'];
             $query .= " WHERE MATCH(" . $search['field'] . ") AGAINST('" . $this->search_phrase . "')";
             if ($search['order'] != "") {
                 $query .= "ORDER BY " . $search['order'];
             }
             if ($limit) {
                 $query .= " LIMIT {$limit}";
             }
         }
         $model = WXInflections::camelize($search['table'], true);
         $table = new $model();
         if (is_array($results[$search['key']])) {
             $results[$search['key']] = array_merge($results[$search['key']], $table->find_by_sql($query));
         } else {
             $results[$search['key']] = $table->find_by_sql($query);
         }
     }
     return $results;
 }
コード例 #3
0
ファイル: WXGenerator.php プロジェクト: phpwax/phpwax
 public function new_migration($name, $table = null)
 {
     if (is_array($name)) {
         $name = $name[0];
     }
     $migrate = new WXMigrate();
     $migrate->increase_version_latest();
     $version = $migrate->get_version_latest();
     $class = WXInflections::camelize($name, true);
     $this->final_output .= $this->start_php_file($class, "WXMigrate");
     if ($table) {
         $this->final_output .= $this->add_function("up", sprintf('    \\$this->create_table(\\"%s\\");', $table) . "\n");
         $this->final_output .= $this->add_function("down", sprintf('    \\$this->drop_table(\\"%s\\");', $table) . "\n");
     } else {
         $this->final_output .= $this->add_function("up");
         $this->final_output .= $this->add_function("down");
     }
     $file = str_pad($version, 3, "0", STR_PAD_LEFT) . "_" . WXInflections::underscore($class);
     $res = $this->write_to_file(APP_DIR . "db/migrate/" . $file . ".php");
     if (!$res) {
         $this->add_perm_error("app/db/migrate/" . $file . ".php");
         return false;
     }
     $this->add_stdout("Created migration file at app/db/migrate/" . $file . ".php");
 }
コード例 #4
0
ファイル: WXActiveRecord.php プロジェクト: phpwax/phpwax
 public function has_many_methods($operation, $column, $value = null, $order = "0")
 {
     if (is_array($value)) {
         if (isset($value[1])) {
             $order = $value[1];
         }
         $value = $value[0];
     }
     $current = $this->row[$this->primary_key];
     $rel = $this->has_many_throughs[$column][0];
     $join = $this->has_many_throughs[$column][1];
     switch ($operation) {
         case "findin":
             if (is_array($order)) {
                 $params = $order;
             }
             $params['distinct'] = "{$this->table}.*";
             $params['table'] = "`{$join}`, `{$rel}`";
             if ($params['conditions']) {
                 $params['conditions'] .= " AND {$join}.{$rel}_id = '{$value}' AND {$join}.{$this->table}_id = {$this->table}.id";
             } else {
                 $params['conditions'] = "{$join}.{$rel}_id = '{$value}' AND {$join}.{$this->table}_id = {$this->table}.id";
             }
             $result = $this->find_all($params);
             return $result;
         case "delete":
             return $this->pdo->query("DELETE FROM {$join} WHERE {$this->table}_id ={$current} and {$rel}_id = {$value}");
             break;
         case "add":
             $this->pdo->query("DELETE FROM {$join} WHERE {$this->table}_id ={$current} AND {$rel}_id = {$value}");
             return $this->pdo->query("INSERT INTO {$join} ({$this->table}_id, {$rel}_id, `order`) VALUES({$current}, {$value}, {$order})");
             break;
         case "clear":
             return $this->pdo->query("DELETE FROM {$join} WHERE {$this->table}_id ={$current}");
             break;
         case "get":
             $rel_class = WXInflections::camelize($rel, true);
             $table = new $rel_class();
             if ($current) {
                 return $table->find_by_sql("SELECT * FROM {$rel} RIGHT JOIN {$join} ON {$join}.{$rel}_id = {$rel}.id \n\t\t\t\t    WHERE {$join}.{$this->table}_id = {$current} ORDER BY `order` ASC");
             } else {
                 return false;
             }
         case "order":
             return $this->pdo->query("UPDATE {$join} SET `order`={$order} WHERE {$this->table}_id = {$current} AND {$value} {$rel}_id = {$value}");
     }
 }
コード例 #5
0
ファイル: TestInflections.php プロジェクト: phpwax/phpwax
 public function test_camelize()
 {
     $input = "an_underscored_word";
     $this->assertEqual(WXInflections::camelize($input), "anUnderscoredWord");
     $this->assertEqual(WXInflections::camelize($input, true), "AnUnderscoredWord");
 }
コード例 #6
0
ファイル: WaxAuthDb.php プロジェクト: phpwax/phpwax
 public function verify($username, $password)
 {
     $object = WXInflections::camelize($this->db_table, true);
     $user = new $object();
     if ($this->encrypt) {
         $password = $this->encrypt($password);
     }
     $result = $user->filter(array($this->user_field => $username, $this->password_field => $password))->first();
     if ($result->primval) {
         $this->user_object = $result;
         $this->user_id = $result->primval;
         return true;
     }
     return false;
 }
コード例 #7
0
ファイル: WXMigrate.php プロジェクト: phpwax/phpwax
 protected function get_class_from_file($file, $strip = true)
 {
     if ($strip) {
         $file = substr($file, 3);
     }
     return WXInflections::camelize(str_replace(".php", "", $file), true);
 }