Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PhotogalleryController extends Zend_Controller_Action
- {
- public function indexAction()
- {
- $this->view->title = 'Фотогалереи';
- $this->view->headTitle($this->view->title, 'PREPEND');
- $photos = new Application_Model_Photogallery();
- if ($this->_getParam('dep_id')) {
- $cur_dep = $this->_getParam('dep_id');
- } else {
- $cur_dep = 1;
- }
- $allphotos = $photos->getPhotosFromDep($cur_dep);
- $cur_dep_object = new Application_Model_PhotogalleryDeps($cur_dep);
- $this->view->cur_dep = $cur_dep_object;
- $sdeps = new Application_Model_PhotogalleryDeps();
- $deps = $sdeps->getAllPhotogalleryDeps();
- $this->view->deps = $deps;
- $this->view->photos = $allphotos;
- }
- public function addAction()
- {
- $this->view->title = 'Добавить фото';
- $this->view->headTitle($this->view->title, 'PREPEND');
- $defaultNamespace = new Zend_Session_Namespace('Default');
- $form = new Application_Form_Photogallery(array(
- 'type' => 'add'
- ));
- if (isset($defaultNamespace->last_photo_dep_id) && !is_null($defaultNamespace->last_photo_dep_id)) {
- $form->setDefault('dep_id', $defaultNamespace->last_photo_dep_id);
- }
- if ($this->getRequest()->isPost()){
- if ($form->isValid($this->getRequest()->getPost())){
- $item = new Application_Model_Photogallery();
- $item->fill($form->getValues());
- $item->upd = time();
- $item->save();
- $defaultNamespace->last_photo_dep_id = $form->getValue('dep_id');
- $this->_helper->getHelper('Redirector')->gotoSimple('index',
- 'photogallery',
- null,
- array('dep_id' => $form->getValue('dep_id'))
- );
- }
- }
- $this->view->form = $form;
- }
- public function editAction()
- {
- $id = $this->_getParam('id');
- $item = new Application_Model_Photogallery($id);
- $this->view->title = 'Изменить фото "'.$item->photo.'"';
- $this->view->headTitle($this->view->title, 'PREPEND');
- $form = new Application_Form_Photogallery(array( 'type' => 'edit', 'photo_file' => $item->photo ));
- if ($this->getRequest()->isPost()) {
- if ($form->isValid($this->getRequest()->getPost())) {
- $item->dep_id = $form->getValue('dep_id');
- $item->preivew = $form->getValue('preview');
- $item->pos = $form->getValue('pos');
- $item->slideshow = $form->getValue('slideshow');
- $item->upd = time();
- // если поставлена галочка на удаление - то удаляем файл и пищем в БД null
- //var_dump($this->getRequest()->getParam('photo_checkbox'));
- if (!is_null($this->getRequest()->getParam('photo_checkbox')) && $this->getRequest()->getParam('photo_checkbox') == 'on') {
- if (file_exists(PUBLIC_PATH . '/userfiles/images/full/' . $item->photo))
- unlink(PUBLIC_PATH . '/userfiles/images/full/' . $item->photo);
- if (file_exists(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo))
- unlink(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo);
- $item->photo = null;
- }
- // если указан новый файл и он загружен, то удаляем старый файл и пишем в БД новый.
- // в случае, если элемент File не заполнен, $form->photo->getFileName() == array(null) ;
- if (!is_null($form->photo->getFileName()) && count($form->photo->getFileName()) != 0) {
- if (file_exists(PUBLIC_PATH . '/userfiles/images/full/' . $item->photo)) {
- unlink(PUBLIC_PATH . '/userfiles/images/full/' . $item->photo);
- }
- if (file_exists(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo)) {
- unlink(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo);
- }
- $item->photo = $form->getValue('photo');
- }
- $item->save();
- $this->_helper->getHelper('Redirector')->gotoSimple('index',
- 'photogallery',
- null,
- array('dep_id' => $form->getValue('dep_id'))
- );
- }
- } else {
- //var_dump($item->populateForm());
- $form->populate($item->populateForm());
- }
- $this->view->form = $form;
- }
- public function viewAction()
- {
- $id = $this->_getParam('dep_id');
- $dep_info = new Application_Model_PhotogalleryDeps($id);
- $this->view->title = $dep_info->name;
- $this->view->headTitle($dep_info->name, 'PREPEND');
- $this->view->headLink(array('href' => $this->view->baseUrl() . '/css/reset.css', 'media' => "screen", 'rel' => 'stylesheet', 'type' => 'text/css'), 'SET')
- ->appendStylesheet($this->view->baseUrl() . '/css/frontend.css', "screen")
- ->headLink(array('rel' => 'icon', 'href' => $this->view->baseUrl() . '/i/favicon.png'), 'APPEND')
- ->headLink(array('rel' => 'shortcut icon', 'href' => $this->view->baseUrl() . '/i/favicon.png'),'APPEND');
- $photos_model = new Application_Model_Photogallery();
- $photos = $photos_model->getExistPhotosFromDep($id);
- $this->view->photos = $photos;
- $this->_helper->layout->setLayout('frontend');
- }
- public function deleteAction()
- {
- $id = $this->_getParam('id');
- $item = new Application_Model_Photogallery($id);
- if (!is_null($item->photo)){
- if (file_exists(PUBLIC_PATH . '/userfiles/images/full/' . $item->photo)) {
- unlink(PUBLIC_PATH . '/userfiles/images/full/' . $item->photo);
- }
- if (file_exists(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo)) {
- unlink(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo);
- }
- }
- // т.к. после $item->delete(); объект/сущность $item будет уничтожен
- $dep_id = $item->dep_id;
- $item->delete();
- $this->_helper->getHelper('Redirector')->gotoSimple('index',
- 'photogallery',
- null,
- array('dep_id' => $dep_id)
- );
- }
- public function addDepAction()
- {
- $this->view->title = 'Добавить фотогалерею';
- $this->view->headTitle($this->view->title, 'PREPEND');
- $form = new Application_Form_PhotogalleryDeps(array('type' => 'add'));
- if ($this->getRequest()->isPost()){
- if ($form->isValid($this->getRequest()->getPost())){
- $sdeps = new Application_Model_PhotogalleryDeps();
- $sdeps->fill($form->getValues());
- $sdeps->date = time();
- $sdeps->save();
- $this->_helper->redirector('index');
- }
- }
- $this->view->form = $form;
- }
- public function editDepAction()
- {
- $id = $this->_getParam('id');
- $item = new Application_Model_PhotogalleryDeps($id);
- $this->view->title = 'Изменить информацию о фотогалерее "'.$item->name.'":';
- $this->view->headTitle($this->view->title, 'PREPEND');
- $form = new Application_Form_PhotogalleryDeps(array( 'type' => 'edit', 'photo_file' => $item->photo ));
- if ($this->getRequest()->isPost()) {
- if ($form->isValid($this->getRequest()->getPost())) {
- $item->name = $form->getValue('name');
- $item->preivew = $form->getValue('preview');
- $item->content = $form->getValue('content');
- $item->pos = $form->getValue('pos');
- $item->visible = $form->getValue('visible');
- $item->date = time();
- // если поставлена галочка на удаление - то удаляем файл и пищем в БД null
- if ($this->getRequest()->getParam('photo_checkbox') == 'on') {
- if (file_exists(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo))
- unlink(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo);
- $item->photo = null;
- }
- // если указан новый файл и он загружен, то удаляем старый файл и пишем в БД новый.
- if (!is_null($form->photo->getFileName())) {
- if (file_exists(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo)) {
- unlink(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo);
- }
- $item->photo = $form->getValue('photo');
- }
- $item->save();
- $this->_helper->redirector('index');
- }
- } else {
- $form->populate($item->populateForm());
- }
- $this->view->form = $form;
- }
- public function deleteDepAction()
- {
- $id = $this->_getParam('id');
- $item = new Application_Model_PhotogalleryDeps($id);
- if (!is_null($item->photo)){
- if (file_exists(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo)) {
- unlink(PUBLIC_PATH . '/userfiles/images/thumb/' . $item->photo);
- }
- }
- $item->delete();
- $this->_helper->redirector('index');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement