function page_model_test($delete)
{
    include_once "adventure_model.php";
    $page = new PageModel("Sample Page Text" . rand(0, 100000), AdventureModel::first()->id, "images/test.png");
    $page->save();
    $page->print_fields();
    $page->set("page_text", "Updated Page Text");
    $page->save();
    $page->print_fields();
    if ($delete) {
        $page->delete();
    }
    $pm = PageModel::find(PageModel::last()->id);
    $pm->print_fields();
    PageModel::find(999);
}
示例#2
0
 /**
  * Update any disable rules associated with this response.
  */
 private function updateDisableRules()
 {
     if (!isset($this->parent)) {
         $this->parent = new QuestionModel(array('questionID' => $this->responseRow->questionID, 'depth' => 'question'));
     }
     $question = $this->parent;
     foreach ($question->prompts as $prompt) {
         foreach ($prompt['rules'] as $rule) {
             if ($prompt['promptID'] == $this->responseText) {
                 if ($rule->enabled != 'Y') {
                     $rule->enabled = 'Y';
                     $rule->save();
                     if (preg_match('/.+Page$/', $rule->type)) {
                         $page = new PageModel(array('pageID' => $rule->targetID, 'depth' => 'question'));
                         $page->save();
                     } elseif (preg_match('/.+Section$/', $rule->type)) {
                         $section = new SectionModel(array('sectionID' => $rule->targetID, 'depth' => 'question'));
                         $section->save();
                     } elseif (preg_match('/.+Question$/', $rule->type)) {
                         $question = new QuestionModel(array('questionID' => $rule->targetID, 'depth' => 'question'));
                         $question->save();
                     }
                 }
             } else {
                 if ($rule->enabled != 'N') {
                     $rule->enabled = 'N';
                     $rule->save();
                     if (preg_match('/.+Page$/', $rule->type)) {
                         $page = new PageModel(array('pageID' => $rule->targetID, 'depth' => 'question'));
                         $page->save();
                     } elseif (preg_match('/.+Section$/', $rule->type)) {
                         $section = new SectionModel(array('sectionID' => $rule->targetID, 'depth' => 'question'));
                         $section->save();
                     } elseif (preg_match('/.+Question$/', $rule->type)) {
                         $question = new QuestionModel(array('questionID' => $rule->targetID, 'depth' => 'question'));
                         $question->save();
                     }
                 }
             }
         }
     }
 }
示例#3
0
 public function approveSaveAction()
 {
     try {
         if ($this->_hasParam('approvals')) {
             $page = new PageModel(array('pageID' => $this->_getParam('id'), 'depth' => 'response'));
             $comments = $this->_getParam('comments');
             foreach ($this->_getParam('approvals') as $questionID => $state) {
                 $question = $page->getQuestion(intval($questionID));
                 if ($question === null) {
                     throw new Exception('Invalid attempt to approve a non-existent question or question on another page');
                 }
                 $response = $question->getResponse();
                 if ($response->requiresAdditionalInfo() && !$response->hasAdditionalInfo()) {
                     throw new Exception('Invalid attempt to approve a response that requires additional information with none provided');
                 }
                 $response->state = intval($state);
                 if (array_key_exists($questionID, $comments)) {
                     if ($comments[$questionID] === '') {
                         $response->approverComments = null;
                     } else {
                         $response->approverComments = $comments[$questionID];
                     }
                 }
                 $response->save();
                 foreach ($question->children as $child) {
                     $response = $child->getResponse();
                     $response->state = intval($state);
                     $response->save();
                 }
             }
             $page->save();
             $instance = new InstanceModel(array('instanceID' => $page->instanceID, 'depth' => 'page'));
             $instance->save();
         }
     } catch (Exception $e) {
         $this->view->error = $e->getMessage();
     }
     $this->view->setRenderLayout(false);
 }
