@@ -58,7 +58,7 @@ |
||
| 58 | 58 | { |
| 59 | 59 | $table = new Table($model->getName()); |
| 60 | 60 | if ($this->db->isUsingUUID()) { |
| 61 | - $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true,]); |
|
| 61 | + $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true, ]); |
|
| 62 | 62 | } else { |
| 63 | 63 | $table->addColumn("id", "integer", array("unsigned" => true, "autoincrement" => true)); |
| 64 | 64 | } |
@@ -67,18 +67,18 @@ |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | - * Get single record by id |
|
| 71 | - * |
|
| 72 | - * @param \Scrawler\Arca\Model $model |
|
| 73 | - * @return \Scrawler\Arca\Model |
|
| 74 | - */ |
|
| 70 | + * Get single record by id |
|
| 71 | + * |
|
| 72 | + * @param \Scrawler\Arca\Model $model |
|
| 73 | + * @return \Scrawler\Arca\Model |
|
| 74 | + */ |
|
| 75 | 75 | public function getById(Model $model, mixed $id): Model |
| 76 | 76 | { |
| 77 | 77 | $qb = new QueryBuilder($this->db->connection); |
| 78 | 78 | $query = $qb |
| 79 | - ->select('*') |
|
| 80 | - ->from($model->getName(), 't') |
|
| 81 | - ->where("t.id = '".$id."'"); |
|
| 79 | + ->select('*') |
|
| 80 | + ->from($model->getName(), 't') |
|
| 81 | + ->where("t.id = '".$id."'"); |
|
| 82 | 82 | $result = $this->db->connection->executeQuery($query)->fetchAssociative(); |
| 83 | 83 | $result = $result ? $result : []; |
| 84 | 84 | $model->setProperties($result)->setLoaded(); |
@@ -75,7 +75,7 @@ |
||
| 75 | 75 | public function getById(Model $model, mixed $id): Model |
| 76 | 76 | { |
| 77 | 77 | $qb = new QueryBuilder($this->db->connection); |
| 78 | - $query = $qb |
|
| 78 | + $query = $qb |
|
| 79 | 79 | ->select('*') |
| 80 | 80 | ->from($model->getName(), 't') |
| 81 | 81 | ->where("t.id = '".$id."'"); |
@@ -69,18 +69,18 @@ |
||
| 69 | 69 | if (preg_match('/[A-Z]/', $key)) { |
| 70 | 70 | $parts = preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
| 71 | 71 | if (strtolower($parts[0]) == 'own') { |
| 72 | - if (strtolower($parts[2]) == 'list') { |
|
| 73 | - return $this->db->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->_id.'"')->get(); |
|
| 72 | + if (strtolower($parts[2]) == 'list') { |
|
| 73 | + return $this->db->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->_id.'"')->get(); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | if (strtolower($parts[0]) == 'shared') { |
| 77 | - if (strtolower($parts[2]) == 'list') { |
|
| 77 | + if (strtolower($parts[2]) == 'list') { |
|
| 78 | 78 | $rel_table = $this->db->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table; |
| 79 | - $relations = $this->db->find($rel_table)->where($this->getName() . '_id = "' . $this->_id.'"')->get(); |
|
| 79 | + $relations = $this->db->find($rel_table)->where($this->getName().'_id = "'.$this->_id.'"')->get(); |
|
| 80 | 80 | $rel_ids = ''; |
| 81 | 81 | foreach ($relations as $relation) { |
| 82 | - $key = strtolower($parts[1]) . '_id'; |
|
| 83 | - $rel_ids .= "'".$relation->$key . "',"; |
|
| 82 | + $key = strtolower($parts[1]).'_id'; |
|
| 83 | + $rel_ids .= "'".$relation->$key."',"; |
|
| 84 | 84 | } |
| 85 | 85 | $rel_ids = substr($rel_ids, 0, -1); |
| 86 | 86 | return $this->db->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get(); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public function setManagers(TableManager $tableManger, RecordManager $recordManager, ModelManager $modelManager){ |
|
| 29 | + public function setManagers(TableManager $tableManger, RecordManager $recordManager, ModelManager $modelManager) { |
|
| 30 | 30 | $this->tableManager = $tableManager; |
| 31 | 31 | $this->recordManager = $recordManager; |
| 32 | 32 | $this->modelManager = $modelManager; |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param array $params |
| 41 | 41 | * @return integer |
| 42 | 42 | */ |
| 43 | - public function exec(string $sql, array $params=array()): int |
|
| 43 | + public function exec(string $sql, array $params = array()): int |
|
| 44 | 44 | { |
| 45 | 45 | return $this->connection->executeStatement($sql, $params); |
| 46 | 46 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param array $params |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - public function getAll(string $sql, array $params=[]): array |
|
| 55 | + public function getAll(string $sql, array $params = []): array |
|
| 56 | 56 | { |
| 57 | 57 | return $this->connection->executeQuery($sql, $params)->fetchAllAssociative(); |
| 58 | 58 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @param mixed|null $id |
| 233 | 233 | * @return mixed |
| 234 | 234 | */ |
| 235 | - public function get(String $table, mixed $id=null) : mixed |
|
| 235 | + public function get(String $table, mixed $id = null) : mixed |
|
| 236 | 236 | { |
| 237 | 237 | if (is_null($id)) { |
| 238 | 238 | return $this->recordManager->getAll($table); |
@@ -12,12 +12,12 @@ |
||
| 12 | 12 | * Create RecordManager |
| 13 | 13 | * @param \Scrawler\Arca\Database $db |
| 14 | 14 | */ |
| 15 | - public function __construct(Database $db){ |
|
| 15 | + public function __construct(Database $db) { |
|
| 16 | 16 | $this->db = $db |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public function create(string $name){ |
|
| 20 | - return new Model($name,$db); |
|
| 19 | + public function create(string $name) { |
|
| 20 | + return new Model($name, $db); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -11,10 +11,10 @@ |
||
| 11 | 11 | class Database { |
| 12 | 12 | private static $database; |
| 13 | 13 | |
| 14 | - public static function connect(array $connectionParams){ |
|
| 14 | + public static function connect(array $connectionParams) { |
|
| 15 | 15 | $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams); |
| 16 | 16 | self::$database = new Database($connection); |
| 17 | - self::$database->setManagers(new TableManager(self::$database),new RecordManager(self::$database),new ModelManager(self::$database)) |
|
| 17 | + self::$database->setManagers(new TableManager(self::$database), new RecordManager(self::$database), new ModelManager(self::$database)) |
|
| 18 | 18 | return self::$database; |
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | \ No newline at end of file |