view->setTemplateAfter('common'); } function indexAction($type) { $params = $this->dispatcher->getParams(); $currentPage = !empty( $params['page'] ) ? $params['page'] : 1; // Набор данных для разбивки на страницы $data = \eventEmail::query() ->where("email_type = 'event_$type'") ->andWhere("project_id = {$this->session->get('project-id')}") ->execute(); // Создаём пагинатор, отображаются 10 элементов на странице, начиная с текущей - $currentPage /* $paginator = new \Phalcon\Paginator\Adapter\Model( array( "data" => $data, "limit"=> 10, "page" => $currentPage ) ); // Получение результатов работы ппагинатора $page = $paginator->getPaginate();*/ $this->view->setVars([ 'data' => $data, 'type' => $type ]); } function deleteAction( $type,$id) { $model = \eventEmail::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' => 'event_email_index', 'type'=>$type ]); } else { $this->flash->error( 'Произошла ошибка при попытке удаления' ); return $this->response->redirect([ 'for' => 'event_email_index','type'=>$type ]); } } function updateAction($type, $id) { $model = new \eventEmail(); $temp_model = new \emailTemplates(); if( $this->request->isPost() ) { $data['send'] = $this->request->getPost('send'); $data['name'] = $this->request->getPost('name', 'string', NULL ); $data['utm_status'] = $this->request->getPost('utm_status', 'int', NULL ); $data['utm_campaign']= $this->request->getPost('utm_campaign', 'string', NULL ); $data['utm_medium'] = $this->request->getPost('utm_medium', 'string', NULL ); $data['utm_source'] = $this->request->getPost('utm_source', 'string', NULL ); $data['status'] = $this->request->getPost('status', 'int', NULL ); $data['unique'] = $this->request->getPost('unique', 'int', NULL ); $data['template_id'] = $template_id = $this->request->getPost('template_id', 'int', NULL ); $data['email_type'] = 'event_'.$type; $data['date'] = $this->request->getPost('date', 'string', NULL ); $data['text_type'] = $this->request->getPost('typeTextData'); $data['utm_status'] = empty( $data['utm_status'] ) ? 0 : 1; $data['status'] = empty( $data['status'] ) ? 0 : 1; $template['project_id'] = $this->session->get('project-id'); $template['title'] = $this->request->getPost('template_title', 'string', NULL ); $template['text'] = $this->request->getPost('template_text'); $template['directory'] = $this->request->getPost('directory', 'string', NULL ); $template['name'] = $this->request->getPost('template_name', 'string', NULL ); $parse['picture_url'] = $this->storage->getEmailTemplateUrl( 'temp', $template['directory']); $data['date'] = $data['date'] * 60; if( $data['text_type'] =='dynamic' ){ $template['header'] = $template['text']['header']; $template['dynamic_content'] = $template['text']['dynamic_content']; $template['footer'] = $template['text']['footer']; $template['text'] = ''; } if($data['text_type'] =='dynamic'){ $template['header'] = str_replace('%!picture_url!%',$parse['picture_url'], $template['header']); $template['footer'] = str_replace('%!picture_url!%', $parse['picture_url'], $template['footer']); } else { $template['text'] = str_replace('%!picture_url!%', $parse['picture_url'], $template['text']['static']); } $template['text_type'] = $data['text_type'] ; $eventModel = $model::findFirst("id = $id AND project_id = {$this->session->get('project-id')}"); if( !empty( $data['name'] ) && !empty( $data['name'] ) ) { if( $eventModel->save( $data ) ) { if($type == 'offline'){ $data['offlineData'] = $this->request->getPost('offlineData', NULL ); $offline_data_model = \eventOfflineData::findFirst("id = {$data['offlineData']['id']}"); $data['offlineData']['recurring_event'] = isset($data['offlineData']['recurring_event']) ? $data['offlineData']['recurring_event'] : 0; $offline_data_model->save($data['offlineData']); } $template['event_id'] = $id; $templModel = $temp_model::findFirst("id = $template_id AND project_id = {$this->session->get('project-id')}"); $templModel->save( $template ); $this->flash->success( 'Сохранение прошло успешно' ); return $this->response->redirect([ 'for' => 'event_email_index', 'type' => $type ]); } else { $this->flash->error( 'Произошла ошибка во время добавления.' ); } } } $data = $model::findFirst("id = $id AND project_id = {$this->session->get('project-id')}"); $templates = $temp_model::find("event_id = 0 AND project_id = {$this->session->get('project-id')}"); $temp = $temp_model::findFirst("id = $data->template_id AND project_id = {$this->session->get('project-id')}"); $offlineData = \eventOfflineData::findFirst("event_id = $id"); $this->view->pick( 'event_email/addEdit' ); $this->view->setVars([ 'page' => $data, 'templates' => $templates, 'temp' => $temp, 'type' => $type, 'offlineData' => $offlineData ]); } function addAction($type) { $model = new \eventEmail(); $temp_model = new \emailTemplates(); $offline_data_model = new \eventOfflineData(); if( $this->request->isPost() ) { $data['project_id'] = $this->session->get('project-id'); $data['name'] = $this->request->getPost('name', 'string', NULL ); $data['utm_status'] = $this->request->getPost('utm_status', 'int', NULL ); $data['utm_campaign']= $this->request->getPost('utm_campaign', 'string', NULL ); $data['utm_medium'] = $this->request->getPost('utm_medium', 'string', NULL ); $data['utm_source'] = $this->request->getPost('utm_source', 'string', NULL ); $data['status'] = $this->request->getPost('status', 'int', NULL ); $data['unique'] = $this->request->getPost('unique', 'int', NULL ); $data['text_type'] = $this->request->getPost('typeTextData'); $data['email_type'] = 'event_'.$type; $data['utm_status'] = empty( $data['utm_status'] ) ? 0 : 1; $data['status'] = empty( $data['status'] ) ? 0 : 1; $template['project_id'] = $this->session->get('project-id'); $template['title'] = $this->request->getPost('template_title', 'string', NULL ); $template['text'] = $this->request->getPost('template_text'); $template['directory'] = $this->request->getPost('directory', 'string', NULL ); $template['name'] = $this->request->getPost('template_name', 'string', NULL ); $parse['picture_url'] = $this->storage->getEmailTemplateUrl( 'temp', $template['directory']); if( $data['text_type'] =='dynamic' ){ $template['header'] = $template['text']['header']; $template['dynamic_content'] = $template['text']['dynamic_content']; $template['footer'] = $template['text']['footer']; $template['text'] = ''; } $template['project_id'] = $this->session->get('project-id'); $template['title'] = $this->request->getPost('template_title', 'string', NULL ); $template['text'] = $this->request->getPost('template_text'); $template['directory'] = $this->request->getPost('directory', 'string', NULL ); $template['name'] = $this->request->getPost('template_name', 'string', NULL ); $template['text_type'] = $data['text_type'] ; $parse['picture_url'] = $this->storage->getEmailTemplateUrl( 'temp', $template['directory']); if($data['text_type'] =='dynamic'){ $template['header'] = str_replace('%!picture_url!%',$parse['picture_url'], $template['header']); $template['footer'] = str_replace('%!picture_url!%', $parse['picture_url'], $template['footer']); } else { $template['text'] = str_replace('%!picture_url!%', $parse['picture_url'], $template['text']['static']); } if( !empty( $data['name'] ) && !empty( $data['name'] ) ) { if( $model->save( $data ) ) { if($type == 'offline'){ $data['offlineData'] = $this->request->getPost('offlineData', NULL ); $data['offlineData']['event_id'] = $model->id; $data['offlineData']['recurring_event'] = isset($data['offlineData']['recurring_event']) ? $data['offlineData']['recurring_event'] : 0; $offline_data_model->save($data['offlineData']); } $template['event_id'] = $model->id; $temp_model->save( $template ); $template_id = $temp_model->id; $eventModel = $model::findFirst("id = {$template['event_id']} AND project_id = {$this->session->get('project-id')}"); $eventModel->save(array('template_id'=>$template_id)); $this->flash->success( 'Сохранение прошло успешно' ); return $this->response->redirect([ 'for' => 'event_email_index', 'type' => $type ]); } else { $this->flash->error( 'Произошла ошибка во время добавления.' ); } } } $templates = $temp_model::find("event_id = 0 AND project_id = {$this->session->get('project-id')}"); $this->view->pick( 'event_email/addEdit' ); $this->view->setVars([ 'templates' => $templates, 'type' => $type ]); } public function checkAjaxDataAction() { $this->view->setTemplateAfter('none'); $model = new \eventEmail(); $name = $this->request->getQuery('name'); $id = $this->request->getQuery('id'); $result = $model::findFirst("name = '$name' AND project_id = {$this->session->get('project-id')}"); $this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT); if($result) { echo "false"; } else { echo "true"; } } function addOneCustomer($get,$template ){ $model = new \customersEmailList(); if($model->save($get)){ $this->MyMailer->OnlineEvent->SendForSelect($template, array($get)); }; } }