Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.55 KB | None | 0 0
  1. <?php
  2.  
  3. class pages_controller extends base_controller {
  4.     public function index( ) {
  5.     }
  6.  
  7.     public function show( $id ) {
  8.         $this->registry->template->node = $this->node( $id );
  9.         $this->registry->template->parent = $this->getParent( $id );
  10.         $this->registry->template->children = $this->getChildren( $id );
  11.         $this->registry->template->show('public_header');
  12.         $this->registry->template->show('public_header_bar');
  13.         $this->registry->template->show('public_home');
  14.         $this->registry->template->show('public_footer');
  15.     }
  16.  
  17.     /**
  18.      * print out a list of all the pages at root level
  19.      */
  20.     public function listNodes( $node_index ) {
  21.         $node_index = (!is_numeric($node_index))?0:$node_index;
  22.  
  23.         $db = db::getInstance();
  24.         $roots = $db->select("*")->where("pages_id = $node_index")->get("pages");
  25.  
  26.         $this->registry->template->roots = $roots;
  27.         $this->registry->template->show('admin_header');
  28.         $this->registry->template->show('admin_header_bar');
  29.         $this->registry->template->show('admin_pageroots');
  30.         $this->registry->template->show('admin_footer');
  31.     }
  32.     public function listRoots() {
  33.         $this->listNodes(0);
  34.     }
  35.  
  36.     // show article by id, or new art, and list any child arts.
  37.     public function admin( $id ) {
  38.         $db = db::getInstance();
  39.         $roots = $db->select("*")->where("pages_id = $id")->get("pages");
  40.  
  41.         $this->registry->template->roots = $roots;
  42.         $this->registry->template->show('admin_header');
  43.         $this->registry->template->show('admin_header_bar');
  44.        
  45.         $this->scaffold_model(
  46.             'pages',
  47.             array('title', 'content'),
  48.             '/pages/admin',
  49.             $id
  50.         );
  51.        
  52.         $this->registry->template->show('admin_pageroots');
  53.         $this->registry->template->show('admin_footer');
  54.     }
  55.  
  56.     protected function getParent( $id ) {
  57.         $db = db::getInstance();
  58.         $tmparr = $db->select("*")->where(
  59.             "id = (SELECT DISTINCT pages_id as pid FROM pages as ppages " .
  60.             "WHERE ppages.id = $id)"
  61.         )->get("pages", 1);
  62.         return $tmparr[0];
  63.     }
  64.  
  65.     protected function getChildren( $id ) {
  66.         $db = db::getInstance();
  67.         return $db->select("id, title")->where("pages_id = $id")->get("pages");
  68.     }
  69.  
  70.     protected function node( $id ) {
  71.         $node = pages::find( $id );
  72.  
  73.         $result = array();
  74.         $result['title'] = $node->title;
  75.         $result['content'] = $node->content;
  76.         // more attributes to add to the result array here...
  77.         // attach an array of any attached images to the result set.
  78.         $result['images'] = array();
  79.         $result['children_ids'] = $this->getChildren( $id );
  80.  
  81.         return $result;
  82.     }
  83.  
  84.     public function jsonNode( $id ) {
  85.         echo json_encode( $this->node( $id ) );
  86.     }
  87. }
  88.  
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement