public function delete($id, $replace_existing = false) { $record = $this->find($id); if ($record->{$this->file_column}) { $file_to_delete = $record->{$this->path_column} . $record->{$this->file_column}; if (is_file($file_to_delete)) { unlink($file_to_delete); } $this->clear_thumbs($id); } if (!$replace_existing) { return parent::delete($id); } }
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; }
public function create_migration($name) { $latest_ver = $this->get_version_latest() + 1; $this->pdo->query("UPDATE migration_info SET version_latest=" . $latest_ver); $name = ucfirst(WXActiveRecord::camelize($name)); $text = "<?php" . "\n"; $text .= "class {$name} extends WXMigrate" . "\n"; $text .= "{" . "\n"; $text .= " public function up() {" . "\n"; $text .= "\n"; $text .= " }" . "\n"; $text .= "\n"; $text .= " public function down() {" . "\n"; $text .= "\n"; $text .= " }" . "\n"; $text .= "}" . "\n"; $text .= "?>" . "\n"; return $text; }
/** * get property * @param string name property name * @return mixed property value */ public function __get($name) { /** * First job is to return the value if it exists in the table */ if (array_key_exists($name, $this->row)) { return stripslashes($this->row[$name]); } /** * Then we see if the attribute has a dedicated method */ if (method_exists($this, $name)) { return $this->{$name}(); } /** * Then we see if it has been setup as a has_many relationship. * This is passed on to the has_many_methods method which will * perform an operation on the associated table based on the join table. */ if (array_key_exists($name, $this->has_many_throughs)) { return $this->has_many_methods("get", $name); } /** * Next we try and link to a child object of the same name */ $link = $name . "_id"; $id = $this->row[$this->primary_key]; $class_name = WXInflections::camelize($name, true); if ($own = $this->row[$link]) { if (class_exists($class_name, false)) { return WXActiveRecord::get_owner($class_name, $this->pdo, $own); } } if ($id) { $foreign_key = $this->table . '_id'; if (class_exists($class_name, false)) { return WXActiveRecord::get_relation($class_name, $this->pdo, $foreign_key, $id); } } return false; }
/** * Instantiates a database connection. It requires PDO which is available in PHP 5.1 * It then passes this information to the ActiveRecord object. * * A few defaults are allowed in case you are too lazy to specify. * Dbtype defaults to mysql * Host defaults to localhost * Port defaults to 3306 * * * @access private * @return void */ private function initialise_database() { if ($db = WXConfiguration::get('db')) { if ($db['dbtype'] == "none") { return false; } if (!$db['host']) { $db['host'] = "localhost"; } if (!$db['port']) { $db['port'] = "3306"; } /****** Deprecated support for WXActiveRecord only around for one more version *****/ WXActiveRecord::$pdo_settings = $db; /**********************************************************/ WaxModel::load_adapter($db); } }