Example #1
0
 /**
  *
  * Migrate a table
  * @param string $fileName
  * @param $dropTable bool drop the table
  */
 public function migrateTable($fileName, $dropTable)
 {
     include_once $fileName;
     $className = "Application\\Model\\" . basename($fileName, ".php");
     // create an instance of the class
     $item = new $className();
     $columns = $this->getProperties($item);
     $reflector = new \ReflectionClass($item);
     // get name of the table
     $tableName = NameDecorator::getTableName($reflector->getShortName());
     $dbColumns = false;
     if ($dropTable) {
         $this->database->executeQuery("DROP TABLE {$tableName}");
     } else {
         $query = "SHOW COLUMNS IN `{$tableName}`";
         $dbColumns = $this->database->executeQuery($query, "Core\\Database\\DBColumn");
     }
     // if there is no such table, create it
     if ($dbColumns === false || sizeof($dbColumns) == 0) {
         $this->createTable($tableName, $columns);
     } else {
         // do a migration
         $this->updateTable($tableName, $columns, $dbColumns);
     }
 }
Example #2
0
 /**
  *
  * Build a query
  *
  */
 public function buildQuery($count = false)
 {
     if ($this->query == null) {
         $database = Database::getInstance();
         $conditionString = array();
         foreach ($this->conditions as $condition) {
             $conditionString[] = "`{$condition->field}` {$condition->criteria} " . $database->escapeString($condition->value);
         }
         if (!$count) {
             $this->query = "SELECT * FROM " . NameDecorator::getTableName($this->entityClass) . "\n";
         } else {
             $this->query = "SELECT COUNT(*) as numberOfRecords FROM " . NameDecorator::getTableName($this->entityClass) . "\n";
         }
         if (sizeof($conditionString) > 0) {
             $this->query .= "WHERE " . join(", ", $conditionString);
         }
         if ($this->paginateOptions) {
             $this->query .= " LIMIT {$this->paginateOptions[0]}, {$this->paginateOptions[1]}";
         }
     }
 }
Example #3
0
 /**
  * @return string the table name
  */
 public function getTableName()
 {
     return NameDecorator::getTableName($this->name);
 }