public function getDB($tables = null, $noid = false) { if (!$tables) { $tables = $this->tables; } if (is_string($tables)) { $tables = array_map('trim', explode(',', $tables)); } $ret = []; foreach ($tables as $table) { $data2 = []; $s = new Query(['connection' => $this->db->connection]); $data = $s->table($table)->get(); foreach ($data as &$row) { foreach ($row as &$val) { if (is_int($val)) { $val = (int) $val; } } if ($noid) { unset($row['id']); $data2[] = $row; } else { $data2[$row['id']] = $row; } } $ret[$table] = $data2; } return $ret; }
/** * Will apply conditions defined inside $m onto query $q. * * @param Model $m * @param \atk4\dsql\Query $q * * @return \atk4\dsql\Query */ public function initQueryConditions($m, $q) { if (!isset($m->conditions)) { // no conditions are set in the model return $q; } foreach ($m->conditions as $cond) { // Options here are: // count($cond) == 1, we will pass the only // parameter inside where() if (count($cond) == 1) { $q->where($cond[0]); continue; } if (is_string($cond[0])) { $cond[0] = $m->getElement($cond[0]); } if (count($cond) == 2) { if ($cond[0] instanceof Field) { $cond[1] = $this->typecastSaveField($cond[0], $cond[1]); } $q->where($cond[0], $cond[1]); } else { if ($cond[0] instanceof Field) { $cond[2] = $this->typecastSaveField($cond[0], $cond[2]); } $q->where($cond[0], $cond[1], $cond[2]); } } return $q; }