function page_children($id, $current_id = 0) { $page_model = NModel::singleton('page'); $child_pages = $page_model->getChildren($id); foreach ($child_pages as &$child) { $child['children'] = $this->first_and_last($this->page_children($child['id'], $current_id)); $child['open'] = false; foreach ($child['children'] as $desc) { if ($desc['open']) { $child['open'] = true; } } if ($child['id'] == $current_id) { $child['open'] = true; } } return $child_pages; }
function test_getFieldType_should_return_proper_types() { $model =& NModel::singleton('test_sample'); $varchar = $model->getFieldType('the_varchar'); $this->assertTrue($varchar == N_DAO_STR || $varchar == N_DAO_STR + N_DAO_NOTNULL); $text = $model->getFieldType('the_text'); $this->assertTrue($text == N_DAO_STR + N_DAO_TXT || $text == N_DAO_STR + N_DAO_TXT + N_DAO_NOTNULL); $blob = $model->getFieldType('the_blob'); $this->assertTrue($blob == N_DAO_BLOB || $blob == N_DAO_BLOB + N_DAO_NOTNULL); $tinyint = $model->getFieldType('the_tinyint'); $this->assertTrue($tinyint == N_DAO_INT + N_DAO_BOOL || $tinyint == N_DAO_INT + N_DAO_BOOL + N_DAO_NOTNULL); $int = $model->getFieldType('the_int'); $this->assertTrue($int == N_DAO_INT || $int == N_DAO_INT + N_DAO_NOTNULL); $float = $model->getFieldType('the_float'); $this->assertTrue($float == N_DAO_FLOAT || $float == N_DAO_FLOAT + N_DAO_NOTNULL); $datetime = $model->getFieldType('the_datetime'); $this->assertTrue($datetime == N_DAO_DATE + N_DAO_TIME || $datetime == N_DAO_DATE + N_DAO_TIME + N_DAO_NOTNULL); $date = $model->getFieldType('the_date'); $this->assertTrue($date == N_DAO_DATE || $date == N_DAO_DATE + N_DAO_NOTNULL); $time = $model->getFieldType('the_time'); $this->assertTrue($time == N_DAO_TIME || $time == N_DAO_TIME + N_DAO_NOTNULL); $year = $model->getFieldType('the_year'); $this->assertTrue($year == N_DAO_INT + N_DAO_DATE || $year == N_DAO_INT + N_DAO_DATE + N_DAO_NOTNULL); }
function changeTemplate($page_id, $to_template_id) { $page_id = (int) $page_id; $to_template_id = (int) $to_template_id; if (!$page_id || !$to_template_id) { // TODO: add a log error return false; } // load the container_vars $tc_model =& NModel::singleton('page_template_containers'); $tc_pk = $tc_model->primaryKey(); $tc_model->reset(); $tc_model->page_template_id = $to_template_id; $containers = array(); if ($tc_model->find()) { while ($tc_model->fetch()) { $containers[$tc_model->{$tc_pk}] = $tc_model->container_var; } } // grab records attached to the old template $model =& $this->getDefaultModel(); $model->reset(); $model->page_id = $page_id; $conditions = ''; foreach ($containers as $container_id => $container_var) { $conditions .= ($conditions ? ' AND ' : '') . 'page_template_container_id != ' . $container_id; } $old_contents = $model->find(array('conditions' => $conditions)) ? $model->fetchAll() : array(); if (empty($old_contents)) { return true; } // loop through the old content. If the new template has the same // container_var and isn't already connected to that template_container, // then update the record foreach ($old_contents as $content) { // grab the old template_container for the content $tc_model->reset(); if ($tc_model->get($content->page_template_container_id)) { if ($new_container_id = array_search($tc_model->container_var, $containers)) { // check if the same content is already connected to the new template_container $model->reset(); $model->page_id = $page_id; $model->content_asset = $content->content_asset; $model->content_asset_id = $content->content_asset_id; $model->page_template_container_id = $new_container_id; if ($model->find()) { continue; } // if not, update the content to the new container_id $content->page_template_container_id = $new_container_id; $content->update(); } } } return true; }
function &getActivePageContent($asset, $asset_id) { if (!$asset || !$asset_id) { $ret = false; return $ret; } $page =& NModel::singleton('page'); $this->reset(); $this->content_asset = (string) $asset; $this->content_asset_id = (int) $asset_id; $page_contents = false; if ($this->find()) { $page_contents = array(); while ($this->fetch()) { $page->reset(); // Only get active pages. $page->cms_deleted = 0; if (!$page->get($this->page_id)) { continue; } $page_contents[] = clone $this; } } return $page_contents; }
function loadSidebar($parameter) { $this->set('SIDEBAR_TITLE', $this->page_title . ' Info'); $page_model =& NModel::singleton('page'); $page_content_model =& NModel::factory('page_content'); $page_content_model->content_asset = $this->name; $page_content_model->content_asset_id = $parameter; $this->setAppend('SIDEBAR_CONTENT', $this->render(array('action' => 'sidebar_edit_status', 'return' => true))); if ($page_content_model->find()) { $pages = array(); while ($page_content_model->fetch()) { $page_model->reset(); if ($page_model->get($page_content_model->page_id)) { $pages[] = $page_model->toArray(); } } $page_model->reset(); unset($page_model); $this->set('pages', $pages); $this->setAppend('SIDEBAR_CONTENT', $this->render(array('action' => 'sidebar_page_content', 'return' => true))); } unset($page_content_model); if ($this->versioning) { $user_model = $this->loadModel('cms_auth'); $model = $this->getDefaultModel(); $model = clone $model; if (!$model->{$model->primaryKey()}) { $model->get($parameter); $this->convertDateTimesToClient($model); } $model_data = $model->toArray(); if ($user_model->get($model_data['cms_modified_by_user'])) { $model_data['user'] = $user_model->toArray(); } $this->set($model_data); $user_model->reset(); $version_model = $this->loadModel('cms_nterchange_versions'); $user_model = $this->loadModel('cms_auth'); $version_model->asset = $this->name; $version_model->asset_id = $parameter; if ($version_model->find(array('order_by' => 'cms_modified DESC'))) { $versions = array(); while ($version_model->fetch()) { $version = $version_model->toArray(); if ($version_data = @unserialize($version['version'])) { if ($user_model->get($version_data['cms_modified_by_user'])) { $version['user'] = $user_model->toArray(); } $user_model->reset(); $versions[] = $version; } } $this->set('versions', $versions); } $this->setAppend('SIDEBAR_CONTENT', $this->render(array('action' => 'sidebar_versions', 'return' => true))); unset($version_model); } }
function __construct() { $this->model =& NModel::singleton('page'); }
function fixPaths($id = 0) { $model =& NModel::singleton($this->name); $model->reset(); if (!$id) { $id = $model->getRootNode(); } $fields = $model->fields(); if ($model->get($id)) { // update the current page $model->path = $model->buildPath($id); if (in_array('cms_modified_by_user', $fields)) { $model->cms_modified_by_user = isset($this->_auth) ? (int) $this->_auth->currentUserID() : 0; } $model->update(); // update all the children $all_children = $model->getAllChildren($id, false, false); foreach ($all_children as $child) { $model->reset(); $model->get($child[$model->primaryKey()]); $model->path = $model->buildPath($child['id']); if (in_array('cms_modified_by_user', $fields)) { $model->cms_modified_by_user = isset($this->_auth) ? (int) $this->_auth->currentUserID() : 0; } $model->update(); } } unset($model); }