22
33namespace ADT \QueryObjectDataSource ;
44
5- interface IQueryObjectDataSourceFactory {
6-
7- /** @return QueryObjectDataSource */
8- function create (\Kdyby \Doctrine \QueryObject $ queryObject , $ primaryKey );
9-
10- }
11-
12-
135class QueryObjectDataSource extends \Nette \Object implements \Ublaboo \DataGrid \DataSource \IDataSource {
146
15- /** @var \Kdyby\Doctrine\EntityManager */
16- protected $ em ;
17-
187 /** @var \Kdyby\Doctrine\ResultSet */
198 protected $ resultSet ;
209
10+ /** @var \Kdyby\Doctrine\EntityRepository */
11+ protected $ repo ;
12+
2113 /** @var \Kdyby\Doctrine\QueryObject */
2214 protected $ queryObject ;
2315
24- /** @var string */
25- protected $ primaryKey ;
26-
2716 /** @var callable */
2817 public $ filterCallback ;
2918
@@ -35,13 +24,11 @@ class QueryObjectDataSource extends \Nette\Object implements \Ublaboo\DataGrid\D
3524
3625 /**
3726 * @param \Kdyby\Doctrine\QueryObject $queryObject
38- * @param string $primaryKey
39- * @param \Kdyby\Doctrine\EntityManager $em
27+ * @param \Kdyby\Doctrine\EntityRepository $repo
4028 */
41- public function __construct (\Kdyby \Doctrine \QueryObject $ queryObject , $ primaryKey , \Kdyby \Doctrine \EntityManager $ em ) {
29+ public function __construct (\Kdyby \Doctrine \QueryObject $ queryObject , \Kdyby \Doctrine \EntityRepository $ repo ) {
4230 $ this ->queryObject = $ queryObject ;
43- $ this ->primaryKey = $ primaryKey ;
44- $ this ->em = $ em ;
31+ $ this ->repo = $ repo ;
4532 }
4633
4734 /**
@@ -73,7 +60,7 @@ public function setSortCallback($callback) {
7360
7461 protected function getResultSet () {
7562 if (!$ this ->resultSet ) {
76- $ this ->resultSet = $ this ->em -> getRepository ( $ this -> queryObject -> getEntity ())
63+ $ this ->resultSet = $ this ->repo
7764 ->fetch ($ this ->queryObject );
7865 }
7966
@@ -85,7 +72,7 @@ protected function getResultSet() {
8572 * @return int
8673 */
8774 public function getCount () {
88- return $ this ->em -> getRepository ( $ this -> queryObject -> getEntity ())
75+ return $ this ->repo
8976 ->fetch ($ this ->queryObject )
9077 ->getTotalCount ();
9178 }
0 commit comments