Exemplo n.º 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;
 }