DeliveryController.php
4 KB
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
<?php
namespace controllers;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class DeliveryController extends \Phalcon\Mvc\Controller
{
public function initialize()
{
$this->view->setTemplateAfter('common');
}
function indexAction($id)
{
if($id){
$this->session->set("project-id", $id);
}
$params = $this->dispatcher->getParams();
$currentPage = !empty( $params['page'] ) ? $params['page'] : 1;
// Набор данных для разбивки на страницы
$data = \delivery::find("project_id = {$this->session->get('project-id')}");
// Создаём пагинатор, отображаются 10 элементов на странице, начиная с текущей - $currentPage
/*$paginator = new \Phalcon\Paginator\Adapter\Model(
array(
"data" => $data,
"limit"=> 10,
"page" => $currentPage
)
);
// Получение результатов работы ппагинатора
$page = $paginator->getPaginate();*/
$this->view->setVars([
'info' => $data
]);
}
function deleteAction($id)
{
$model = \delivery::query()
->where("id = $id")
->andWhere("project_id = {$this->session->get('project-id')}")
->execute();
if($model->toArray()){
$model->delete();
$this->flash->error( 'Данные успешно удалены' );
return $this->response->redirect([ 'for' => 'delivery_index' ]);
} else {
$this->flash->error( 'Произошла ошибка при попытке удаления' );
return $this->response->redirect([ 'for' => 'delivery_index' ]);
}
}
function moreInfoAction($id)
{
$this->view->pick( 'delivery/addEdit' );
$this->view->setVars([
]);
}
function updateAction($id)
{
$model = \delivery::findFirst("campaign_id = '$id' AND project_id = {$this->session->get('project-id')}");
//$model->status = $this->MyMailer->Delivery->getCampaignDeliveryStats( $id);
$result = $this->MyMailer->Delivery->getCampaignAggregateStats( $id);
$result['status'] = $this->MyMailer->Delivery->getDeliveryStatus( $id);
//$model->status = $this->MyMailer->Delivery->getVisitedLinks($id);
if( $model->save($result ))
{
$this->flash->success( 'Обновление прошло успешно' );
}
else
{
$this->flash->error( 'Произошла ошибка во время обновления.' );
}
return $this->response->redirect([ 'for' => 'delivery_index' ]);
}
public function getUsersLikeAction()
{
$like = $this->request->getPost('like', 'string', NULL );
$users = $this->models->getCustomers()->getActiveUsers($like);
$result = json_encode($users);
$this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
echo $result;
}
public function getCampaignListAction()
{
$this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
$name = $this->request->getQuery('term');
$model = new \delivery();
$modelsManager = $this->modelsManager;
$projectId = $this->session->get('project-id');
$result = $model->getDistinct("campaign",$name,$modelsManager, $projectId);
echo json_encode(
array_reduce(
$result,
function($return, $elem) {
$return[] = array(
"label" => $elem['campaign'],
"value" => $elem['campaign']
);
return $return;
}
)
);
}
}