File indexing completed on 2024-05-12 05:58:31

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 
0023 /*
0024  * To change this template, choose Tools | Templates
0025  * and open the template in the editor.
0026  */
0027 
0028 class Backend_ContentController extends Local_Controller_Action_Backend
0029 {
0030 
0031     private $_contentTable;
0032 
0033     public function init()
0034     {
0035         $this->_contentTable = new Default_Model_DbTable_Content();
0036         parent::init();
0037     }
0038 
0039     public function indexAction()
0040     {
0041         $selCon = $this->_contentTable->select()->setIntegrityCheck(false);
0042 
0043         $selCon->from($this->_contentTable)->where('is_deleted=0');
0044 
0045         $paginator = Zend_Paginator::factory($selCon);
0046         $paginator->setCurrentPageNumber($this->getParam('page'));
0047 
0048         $this->view->paginator = $paginator;
0049     }
0050 
0051     public function addAction()
0052     {
0053         if ($this->_request->isPost()) {
0054             // is Post-Request - das Formular
0055             $form = $this->getForm();
0056             if ($form->isValid($_POST)) {
0057                 //alles ok
0058                 $values = $form->getValues();
0059 
0060                 $insertValues = array(
0061                     'title'      => $values['title_intern'],
0062                     'url_name'   => $values['url_name'],
0063                     'content'    => $values['content'],
0064                     'created_at' => new Zend_Db_Expr('Now()'),
0065                     'changed_at' => new Zend_Db_Expr('Now()')
0066                 );
0067 
0068                 $this->_contentTable->insert($insertValues);
0069 
0070                 $this->view->saveTitle = "Content gespeichert";
0071             } else {
0072                 //fehler
0073                 $this->view->form = $form;
0074             }
0075         } else {
0076             // normaler Aufruf (GET) - kein Formular
0077             $this->view->form = $this->getForm();
0078         }
0079     }
0080 
0081     public function getForm($valTitleIntern = "", $valContent = "", $valUrlName = "")
0082     {
0083 
0084         $form = new Zend_Form();
0085         $form->setMethod('POST');
0086 
0087         $title = $form->createElement('text', 'title_intern');
0088         $title->setLabel('Interner Titel: ');
0089         $title->setValue($valTitleIntern);
0090         $title->setRequired(true);
0091 
0092         $urlName = $form->createElement('text', 'url_name');
0093         $urlName->setLabel('URL Name: ');
0094         $urlName->setValue($valUrlName);
0095         $urlName->setRequired(true);
0096 
0097         $content = $form->createElement('textarea', 'content');
0098         $content->setLabel('Content: ');
0099         $content->setValue($valContent);
0100         $content->setRequired(true);
0101 
0102         $form->addElement($title)->addElement($urlName)->addElement($content)
0103              ->addElement('submit', 'save', array('label' => 'Speichern'))
0104         ;
0105 
0106         return $form;
0107     }
0108 
0109     public function editAction()
0110     {
0111         if ($this->_request->isPost()) {
0112             // is Post-Request - das Formular
0113             $form = $this->getForm();
0114             if ($form->isValid($_POST)) {
0115                 //alles ok
0116                 $values = $form->getValues();
0117 
0118                 $updateValues = array(
0119                     'title'      => $values['title_intern'],
0120                     'url_name'   => $values['url_name'],
0121                     'content'    => $values['content'],
0122                     'changed_at' => new Zend_Db_Expr('Now()')
0123                 );
0124 
0125                 $id = $this->_request->getParam('id');
0126 
0127                 $this->_contentTable->update($updateValues, "content_id=" . $id);
0128 
0129                 $this->view->saveTitle = "Content gespeichert";
0130             } else {
0131                 //fehler
0132                 $this->view->form = $form;
0133             }
0134         } else {
0135             // normaler Aufruf (GET) - kein Formular
0136             $id = $this->_request->getParam('id');
0137 
0138             $editItem = $this->_contentTable->find($id);
0139             $editItem = $editItem[0];
0140             $this->view->form =
0141                 $this->getForm(stripslashes($editItem->title), stripslashes($editItem->content), stripslashes($editItem->url_name));
0142         }
0143     }
0144 
0145     public function setstatusAction()
0146     {
0147         $this->_helper->layout->disableLayout();
0148 
0149         $id = $this->getParam('id');
0150         $status = $this->getParam("status");
0151 
0152         $this->_contentTable->setStatus($status, $id);
0153 
0154         $this->_helper->json(true);
0155     }
0156 
0157     public function deleteAction()
0158     {
0159         $this->_helper->layout->disableLayout();
0160 
0161         $id = $this->getParam('id');
0162 
0163         $this->_contentTable->setDelete($id);
0164 
0165         $this->_helper->json(true);
0166     }
0167 
0168 }