Esempio n. 1
0
 public function next()
 {
     $this->_array->next();
     if (0 !== $this->_limit and !$this->valid()) {
         $this->_array = Pix_Array::factory($this->_origin_array->after($this->_origin_array->getVolumePos($this->_last_row))->limit($this->_chunk)->rewind());
     }
 }
Esempio n. 2
0
 public function before()
 {
     $args = func_get_args();
     if (!count($args)) {
         return $this->_before;
     }
     $row = $args[0];
     $this->_after = null;
     $this->_before = is_array($row) ? Pix_Array::factory($row) : $row;
     return $this;
 }
Esempio n. 3
0
 /**
  * @dataProvider arrayProvider
  */
 public function testReverse($array)
 {
     $original_array = $array;
     $array = Pix_Array::factory($array);
     array_reverse($original_array);
     $array->reverse();
     $this->assertEquals($original_array, $array->toArray());
 }
Esempio n. 4
0
 public function before()
 {
     $args = func_get_args();
     if (!count($args)) {
         return $this->_before;
     }
     $row = $args[0];
     $this->_after = null;
     $this->_before = is_array($row) ? Pix_Array::factory($row) : $row;
     $this->_before_include = array_key_exists(1, $args) ? $args[1] : false;
     return $this;
 }
Esempio n. 5
0
 /**
  * getVolumePos 回傳這個 $row 在 Volumable 的位置
  *
  * @param Pix_Table_Row $row
  * @access public
  * @return array
  */
 public function getVolumePos($row)
 {
     if (!($orders = $this->_search_object->order())) {
         foreach ($this->getTable()->getPrimaryColumns() as $col) {
             $orders[$col] = 'asc';
         }
     }
     $terms = array();
     if (is_array($row)) {
         $row = Pix_Array::factory($row);
     } elseif (is_object($row) and is_a($row, 'Pix_Table_Row')) {
         $row = $row;
     } else {
         return null;
     }
     foreach ($orders as $order => $way) {
         if (!is_null($row->{$order})) {
             $terms[$order] = $row->{$order};
         }
     }
     return $terms;
 }
Esempio n. 6
0
 /**
  * @dataProvider arrayProvider
  * @expectedException Pix_Exception
  */
 public function testNoOrder($array_male, $array_female)
 {
     $array_male = Pix_Array::factory($array_male);
     $array_female = Pix_Array::factory($array_female);
     $array_merged = new Pix_Array_Merger($array_male, $array_female);
     foreach ($array_merged as $row) {
     }
 }
Esempio n. 7
0
<?php

// example/array/basic.php
include __DIR__ . '/../init.inc.php';
$array = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
$array = Pix_Array::factory($array);
// 得到 0 1 2
foreach ($array->limit(3) as $num) {
    echo $num . PHP_EOL;
}
echo "===" . PHP_EOL;
// 得到 5 6
foreach ($array->offset(5)->limit(2) as $num) {
    echo $num . PHP_EOL;
}
Esempio n. 8
0
<?php

// example/array/basic.php
include __DIR__ . '/../init.inc.php';
$members = array(array('name' => 'alice', 'height' => 158, 'weight' => 42, 'money' => 200), array('name' => 'bob', 'height' => 182, 'weight' => 72, 'money' => 150), array('name' => 'carol', 'height' => 170, 'weight' => 58, 'money' => 200));
$members = Pix_Array::factory($members);
// 照身高排序 bob(182), carol(170), alice(158)
foreach ($members->order('height DESC') as $member) {
    echo $member['name'] . '(' . $member['height'] . ')' . PHP_EOL;
}
echo "===" . PHP_EOL;
// 照體重排序 alice(42), carol(58), bob(72)
foreach ($members->order('weight ASC') as $member) {
    echo $member['name'] . '(' . $member['weight'] . ')' . PHP_EOL;
}
echo "===" . PHP_EOL;
// 照錢以及身高排序 carol(200,170), alice(200,158), bob(150,182)
foreach ($members->order('money DESC, height DESC') as $member) {
    echo $member['name'] . '(' . $member['money'] . ',' . $member['height'] . ')' . PHP_EOL;
}