Support Joomla!

Packages

Package: Joomla-Framework

License

Content on this site is copyright © 2005 - 2008 Open Source Matters Inc and can be used in accordance with the Joomla! Electronic Documentation License. Some parts of this website may be subject to other licenses.
Source code for file /joomla/application/pathway.php

Documentation is available at pathway.php

  1. <?php
  2. /**
  3. @version        $Id: pathway.php 13354 2009-10-28 02:05:38Z ian $
  4. @package        Joomla.Framework
  5. @subpackage    Application
  6. @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  7. @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Class to maintain a pathway.
  20.  *
  21.  * Main example of use so far is the mod_breadcrumbs module that keeps track of
  22.  * the user's navigated path within the Joomla application.
  23.  *
  24.  * @abstract
  25.  * @package     Joomla.Framework
  26.  * @subpackage    Application
  27.  * @since        1.5
  28.  */
  29. class JPathway extends JObject
  30. {
  31.     /**
  32.      * Array to hold the pathway item objects
  33.      * @access private
  34.      */
  35.     var $_pathway null;
  36.  
  37.     /**
  38.      * Integer number of items in the pathway
  39.      * @access private
  40.      */
  41.     var $_count 0;
  42.  
  43.     /**
  44.      * Class constructor
  45.      */
  46.     function __construct($options array())
  47.     {
  48.         //Initialise the array
  49.         $this->_pathway array();
  50.     }
  51.  
  52.     /**
  53.      * Returns a reference a JPathway object
  54.      *
  55.      * This method must be invoked as:
  56.      *         <pre>  $menu = &JPathway::getInstance();</pre>
  57.      *
  58.      * @access    public
  59.      * @param   string  $client  The name of the client
  60.      * @param array     $options An associative array of options
  61.      * @return JPathway     A pathway object.
  62.      * @since    1.5
  63.      */
  64.     function &getInstance($client$options array())
  65.     {
  66.         static $instances;
  67.  
  68.         if (!isset$instances )) {
  69.             $instances array();
  70.         }
  71.  
  72.         if (empty($instances[$client]))
  73.         {
  74.             //Load the router object
  75.             $info =JApplicationHelper::getClientInfo($clienttrue);
  76.  
  77.             $path $info->path.DS.'includes'.DS.'pathway.php';
  78.             if(file_exists($path))
  79.             {
  80.                 require_once $path;
  81.  
  82.                 // Create a JPathway object
  83.                 $classname 'JPathway'.ucfirst($client);
  84.                 $instance new $classname($options);
  85.             }
  86.             else
  87.             {
  88.                 $error JError::raiseError500'Unable to load pathway: '.$client);
  89.                 return $error;
  90.             }
  91.  
  92.             $instances[$client$instance;
  93.         }
  94.  
  95.         return $instances[$client];
  96.     }
  97.  
  98.     /**
  99.      * Return the JPathWay items array
  100.      *
  101.      * @access public
  102.      * @return array Array of pathway items
  103.      * @since 1.5
  104.      */
  105.     function getPathway()
  106.     {
  107.         $pw $this->_pathway;
  108.  
  109.         // Use array_values to reset the array keys numerically
  110.         return array_values($pw);
  111.     }
  112.  
  113.     /**
  114.      * Set the JPathway items array.
  115.      *
  116.      * @access    public
  117.      * @param    array    $pathway    An array of pathway objects.
  118.      * @return    array    The previous pathway data.
  119.      * @since    1.5
  120.      */
  121.     function setPathway($pathway)
  122.     {
  123.         $oldPathway    $this->_pathway;
  124.         $pathway    = (array) $pathway;
  125.  
  126.         // Set the new pathway.
  127.         $this->_pathway array_values($pathway);
  128.  
  129.         return array_values($oldPathway);
  130.     }
  131.  
  132.     /**
  133.      * Create and return an array of the pathway names.
  134.      *
  135.      * @access public
  136.      * @return array Array of names of pathway items
  137.      * @since 1.5
  138.      */
  139.     function getPathwayNames()
  140.     {
  141.         // Initialize variables
  142.         $names array (null);
  143.  
  144.         // Build the names array using just the names of each pathway item
  145.         foreach ($this->_pathway as $item{
  146.             $names[$item->name;
  147.         }
  148.  
  149.         //Use array_values to reset the array keys numerically
  150.         return array_values($names);
  151.     }
  152.  
  153.     /**
  154.      * Create and add an item to the pathway.
  155.      *
  156.      * @access public
  157.      * @param string $name 
  158.      * @param string $link 
  159.      * @return boolean True on success
  160.      * @since 1.5
  161.      */
  162.     function addItem($name$link='')
  163.     {
  164.         // Initalize variables
  165.         $ret false;
  166.  
  167.         if ($this->_pathway[$this->_makeItem($name$link)) {
  168.             $ret true;
  169.             $this->_count++;
  170.         }
  171.  
  172.         return $ret;
  173.     }
  174.  
  175.     /**
  176.      * Set item name.
  177.      *
  178.      * @access public
  179.      * @param integer $id 
  180.      * @param string $name 
  181.      * @return boolean True on success
  182.      * @since 1.5
  183.      */
  184.     function setItemName($id$name)
  185.     {
  186.         // Initalize variables
  187.         $ret false;
  188.  
  189.         if (isset($this->_pathway[$id])) {
  190.             $this->_pathway[$id]->name $name;
  191.             $ret true;
  192.         }
  193.  
  194.         return $ret;
  195.     }
  196.  
  197.     /**
  198.      * Create and return a new pathway object.
  199.      *
  200.      * @access private
  201.      * @param string $name Name of the item
  202.      * @param string $link Link to the item
  203.      * @return object Pathway item object
  204.      * @since 1.5
  205.      */
  206.     function _makeItem($name$link)
  207.     {
  208.         $item new stdClass();
  209.         $item->name html_entity_decode($nameENT_COMPAT'UTF-8');
  210.         $item->link $link;
  211.  
  212.         return $item;
  213.     }
  214. }

Documentation generated on Sat, 14 Nov 2009 11:16:56 +0000 by phpDocumentor 1.3.1