@@ -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 | } |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | */ |
| 75 | 75 | public function getById(Model $model, mixed $id): Model |
| 76 | 76 | { |
| 77 | - $query = (new QueryBuilder($this->db)) |
|
| 77 | + $query = (new QueryBuilder($this->db)) |
|
| 78 | 78 | ->select('*') |
| 79 | 79 | ->from($model->getName(), 't') |
| 80 | 80 | ->where("t.id = '".$id."'"); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param ModelManager $modelManager |
| 70 | 70 | * @return void |
| 71 | 71 | */ |
| 72 | - public function setManagers(TableManager $tableManager, RecordManager $recordManager, ModelManager $modelManager){ |
|
| 72 | + public function setManagers(TableManager $tableManager, RecordManager $recordManager, ModelManager $modelManager) { |
|
| 73 | 73 | $this->tableManager = $tableManager; |
| 74 | 74 | $this->recordManager = $recordManager; |
| 75 | 75 | $this->modelManager = $modelManager; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param array $params |
| 84 | 84 | * @return integer |
| 85 | 85 | */ |
| 86 | - public function exec(string $sql, array $params=array()): int |
|
| 86 | + public function exec(string $sql, array $params = array()): int |
|
| 87 | 87 | { |
| 88 | 88 | return $this->connection->executeStatement($sql, $params); |
| 89 | 89 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param array $params |
| 96 | 96 | * @return array |
| 97 | 97 | */ |
| 98 | - public function getAll(string $sql, array $params=[]): array |
|
| 98 | + public function getAll(string $sql, array $params = []): array |
|
| 99 | 99 | { |
| 100 | 100 | return $this->connection->executeQuery($sql, $params)->fetchAllAssociative(); |
| 101 | 101 | } |
@@ -286,11 +286,11 @@ discard block |
||
| 286 | 286 | * @param mixed|null $id |
| 287 | 287 | * @return mixed |
| 288 | 288 | */ |
| 289 | - public function get(String $table,mixed $id = null) : Model|Collection |
|
| 289 | + public function get(String $table, mixed $id = null) : Model | Collection |
|
| 290 | 290 | { |
| 291 | 291 | // For backward compatibility reason |
| 292 | - if($id != null){ |
|
| 293 | - return $this->getOne($table,$id); |
|
| 292 | + if ($id != null) { |
|
| 293 | + return $this->getOne($table, $id); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | return $this->recordManager->getAll($table); |
@@ -101,20 +101,20 @@ discard block |
||
| 101 | 101 | $parts = preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
| 102 | 102 | if (strtolower($parts[0]) == 'own') { |
| 103 | 103 | if (strtolower($parts[2]) == 'list') { |
| 104 | - return $this->db->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->_id . '"')->get(); |
|
| 104 | + return $this->db->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->_id.'"')->get(); |
|
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | if (strtolower($parts[0]) == 'shared') { |
| 108 | 108 | if (strtolower($parts[2]) == 'list') { |
| 109 | - $rel_table = $this->db->getTableManager()->tableExists($this->table . '_' . strtolower($parts[1])) ? $this->table . '_' . strtolower($parts[1]) : strtolower($parts[1]) . '_' . $this->table; |
|
| 110 | - $relations = $this->db->find($rel_table)->where($this->getName() . '_id = "' . $this->_id . '"')->get(); |
|
| 109 | + $rel_table = $this->db->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table; |
|
| 110 | + $relations = $this->db->find($rel_table)->where($this->getName().'_id = "'.$this->_id.'"')->get(); |
|
| 111 | 111 | $rel_ids = ''; |
| 112 | 112 | foreach ($relations as $relation) { |
| 113 | - $key = strtolower($parts[1]) . '_id'; |
|
| 114 | - $rel_ids .= "'" . $relation->$key . "',"; |
|
| 113 | + $key = strtolower($parts[1]).'_id'; |
|
| 114 | + $rel_ids .= "'".$relation->$key."',"; |
|
| 115 | 115 | } |
| 116 | 116 | $rel_ids = substr($rel_ids, 0, -1); |
| 117 | - return $this->db->find(strtolower($parts[1]))->where('id IN (' . $rel_ids . ')')->get(); |
|
| 117 | + return $this->db->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get(); |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | return $this->properties[$key]; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if (array_key_exists($key . '_id', $this->properties)) { |
|
| 127 | - return $this->db->get($key, $this->properties[$key . '_id']); |
|
| 126 | + if (array_key_exists($key.'_id', $this->properties)) { |
|
| 127 | + return $this->db->get($key, $this->properties[$key.'_id']); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | throw new Exception\KeyNotFoundException(); |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * Create ModelManager |
| 16 | 16 | * @param \Scrawler\Arca\Database $db |
| 17 | 17 | */ |
| 18 | - public function __construct(Database $db){ |
|
| 18 | + public function __construct(Database $db) { |
|
| 19 | 19 | $this->db = $db; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | * @param string $name |
| 25 | 25 | * @return Model |
| 26 | 26 | */ |
| 27 | - public function create(string $name){ |
|
| 28 | - return new Model($name,$this->db); |
|
| 27 | + public function create(string $name) { |
|
| 28 | + return new Model($name, $this->db); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | } |
| 32 | 32 | \ No newline at end of file |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | return self::getDB()->exec($sql); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public static function delete($model){ |
|
| 53 | + public static function delete($model) { |
|
| 54 | 54 | return self::getDB()->delete($model); |
| 55 | 55 | } |
| 56 | 56 | |