瀏覽代碼

N°1067 Rework on ormLinkSet BC with DBObjectSet.
- PHP notice are not thrown anymore, see PHPDoc instead.
- GetColumnAsArray() introduced.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4949 a333f486-631f-4898-b8df-5754b55c2be0

glajarige 7 年之前
父節點
當前提交
aa4f7e209c
共有 1 個文件被更改,包括 24 次插入8 次删除
  1. 24 8
      core/ormlinkset.class.inc.php

+ 24 - 8
core/ormlinkset.class.inc.php

@@ -130,12 +130,10 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
     /**
      * @param DBObject $oObject
      * @param string $sClassAlias
-     * @deprecated
+     * @deprecated Since iTop 2.4, use ormLinkset->AddItem() instead.
      */
 	public function AddObject(DBObject $oObject, $sClassAlias = '')
     {
-        trigger_error('iTop: ormLinkSet::AddObject() is deprecated use ormLinkSet::AddItem() instead.', E_USER_DEPRECATED);
-
         $this->AddItem($oObject);
     }
 
@@ -190,16 +188,12 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
 	}
 
     /**
-     * Note: After calling this method, the set cursor will be at the end of the set. You might to rewind it.
-     *
      * @param bool $bWithId
      * @return array
-     * @deprecated
+     * @deprecated Since iTop 2.4, use foreach($this as $oItem){} instead
      */
     public function ToArray($bWithId = true)
     {
-        trigger_error('iTop: ormLinkSet::ToArray() is deprecated use foreach instead.', E_USER_DEPRECATED);
-
         $aRet = array();
         foreach($this as $oItem)
         {
@@ -216,6 +210,28 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
     }
 
     /**
+     * @param string $sAttCode
+     * @param bool $bWithId
+     * @return array
+     */
+    public function GetColumnAsArray($sAttCode, $bWithId = true)
+    {
+        $aRet = array();
+        foreach($this as $oItem)
+        {
+            if ($bWithId)
+            {
+                $aRet[$oItem->GetKey()] = $oItem->Get($sAttCode);
+            }
+            else
+            {
+                $aRet[] = $oItem->Get($sAttCode);
+            }
+        }
+        return $aRet;
+    }
+
+    /**
 	 * The class of the objects of the collection (at least a common ancestor)
 	 *
 	 * @return string