summaryrefslogtreecommitdiff
path: root/framework/Collections/TList.php
diff options
context:
space:
mode:
authorjavalizard <>2010-04-12 00:07:29 +0000
committerjavalizard <>2010-04-12 00:07:29 +0000
commitcbeed6e51bd1c7ea34b0cd934f3da0afe1b45d95 (patch)
tree3ddb230b10375648aaa84e69c89a5286ca175d45 /framework/Collections/TList.php
parentbbe6b5b15b523ff7ca50feaffce30004e746146d (diff)
added insertBefore and insertAfter
Diffstat (limited to 'framework/Collections/TList.php')
-rw-r--r--framework/Collections/TList.php36
1 files changed, 33 insertions, 3 deletions
diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php
index 50cbaf01..1a3dffb7 100644
--- a/framework/Collections/TList.php
+++ b/framework/Collections/TList.php
@@ -4,7 +4,7 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Collections
@@ -16,7 +16,7 @@
* TList implements an integer-indexed collection class.
*
* You can access, append, insert, remove an item by using
- * {@link itemAt}, {@link add}, {@link insert}, {@link remove}, and {@link removeAt}.
+ * {@link itemAt}, {@link add}, {@link insertAt}, {@link remove}, and {@link removeAt}.
* To get the number of the items in the list, use {@link getCount}.
* TList can also be used like a regular array as follows,
* <code>
@@ -47,7 +47,7 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countabl
* number of items
* @var integer
*/
- private $_c=0;
+ protected $_c=0;
/**
* @var boolean whether this list is read-only
*/
@@ -244,6 +244,36 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countabl
}
/**
+ * Finds the base item. If found, the item is inserted before it.
+ * @param mixed the base item which will be pushed back by the second parameter
+ * @param mixed the item
+ * @return object $this. null if the $baseitem is not found
+ */
+ public function insertBefore($baseitem, $item)
+ {
+ if(($index = $this->indexOf($baseitem)) == -1) return null;
+
+ $this->insertAt($index, $item);
+
+ return $this;
+ }
+
+ /**
+ * Finds the base item. If found, the item is inserted after it.
+ * @param mixed the base item which comes before the second parameter when added to the list
+ * @param mixed the item
+ * @return object $this. null if the $baseitem is not found
+ */
+ public function insertAfter($baseitem, $item)
+ {
+ if(($index = $this->indexOf($baseitem)) == -1) return null;
+
+ $this->insertAt($index + 1, $item);
+
+ return $this;
+ }
+
+ /**
* @return array the list of items in array
*/
public function toArray()