/**
  * Applies operation to source and returns modified source.
  *
  * @param $src
  * @param OperationInterface|FilterOperation $operation
  * @return mixed
  */
 public function process($src, OperationInterface $operation)
 {
     $res = [];
     foreach ($src as $row) {
         $testedValue = mp\getValue($row, $operation->getField());
         $argument = $operation->getValue();
         $operator = $operation->getOperator();
         if ($this->checkValue($testedValue, $operator, $argument)) {
             $res[] = $row;
         }
     }
     return $res;
 }
 /**
  * Applies operation to source and returns modified source.
  *
  * @param $src
  * @param OperationInterface|SortOperation $operation
  * @return mixed
  */
 public function process($src, OperationInterface $operation)
 {
     $field = $operation->getField();
     $desc = $operation->getOrder() === SortOperation::DESC;
     usort($src, function ($row1, $row2) use($field, $desc) {
         $val1 = mp\getValue($row1, $field);
         $val2 = mp\getValue($row2, $field);
         if ($val1 == $val2) {
             return 0;
         }
         $res = $val1 < $val2 ? -1 : 1;
         return $desc ? -$res : $res;
     });
     return $src;
 }
 /**
  * Returns array indexed by specified property of collection elements.
  * If there is few elements with same property value, last will be used.
  *
  * @param string $propertyName
  * @return array|object[]
  */
 public function indexByProperty($propertyName)
 {
     $results = [];
     foreach ($this->toArray() as $item) {
         $key = mp\getValue($item, $propertyName);
         if ($key) {
             $results[$key] = $item;
         }
     }
     return $results;
 }
示例#4
0
 /**
  * Returns current data cell value.
  *
  * @return mixed
  */
 public function getCurrentValue()
 {
     $func = $this->getValueCalculator();
     $currentDataRow = $this->getGrid()->getCurrentRow();
     if ($func !== null) {
         return call_user_func($func, $currentDataRow);
     } else {
         return mp\getValue($currentDataRow, $this->getDataFieldName());
     }
 }
示例#5
0
 public function testSetValue()
 {
     $data = ['a' => ['b' => ['c' => []]]];
     $res = mp\setValue($data, 'a.b.c', 7);
     self::assertTrue($res);
     self::assertEquals(7, mp\getValue($data, 'a.b.c'));
     self::assertFalse(mp\setValue($data, 'c.d.b', 8));
     self::assertTrue(mp\setValue($data, 'b', 9));
     self::assertEquals(9, $data['b']);
 }