view->setTemplateAfter('common'); } function indexAction() { $params = $this->dispatcher->getParams(); $currentPage = $this->request->get('page', 'int', 1); // Набор данных для разбивки на страницы $data = \emailTemplates::find(array("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([ 'data' => $data ]); } function deleteAction($id) { $model = \emailTemplates::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' => 'email_templates_index' ]); } else { $this->flash->error( 'Произошла ошибка при попытке удаления' ); return $this->response->redirect([ 'for' => 'email_templates_index' ]); } } function updateAction($id) { $model = \emailTemplates::findFirst("id = '$id' AND project_id = {$this->session->get('project-id')}"); $this->assets ->addJs('js/jquery-file-upload/js/vendor/jquery.ui.widget.js') ->addJs('js/jquery-file-upload/js/jquery.iframe-transport.js') ->addJs('js/jquery-file-upload/js/jquery.fileupload.js'); if( $this->request->isPost() ) { $data['title'] = $this->request->getPost('title', 'string', NULL ); $data['name'] = $this->request->getPost('name', 'string', NULL ); $data['text'] = $this->request->getPost('page_content_text'); $data['directory'] = $this->request->getPost('directory', 'string', NULL ); $data['event_id'] = '0'; $parse['picture_url'] = $this->storage->getEmailTemplateUrl( 'temp', $data['directory']); $data['text'] = str_replace('%!picture_url!%', $parse['picture_url'], $data['text']); if( !empty( $data['name'] ) && !empty( $data['text'])) { if( $model->save($data) ) { $this->flash->success( 'Сохранение прошло успешно' ); return $this->response->redirect([ 'for' => 'email_templates_index' ]); } else { $this->flash->error( 'Произошла ошибка во время обновления.' ); } } } $this->view->pick( 'email_templates/addEdit' ); $this->view->setVars([ 'page' => $model ]); } function addAction() { /*p($data,1);*/ if( $this->request->isPost() ) { $data['project_id'] = $this->session->get('project-id'); $data['title'] = $this->request->getPost('title', 'string', NULL ); $data['name'] = $this->request->getPost('name', 'string', NULL ); $data['text'] = $this->request->getPost('page_content_text'); $data['directory'] = $this->request->getPost('directory', 'string', NULL ); $data['event_id'] = '0'; $model = new \emailTemplates(); $parse['picture_url'] = $this->storage->getEmailTemplateUrl( 'temp', $data['directory']); preg_match_all('/\%!(.+)\!%/U', $data['text'], $matches); $data['text'] = str_replace('%!picture_url!%', $parse['picture_url'], $data['text']); if( !empty( $data['name'] ) && !empty( $data['text'])) { if( $model->save( $data ) ) { $this->flash->success( 'Сохранение прошло успешно' ); return $this->response->redirect([ 'for' => 'email_templates_index' ]); } else { $this->flash->error( 'Произошла ошибка во время добавления.' ); } } } $this->view->pick( 'email_templates/addEdit' ); $this->view->setVars([ ]); } function ajaxAction() { $this->view->setTemplateAfter('none'); if( $this->request->isPost() ) { $id = $this->request->getPost('id', 'int', NULL ); $model = \emailTemplates::findFirst("id = '$id' AND project_id = {$this->session->get('project-id')}"); $data = json_encode($model); $this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT); echo !empty($data) ? $data : ''; } } public function sortAction() { $sort = $this->request->getPost('data', 'string', NULL ); $data = \projects::find(array("order" => $sort)); $this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT); $this->view->setVars([ "data" =>$data ]); } }