Пример #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();
     $photoTable = Engine_Api::_()->getItemTable('album_photo');
     $this->view->paginator = $paginator = $photoTable->getPhotoPaginator(array('album' => $album));
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $paginator->setItemCountPerPage(10);
     // Get albums
     $albumTable = Engine_Api::_()->getItemTable('album');
     $myAlbums = $albumTable->select()->from($albumTable, array('album_id', 'title'))->where('owner_type = ?', 'user')->where('owner_id = ?', Engine_Api::_()->user()->getViewer()->getIdentity())->query()->fetchAll();
     $albumOptions = array('' => '');
     foreach ($myAlbums as $myAlbum) {
         $albumOptions[$myAlbum['album_id']] = $myAlbum['title'];
     }
     if (count($albumOptions) == 1) {
         $albumOptions = array();
     }
     // Make form
     $this->view->form = $form = new Album_Form_Album_Photos();
     foreach ($paginator as $photo) {
         $subform = new Album_Form_Album_EditPhoto(array('elementsBelongTo' => $photo->getGuid()));
         $subform->populate($photo->toArray());
         $form->addSubForm($subform, $photo->getGuid());
         $form->cover->addMultiOption($photo->getIdentity(), $photo->getIdentity());
         if (empty($albumOptions)) {
             $subform->removeElement('move');
         } else {
             $subform->move->setMultiOptions($albumOptions);
         }
     }
     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 {
                 if (!empty($values['move'])) {
                     $nextPhoto = $photo->getNextPhoto();
                     $old_album_id = $photo->album_id;
                     $photo->album_id = $values['move'];
                     $photo->save();
                     // Change album cover if necessary
                     if ($nextPhoto instanceof Album_Model_Photo && (int) $album->photo_id == (int) $photo->getIdentity()) {
                         $album->photo_id = $nextPhoto->getIdentity();
                         $album->save();
                     }
                     // Remove activity attachments for this photo
                     Engine_Api::_()->getDbtable('actions', 'activity')->detachFromActivity($photo);
                 } 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 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);
 }