コード例 #1
0
    /**
     * ContentController::index()
     *
     * The Home page
     */
    public function index($args)
    {
        $this->setContent('browser_title', SITE_TITLE . ': The ' . LAWS_NAME . ', for Humans.');
        /*
         * Initialize the sidebar variable.
         */
        $sidebar = '
			<section>
			<p>Powered by <a href="http://www.statedecoded.com/">The State Decoded</a>.</p>
			</section>';
        /*
         * Put the shorthand $sidebar variable into its proper place.
         */
        $this->setContent('sidebar', $sidebar);
        unset($sidebar);
        /*
         * Get an object containing a listing of the fundamental units of the code.
         */
        $struct = new Structure();
        $structures = $struct->list_children();
        /*
         * Initialize the body variable.
         */
        $body .= '
			<article>
			<h1>' . ucwords($structures->{0}->label) . 's of the ' . LAWS_NAME . '</h1>
			<p>These are the fundamental units of the ' . LAWS_NAME . '.</p>';
        if (!empty($structures)) {
            $body .= '<dl class="level-1">';
            foreach ($structures as $structure) {
                $body .= '	<dt><a href="' . $structure->url . '">' . $structure->identifier . '</a></dt>
							<dd><a href="' . $structure->url . '">' . $structure->name . '</a></dd>';
            }
            $body .= '</dl>';
        }
        $body .= '</article>';
        /*
         * Put the shorthand $body variable into its proper place.
         */
        $this->setContent('body', $body);
        unset($body);
        return $this->renderContent();
    }
コード例 #2
0
$response = isset($struct->structure) ? $struct->structure : '';
/*
 * If the URL doesn't represent a valid structural portion of the code, then bail.
 */
if ($response === FALSE) {
    send_404();
}
/*
 * Set aside the ancestry for this structural unit, to be accessed separately.
 */
// Again, if we at the top level, this will return null
$structure = isset($struct->structure) ? $struct->structure : '';
/*
 * Get a listing of all the structural children of this portion of the structure.
 */
$children = $struct->list_children();
/*
 * Create a container for our content.
 */
$content = new Content();
/*
 * Define the title page elements.
 */
if (strlen($structure_id) > 0) {
    $content->set('browser_title', $struct->name);
    $content->set('page_title', '<h2>' . $struct->name . '</h2>');
} else {
    $content->set('browser_title', SITE_TITLE . ': The ' . LAWS_NAME . ', for Humans.');
}
/*
 * Make some section information available globally to JavaScript.
コード例 #3
0
 /**
  * Recurse through structural information
  *
  * A helper method for structural_stats_generate(); not intended to be called on its own.
  */
 function structural_stats_recurse()
 {
     /*
      * Retrieve basic stats about the children of this structural unit.
      */
     $struct = new Structure();
     $struct->id = $this->structure_id;
     $child_structures = $struct->list_children();
     $child_laws = $struct->list_laws();
     /*
      * Append the structure's ID to the structural ancestry.
      */
     $this->ancestry[] = $this->structure_id;
     /*
      * Store the tallies.
      */
     $this->stats->{$this->structure_id} = new stdClass();
     if ($child_structures !== FALSE) {
         $this->stats->{$this->structure_id}->child_structures = count((array) $child_structures);
     }
     if ($child_laws !== FALSE) {
         $this->stats->{$this->structure_id}->child_laws = count((array) $child_laws);
     }
     $this->stats->{$this->structure_id}->depth = $this->depth;
     $this->stats->{$this->structure_id}->ancestry = $this->ancestry;
     /*
      * If this structural unit has child structural units of its own, recurse into those.
      */
     if (isset($this->stats->{$this->structure_id}->child_structures) && $this->stats->{$this->structure_id}->child_structures > 0) {
         foreach ($child_structures as $child_structure) {
             $this->depth++;
             $this->structure_id = $child_structure->id;
             $this->structural_stats_recurse();
         }
     }
     /*
      * Having just finished a recursion, we can remove the last member of the ancestry array
      * and eliminate one level of the depth tracking.
      */
     $this->ancestry = array_slice($this->ancestry, 0, -1);
     $this->depth--;
 }
 function handle($args)
 {
     /*
      * If the request is for the structural units sorted by a specific criteria.
      */
     if (isset($_GET['sort'])) {
         /*
          * Explicitly reassign the external value to an internal one, for safety's sake.
          */
         if ($_GET['sort'] == 'views') {
             $order_by = filter_var($_GET['sort'], FILTER_SANITIZE_STRING);
         }
     }
     /*
      * Create a new instance of the class that handles information about individual laws.
      */
     $struct = new Structure();
     /*
      * Get the structure based on our identifier.
      */
     if ($args['relational_id']) {
         $struct->structure_id = $args['relational_id'];
     } else {
         $struct->structure_id = '';
     }
     $struct->get_current();
     $response = $struct->structure;
     /*
      * If this structural element does not exist.
      */
     if ($response === FALSE) {
         $this->handleNotFound();
     }
     /*
      * List all child structural units.
      */
     $struct->order_by = $order_by;
     $response->children = $struct->list_children();
     /*
      * List all laws.
      */
     $response->laws = $struct->list_laws();
     /*
      * If the request contains a specific list of fields to be returned.
      */
     if (isset($_GET['fields'])) {
         /*
          * Turn that list into an array.
          */
         $returned_fields = explode(',', urldecode($_GET['fields']));
         foreach ($returned_fields as &$field) {
             $field = trim($field);
         }
         /*
          * It's essential to unset $field at the conclusion of the prior loop.
          */
         unset($field);
         /*
          * Step through our response fields and eliminate those that aren't in the requested list.
          */
         foreach ($response as $field => &$value) {
             if (in_array($field, $returned_fields) === false) {
                 unset($response->{$field});
             }
         }
     }
     $this->render($response, 'OK');
 }