Definition at line 5 of file ModelBase.php.
| __construct |
( |
|
$id = null | ) |
|
Definition at line 85 of file ModelBase.php.
90 return $this->
id === null ? null : (int) $this->
id;
91 if (!isset($this->fieldsValues[$key]))
93 return $this->fieldsValues[$key];
Definition at line 96 of file ModelBase.php.
98 if ($value instanceof \DateTime)
99 $value = $value->format(
"Y-m-d");
100 $this->fieldsValues[$key] = $value;
102 $this->changed[$key] = $value ? 1 : 0;
103 else if ($value === null)
104 $this->changed[$key] =
"NULL";
106 $this->changed[$key] = self::$dbo->quote($value);
Definition at line 79 of file ModelBase.php.
81 $fetcher = new \Entity\Meta();
82 return $fetcher->query(array(
"type" => get_class($this)));
Definition at line 47 of file ModelBase.php.
49 $className = new \ReflectionClass($this);
50 return $this->
getDbPrefix().strtolower($className->getShortName());
| static init |
( |
|
$config = null | ) |
|
|
static |
Definition at line 23 of file ModelBase.php.
25 if (self::$dbo !== null)
29 if (
$config === null && self::$config === null)
31 self::$config = @include(
"core/config.inc.php");
32 if (empty(self::$config))
38 self::$dbo = new \PDO(self::$config[0], self::$config[1], self::$config[2]);
Definition at line 217 of file ModelBase.php.
220 foreach ($data as $i => $j)
221 $this->fieldsValues[$i] = $j;
222 if (isset($this->fieldsValues[
"id"]))
223 $this->
id = (int) $this->fieldsValues[
"id"];
224 $this->changed = array();
Definition at line 110 of file ModelBase.php.
114 if ($this->
id === null)
116 if (empty ($this->changed))
118 $query =
"INSERT INTO `{$this->getTableName()}` () VALUES ()";
119 $result = self::$dbo->exec($query);
121 throw new \Exception(self::$dbo->errorInfo()[2]);
125 $query =
"INSERT INTO `{$this->getTableName()}` (`" .implode(
"`,`", array_keys($this->changed)) .
"`) VALUES (" . implode(
",", $this->changed) .
")";
126 $result = self::$dbo->exec($query);
128 throw new \Exception(self::$dbo->errorInfo()[2]);
129 $this->changed = array();
131 $this->
id = self::$dbo->lastInsertId();
135 if (!empty($this->changed))
137 if ($this->
id ===
false)
138 throw new \Exception(
"Cannot update private row");
139 $query =
"UPDATE {$this->getTableName()} SET ";
140 $newValues = array();
141 foreach ($this->changed as $i => $j)
142 $newValues[] =
"`{$i}`=" . $j;
143 $query .= implode(
",",$newValues).
" WHERE id={$this->id}";
144 $result = self::$dbo->exec($query);
146 throw new \Exception(self::$dbo->errorInfo()[2]);
147 $this->changed = array();
Definition at line 208 of file ModelBase.php.
210 $query =
"SELECT * FROM {$this->getTableName()} WHERE id=".(int)
$id.
" LIMIT 1";
211 $result = self::$dbo->query($query, \PDO::FETCH_ASSOC);
212 if ($result ===
false || empty($result))
213 throw new \Exception(
"Cannot fetch data: ".self::$dbo->errorInfo()[2]);
| selects |
( |
|
$criteria = null, |
|
|
|
$orderBy = null |
|
) |
| |
Definition at line 154 of file ModelBase.php.
156 $query =
"SELECT * FROM {$this->getTableName()}";
158 if (!empty($criteria))
161 foreach ($criteria as $i => $j)
164 $subQuery[] =
"`{$i}` IS NULL";
165 else if (is_array($j))
169 $inArray[] = self::$dbo->quote($k);
170 $subQuery[] =
"`{$i}` IN (".implode(
",", $inArray).
")";
173 $subQuery[] =
"`{$i}`=".self::$dbo->quote($j);
175 $query .=
" WHERE ".implode(
" AND ", $subQuery);
177 if (!empty($orderBy))
180 foreach ($orderBy as $i => $j)
183 $_orderBy[] =
"`{$j}` ASC";
187 if (strtoupper($j ==
"DESC"))
189 $_orderBy[] =
"`{$i}` {$orderType}";
192 $query .=
" ORDER BY ".implode(
",", $_orderBy);
194 $result = self::$dbo->query($query, \PDO::FETCH_ASSOC);
195 if ($result ===
false)
196 throw new \Exception(self::$dbo->errorInfo()[2]);
197 $resultObj = array();
198 $className = get_class($this);
199 foreach ($result as $i)
201 $iObj =
new $className();
203 $resultObj[] = $iObj;
Definition at line 53 of file ModelBase.php.
55 $tables = array(
"Admin",
"User",
"Address",
"Cart",
"Category",
"Product",
"CartProduct",
"Meta",
"Cms",
"Config",
"Module",
"ModuleHook");
58 self::$dbo->beginTransaction();
61 foreach ($tables as $i)
65 if ($table->install() !=
true)
66 throw new \
Exception(
"{$i}: Cannot table setup failure");
71 self::$dbo->rollBack();
72 error_log($e->getMessage());
The documentation for this class was generated from the following file: