diff options
-rw-r--r-- | framework/Collections/TList.php | 36 |
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 © 2005-2008 PradoSoft + * @copyright Copyright © 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()
|