From: <tr...@us...> - 2011-10-16 17:48:31
|
Revision: 7900 http://xoops.svn.sourceforge.net/xoops/?rev=7900&view=rev Author: trabis Date: 2011-10-16 17:48:24 +0000 (Sun, 16 Oct 2011) Log Message: ----------- Refactoring class/model Modified Paths: -------------- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/joint.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/read.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/stats.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/sync.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/write.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/xoopsmodel.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/class/maintenance.php Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/joint.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/joint.php 2011-10-16 16:15:42 UTC (rev 7899) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/joint.php 2011-10-16 17:48:24 UTC (rev 7900) @@ -11,12 +11,13 @@ * * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage model * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> * @version $Id$ */ + defined('XOOPS_ROOT_PATH') or die('Restricted access'); /** @@ -25,8 +26,7 @@ * @author Taiwen Jiang <ph...@us...> * * {@link XoopsObjectAbstract} - */ -/** + * * Usage of methods provided by XoopsModelJoint: * * Step #1: set linked table and adjoint fields through XoopsPersistableObjectHandler: @@ -88,9 +88,7 @@ $limit = null; $start = null; // $field_object = empty($field_object) ? $field_link : $field_object; - $sql = " SELECT {$select}" - . " FROM {$this->handler->table} AS o" - . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; + $sql = " SELECT {$select}" . " FROM {$this->handler->table} AS o" . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) { $sql .= " " . $criteria->renderWhere(); if ($sort = $criteria->getSort()) { @@ -135,9 +133,7 @@ return null; } - $sql = " SELECT COUNT(DISTINCT {$this->handler->keyName}) AS count" - . " FROM {$this->handler->table} AS o" - . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; + $sql = " SELECT COUNT(DISTINCT {$this->handler->keyName}) AS count" . " FROM {$this->handler->table} AS o" . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) { $sql .= " " . $criteria->renderWhere(); } @@ -159,9 +155,7 @@ if (!$this->validateLinks()) { return null; } - $sql = " SELECT l.{$this->handler->keyName_link}, COUNT(*)" - . " FROM {$this->handler->table} AS o" - . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; + $sql = " SELECT l.{$this->handler->keyName_link}, COUNT(*)" . " FROM {$this->handler->table} AS o" . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) { $sql .= " " . $criteria->renderWhere(); } @@ -177,13 +171,13 @@ } /** - * upate objects matching a condition against linked objects + * update objects matching a condition against linked objects * * @param array $data array of key => value * @param CriteriaElement|null $criteria {@link CriteriaElement} to match * @return int count of objects */ - function updateByLink($data, CriteriaElement $criteria = null) + public function updateByLink($data, CriteriaElement $criteria = null) { if (!$this->validateLinks()) { return null; @@ -192,9 +186,7 @@ foreach ($data as $key => $val) { $set[] = "o.{$key}=" . $this->handler->db->quoteString($val); } - $sql = " UPDATE {$this->handler->table} AS o" - . " SET " . implode(", ", $set) - . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; + $sql = " UPDATE {$this->handler->table} AS o" . " SET " . implode(", ", $set) . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) { $sql .= " " . $criteria->renderWhere(); } @@ -207,13 +199,12 @@ * @param CriteriaElement|null $criteria {@link CriteriaElement} to match * @return int count of objects */ - function deleteByLink(CriteriaElement $criteria = null) + public function deleteByLink(CriteriaElement $criteria = null) { if (!$this->validateLinks()) { return null; } - $sql = "DELETE FROM {$this->handler->table} AS o " - . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; + $sql = "DELETE FROM {$this->handler->table} AS o " . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}"; if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) { $sql .= " " . $criteria->renderWhere(); } Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/read.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/read.php 2011-10-16 16:15:42 UTC (rev 7899) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/read.php 2011-10-16 17:48:24 UTC (rev 7900) @@ -11,7 +11,7 @@ * * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage model * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> @@ -26,7 +26,6 @@ * * {@link XoopsObjectAbstract} */ - class XoopsModelRead extends XoopsModelAbstract { /** @@ -146,7 +145,8 @@ $myts = MyTextSanitizer::getInstance(); while ($myrow = $this->handler->db->fetchArray($result)) { // identifiers should be textboxes, so sanitize them like that - $ret[$myrow[$this->handler->keyName]] = empty($this->handler->identifierName) ? 1 : $myts->htmlSpecialChars($myrow[$this->handler->identifierName]); + $ret[$myrow[$this->handler->keyName]] = empty($this->handler->identifierName) ? 1 + : $myts->htmlSpecialChars($myrow[$this->handler->identifierName]); } return $ret; } Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/stats.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/stats.php 2011-10-16 16:15:42 UTC (rev 7899) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/stats.php 2011-10-16 17:48:24 UTC (rev 7900) @@ -11,12 +11,13 @@ * * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage model * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> * @version $Id$ */ + defined('XOOPS_ROOT_PATH') or die('Restricted access'); /** @@ -87,10 +88,7 @@ $groupby_key = $groupby; } } - $sql = "SELECT {$groupby_key}, COUNT(*) AS count" - . " FROM `{$this->handler->table}`" - . " {$sql_where}" - . " GROUP BY {$groupby_key}"; + $sql = "SELECT {$groupby_key}, COUNT(*) AS count" . " FROM `{$this->handler->table}`" . " {$sql_where}" . " GROUP BY {$groupby_key}"; if (!$result = $this->handler->db->query($sql, $limit, $start)) { return $ret; } Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/sync.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/sync.php 2011-10-16 16:15:42 UTC (rev 7899) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/sync.php 2011-10-16 17:48:24 UTC (rev 7900) @@ -11,12 +11,13 @@ * * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage model * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> * @version $Id$ */ + defined('XOOPS_ROOT_PATH') or die('Restricted access'); /** @@ -25,8 +26,7 @@ * @author Taiwen Jiang <ph...@us...> * * {@link XoopsObjectAbstract} - */ -/** + * * Usage of methods provided by XoopsModelSync: * * Step #1: set linked table and adjoint fields through XoopsPersistableObjectHandler: @@ -35,7 +35,6 @@ * $handler->field_object = "the_object_field"; // name of field in current table that will be used to link the linked table with current table; linked field name will be used if the field name is not set * Step #2: perform query */ - class XoopsModelSync extends XoopsModelAbstract { /** @@ -80,18 +79,6 @@ } return true; } - - /** - * Synchronizing objects - * @deprecated - * - * @return bool true on success - */ - public function synchronization() - { - $retval = $this->cleanOrphan(); - return $retval; - } } ?> \ No newline at end of file Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/write.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/write.php 2011-10-16 16:15:42 UTC (rev 7899) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/write.php 2011-10-16 17:48:24 UTC (rev 7900) @@ -11,12 +11,13 @@ * * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage model * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> * @version $Id$ */ + defined('XOOPS_ROOT_PATH') or die('Restricted access'); /** @@ -27,7 +28,6 @@ * * {@link XoopsObjectAbstract} */ - class XoopsModelWrite extends XoopsModelAbstract { /** @@ -145,9 +145,9 @@ break; case XOBJ_DTYPE_ARRAY: - $cleanv = (array) $cleanv; + $cleanv = (array)$cleanv; if (!$v['not_gpc']) { - $cleanv = array_map(array(&$ts , "stripSlashesGPC"), $cleanv); + $cleanv = array_map(array(&$ts, "stripSlashesGPC"), $cleanv); } foreach (array_keys($cleanv) as $key) { $cleanv[$key] = str_replace('\\"', '"', addslashes($cleanv[$key])); @@ -208,21 +208,23 @@ trigger_error("Data entry is not inserted - no variable is changed in object of '" . get_class($object) . "'", E_USER_NOTICE); return $object->getVar($this->handler->keyName); } - if (!$this->handler->db->{$queryFunc}($sql)) { + if (!$this->handler->db->$queryFunc($sql)) { return false; } if (!$object->getVar($this->handler->keyName) && $object_id = $this->handler->db->getInsertId()) { $object->assignVar($this->handler->keyName, $object_id); } - } else if (!empty($object->cleanVars)) { - $keys = array(); - foreach ($object->cleanVars as $k => $v) { - $keys[] = " `{$k}` = {$v}"; + } else { + if (!empty($object->cleanVars)) { + $keys = array(); + foreach ($object->cleanVars as $k => $v) { + $keys[] = " `{$k}` = {$v}"; + } + $sql = "UPDATE `" . $this->handler->table . "` SET " . implode(",", $keys) . " WHERE `" . $this->handler->keyName . "` = " . $this->handler->db->quote($object->getVar($this->handler->keyName)); + if (!$this->handler->db->$queryFunc($sql)) { + return false; + } } - $sql = "UPDATE `" . $this->handler->table . "` SET " . implode(",", $keys) . " WHERE `" . $this->handler->keyName . "` = " . $this->handler->db->quote($object->getVar($this->handler->keyName)); - if (!$this->handler->db->{$queryFunc}($sql)) { - return false; - } } return $object->getVar($this->handler->keyName); } @@ -251,7 +253,7 @@ } $sql = "DELETE FROM `" . $this->handler->table . "` WHERE " . $whereclause; $queryFunc = empty($force) ? "query" : "queryF"; - $result = $this->handler->db->{$queryFunc}($sql); + $result = $this->handler->db->$queryFunc($sql); return empty($result) ? false : true; } @@ -279,7 +281,7 @@ if (!empty($criteria)) { $sql .= ' ' . $criteria->renderWhere(); } - if (!$this->handler->db->{$queryFunc}($sql)) { + if (!$this->handler->db->$queryFunc($sql)) { return false; } return $this->handler->db->getAffectedRows(); @@ -299,17 +301,19 @@ $set_clause = "`{$fieldname}` = "; if (is_numeric($fieldvalue)) { $set_clause .= $fieldvalue; - } else if (is_array($fieldvalue)) { - $set_clause .= $this->handler->db->quote(implode(',', $fieldvalue)); } else { - $set_clause .= $this->handler->db->quote($fieldvalue); + if (is_array($fieldvalue)) { + $set_clause .= $this->handler->db->quote(implode(',', $fieldvalue)); + } else { + $set_clause .= $this->handler->db->quote($fieldvalue); + } } $sql = 'UPDATE `' . $this->handler->table . '` SET ' . $set_clause; if (isset($criteria)) { $sql .= ' ' . $criteria->renderWhere(); } $queryFunc = empty($force) ? 'query' : 'queryF'; - $result = $this->handler->db->{$queryFunc}($sql); + $result = $this->handler->db->$queryFunc($sql); return empty($result) ? false : true; } } Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/xoopsmodel.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/xoopsmodel.php 2011-10-16 16:15:42 UTC (rev 7899) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/xoopsmodel.php 2011-10-16 17:48:24 UTC (rev 7900) @@ -17,9 +17,11 @@ * @author Taiwen Jiang <ph...@us...> * @version $Id$ */ + defined('XOOPS_ROOT_PATH') or die('Restricted access'); include_once XOOPS_ROOT_PATH . '/kernel/object.php'; + /** * Factory for object handlers * @@ -34,13 +36,6 @@ static private $handlers = array(); /** - * XoopsModelFactory::__construct() - */ - private function __construct() - { - } - - /** * Get singleton instance * * @access public @@ -50,7 +45,8 @@ { static $instance; if (!isset($instance)) { - $instance = new XoopsModelFactory(); + $class = __CLASS__; + $instance = new $class(); } return $instance; } @@ -74,8 +70,10 @@ include_once $file; $className = 'XoopsModel' . ucfirst($name); $handler = new $className(); - } else if (xoops_load('model', 'framework')) { - $handler = XoopsModel::loadHandler($name); + } else { + if (xoops_load('model', 'framework')) { + $handler = XoopsModel::loadHandler($name); + } } if (!is_object($handler)) { trigger_error('Handler not found in file ' . __FILE__ . 'at line ' . __LINE__, E_USER_WARNING); Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/class/maintenance.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/class/maintenance.php 2011-10-16 16:15:42 UTC (rev 7899) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/class/maintenance.php 2011-10-16 17:48:24 UTC (rev 7900) @@ -33,7 +33,7 @@ * Constructor */ function SystemMaintenance() { - $db = Database::getInstance(); + $db = XoopsDatabaseFactory::getDatabaseConnection(); $this->db = $db; $this->prefix = $this->db->prefix.'_'; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |