예제 #1
0
 public function testShouldWalkOnTreeUsingIterator()
 {
     //GIVEN
     $oPageRoot = new AM_Model_Db_Page(array('data' => array('id' => 1)));
     $oPageChild = new AM_Model_Db_Page(array('data' => array('id' => 2)));
     $oPageRoot->addChild($oPageChild);
     $aExpectedNodes = array('1' => $oPageRoot, '2' => $oPageChild);
     $eGivenNodes = array();
     //WHEN
     foreach ($oPageRoot as $iKey => $oNode) {
         $eGivenNodes[$iKey] = $oNode;
     }
     //THEN
     $this->assertEquals($aExpectedNodes, $eGivenNodes, 'Wrong nodes given while walk on tree');
 }
 public function testShouldCopyToPage()
 {
     //GIVEN
     $oElement = AM_Model_Db_Table_Abstract::factory('element')->findOneBy('id', 1);
     $oResourceMock = $this->getMock('AM_Model_Db_Element_Data_Resource', array('copy'), array($oElement));
     $oElement->setResources($oResourceMock);
     $aPageData = array('id' => 2, 'title' => 'test_page');
     $oPage = new AM_Model_Db_Page();
     $oPage->setFromArray($aPageData);
     //THEN
     $oResourceMock->expects($this->once())->method('copy');
     //WHEN
     $oElement->copyToPage($oPage);
     $oElement->refresh();
     //THEN
     $this->assertEquals(2, $oElement->page, 'Page id should change');
     $oGivenDataSet = $this->getConnection()->createQueryTable('element', 'SELECT id, page FROM element ORDER BY id');
     $oExpectedDataSet = $this->createFlatXMLDataSet(dirname(__FILE__) . '/_dataset/ElementCopyToPageTest.xml')->getTable('element');
     $this->assertTablesEqual($oExpectedDataSet, $oGivenDataSet);
 }
예제 #3
0
 public function show()
 {
     $oEditorViewHelper = new AM_View_Helper_Editor_Page($this->_oPage);
     $oEditorViewHelper->setViewHelper($this->_oView)->show();
     $oFields = $this->_oPage->getFields();
     $aFieldsData = array();
     foreach ($oFields as $oField) {
         /* @var $oField AM_Model_Db_Field */
         $sFieldType = ucfirst(Zend_Filter::filterStatic($oField->getFieldType()->title, 'Word_UnderscoreToCamelCase'));
         $sHelperClass = 'AM_View_Helper_Field_' . $sFieldType;
         $oEditorViewHelper = new $sHelperClass($oField, $this->_oPage);
         /* @var $oEditorViewHelper AM_View_Helper_Field */
         $oEditorViewHelper->setViewHelper($this->getActionController()->view)->show();
         $aFieldsData[] = array('fid' => $oField->id, 'template_title' => $this->_oPage->getTemplate()->title, 'name' => $oField->name, 'descr' => $oField->description, 'type' => $oField->getFieldType()->title, 'min' => $oField->min, 'max' => $oField->max, 'weight' => $oField->weight);
     }
     $aRecord = array('pid' => $this->_oPage->id, 'fields' => $aFieldsData);
     if (isset($this->getActionController()->view->editor)) {
         $aRecord = array_merge($aRecord, $this->getActionController()->view->editor);
     }
     $this->getActionController()->view->editor = $aRecord;
 }
예제 #4
0
 /**
  * Get page's tags
  * @return null | array
  */
 protected function _getTags()
 {
     $oTags = $this->_oPage->getTags();
     if (!count($oTags)) {
         return null;
     }
     $aResult = array();
     foreach ($oTags as $oTag) {
         $aResult[] = array('id' => $oTag->id, 'title' => $oTag->title);
     }
     return $aResult;
 }
예제 #5
0
 /**
  * Soft delete
  * @param AM_Model_Db_Page $oPage
  * @return void
  */
 public function softDelete(AM_Model_Db_Page $oPage)
 {
     $oPageParent = $oPage->getParent();
     if ($oPageParent) {
         $this->getAdapter()->update('page_imposition', array('page' => $oPageParent->id), $this->getAdapter()->quoteInto('page = ?', $oPage->id));
         $this->getAdapter()->delete('page_imposition', $this->getAdapter()->quoteInto('page = ?', $oPage->id));
     }
     $this->getAdapter()->delete('page_imposition', $this->getAdapter()->quoteInto('is_linked_to = ?', $oPage->id));
     $oPage->deleted = 'yes';
     $oPage->save();
 }
예제 #6
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;
 }
