コード例 #1
0
ファイル: DataTable.php プロジェクト: mzf/phalcon-datatables
 public function fromResultSet($resultSet, $columns = [])
 {
     if (empty($columns) && $resultSet->count() > 0) {
         $columns = array_keys($resultSet->getFirst()->toArray());
         $resultSet->rewind();
     }
     $adapter = new ResultSet($this->options['length']);
     $adapter->setResultSet($resultSet);
     $adapter->setParser($this->parser);
     $adapter->setColumns($columns);
     $this->response = $adapter->getResponse();
     return $this;
 }
コード例 #2
0
        $names = array_reduce($response['data'], function ($carry, $item) {
            $carry[] = $item['name'];
            return $carry;
        });
        expect($names)->toBe(['gebert', 'marvin.maybelle', 'zabernathy']);
    });
    it("should order", function () {
        $_GET = ['columns' => [['data' => 'name', 'searchable' => "true"]], 'order' => [['column' => 0, 'dir' => 'desc']]];
        $dataTables = new ResultSet(20);
        $dataTables->setResultSet($this->query);
        $dataTables->setColumns(['name', 'email']);
        $dataTables->setParser(new ParamsParser(10));
        $response = $dataTables->getResponse();
        expect(count($response['data']))->toBe(10);
        expect($response['data'][0]['name'])->toBe('zcremin');
    });
    it("should order asc", function () {
        $_GET = ['columns' => [['data' => 'name', 'searchable' => "true"]], 'order' => [['column' => 0, 'dir' => 'asc']]];
        $dataTables = new ResultSet(20);
        $dataTables->setResultSet($this->query);
        $dataTables->setColumns(['name', 'email']);
        $dataTables->setParser(new ParamsParser(10));
        $response = $dataTables->getResponse();
        expect(count($response['data']))->toBe(10);
        expect($response['data'][0]['name'])->toBe('adelia13');
    });
    afterEach(function () {
        unset($_GET);
        unset($_POST);
    });
});