Example #1
0
 /**
  * @param string $where
  * @param array $params
  * @param int $page
  * @param int $pageSize
  * @return array
  */
 public function GetSetWhere($where = '', $params = [], $page = 1, $pageSize = 0)
 {
     $propertyDbMap = $this->model->GetPropertyDbMap();
     $sql = "SELECT * FROM `{$this->model->GetDbTable()}`";
     if (!empty($where)) {
         $sql .= $this->translateWhere($where, $propertyDbMap);
     }
     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;
 }
Example #2
0
 /**
  * @param Model $model
  * @throws \Doctrine\DBAL\DBALException
  */
 private function update(Model $model)
 {
     $idProperty = $model->GetIDProperty();
     $properties = $model->GetProperties();
     $modified = $model->GetModifiedProperties();
     $propertyDbMap = $model->GetPropertyDbMap();
     if (!empty($modified)) {
         $cols = [];
         $types = [];
         $values = [];
         foreach ($modified as $property => $value) {
             $cols[] = $propertyDbMap[$property]['col'];
             $types[] = $propertyDbMap[$property]['type'];
             $values[$propertyDbMap[$property]['col']] = $value;
         }
         $values[$propertyDbMap[$idProperty]['col']] = $properties[$idProperty];
         $types[] = $propertyDbMap[$idProperty]['type'];
         $sql = "UPDATE `{$model->GetDbTable()}` SET ";
         foreach ($cols as $col) {
             $sql .= "`{$col}` = :{$col},";
         }
         $sql = substr($sql, 0, -1);
         // remove trailing comma
         $sql .= " WHERE `{$propertyDbMap[$idProperty]['col']}` = :{$propertyDbMap[$idProperty]['col']}";
         $this->writer->executeQuery($sql, $values, $types);
     }
 }