/** * Action method shows and processes form used for editing specific * collection based on param id * * @before _secured, _admin * @param int $id collection id */ public function edit($id) { $view = $this->getActionView(); $gallery = App_Model_Gallery::fetchGalleryById((int) $id); if (NULL === $gallery) { $view->warningMessage(self::ERROR_MESSAGE_2); $this->_willRenderActionView = false; self::redirect('/admin/gallery/'); } $view->set('gallery', $gallery); if (RequestMethods::post('submitEditGallery')) { if ($this->checkCSRFToken() !== true) { self::redirect('/admin/gallery/'); } $errors = array(); $urlKey = $this->_createUrlKey(RequestMethods::post('title')); if ($gallery->getUrlKey() !== $urlKey && !$this->_checkUrlKey($urlKey)) { $errors['title'] = array('Galerie s tímto názvem již existuje'); } $gallery->title = RequestMethods::post('title'); $gallery->avatarPhotoId = RequestMethods::post('avatar'); $gallery->isPublic = RequestMethods::post('public'); $gallery->showDate = RequestMethods::post('showdate'); $gallery->active = RequestMethods::post('active'); $gallery->urlKey = $urlKey; $gallery->description = RequestMethods::post('description', ''); if (empty($errors) && $gallery->validate()) { $gallery->save(); Event::fire('admin.log', array('success', 'Gallery id: ' . $id)); $view->successMessage(self::SUCCESS_MESSAGE_2); self::redirect('/admin/gallery/'); } else { Event::fire('admin.log', array('fail', 'Gallery id: ' . $id)); $view->set('errors', $gallery->getErrors()); } } }