Exemplo n.º 1
0
 /**
  * Action for editing a particular page
  */
 public function editAction()
 {
     $pageID = $this->_getParam('id');
     $subPageNum = $this->_hasParam('sp') ? $this->_getParam('sp') : 1;
     $this->view->spNum = $subPageNum;
     $this->view->spNumSkip = ($subPageNum - 1) * 100;
     $this->view->spNumLeft = 100;
     $this->view->currentPageID = $pageID;
     if ($pageID > 0) {
         $page = new PageModel(array('pageID' => $pageID, 'depth' => 'page'));
         $this->view->attachmentQuestions = FileModel::fetchObjectIdsByInstance($page->instanceID);
     }
     // get a PageModel object for the current page
     $this->view->page = new PageModel(array('pageID' => $this->view->currentPageID));
     if (!$this->_user->hasAccess('edit', $this->view->page)) {
         $this->denyAccess();
     }
     // get a lock on this page (if possible)
     $auth = Zend_Auth::getInstance();
     $user = DbUserModel::findByUsername($auth->getIdentity());
     $lock = LockModel::obtain($this->view->page, $user);
     if (is_null($lock)) {
         $lockUser = new DbUserModel(array('dbUserID' => LockModel::isLocked($this->view->page)));
         $this->flash('error', 'A lock could not be obtained because the page is currently lock by ' . $lockUser->dbUserFullName);
         // redirect to the view action
         $this->_redirector->gotoRoute(array('action' => 'view', 'id' => $this->view->currentPageID));
     }
 }
Exemplo n.º 2
0
 /**
  * Render the lock icon next to a menu item where appropriate
  *
  * @param  PageModel the page for which we are rendering a lock icon
  * @return string
  */
 protected function renderMenuLockIcon(PageModel $page)
 {
     $builder = new Tag_Builder();
     if (LockModel::isLocked($page)) {
         return ' ' . $builder->image('lock.png', array('class' => 'inline'));
     }
     return '';
 }
Exemplo n.º 3
0
 public function testIsLocked()
 {
     $page = new PageModel(array('pageID' => 1, 'depth' => 'page'));
     $user = new DbUserModel(array('dbUserID' => 1));
     $this->assertFalse(LockModel::isLocked($page));
     $this->assertTrue(LockModel::obtain($page, $user) instanceof LockModel);
     $this->assertEquals(LockModel::isLocked($page), 1);
 }