示例#4
0
	/**
	 * Shortcut for unpublishing a page.
	 */
	public function page_unpublish() {
		$view    = $this->getView();
		$request = $this->getPageRequest();

		if(!\Core\user()->checkAccess('p:/core/pages/manage')){
			return View::ERROR_ACCESSDENIED;
		}

		$baseurl = $request->getParameter('baseurl');

		$page = new PageModel($baseurl);
		if(!$page->exists()){
			return View::ERROR_NOTFOUND;
		}

		if(!$request->isPost()){
			return View::ERROR_BADREQUEST;
		}

		// Is this page already un-published?
		if($page->get('published_status') == 'draft'){
			\Core\set_message('t:MESSAGE_ERROR_PAGE_ALREADY_UNPUBLISHED');
			\Core\go_back();
		}

		$page->set('published_status', 'draft');
		$page->save();

		\Core\set_message('t:MESSAGE_SUCCESS_PAGE_UNPUBLISHED');
		\Core\go_back();
	}
示例#5
0
	/**
	 * Internal function to parse and handle the configs in the component.xml file.
	 * This is used for installations and upgrades.
	 *
	 * @param boolean $install   Set to false to force uninstall/disable mode.
	 * @param int     $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output.
	 *
	 * @return boolean | int
	 * @throws InstallerException
	 */
	public function _parsePages($install = true, $verbosity = 0) {
		$changes = array();

		$overallAction = $install ? 'Installing' : 'Uninstalling';

		Core\Utilities\Logger\write_debug($overallAction . ' pages for ' . $this->getName());

		// I need to get the schema definitions first.
		$node = $this->_xmlloader->getElement('pages');
		//$prefix = $node->getAttribute('prefix');

		// Now, get every table under this node.
		foreach ($node->getElementsByTagName('page') as $subnode) {
			/** @var DomElement $subnode */
			$baseurl = $subnode->getAttribute('baseurl');
			// Insert/Update the defaults for an entry in the database.
			// These are always global pages.
			$m = new PageModel(-1, $baseurl);

			if($verbosity == 2){
				CLI::PrintActionStart($overallAction . ' page ' . $baseurl);
			}

			// Hard-set pages get removed upon disabling.  They'll be recreated if re-enabled.
			if($install){
				// Just something to help the log.
				$action     = ($m->exists()) ? 'Updated' : 'Added';
				$admin      = $subnode->getAttribute('admin');
				$selectable = ($admin ? '0' : '1'); // Defaults
				$group      = ($admin ? $subnode->getAttribute('group') : '');
				if($subnode->getAttribute('selectable') !== ''){
					$selectable = $subnode->getAttribute('selectable');
				}
				$indexable = ($subnode->getAttribute('indexable') !== '') ? $subnode->getAttribute('indexable') : $selectable;
				$editurl = $subnode->getAttribute('editurl') ? $subnode->getAttribute('editurl') : '';
				$access = ($subnode->getAttribute('access')) ? $subnode->getAttribute('access') : null;

				// Do not "update" value, keep whatever the user set previously.
				if (!$m->get('rewriteurl')) {
					if ($subnode->getAttribute('rewriteurl')) $m->set('rewriteurl', $subnode->getAttribute('rewriteurl'));
					else $m->set('rewriteurl', $subnode->getAttribute('baseurl'));
				}
				// Do not "update" value, keep whatever the user set previously.
				if (!$m->get('title')) $m->set('title', $subnode->getAttribute('title'));

				if($access !== null){
					$m->set('access', $access);
				}

				// Do not update parent urls if the page already exists.
				if(!$m->exists()) $m->set('parenturl', $subnode->getAttribute('parenturl'));
				//$m->set('widget', $subnode->getAttribute('widget'));
				$m->set('admin', $admin);
				$m->set('admin_group', $group);
				$m->set('selectable', $selectable);
				$m->set('indexable', $indexable);
				$m->set('component', $this->getKeyName());
				$m->set('editurl', $editurl);
				if ($m->save()){
					$changes[] = $action . ' page [' . $baseurl . ']';
					if($verbosity == 2){
						CLI::PrintActionStatus(true);
					}
				}
				else{
					if($verbosity == 2){
						CLI::PrintActionStatus('skip');
					}
				}
			}
			else{
				$m->delete();
				$changes[] = 'Removed page [' . $subnode->getAttribute('baseurl') . ']';
				if($verbosity == 2){
					CLI::PrintActionStatus(true);
				}
			}
		}

		return ($changes > 0) ? $changes : false;
	}