/**
  * Find all blocks on a page.
  *
  * @param ExhibitPage $page
  * @return ExhibitPageBlock[]
  */
 public function findByPage($page)
 {
     if (!$page->exists()) {
         return array();
     }
     $select = $this->getSelect()->where('exhibit_page_blocks.page_id = ?', $page->id);
     return $this->fetchObjects($select);
 }
 public function createNewExhibitPage($exhibit, $parentPage = null, $title, $slug = '', $order = 1, $layout = 'text')
 {
     $exhibitPage = new ExhibitPage();
     $exhibitPage->exhibit_id = $exhibit->id;
     if ($parentPage) {
         $exhibitPage->parent_id = $parentPage->id;
     }
     $exhibitPage->title = $title;
     $exhibitPage->layout = $layout;
     $exhibitPage->order = $order;
     if ($slug != '') {
         $exhibitPage->slug = $slug;
     }
     $exhibitPage->save();
     return $exhibitPage;
 }
/**
 * Return a URI to an exhibit.
 *
 * @param Exhibit $exhibit If null, it uses the current exhibit.
 * @param ExhibitPage $exhibitPage A specific page to link to
 * @return string
 */
function exhibit_builder_exhibit_uri($exhibit = null, $exhibitPage = null)
{
    if (!$exhibit) {
        $exhibit = get_current_record('exhibit');
    }
    $exhibitSlug = $exhibit instanceof Exhibit ? $exhibit->slug : $exhibit;
    //If there is no page slug available, we want to build a URL for the summary page
    if (!$exhibitPage) {
        $uri = public_url(array('slug' => $exhibitSlug), 'exhibitSimple');
    } else {
        $pagesTrail = $exhibitPage->getAncestors();
        $pagesTrail[] = $exhibitPage;
        $options = array();
        $options['slug'] = $exhibitSlug;
        foreach ($pagesTrail as $index => $page) {
            $adjustedIndex = $index + 1;
            $options["page_slug_{$adjustedIndex}"] = $page->slug;
        }
        $uri = public_url($options, 'exhibitShow', array(), true);
    }
    return $uri;
}
 /**
  * Tests to make sure the exhibits controller will return a 404 error for a bad exhibit page slug
  *
  **/
 public function testNoError404WithGoodExhibitPageSlug()
 {
     $exhibits = get_records('Exhibit');
     $this->assertEquals(1, count($exhibits));
     $exhibit = $exhibits[0];
     $exhibit->slug = 'goodexhibitslug';
     $exhibit->save();
     $this->assertEquals('goodexhibitslug', $exhibit->slug, 'Bad exhibit slug.');
     $exhibitPage = new ExhibitPage();
     $exhibitPage->title = 'Test Page';
     $exhibitPage->order = 1;
     $exhibitPage->layout = 'image-list-left-thumbs';
     $exhibitPage->slug = 'goodexhibitpageslug';
     $exhibitPage->exhibit_id = $exhibit->id;
     $exhibitPage->save();
     $this->assertTrue($exhibitPage->exists());
     try {
         $this->dispatch('exhibits/show/goodexhibitslug/goodexhibitpageslug');
     } catch (Exception $e) {
         $this->fail('Should not have thrown a 404 error for a good exhibit page slug.');
     }
 }
 /**
  * AJAX action for checking exhibit page data.
  */
 public function validatePageAction()
 {
     try {
         $exhibitPage = $this->_helper->db->findById(null, 'ExhibitPage');
     } catch (Exception $e) {
         $exhibitPage = new ExhibitPage();
         if ($exhibit_id = $this->getParam('exhibit_id')) {
             $exhibitPage->exhibit_id = $exhibit_id;
         }
         if ($parent_id = $this->getParam('parent_id')) {
             $exhibitPage->parent_id = $parent_id;
         }
     }
     $exhibitPage->setPostData($_POST);
     $exhibitPage->validateSlug();
     if ($exhibitPage->isValid()) {
         $data = array('success' => true);
     } else {
         $data = array('success' => false, 'messages' => $exhibitPage->getErrors()->get());
     }
     $this->_helper->json($data);
 }
 /**
  * Create an exhibit page.
  *
  * @param Exhibit $exhibit The parent exhibit.
  * @param string $title The page title.
  * @param string $slug The page slug.
  * @param string $layout The layout template.
  * @param integer $order The page order.
  * @return ExhibitPage
  */
 protected function _exhibitPage($exhibit = null, $title = 'Test Title', $slug = 'test-slug', $layout = 'text', $order = 1)
 {
     // Create a parent exhibit if none is passed.
     if (is_null($exhibit)) {
         $exhibit = $this->_exhibit();
     }
     $page = new ExhibitPage();
     $page->exhibit_id = $exhibit->id;
     $page->slug = $slug;
     $page->layout = $layout;
     $page->title = $title;
     $page->order = $order;
     $page->save();
     return $page;
 }