29 $tableName = $metaDatas[
'#tableName'];
31 $query =
$db->prepareAndExecute($tableName, SqlUtils::checkWhere($conditionParser->
getCondition()), self::_getFieldList($tableName, $metaDatas), $conditionParser->
getParams(), $useCache,
true);
34 EventsManager::trigger(DAOEvents::GET_ONE, $object, $className);
52 $tableName = $metaDatas[
'#tableName'];
54 $query =
$db->prepareAndExecute($tableName, SqlUtils::checkWhere($conditionParser->
getCondition()), self::_getFieldList($tableName, $metaDatas), $conditionParser->
getParams(), $useCache);
56 foreach ($query as $row) {
59 EventsManager::trigger(DAOEvents::GET_ALL, $objects, $className);
64 $o =
new $className();
65 foreach ($row as $k => $v) {
81 public static function update($instance, $updateMany =
false) {
82 EventsManager::trigger(
'dao.before.update', $instance);
83 $className = \get_class($instance);
87 $ColumnskeyAndValues = Reflexion::getPropertiesAndValues($instance);
89 $sql =
"UPDATE {$quote}{$tableName}{$quote} SET " . SqlUtils::getUpdateFieldsKeyAndParams($ColumnskeyAndValues) .
' WHERE ' . SqlUtils::getWhere($keyFieldsAndValues);
90 $statement =
$db->getUpdateStatement($sql);
92 $result = $statement->execute($ColumnskeyAndValues);
93 EventsManager::trigger(DAOEvents::AFTER_UPDATE, $instance, $result);
94 if (Logger::isActive()) {
95 Logger::info(
"DAOUpdates", $sql,
"update");
96 Logger::info(
"DAOUpdates", \json_encode($ColumnskeyAndValues),
"Key and values");
98 $instance->_rest = \array_merge($instance->_rest, $ColumnskeyAndValues);
100 }
catch (\Exception $e) {
101 Logger::warn(
"DAOUpdates", $e->getMessage(),
"update");
Ubiquity Generic database class.
Abstract class for logging Ubiquity\log$Logger This class is part of Ubiquity.
Gateway class between database and object model.
static getTableName($class)
static getKeyFieldsAndValues($instance, $prefix='')
static getModelMetadata($className)
DAO class for models without relationships Model classes must declare public members only Ubiquity\or...
static sloadObjectFromRow($row, $className)
static update($instance, $updateMany=false)
Updates an existing $instance in the database.
static _getOne(Database $db, $className, ConditionParser $conditionParser, $included, $useCache)
static _getAll(Database $db, $className, ConditionParser $conditionParser, $included=true, $useCache=NULL)
Represents a query condition.
Reflection utilities in dev environment only.