[xoops-cvslog 3481] CVS update: xoops2jp/html/modules/base/kernel

Back to archive index

Minahito minah****@users*****
2006年 7月 10日 (月) 18:37:08 JST


Index: xoops2jp/html/modules/base/kernel/handler.php
diff -u xoops2jp/html/modules/base/kernel/handler.php:1.1.2.16 xoops2jp/html/modules/base/kernel/handler.php:1.1.2.17
--- xoops2jp/html/modules/base/kernel/handler.php:1.1.2.16	Tue Jun 20 19:53:44 2006
+++ xoops2jp/html/modules/base/kernel/handler.php	Mon Jul 10 18:37:08 2006
@@ -13,6 +13,11 @@
 	var $mPrimary = null;
 	var $mClass = null;
 
+	/**
+	 * A instance of xoops simple object to get type information.
+	 */	
+	var $_mDummyObj = null;
+
 	function XoopsObjectGenericHandler(&$db)
 	{
 		parent::XoopsObjectHandler($db);
@@ -34,31 +39,34 @@
 	{
 		$ret = null;
 		
-		$id = $this->db->quoteString($id);
-		$sql = "SELECT * FROM " . $this->mTable . " WHERE " . $this->mPrimary . "=${id}";
-
-		$result = $this->db->query($sql);
+		$criteria =& new Criteria($this->mPrimary, $id);
+		$objArr =& $this->getObjects($criteria);
 		
-		if (!$result) {
-			return $ret;
-		}
-		
-		if ($this->db->getRowsNum($result) == 1) {
-			$ret =& new $this->mClass();
-			$ret->assignVars($this->db->fetchArray($result));
-			$ret->unsetNew();
+		if (count($objArr) == 1) {
+			$ret =& $objArr[0];
 		}
 
 		return $ret;
 	}
 
+	/**
+	 * Return array of object with $criteria.
+	 * 
+	 * @access public
+	 * @param CriteriaElement $criteria
+	 * @param int  $limit
+	 * @param int  $start
+	 * @param bool $id_as_key
+	 * 
+	 * @return array
+	 */
 	function &getObjects($criteria = null, $param1 = false, $param2 = false, $param3 = false)
 	{
 		$ret = array();
 
-		$sql = "SELECT * FROM " . $this->mTable;
-
 		if($criteria !== null && is_a($criteria, 'CriteriaElement')) {
+			$sql = "SELECT * FROM " . $this->mTable;
+			
 			$where = $this->_makeCriteria4sql($criteria);
 			
 			if (trim($where)) {
@@ -73,51 +81,36 @@
 				$sql .= " ORDER BY " . implode(',', $sorts);
 			}
 			
-			$limit=$criteria->getLimit();
-			$start=$criteria->getStart();
+			$limit = $criteria->getLimit();
+			$start = $criteria->getStart();
 			
-			$ret =& $this->_getObjects($sql, $limit, $start, $param1);
-		}
-		else {
-			$ret =& $this->_getObjects($sql, $param1, $param2, $param3);
-		}
-		
-		return $ret;
-	}
-	
-	/**
-	 * @access private
-	 */
-	function &_getObjects($sql = null, $limit = 0, $start = 0, $id_as_key = false)
-	{
-		$ret = array();
-
-		$result = $this->db->query($sql, $limit, $start);
+			$result = $this->db->query($sql, $limit, $start);
 
-		if (!$result) {
-			return $ret;
-		}
+			if (!$result) {
+				return $ret;
+			}
 
-		while($row=$this->db->fetchArray($result)) {
-			$obj =& new $this->mClass();
-			$obj->assignVars($row);
-			$obj->unsetNew();
+			while($row = $this->db->fetchArray($result)) {
+				$obj =& new $this->mClass();
+				$obj->assignVars($row);
+				$obj->unsetNew();
 			
-			if ($id_as_key)
-			{
-				$ret[$obj->get($this->mPrimary)]=&$obj;
-			}
-			else
-			{
-				$ret[]=&$obj;
-			}
+				if ($id_as_key)	{
+					$ret[$obj->get($this->mPrimary)] =& $obj;
+				}
+				else {
+					$ret[]=&$obj;
+				}
 			
-			unset($obj);
+				unset($obj);
+			}
+		
+			return $ret;
 		}
 		
 		return $ret;
 	}
-
+	
 	function getCount($criteria = null)
 	{
 		$ret = array();
@@ -247,9 +240,11 @@
 	
 	function _makeCriteria4sql($criteria)
 	{
-		$dmmyObj =& $this->create();
+		if ($this->_mDummyObj == null) {
+			$this->_mDummyObj =& $this->create();
+		}
 
-		return $this->_makeCriteriaElement4sql($criteria, $dmmyObj);
+		return $this->_makeCriteriaElement4sql($criteria, $this->_mDummyObj);
 	}
 
 	/**
@@ -350,8 +345,10 @@
 	 */
 	function &createCriteria()
 	{
-		$dmy =& $this->create();
-		$criteria =& new Legacy_Criteria($dmy->getTypeInformations());
+		if ($this->_mDummyObj == null) {
+			$this->_mDummyObj =& $this->create();
+		}
+		$criteria =& new Legacy_Criteria($this->_mDummyObj->getTypeInformations());
 		
 		return $criteria;
 	}


xoops-cvslog メーリングリストの案内
Back to archive index