/
class.atkselector.inc
899 lines (792 loc) · 24.3 KB
/
class.atkselector.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
<?php
/**
* This file is part of the ATK distribution on GitHub.
* Detailed copyright and licensing information can be found
* in the doc/COPYRIGHT and doc/LICENSE files which should be
* included in the distribution.
*
* @package atk
* @subpackage utils
*
* @copyright (c) 2010 Peter C. Verhage <peter@achievo.org>
* @license http://www.achievo.org/atk/licensing ATK Open Source License
*
* @version $Revision$
* $Id$
*/
/**
* Fluent interface helper class for retrieving records from a node.
*
* @author Peter C. Verhage <peter@achievo.org>
* @package atk
* @subpackage utils
*/
class atkSelector implements ArrayAccess, Countable, IteratorAggregate
{
/**
* This selector's node.
*
* @var atkNode
*/
protected $m_node;
/**
* Selector parameters.
*/
protected $m_conditions = array();
protected $m_distinct = false;
protected $m_mode = '';
protected $m_order = '';
protected $m_limit = -1;
protected $m_offset = 0;
protected $m_excludes = null;
protected $m_includes = null;
protected $m_ignoreDefaultFilters = false;
protected $m_ignorePostvars = false;
protected $m_ignoreForceLoad = false;
protected $m_ignorePrimaryKey = false;
/**
* Rows cache.
*
* @var array
*/
protected $m_rows = null;
/**
* Row count cache.
*
* @var int
*/
protected $m_rowCount = null;
/**
* Indices cache.
*
* @var array
*/
protected $m_indices = null;
/**
* Current iterator instance (if iterator is used).
*
* @var atkSelectorIterator
*/
private $m_iterator = null;
/**
* Current statement object (if iterator is used).
*
* @var atkStatement
*/
private $m_stmt = null;
/**
* Current query object (if iterator is used).
*
* @var atkQuery
*/
private $m_query = null;
/**
* Current attributes by load type (if iterator is used).
*
* @var array
*/
private $m_attrsByLoadType = null;
/**
* Constructor.
*
* @param atkNode $node this selector's node
*/
public function __construct($node)
{
$this->m_node = $node;
}
/**
* Returns the node for this selector.
*
* @return atkNode
*/
protected function _getNode()
{
return $this->m_node;
}
/**
* Returns the node's database.
*
* @return atkDb
*/
protected function _getDb()
{
return $this->_getNode()->getDb();
}
/**
* Adds a condition..
*
* @param string $condition where clause
* @param array $params bind parameters
*
* @return atkSelector
*/
public function where($condition, $params = array())
{
if (strlen(trim($condition)) > 0) {
$this->m_conditions[] = array('condition' => $condition, 'params' => $params);
}
return $this;
}
/**
* Ignore default node filters.
*
* @param boolean $ignore ignore default node filters?
* @return atkSelector
*/
public function ignoreDefaultFilters($ignore = true)
{
$this->m_ignoreDefaultFilters = $ignore;
return $this;
}
/**
* Ignore criteria set in the postvars, like search criteria etc.
*
* @param boolean $ignore ignore postvars?
* @return atkSelector
*/
public function ignorePostvars($ignore = true)
{
$this->m_ignorePostvars = $ignore;
return $this;
}
/**
* Ignore force load flags.
*
* @param boolean $ignore ignore force load flags
* @return atkSelector
*/
public function ignoreForceLoad($ignore = true)
{
$this->m_ignoreForceLoad = $ignore;
return $this;
}
/**
* Don't forcefully load the primary key. The result records also won't
* contain the special "atkprimkey" entry.
*
* @param boolean $ignore ignore primary key
* @return atkSelector
*/
public function ignorePrimaryKey($ignore = true)
{
$this->m_ignorePrimaryKey = $ignore;
return $this;
}
/**
* Distinct selection?
*
* @param boolean $distinct distinct selection?
* @return atkSelector
*/
public function distinct($distinct)
{
$this->m_distinct = $distinct;
return $this;
}
/**
* Set the select mode.
*
* @param string $mode select mode
* @return atkSelector
*/
public function mode($mode)
{
$this->m_mode = $mode;
return $this;
}
/**
* Order by the given order by string.
*
* @param string $order order by string
* @return atkSelector
*/
public function orderBy($order)
{
$this->m_order = $order;
return $this;
}
/**
* Limit the results bij the given limit (and from the optional offset).
*
* @param int $limit limit
* @param int $offset offset
* @return atkSelector
*/
public function limit($limit, $offset = 0)
{
$this->m_limit = $limit;
$this->m_offset = $offset;
return $this;
}
/**
* Include only the following list of attributes.
*
* @param array $includes list of includes
* @return atkSelector
*/
public function includes($includes)
{
if ($includes == null) {
$includes = null;
} else if (!is_array($includes)) {
$includes = func_get_args();
}
$this->m_includes = $includes;
return $this;
}
/**
* Exclude the following list of attributes.
*
* @param array $excludes list of excludes
* @return atkSelector
*/
public function excludes($excludes)
{
if ($excludes == null) {
$excludes = null;
} else if (!is_array($excludes)) {
$excludes = func_get_args();
}
$this->m_excludes = $excludes;
return $this;
}
/**
* Are we searching?
*/
protected function _isSearching()
{
if ($this->m_ignorePostvars) {
return false;
}
$searchCriteria = atkArrayNvl($this->_getNode()->m_postvars, 'atksearch');
$smartSearchCriteria = atkArrayNvl($this->_getNode()->m_postvars, 'atksmartsearch');
$indexValue = $this->_getNode()->m_index != '' ? atkArrayNvl($this->_getNode()->m_postvars, 'atkindex', '')
: '';
return (is_array($searchCriteria) && count($searchCriteria) > 0) ||
(is_array($smartSearchCriteria) && count($smartSearchCriteria) > 0) ||
!empty($indexValue);
}
/**
* Apply set conditions to query.
*
* @param atkQuery $query query object
*/
protected function _applyConditionsToQuery($query)
{
foreach ($this->m_conditions as $condition) {
$query->addCondition($condition['condition']);
}
}
/**
* Apply posted filter to query.
*
* @param atkQuery $query query object
*/
protected function _applyPostedFilterToQuery($query)
{
$filter = atkArrayNvl($this->_getNode()->m_postvars, 'atkfilter', '');
if (empty($filter)) {
return;
}
$filter = $this->_getNode()->validateFilter($filter);
$query->addCondition($filter);
}
/**
* Apply posted index value to query.
*
* @param atkQuery $query query object
*/
protected function _applyPostedIndexValueToQuery(atkQuery $query)
{
$indexAttrName = $this->_getNode()->m_index;
$indexValue = atkArrayNvl($this->_getNode()->m_postvars, 'atkindex', '');
if (empty($indexAttrName) || empty($indexValue) || !is_object($this->_getNode()->getAttribute($indexAttrName))) {
return;
}
$attr = $this->_getNode()->getAttribute($indexAttrName);
$attr->searchCondition($query, $this->_getNode()->getTable(), $indexValue, 'wildcard', '');
}
/**
* Set search method for query.
*
* @param atkQuery $query query object
*/
protected function _applyPostedSearchMethodToQuery(atkQuery $query)
{
// fix missing _getNode() since $this does noe have any m_postvars method itself
if (isset($this->_getNode()->m_postvars['atksearchmethod'])) {
$query->setSearchMethod($this->_getNode()->m_postvars['atksearchmethod']);
}
}
/**
* Apply posted (normal) search criteria to query
*
* @param atkQuery $query query object
* @param array $attrsByLoadType attributes by load type
*/
protected function _applyPostedSearchCriteriaToQuery(atkQuery $query, array $attrsByLoadType)
{
$searchCriteria = atkArrayNvl($this->_getNode()->m_postvars, 'atksearch');
if (!is_array($searchCriteria) || count($searchCriteria) == 0) {
return;
}
foreach ($searchCriteria as $key => $value) {
if ($value === null || $value === '' ||
($this->m_mode != 'admin' && $this->m_mode != 'export' && !array_key_exists($key, $attrsByLoadType[ADDTOQUERY]))) {
continue;
}
$attr = $this->_getNode()->getAttribute($key);
if (is_object($attr)) {
if (is_array($value) && isset($value[$key]) && count($value) == 1) {
$value = $value[$key];
}
$searchMode = $this->_getNode()->getSearchMode();
if (is_array($searchMode)) {
$searchMode = $searchMode[$key];
}
if ($searchMode == null) {
$searchMode = atkconfig('search_defaultmode');
}
$attr->searchCondition($query, $this->_getNode()->getTable(), $value, $searchMode, '');
} else {
atkdebug("Using default search method for $key");
$condition = "LOWER(" . $this->_getNode()->getTable() . "." . $key . ") LIKE LOWER('%" . $this->_getDb()->escapeSQL($value, true) . "%')";
$query->addSearchCondition($condition);
}
}
}
/**
* Apply posted smart search criteria to query.
*
* @param atkQuery $query query object
*/
protected function _applyPostedSmartSearchCriteriaToQuery(atkQuery $query)
{
$searchCriteria = atkArrayNvl($this->_getNode()->m_postvars, 'atksmartsearch');
if (!is_array($searchCriteria) || count($searchCriteria) == 0) {
return;
}
foreach ($searchCriteria as $id => $criterium) {
$path = $criterium['attrs'];
$value = $criterium['value'];
$mode = $criterium['mode'];
$attrName = array_shift($path);
$attr = $this->_getNode()->getAttribute($attrName);
if (is_object($attr)) {
$attr->smartSearchCondition($id, 0, $path, $query, $this->_getNode()->getTable(), $value, $this->m_mode, '');
}
}
}
/**
* Apply criteria that are part of the postvars (e.g. filter, index, search criteria)
*
* @param atkQuery $query query
* @param array $attrsByLoadType attributes by load type
*/
protected function _applyPostvarsToQuery(atkQuery $query, array $attrsByLoadType)
{
if (!$this->m_ignorePostvars) {
$this->_applyPostedFilterToQuery($query);
$this->_applyPostedIndexValueToQuery($query);
$this->_applyPostedSearchMethodToQuery($query);
$this->_applyPostedSearchCriteriaToQuery($query, $attrsByLoadType);
$this->_applyPostedSmartSearchCriteriaToQuery($query);
}
}
/**
* Apply node filters to query.
*
* @param atkQuery $query query
*/
protected function _applyFiltersToQuery(atkQuery $query)
{
if ($this->m_ignoreDefaultFilters) {
return;
}
// key/value filters
foreach ($this->_getNode()->m_filters as $key => $value) {
$query->addCondition($key . "='" . $this->_getDb()->escapeSQL($value) . "'");
}
// fuzzy filters
atkimport("atk.utils.atkstringparser");
foreach ($this->_getNode()->m_fuzzyFilters as $filter) {
$parser = new atkStringParser($filter);
$filter = $parser->parse(array('table' => $this->_getNode()->getTable()));
$query->addCondition($filter);
}
}
/**
* Is attribute load required?
*
* @param atkAttribute $attr attribute
*
* @return boolean load required?
*/
protected function _isAttributeLoadRequired($attr)
{
$attrName = $attr->fieldName();
return
(!$this->m_ignorePrimaryKey && in_array($attrName, $this->_getNode()->m_primaryKey)) ||
(!$this->m_ignoreForceLoad && $attr->hasFlag(AF_FORCE_LOAD)) ||
(($this->m_includes != null && in_array($attrName, $this->m_includes)) || ($this->m_excludes != null && !in_array($attrName, $this->m_excludes))) ||
($this->m_excludes == null && $this->m_includes == null);
}
/**
* Returns the attributes for each load type (PRELOAD, ADDTOQUERY, POSTLOAD)
*
* @return array attributes by load type
*/
protected function _getAttributesByLoadType()
{
$isSearching = $this->_isSearching();
$result = array(PRELOAD => array(), ADDTOQUERY => array(), POSTLOAD => array());
foreach ($this->_getNode()->getAttributes() as $attr) {
if (!$this->_isAttributeLoadRequired($attr)) {
continue;
}
$loadType = $attr->loadType($this->m_mode, $isSearching);
if (hasFlag($loadType, PRELOAD)) {
$result[PRELOAD][$attr->fieldName()] = $attr;
}
if (hasFlag($loadType, ADDTOQUERY)) {
$result[ADDTOQUERY][$attr->fieldName()] = $attr;
}
if (hasFlag($loadType, POSTLOAD)) {
$result[POSTLOAD][$attr->fieldName()] = $attr;
}
}
return $result;
}
/**
* Apply attributes to query, e.g. add columns etc.
*
* @param atkQuery $query query object
* @param array $attrsByLoadType attributes by load type
*/
protected function _applyAttributesToQuery(atkQuery $query, array $attrsByLoadType)
{
$record = array();
foreach ($attrsByLoadType[PRELOAD] as $attr) {
$record[$attr->fieldName()] = $attr->load($this->_getDb(), $record, $this->m_mode);
}
foreach ($attrsByLoadType[ADDTOQUERY] as $attr) {
$attr->addToQuery($query, $this->_getNode()->getTable(), '', $record, 1, $this->m_mode);
}
}
/**
* Build base query object.
*
* @param array $attrsByLoadType attributes by load type
*
* @return atkQuery query object
*/
protected function _buildQuery(array $attrsByLoadType)
{
$query = $this->_getNode()->getDb()->createQuery();
$query->setDistinct($this->m_distinct);
$query->addTable($this->_getNode()->getTable());
$this->_applyConditionsToQuery($query);
$this->_applyFiltersToQuery($query);
$this->_applyPostvarsToQuery($query, $attrsByLoadType);
$this->_applyAttributesToQuery($query, $attrsByLoadType);
return $query;
}
/**
* Build select query object.
*
* @param array $attrsByLoadType attributes by load type
*
* @return atkQuery query object
*/
protected function _buildSelectQuery(array $attrsByLoadType)
{
$query = $this->_buildQuery($attrsByLoadType);
if (!empty($this->m_order)) {
$query->addOrderBy($this->m_order);
}
if ($this->m_limit >= 0) {
$query->setLimit($this->m_offset, $this->m_limit);
}
return $query;
}
/**
* Build count query object.
*
* @param array $attrsByLoadType attributes by load type
*
* @return atkQuery query object
*/
protected function _buildCountQuery(array $attrsByLoadType)
{
return $this->_buildQuery($attrsByLoadType);
}
/**
* Returns all bind parameters for all conditions.
*
* @return array bind parameters
*/
protected function _getBindParameters()
{
$params = array();
foreach ($this->m_conditions as $condition) {
$params = array_merge($params, $condition['params']);
}
return $params;
}
/**
* Transform raw database row to node compatible row.
*
* @param array $row raw database row
* @param atkQuery $query query object
* @param array $attrsByLoadType attributes by load type
*
* @return array node compatible row
*/
protected function _transformRow($row, atkQuery $query, array $attrsByLoadType)
{
$query->deAlias($row);
atkDataDecode($row);
$result = array();
foreach ($attrsByLoadType[ADDTOQUERY] as $attr) {
$result[$attr->fieldName()] = $attr->db2value($row);
}
if (!$this->m_ignorePrimaryKey) {
$result['atkprimkey'] = $this->_getNode()->primaryKey($result);
}
foreach ($attrsByLoadType[POSTLOAD] as $attr) {
$result[$attr->fieldName()] = $attr->load($this->_getDb(), $result, $this->m_mode);
}
return $result;
}
/**
* Transform raw database rows to node compatible rows.
*
* @param array $rows raw database rows
* @param atkQuery $query query object
* @param array $attrsByLoadType attributes by load type
*
* @return array node compatible rows
*/
protected function _transformRows($rows, atkQuery $query, array $attrsByLoadType)
{
foreach ($rows as &$row) {
$row = $this->_transformRow($row, $query, $attrsByLoadType);
}
return $rows;
}
/**
* Transform raw database row to node compatible row for the current iterator.
*
* @param array $row raw database row
*
* @return array node compatible row
*/
public function transformRow($row)
{
if ($this->m_iterator == null) {
throw new Exception(__METHOD__ . ' should only be called by the current atkSelectorIterator instance!');
}
return $this->_transformRow($row, $this->m_query, $this->m_attrsByLoadType);
}
/**
* Returns the first found row.
*
* @return array first row
*/
public function getFirstRow()
{
$this->limit(1, $this->m_offset);
$rows = $this->getAllRows();
return count($rows) == 1 ? $rows[0] : null;
}
/**
* Return all rows.
*
* @return array all rows
*/
public function getAllRows()
{
if ($this->m_rows === null) {
$attrsByLoadType = $this->_getAttributesByLoadType();
$query = $this->_buildSelectQuery($attrsByLoadType);
$stmt = $this->_getDb()->prepare($query->buildSelect());
$stmt->execute($this->_getBindParameters());
$rows = $stmt->getAllRows();
$stmt->close();
$this->m_rows = $this->_transformRows($rows, $query, $attrsByLoadType);
}
return $this->m_rows;
}
/**
* Return row count.
*
* @return int row count
*/
public function getRowCount()
{
if ($this->m_rowCount === null) {
$attrsByLoadType = $this->_getAttributesByLoadType();
$query = $this->_buildCountQuery($attrsByLoadType);
$stmt = $this->_getDb()->prepare($query->buildCount());
$stmt->execute($this->_getBindParameters());
$rows = $stmt->getAllRows();
$stmt->close();
$this->m_rowCount = count($rows) == 1 ? $rows[0]['count'] : count($rows); // group by fix
}
return $this->m_rowCount;
}
/**
* Returns the available indices for the index field based on the criteria.
*
* @return array available indices
*/
public function getIndices()
{
if ($this->_getNode()->m_index == null) {
return array();
} else if ($this->m_indices != null) {
return $this->m_indices;
}
$attrsByLoadType = $this->_getAttributesByLoadType();
$index = $this->_getNode()->m_index;
$this->_getNode()->m_index = null;
$query = $this->_buildQuery($attrsByLoadType);
$this->_getNode()->m_index = $index;
$query->clearFields();
$query->clearExpressions();
$indexColumn = $this->_getDb()->quoteIdentifier($this->_getNode()->getTable()) . '.' . $this->_getDb()->quoteIdentifier($index);
$expression = "UPPER(" . $this->_getDb()->func_substring($indexColumn, 1, 1) . ")";
$query->addExpression('index', $expression);
$query->addGroupBy($expression);
$query->addOrderBy($expression);
$stmt = $this->_getDb()->prepare($query->buildSelect());
$stmt->execute($this->_getBindParameters());
$this->m_indices = $stmt->getAllValues();
$stmt->close();
return $this->m_indices;
}
/**
* Deprecated alias for atkSelector::getFirstRow().
*
* @see atkSelector::getFirstRow
* @deprecated
*/
public function firstRow()
{
return $this->getFirstRow();
}
/**
* Deprecated alias for atkSelector::getAllRows().
*
* @see atkSelector::getAllRows
* @deprecated
*/
public function allRows()
{
return $this->getAllRows();
}
/**
* Deprecated alias for atkSelector::getRowCount().
*
* @see atkSelector::getRowCount
* @deprecated
*/
public function rowCount()
{
return $this->getRowCount();
}
/**
* Does the given offset exist?
*
* @param string|int $key key
* @return boolean offset exists?
*/
public function offsetExists($key)
{
$this->getAllRows();
return isset($this->m_rows[$key]);
}
/**
* Returns the given offset.
*
* @param string|int $key key
* @return mixed
*/
public function offsetGet($key)
{
$this->getAllRows();
return $this->m_rows[$key];
}
/**
* Sets the value for the given offset.
*
* @param string|int $key
* @param mixed $value
*/
public function offsetSet($key, $value)
{
$this->getAllRows();
return $this->m_rows[$key] = $value;
}
/**
* Unset the given element.
*
* @param string|int $key
*/
public function offsetUnset($key)
{
$this->getAllRows();
unset($this->m_rows[$key]);
}
/**
* Returns this selector's iterator.
*
* NOTE: if you call this method multiple times, the same iterator will
* be returned, unless you have closed the selector first
*/
public function getIterator()
{
if ($this->m_iterator == null) {
$attrsByLoadType = $this->_getAttributesByLoadType();
$query = $this->_buildSelectQuery($attrsByLoadType);
$stmt = $this->_getDb()->prepare($query->buildSelect());
$stmt->execute($this->_getBindParameters());
$this->m_attrsByLoadType = $attrsByLoadType;
$this->m_query = $query;
$this->m_stmt = $stmt;
atkimport('atk.utils.atkselectoriterator');
$this->m_iterator = new atkSelectorIterator($this->m_stmt->getIterator(), $this);
}
return $this->m_iterator;
}
/**
* Closes the current statement used for this selector.
* Also clears the row and row count cache.
*/
public function close()
{
if ($this->m_iterator != null) {
$this->m_iterator = null;
$this->m_stmt->close();
$this->m_stmt = null;
$this->m_query = null;
$this->m_attrsByLoadType = null;
}
$this->m_rows = null;
$this->m_rowCount = null;
$this->m_indices = null;
}
/**
* Returns the row count (used when calling count on an atkSelector object,
* don't use this if you want to efficiently retrieve the row count using
* a count() select statement, use rowCount instead!
*
* @return int row count
*/
public function count()
{
$this->getAllRows();
return count($this->m_rows);
}
}