public function construct() { if (!$this->sql) { $this->sql = $this->model->framework->sql; } if (!$this->table) { $this->table = strtolower($this->model->id); } foreach ($this->fields as $index => $mapping) { $this->model->fields[$index]->mapping = $mapping; } $mappings = array(); $formats = array(); $sets = array(); $fields = array(); foreach ($this->model->fields as $field) { $mappings[] = $field->mapping; $formats[] = "'%s'"; $sets[] = "`{$field->mapping}`='%s'"; $fields[] = "`{$field->mapping}` as `{$field->name}`"; } $fields[] = "`{$this->id}`"; $this->_insert = "insert into `{$this->table}` (`" . implode("`,`", $mappings) . "`)values(" . implode(",", $formats) . ")"; $this->_update = "update `{$this->table}` set " . implode(",", $sets) . " where `{$this->id}`='%s' limit 1"; $this->_select_fields = implode(",", $fields); $this->_select_from = "`{$this->table}`"; $this->_select_where = $this->where; $this->_select = "select %s from {$this->_select_from} where {$this->_select_where}"; parent::construct(); }
public function construct() { $cols = array(); if ($this->collection) { $cols = $this->model->framework->mongodb->listCollections(); } $count = 0; foreach ($cols as $i => $v) { if ($this->collection == $v->getName()) { $count++; } } if ($count == 0) { $this->_create(); } if ($count > 1) { exit("too many collections with the same name"); } $this->collectionref = $this->model->framework->mongodb->selectCollection($this->collection); parent::construct(); }
public function construct() { if (!$this->ids) { $this->ids = array($this->id); } $this->id = $this->ids[0]; if (!$this->sql) { $this->sql = $this->model->framework->sql; } if (!$this->tables) { if (!$this->table) { $this->table = strtolower($this->model->id); } $this->tables = array($this->table); } $this->table = $this->tables[0]; $this->tables[0] = array($this->tables[0]); $this->_join = array(); for ($i = 1, $ii = count($this->tables); $i < $ii; $i++) { $table =& $this->tables[$i]; if (!is_array($table)) { $table = array($table); } $count = count($table); if ($count == 1) { $table[1] = "`{$table[0]}`.`{$this->ids[$i]}`=`{$this->tables[0][0]}`.`{$this->ids[0]}`"; $table[2] = "inner"; } elseif ($count == 2) { $table[2] = "inner"; } elseif ($count == 4) { if ($table['has']) { $this->has[$i] = $this->model->framework->getModel($table['has']); } } $this->_join[] = "{$table[2]} join `{$table[0]}` on {$table[1]}"; unset($table); } $this->_join = implode(" ", $this->_join); if (!$this->Fields) { if (!$this->fields) { foreach ($this->model->fields as $field) { $this->fields[] = $field->mapping; } } $this->Fields = array($this->fields); } $index = 0; foreach ($this->Fields as $i => $fields) { foreach ($fields as $j => $mapping) { $this->model->fields[$index]->mapping = array($this->tables[$i][0], $mapping); $index++; } } $mappings = array(); $formats = array(); $sets = array(); $fields = array(); foreach ($this->model->fields as $field) { $mappings[$field->mapping[0]][] = $field->mapping[1]; $formats[$field->mapping[0]][] = "'%s'"; $sets[$field->mapping[0]][] = "`{$field->mapping[1]}`='%s'"; $fields[] = "`{$field->mapping[0]}`.`{$field->mapping[1]}` as `{$field->name}`"; } $fields[] = "`{$this->tables[0][0]}`.`{$this->ids[0]}`"; foreach ($this->ids as $index => $id) { $table = $this->tables[$index][0]; $this->_insert[$table] = "insert into `{$table}` (`" . implode("`,`", $mappings[$table]) . "`)values(" . implode(",", $formats[$table]) . ")"; $this->_update[$table] = "update `{$table}` set " . implode(",", $sets[$table]) . " where `{$this->ids[$index]}`='%s' limit 1"; $fields[] = "`{$table}`.`{$this->ids[$index]}` as `_id_{$index}`"; } $this->_select_fields = implode(",", $fields); $this->_select_from = "`{$this->tables[0][0]}` {$this->_join}"; $this->_select_where = $this->where; $this->_select = "select %s from {$this->_select_from} where {$this->_select_where}"; ModelStore::construct(); }