/** * Find the attachments for a block. * * @param ExhibitPageBlock $block * @return ExhibitBlockAttachment[] */ public function findByBlock($block) { if (!$block->exists()) { return array(); } $select = $this->getSelect()->where('exhibit_block_attachments.block_id = ?', $block->id); return $this->fetchObjects($select); }
/** * Return the form for adding text to an Exhibit block. * * @param ExhibitPageBlock $block * @return string */ public function exhibitFormText($block) { return $this->view->formTextarea($block->getFormStem() . '[text]', $block->text, array('rows' => 8)); }
/** * Set data for this page's blocks. * * @param array $blocksData An array of key-value arrays for each block. * @param boolean $deleteExtras Whether to delete any extra preexisting * blocks. */ public function setPageBlocks($blocksData, $deleteExtras = true) { $existingBlocks = $this->getPageBlocks(); foreach ($blocksData as $i => $blockData) { if (!empty($existingBlocks)) { $block = array_pop($existingBlocks); } else { $block = new ExhibitPageBlock(); $block->page_id = $this->id; } $block->order = $i; $block->setData($blockData); $block->save(); } // Any leftover blocks beyond the new data get erased. if ($deleteExtras) { foreach ($existingBlocks as $extraBlock) { $extraBlock->delete(); } } }
/** * Create an exhibit page block. * * @param ExhibitPage $page The parent page. * @param string $text The entry content. * @param integer $order The entry order. * @return ExhibitPageBlock */ protected function _exhibitBlock($page = null, $text = 'Test text.') { // Create a parent page if none is passed. if (is_null($page)) { $page = $this->_exhibitPage(); } $block = new ExhibitPageBlock(); $block->page_id = $page->id; $block->text = $text; $block->layout = 'text'; $block->save(); return $block; }