|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Zenc_EmailLogger_RestController extends Zenc_EmailLogger_Controller_Restful |
|
4
|
|
|
{ |
|
5
|
|
|
const PAGE_SIZE = 20; |
|
6
|
|
|
|
|
7
|
|
|
protected $_methods = array('get'); |
|
8
|
|
|
|
|
9
|
|
|
public function getListAction() |
|
10
|
|
|
{ |
|
11
|
|
|
$this->_formats['html'] = 'zenc_emaillogger/render_dump'; |
|
12
|
|
|
|
|
13
|
|
|
$data = $this->_getRestData(); |
|
14
|
|
|
$this->render(array( |
|
15
|
|
|
'count' => $this->_getCollection()->getSize(), |
|
16
|
|
|
'itemsCount' => $this->_getCollection()->getSize(), |
|
17
|
|
|
'items' => $data, |
|
18
|
|
|
'data' => array_values($data), |
|
19
|
|
|
)); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function getReadAction() |
|
23
|
|
|
{ |
|
24
|
|
|
$item = $this->_getItem(); |
|
25
|
|
|
$this->render($item->getData()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
private function _getRestData() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->_getCollection()->walk(function($item) { |
|
31
|
|
|
return array( |
|
32
|
|
|
'id' => $item->getId(), |
|
33
|
|
|
'subject' => $item->getSubject(), |
|
34
|
|
|
'to_email' => $item->getToEmail(), |
|
35
|
|
|
'to_name' => $item->getToName(), |
|
36
|
|
|
'created_at' => $item->getCreatedAt(), |
|
37
|
|
|
); |
|
38
|
|
|
}); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
private function _getCollection() |
|
42
|
|
|
{ |
|
43
|
|
|
$collection = Mage::getModel('zenc_emaillogger/log')->getCollection() |
|
44
|
|
|
->orderByTimeDesc(); |
|
45
|
|
|
if ($index = $this->getRequest()->getParam('pageIndex')) { |
|
46
|
|
|
$collection->setCurPage($index); |
|
47
|
|
|
$collection->setPageSize($this->getRequest()->getParam('pageSize') ?: self::PAGE_SIZE); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $collection; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
private function _getItem() |
|
54
|
|
|
{ |
|
55
|
|
|
$id = $this->getRequest()->get('id'); |
|
56
|
|
|
if ($id == 'last') { |
|
57
|
|
|
$id = $this->_getCollection()->getLastItem()->getId(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return Mage::getModel('zenc_emaillogger/log')->load($id); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|