예제 #7
0
 /**
  * Retruns tags for autocomplete
  * @param AM_Model_Db_Page $oPage
  * @param string $sTagName
  * @return AM_Model_Db_Rowset_Term
  */
 public function getTagsForAutocomplete(AM_Model_Db_Page $oPage, $sTagName)
 {
     $oVocabulary = $oPage->getRevision()->getVocabularyTag();
     $oQuery = $this->select()->from('term')->setIntegrityCheck(false)->joinLeft('page', $this->getAdapter()->quoteInto('page.id = ?', $oPage->id), null)->joinLeft('term_page', 'term_page.page = page.id AND term_page.term = term.id', null)->where('term.vocabulary = ?', $oVocabulary->id)->where('term.deleted = "no"')->where('term_page.id IS NULL')->where('term.title LIKE CONCAT("%", ?, "%")', trim($sTagName));
     $oTerms = $this->fetchAll($oQuery);
     return $oTerms;
 }
예제 #8
0
 /**
  * Callback for save logic
  * @param AM_Model_Db_Page $oPage
  * @param string $sValue
  */
 protected function _savePdfPage(AM_Model_Db_Page $oPage, $sValue)
 {
     $oPage->setPdfPageForChild($sValue);
 }
예제 #9
0
 /**
  * Save page and term relations
  * @param AM_Model_Db_Page $oPage
  * @return AM_Model_Db_Term
  */
 public function saveToPage(AM_Model_Db_Page $oPage)
 {
     $oTermPage = AM_Model_Db_Table_Abstract::factory('term_page')->findOneBy(array('page' => $oPage->id, 'term' => $this->id));
     if (is_null($oTermPage)) {
         $oTermPage = new AM_Model_Db_TermPage();
         $oTermPage->page = $oPage->id;
         $oTermPage->term = $this->id;
         $oTermPage->save();
         if ($this->_isToc()) {
             $oPage->toc = $this->id;
             $oPage->save();
         }
     }
     return $this;
 }
예제 #10
0
 /**
  * Returns an array with pages data for view
  *
  * @param AM_Model_Db_Page $oPage
  * @return array
  */
 public static function parsePage(AM_Model_Db_Page $oPage)
 {
     $aPage = $oPage->toArray();
     $aPage['tpl_title'] = $oPage->getTemplate()->description;
     $aPage['has_left'] = $oPage->hasConnection(AM_Model_Db_Page::LINK_LEFT);
     $aPage['has_right'] = $oPage->hasConnection(AM_Model_Db_Page::LINK_RIGHT);
     $aPage['has_top'] = $oPage->hasConnection(AM_Model_Db_Page::LINK_TOP);
     $aPage['has_bottom'] = $oPage->hasConnection(AM_Model_Db_Page::LINK_BOTTOM);
     //Restrict user to add left and right childs in pages which have bottom or top parent
     $aPage['tpl']['has_left'] = $oPage->getLinkType() != AM_Model_Db_Page::LINK_RIGHT && !is_null($oPage->getLinkType()) ? 0 : $oPage->getTemplate()->has_left_connector;
     $aPage['tpl']['has_right'] = $oPage->getLinkType() != AM_Model_Db_Page::LINK_RIGHT && !is_null($oPage->getLinkType()) ? 0 : $oPage->getTemplate()->has_right_connector;
     $aPage['tpl']['has_top'] = $oPage->getTemplate()->has_top_connector;
     $aPage['tpl']['has_bottom'] = $oPage->getTemplate()->has_bottom_connector;
     $oPageRoot = $oPage->getParent();
     if (!is_null($oPageRoot)) {
         $sLinkType = $oPage->reverseLinkType($oPage->getLinkType());
         $aPage[$sLinkType] = $oPageRoot->id;
         $aPage['jumper_' . $sLinkType] = $oPage->getLinkType();
         //The direction of the arrow in the pages tree
     }
     foreach ($oPage->getChilds() as $oPageChild) {
         $sLinkType = $oPageChild->getLinkType();
         $aPage[$sLinkType] = $oPageChild->id;
         $aPage['jumper_' . $sLinkType] = $sLinkType;
         //The direction of the arrow in the pages tree
     }
     $aPage['link_type'] = $oPage->getLinkType();
     $aPage['thumbnailUri'] = $oPage->getPageBackgroundUri();
     return $aPage;
 }
예제 #11
0
 /**
  * @param AM_Model_Db_Field $oField
  * @param AM_Model_Db_Page $oPage
  */
 public function __construct(AM_Model_Db_Field $oField, AM_Model_Db_Page $oPage)
 {
     $this->_oField = $oField;
     $this->_oPage = $oPage;
     $this->_sPageOrientation = $oPage->getOrientation();
 }