Projekt

Obecné

Profil

<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/

/**
* @author Michal Kliment
* @version 1.0
*
* This is library for path = history of urls
* It works as iterarator
*/
class Path
{
/**
* Actual path
* @var string
*/
private $path = NULL;

/**
* Id of current position in pathl
* @var integer
*/
private $id = NULL;

/**
* Array of all paths
* @var array
*/
private $paths = NULL;

/**
* For singleton instance
* @var Path object
*/
private static $instance = NULL;

/**
* Creates or return instance of object
*
* @author Michal Kliment
* @return Path object
*/
public static function instance()
{
// Create the instance if it does not exist
empty(self::$instance) and new Path;

return self::$instance;
}

/**
* Constructor, only clear object
*
* @author Michal Kliment
*/
public function __construct ()
{
if (self::$instance === NULL)
{
$this->clear();
self::$instance = $this;
}
}

/**
* Clear object - sets to default value
*
*@author Michal Kliment
* @return Path object
*/
public function clear()
{
$this->paths = Session::instance()->get('paths');
$this->set_path (Session::instance()->get('last_path_id'));
return $this;
}

/**
* Sets path to given id
*
* @author Michal Kliment
* @param integer $path_id
* @return boolean
*/
public function set_path ($path_id = NULL)
{
if (isset($this->paths[$path_id]))
{
$this->path = $this->paths[$path_id];
$this->last();
return true;
}
else
return false;
}

/**
* Returns URL of current position in object
*
* @author Michal Kliment
* @return string
*/
public function current()
{
return $this->path[$this->id];
}

/**
* Goes to previous position
*
* @author Michal Kliment
* @return Path object
*/
public function previous()
{
if ($this->id > 0)
$this->id--;
return $this;
}

/**
* Goes to next position
*
* @author Michal Kliment
* @return Path object
*/
public function next()
{
if ($this->id < (count($this->path)-1))
$this->id++;
return $this;
}

/**
* Goes to first position
*
* @author Michal Kliment
* @return Path object
*/
public function first()
{
$this->id = 0;
return $this;
}

/**
* Goes to last position
*
* @author Michal Kliment
* @return Path object
*/
public function last()
{
$this->id = count($this->path)-1;
return $this;
}
}

?>
(40-40/49)