Beispiel #1
0
 /**
  * Creates new page
  * TODO: there is a bug in JS - when page has been created, jumpers are not updated and has wrong id's
  * @param AM_Model_Db_Page $oPageParent
  * @param AM_Model_Db_Template $oTemplate
  * @param string $sConnectionType
  * @param array $aUser
  * @param bool $bBetween
  * @return \AM_Model_Db_Page
  */
 public function addPage(AM_Model_Db_Page $oPageParent, AM_Model_Db_Template $oTemplate, $sConnectionType, $aUser, $bBetween = false)
 {
     $oPageConnectedToParent = null;
     if (empty($aUser)) {
         throw new AM_Handler_Exception('Wrong user was given');
     }
     if (!in_array($sConnectionType, AM_Model_Db_Page::$aLinkTypes)) {
         throw new AM_Handler_Exception('Wrong connection type was given');
     }
     if ($bBetween) {
         //We trying to insert new page between two pages. We have to get both pages
         $oPageConnectedToParent = AM_Model_Db_Table_Abstract::factory('page')->findChildConnectedPage($oPageParent, $sConnectionType);
         if (is_null($oPageParent)) {
             throw new AM_Handler_Exception('Can\'t find parent page');
         }
         $oPageParent->setReadOnly(false);
     }
     if (is_null($oPageParent)) {
         throw new AM_Handler_Exception('Wrong parent page was given');
     }
     $oPage = new AM_Model_Db_Page();
     $oPage->title = $sConnectionType . ' connected to page ' . $oPageParent->id;
     $oPage->template = $oTemplate->id;
     $oPage->revision = $oPageParent->revision;
     $oPage->user = $aUser['id'];
     $oPage->created = new Zend_Db_Expr('NOW()');
     $oPage->updated = new Zend_Db_Expr('NOW()');
     $oPage->setConnectionBit($oPage->reverseLinkType($sConnectionType));
     $oPage->save();
     $oPage->setLinkType($sConnectionType);
     $oPage->setParent($oPageParent);
     $oPage->savePageImposition();
     $oPageParent->setConnectionBit($sConnectionType);
     $oPageParent->save();
     if (!is_null($oPageConnectedToParent)) {
         //Remove old connections
         AM_Model_Db_Table_Abstract::factory('page_imposition')->deleteBy(array('is_linked_to' => $oPageConnectedToParent->id, 'link_type' => $sConnectionType));
         $oPageConnectedToParent->setLinkType($sConnectionType);
         $oPageConnectedToParent->setParent($oPage);
         $oPageConnectedToParent->savePageImposition();
         $oPage->setConnectionBit($sConnectionType);
         $oPage->save();
     }
     return $oPage;
 }
Beispiel #2
0
 /**
  * Create revision from simple pdf
  * @param AM_Model_Db_IssueSimplePdf $oSimplePdf
  * @return AM_Model_Db_Revision
  * @throws AM_Handler_Issue_Exception
  */
 public function createRevisionFromSimplePdf(AM_Model_Db_IssueSimplePdf $oSimplePdf)
 {
     $aImages = $oSimplePdf->getAllPagesThumbnails();
     //Create revision
     $oRevision = new AM_Model_Db_Revision();
     $oRevision->state = AM_Model_Db_Issue::STATUS_WIP;
     $oRevision->user = $this->getIssue()->user;
     $oRevision->issue = $this->getIssue()->id;
     $oRevision->save();
     $oRevision->title = 'Revision #' . $oRevision->id;
     $oRevision->save();
     //Create cover page
     $oPage = new AM_Model_Db_Page();
     $oPage->title = 'Root page';
     $oPage->template = AM_Model_Db_Template::TPL_COVER_PAGE;
     $oPage->revision = $oRevision->id;
     $oPage->user = $this->getIssue()->user;
     $oPage->root_page = true;
     $oPage->save();
     //Find field record for type 'Body'
     $oFieldBody = AM_Model_Db_Table_Abstract::factory('field')->findOneBy(array('field_type' => 1, 'template' => AM_Model_Db_Template::TPL_COVER_PAGE));
     if (is_null($oFieldBody)) {
         throw new AM_Handler_Issue_Exception('Field "Body" not found');
     }
     //Create element for cover page
     $oElement = new AM_Model_Db_Element();
     $oElement->field = $oFieldBody->id;
     $oElement->page = $oPage->id;
     $oElement->save();
     AM_Tools::clearContent(AM_Model_Db_Element::RESOURCE_TYPE, $oElement->id);
     AM_Tools::clearResizerCache(AM_Model_Db_Element::RESOURCE_TYPE, $oElement->getResources()->getThumbnailPresetName(), $oElement->id);
     //Prepare resources for the element
     $sImage = array_shift($aImages);
     $oElement->getResources()->setData(array(AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE => $sImage))->save();
     //Set page background
     $oElement->getResources()->setPageBackground();
     //Create childs
     $oFieldBody = AM_Model_Db_Table_Abstract::factory('field')->findOneBy(array('field_type' => 1, 'template' => AM_Model_Db_Template::TPL_SIMPLE_PAGE));
     if (is_null($oFieldBody)) {
         throw new AM_Handler_Issue_Exception('Field "Body" not found');
     }
     $oPageRoot = clone $oPage;
     foreach ($aImages as $sImage) {
         $oPage = new AM_Model_Db_Page();
         $oPage->title = 'Right connected to page ' . $oPageRoot->id;
         $oPage->template = AM_Model_Db_Template::TPL_SIMPLE_PAGE;
         $oPage->revision = $oRevision->id;
         $oPage->user = $this->getIssue()->user;
         $oPage->setConnectionBit(AM_Model_Db_page::LINK_LEFT);
         $oPage->save();
         $oPageRoot->setConnectionBit(AM_Model_Db_page::LINK_RIGHT);
         $oPageRoot->save();
         $oPage->setParent($oPageRoot);
         $oPage->setLinkType(AM_Model_Db_page::LINK_RIGHT)->savePageImposition();
         //Create element for cover page
         $oElement = new AM_Model_Db_Element();
         $oElement->field = $oFieldBody->id;
         $oElement->page = $oPage->id;
         $oElement->save();
         AM_Tools::clearContent(AM_Model_Db_Element::RESOURCE_TYPE, $oElement->id);
         AM_Tools::clearResizerCache(AM_Model_Db_Element::RESOURCE_TYPE, $oElement->getResources()->getThumbnailPresetName(), $oElement->id);
         //Prepare resources for the element
         $oElement->getResources()->setData(array(AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE => $sImage))->save();
         //Set page background
         $oElement->getResources()->setPageBackground();
         $oPageRoot = clone $oPage;
     }
     $oRevision->exportRevision();
     return $oRevision;
 }