コード例 #1
0
ファイル: UtilTest.php プロジェクト: aladin1394/CM
 public function testGetArrayTree()
 {
     $array = array(array('id' => 1, 'type' => 1, 'amount' => 1), array('id' => 2, 'type' => 1, 'amount' => 2), array('id' => 3, 'type' => 1, 'amount' => 3), array('id' => 4, 'type' => 1, 'amount' => 4));
     $this->assertSame(array(1 => array('type' => 1, 'amount' => 1), 2 => array('type' => 1, 'amount' => 2), 3 => array('type' => 1, 'amount' => 3), 4 => array('type' => 1, 'amount' => 4)), CM_Util::getArrayTree($array));
     $this->assertSame(array(1 => array('id' => 1, 'type' => 1), 2 => array('id' => 2, 'type' => 1), 3 => array('id' => 3, 'type' => 1), 4 => array('id' => 4, 'type' => 1)), CM_Util::getArrayTree($array, 1, true, 'amount'));
     $this->assertSame(array(1 => array(1 => 1), 2 => array(1 => 2), 3 => array(1 => 3), 4 => array(1 => 4)), CM_Util::getArrayTree($array, 2, true, array('amount', 'type')));
     try {
         CM_Util::getArrayTree($array, 1, true, 'foo');
         $this->fail('Item has key `foo`.');
     } catch (CM_Exception_Invalid $ex) {
         $this->assertContains('Item has no key `foo`.', $ex->getMessage());
     }
     try {
         CM_Util::getArrayTree(array(1, 2));
         $this->fail('Item is not an array.');
     } catch (CM_Exception_Invalid $ex) {
         $this->assertContains('Item is not an array or has less than `2` elements.', $ex->getMessage());
     }
     try {
         CM_Util::getArrayTree(array(array(1), array(2)));
         $this->fail('Item has less than two elements.');
     } catch (CM_Exception_Invalid $ex) {
         $this->assertContains('Item is not an array or has less than `2` elements.', $ex->getMessage());
     }
 }
コード例 #2
0
ファイル: Result.php プロジェクト: cargomedia/cm
 /**
  * @param int|null  $level
  * @param bool|null $distinctLeaves
  * @return array[]
  */
 public function fetchAllTree($level = null, $distinctLeaves = null)
 {
     return CM_Util::getArrayTree($this->fetchAll(), $level, $distinctLeaves);
 }
コード例 #3
0
ファイル: Abstract.php プロジェクト: cargomedia/cm
 /**
  * @param string|null $keyName
  * @return array[]
  */
 public function getItemsRawTree($keyName = null)
 {
     return CM_Util::getArrayTree($this->getItemsRaw(), 1, true, $keyName);
 }