/** * Updates an element in database * @param Element $element The element to update * @return int The affected rows number */ public static function updateElement($element) { $elementClass = $element->getElementClass(); $tableName = DatabaseFactory::getElementTableName($elementClass); // '_has_' tables have 2 primary keys if (!StringTool::contains($tableName, ElementFactory::TABLE_JOIN_SEPARATOR)) { $conditions = $tableName . '_id = \'' . $element->id . '\''; } else { $tableList = StringTool::split(ElementFactory::TABLE_JOIN_SEPARATOR, $tableName); // Sets condition from both tables $tableFieldName = $tableList[0] . '_id'; $conditions = $tableFieldName . ' = \'' . $element->{$tableFieldName} . '\''; $tableFieldName = $tableList[1] . '_id'; $conditions .= ' AND ' . $tableFieldName . ' = \'' . $element->{$tableFieldName} . '\''; } $updatedPropertyList = $element->getUpdatedPropertyList(); // Updates the element in database $affectedRowNumber = DatabaseFactory::updateElementList($elementClass, $updatedPropertyList, $conditions); return $affectedRowNumber; }