public function GetSetWhere($where = '', $params = [], $page = 1, $pageSize = 0) { $properties = $this->model->GetProperties(); $sql = "SELECT * FROM {$this->model->GetDbTable()}"; if (!empty($where)) { $sql .= ' WHERE ' . $this->translateWhere($where, $properties); } if ($pageSize > 0) { $sql .= " LIMIT {$pageSize} OFFSET " . $pageSize * ($page - 1); } $values = []; $types = []; foreach ($params as $key => $value) { if (is_array($value)) { $values[$key] = $value['value']; if (isset($value['type'])) { $types[] = $value['type']; } } else { $values[$key] = $value; } } $set = []; $results = $this->reader->fetchAll($sql, $values, $types); foreach ($results as $result) { $set[] = new $this->modelClass($result); } return $set; }
private function update(Model $model) { $idProperty = $model->GetIDProperty(); $properties = $model->GetProperties(); $modified = $model->GetModifiedProperties(); if (!empty($modified)) { $cols = []; $types = []; $values = []; foreach ($modified as $property => $dbMap) { $cols[] = $dbMap['col']; $types[] = $dbMap['type']; $values[$dbMap['col']] = $dbMap['value']; } $sql = "UPDATE {$model->GetDbTable()} SET "; foreach ($cols as $col) { $sql .= "{$col} = :{$col},"; } $sql = substr($sql, 0, -1); // remove trailing comma $sql .= " WHERE {$properties[$idProperty]['col']} = :{$properties[$idProperty]['col']}"; $types[] = $properties[$idProperty]['type']; $values[$properties[$idProperty]['col']] = $properties[$idProperty]['value']; $this->writer->executeQuery($sql, $values, $types); } }