diff --git a/libraries/joomla/table/table.php b/libraries/joomla/table/table.php index 61182d896e350..a9f130ce89b63 100644 --- a/libraries/joomla/table/table.php +++ b/libraries/joomla/table/table.php @@ -1037,8 +1037,11 @@ public function delete($pk = null) */ public function checkOut($userId, $pk = null) { + $checkedOutField = $this->getColumnAlias('checked_out'); + $checkedOutTimeField = $this->getColumnAlias('checked_out_time'); + // If there is no checked_out or checked_out_time field, just return true. - if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) + if (!property_exists($this, $checkedOutField) || !property_exists($this, $checkedOutTimeField)) { return true; } @@ -1073,15 +1076,15 @@ public function checkOut($userId, $pk = null) // Check the row out by primary key. $query = $this->_db->getQuery(true) ->update($this->_tbl) - ->set($this->_db->quoteName($this->getColumnAlias('checked_out')) . ' = ' . (int) $userId) - ->set($this->_db->quoteName($this->getColumnAlias('checked_out_time')) . ' = ' . $this->_db->quote($time)); + ->set($this->_db->quoteName($checkedOutField) . ' = ' . (int) $userId) + ->set($this->_db->quoteName($checkedOutTimeField) . ' = ' . $this->_db->quote($time)); $this->appendPrimaryKeys($query, $pk); $this->_db->setQuery($query); $this->_db->execute(); // Set table values in the object. - $this->checked_out = (int) $userId; - $this->checked_out_time = $time; + $this->$checkedOutField = (int) $userId; + $this->$checkedOutTimeField = $time; return true; } @@ -1100,8 +1103,11 @@ public function checkOut($userId, $pk = null) */ public function checkIn($pk = null) { + $checkedOutField = $this->getColumnAlias('checked_out'); + $checkedOutTimeField = $this->getColumnAlias('checked_out_time'); + // If there is no checked_out or checked_out_time field, just return true. - if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) + if (!property_exists($this, $checkedOutField) || !property_exists($this, $checkedOutTimeField)) { return true; } @@ -1133,8 +1139,8 @@ public function checkIn($pk = null) // Check the row in by primary key. $query = $this->_db->getQuery(true) ->update($this->_tbl) - ->set($this->_db->quoteName($this->getColumnAlias('checked_out')) . ' = 0') - ->set($this->_db->quoteName($this->getColumnAlias('checked_out_time')) . ' = ' . $this->_db->quote($this->_db->getNullDate())); + ->set($this->_db->quoteName($checkedOutField) . ' = 0') + ->set($this->_db->quoteName($checkedOutTimeField) . ' = ' . $this->_db->quote($this->_db->getNullDate())); $this->appendPrimaryKeys($query, $pk); $this->_db->setQuery($query); @@ -1142,8 +1148,8 @@ public function checkIn($pk = null) $this->_db->execute(); // Set table values in the object. - $this->checked_out = 0; - $this->checked_out_time = ''; + $this->$checkedOutField = 0; + $this->$checkedOutTimeField = ''; return true; } @@ -1202,8 +1208,10 @@ public function hasPrimaryKey() */ public function hit($pk = null) { + $hitsField = $this->getColumnAlias('hits'); + // If there is no hits field, just return true. - if (!property_exists($this, 'hits')) + if (!property_exists($this, $hitsField)) { return true; } @@ -1235,7 +1243,7 @@ public function hit($pk = null) // Check the row in by primary key. $query = $this->_db->getQuery(true) ->update($this->_tbl) - ->set($this->_db->quoteName($this->getColumnAlias('hits')) . ' = (' . $this->_db->quoteName($this->getColumnAlias('hits')) . ' + 1)'); + ->set($this->_db->quoteName($hitsField) . ' = (' . $this->_db->quoteName($hitsField) . ' + 1)'); $this->appendPrimaryKeys($query, $pk); $this->_db->setQuery($query); $this->_db->execute(); @@ -1266,7 +1274,8 @@ public function isCheckedOut($with = 0, $against = null) // Handle the non-static case. if (isset($this) && ($this instanceof JTable) && is_null($against)) { - $against = $this->get('checked_out'); + $checkedOutField = $this->getColumnAlias('checked_out'); + $against = $this->get($checkedOutField); } // The item is not checked out or is checked out by the same user. @@ -1565,17 +1574,20 @@ public function publish($pks = null, $state = 1, $userId = 0) $pks = array($pk); } + $publishedField = $this->getColumnAlias('published'); + $checkedOutField = $this->getColumnAlias('checked_out'); + foreach ($pks as $pk) { // Update the publishing state for rows with the given primary keys. $query = $this->_db->getQuery(true) ->update($this->_tbl) - ->set($this->_db->quoteName($this->getColumnAlias('published')) . ' = ' . (int) $state); + ->set($this->_db->quoteName($publishedField) . ' = ' . (int) $state); // Determine if there is checkin support for the table. if (property_exists($this, 'checked_out') || property_exists($this, 'checked_out_time')) { - $query->where('(' . $this->getColumnAlias('checked_out') . ' = 0 OR ' . $this->getColumnAlias('checked_out') . ' = ' . (int) $userId . ')'); + $query->where('(' . $this->_db->quoteName($checkedOutField) . ' = 0 OR ' . $this->_db->quoteName($checkedOutField) . ' = ' . (int) $userId . ')'); $checkin = true; } else @@ -1618,7 +1630,6 @@ public function publish($pks = null, $state = 1, $userId = 0) if ($ours) { - $publishedField = $this->getColumnAlias('published'); $this->$publishedField = $state; } }