* @copyright 2002-2008 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version Release: 1.4.4
* @filesource
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* @see parserStringWithInlineTags
* @tutorial tags.inlinetoc.pkg
* @todo CS cleanup - change package to PhpDocumentor
* @todo CS cleanup - change classname to PhpDocumentor_*
*/
class parserTocInlineTag extends parserInlineTag
{
/**
* always 'toc'
* @var string
*/
var $inlinetype = 'toc';
/**
* @var array format:
*
* array(
* array(
* 'tagname' => section,
* 'link' => returnsee link,
* 'id' => anchor name,
* 'title' => from title tag
* ),
* ...
* )
*
* @access private
*/
var $_toc = false;
/**
* full path to tutorial, used in conversion
* @var string
* @access private
*/
var $_path = false;
/**
* constructor
*/
function parserTocInlineTag()
{
parent::parserInlineTag('toc', '');
}
/**
* set the TOC
*
* @param array $toc format:
*
* array(
* array(
* 'tag' => {@link parserXMLDocBookTag},
* 'id' => {@link parserIdInlineTag},
* 'title' => {@link parserXMLDocBookTag title}
* ),
* ...
* )
*
*
* @return void
*/
function setTOC($toc)
{
$this->toc = $toc;
}
/**
* set the path
*
* @param string $path the path
*
* @return void
*/
function setPath($path)
{
$this->_path = $path;
}
/**
* converter method
*
*
* array(
* 'tagname' => string name of tag,
* 'link' => {@link tutorialLink} to the tutorial,
* 'id' => converter specific tutorial ID from
* {@link Converter::getTutorialId()}
* 'title' => title of the tutorial)
*
* and returns the results as the table of contents
*
* @param Converter &$c converter object
*
* @return mixed
* @uses Converter::getTutorialId() retrieve the tutorial ID for
* @uses Converter::formatTutorialTOC() passes an array of format:
* @todo CS cleanup - rename to convert for camelCase rule
*/
function Convert(&$c)
{
$newtoc = array();
if (isset($this->toc) && is_array($this->toc)) {
foreach ($this->toc as $i => $toc) {
if (isset($toc['title'])) {
$toc['tag']->setTitle($toc['title']);
} else {
$toc['tag']->setTitle(new parserStringWithInlineTags);
}
$newtoc[$i]['tagname'] = $toc['tag']->name;
$l = new tutorialLink;
if (!isset($toc['title'])) {
$title = 'section '.$toc['id']->id;
} else {
$title = $toc['title']->Convert($c);
}
$l->addLink($toc['id']->id, $this->_path, basename($this->_path),
$toc['id']->package, $toc['id']->subpackage, strip_tags($title));
$newtoc[$i]['link'] = $c->returnSee($l);
$newtoc[$i]['id'] = $c->getTutorialId($toc['id']->package,
$toc['id']->subpackage, basename($this->_path),
$toc['id']->id, $toc['id']->category);
$newtoc[$i]['title'] = $title;
}
}
return $c->formatTutorialTOC($newtoc);
}
}
?>