Пример #1
0
 public function editphotosAction()
 {
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     if (!$this->_helper->requireSubject('album')->isValid()) {
         return;
     }
     if (!$this->_helper->requireAuth()->setAuthParams(null, null, 'edit')->isValid()) {
         return;
     }
     // Get navigation
     $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('album_main');
     // Hack navigation
     foreach ($navigation->getPages() as $page) {
         if ($page->route != 'album_general' || $page->action != 'manage') {
             continue;
         }
         $page->active = true;
     }
     // Prepare data
     $this->view->album = $album = Engine_Api::_()->core()->getSubject();
     $this->view->paginator = $paginator = $album->getCollectiblesPaginator();
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $paginator->setItemCountPerPage($paginator->getTotalItemCount());
     // Make form
     $this->view->form = $form = new Album_Form_Album_Photos();
     foreach ($paginator as $photo) {
         $subform = new Album_Form_Photo_Edit(array('elementsBelongTo' => $photo->getGuid()));
         $subform->populate($photo->toArray());
         $form->addSubForm($subform, $photo->getGuid());
         $form->cover->addMultiOption($photo->getIdentity(), $photo->getIdentity());
     }
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $table = $album->getTable();
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         $values = $form->getValues();
         if (!empty($values['cover'])) {
             $album->photo_id = $values['cover'];
             $album->save();
         }
         // Process
         foreach ($paginator as $photo) {
             $subform = $form->getSubForm($photo->getGuid());
             $values = $subform->getValues();
             $values = $values[$photo->getGuid()];
             unset($values['photo_id']);
             if (isset($values['delete']) && $values['delete'] == '1') {
                 $photo->delete();
             } else {
                 $photo->setFromArray($values);
                 $photo->save();
             }
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     return $this->_helper->redirector->gotoRoute(array('action' => 'view', 'album_id' => $album->album_id), 'album_specific', true);
 }
Пример #2
0
 public function editAction()
 {
     if (!$this->_helper->requireSubject('album_photo')->isValid()) {
         return;
     }
     if (!$this->_helper->requireAuth()->setAuthParams(null, null, 'edit')->isValid()) {
         return;
     }
     $viewer = Engine_Api::_()->user()->getViewer();
     $photo = Engine_Api::_()->core()->getSubject('album_photo');
     $this->view->form = $form = new Album_Form_Photo_Edit();
     $form->populate($photo->toArray());
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = $form->getValues();
     $db = $photo->getTable()->getAdapter();
     $db->beginTransaction();
     try {
         $photo->setFromArray($values);
         $photo->save();
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Your changes have been saved.')), 'layout' => 'default-simple', 'parentRefresh' => true));
 }