forked from ershov-ilya/miniShop2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getlist.class.php
85 lines (70 loc) · 2.81 KB
/
getlist.class.php
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
<?php
/**
* Get a list of Orders
*
* @package minishop2
* @subpackage processors
*/
class msOrderGetListProcessor extends modObjectGetListProcessor {
public $classKey = 'msOrder';
public $defaultSortField = 'id';
public $defaultSortDirection = 'DESC';
public $languageTopics = array('default','minishop2:manager');
public function prepareQueryBeforeCount(xPDOQuery $c) {
$c->leftJoin('modUserProfile','modUserProfile', '`msOrder`.`user_id` = `modUserProfile`.`internalKey`');
$c->leftJoin('msOrderStatus','msOrderStatus', '`msOrder`.`status` = `msOrderStatus`.`id`');
$c->leftJoin('msDelivery','msDelivery', '`msOrder`.`delivery` = `msDelivery`.`id`');
$c->leftJoin('msPayment','msPayment', '`msOrder`.`payment` = `msPayment`.`id`');
$orderColumns = $this->modx->getSelectColumns('msOrder', 'msOrder', '', array('status','delivery','payment'), true);
$c->select($orderColumns . ', `modUserProfile`.`fullname` as `customer`, `msOrderStatus`.`name` as `status`, `msOrderStatus`.`color`, `msDelivery`.`name` as `delivery`, `msPayment`.`name` as `payment`');
if ($query = $this->getProperty('query')) {
$c->where(array(
'num:LIKE' => '%'.$query.'%'
,'OR:comment:LIKE' => '%'.$query.'%'
,'OR:modUserProfile.fullname:LIKE' => '%'.$query.'%'
));
}
if ($status = $this->getProperty('status')) {
$c->where(array('status' => $status));
}
return $c;
}
public function getData() {
$data = array();
$limit = intval($this->getProperty('limit'));
$start = intval($this->getProperty('start'));
/* query for chunks */
$c = $this->modx->newQuery($this->classKey);
$c = $this->prepareQueryBeforeCount($c);
$data['total'] = $this->modx->getCount($this->classKey,$c);
$c = $this->prepareQueryAfterCount($c);
$sortClassKey = $this->getSortClassKey();
$sortKey = $this->modx->getSelectColumns($sortClassKey,$this->getProperty('sortAlias',$sortClassKey),'',array($this->getProperty('sort')));
if (empty($sortKey)) $sortKey = $this->getProperty('sort');
$c->sortby($sortKey,$this->getProperty('dir'));
if ($limit > 0) {
$c->limit($limit,$start);
}
if ($c->prepare() && $c->stmt->execute()) {
$data['results'] = $c->stmt->fetchAll(PDO::FETCH_ASSOC);
}
return $data;
}
public function iterate(array $data) {
$list = array();
$list = $this->beforeIteration($list);
$this->currentIndex = 0;
/** @var xPDOObject|modAccessibleObject $object */
foreach ($data['results'] as $array) {
$list[] = $this->prepareArray($array);
$this->currentIndex++;
}
$list = $this->afterIteration($list);
return $list;
}
public function prepareArray(array $data) {
$data['status'] = '<span style="color:#'.$data['color'].';">'.$data['status'].'</span>';
return $data;
}
}
return 'msOrderGetListProcessor';