MenuLeaf.php in Taxonomy Facets 7.3
File
classes/MenuLeaf.php
View source
<?php
namespace taxonomyFacets;
include_once 'SelectedFilters.php';
class MenuLeaf {
private $vid = NULL;
public $tid = NULL;
public $termName = NULL;
public $urlAlias = NULL;
public $leafClass = NULL;
public $linkClass = NULL;
public $linkUrl = null;
private $filtersObject = null;
public function __construct($leaf, $numberOfItems = 1, $itemNumber = 1, $leafClass = 'first') {
$this->filtersObject = TaxoFacets::getInstance();
$this->termName = check_plain($leaf->name);
$this->tid = $leaf->tid;
$this->vid = $leaf->vid;
$this
->getTermUrlAlias();
$this
->calculateLeafClass($numberOfItems, $itemNumber, $leafClass);
$this
->buildLinkUrl();
}
private function getTermUrlAlias() {
$query = db_select('url_alias', 'u')
->fields('u', array(
'alias',
))
->condition('source', 'taxonomy/term/' . $this->tid)
->execute();
$this->urlAlias = current($query
->fetchAll())->alias;
}
private function calculateLeafClass($numberOfItems, $itemNumber, $leafClass) {
switch ($itemNumber) {
case 1:
$this->leafClass = 'first';
break;
case $numberOfItems:
$this->leafClass = 'last';
break;
}
$this->leafClass .= ' ' . $leafClass;
}
private function buildLinkUrl() {
$url = array();
$noTermFromCurrentVocabularyFound = true;
if ($filters = $this->filtersObject
->getAppliedFilters()) {
foreach ($filters as $filter) {
if ($filter->vid == $this->vid) {
$obj = new \stdClass();
$obj->vid = $this->vid;
$obj->url = $this->urlAlias;
$url[] = $obj;
$noTermFromCurrentVocabularyFound = false;
}
else {
$obj = new \stdClass();
$obj->vid = $filter->vid;
$obj->url = $filter->term_path_alias;
$url[] = $obj;
}
}
}
if ($noTermFromCurrentVocabularyFound == true) {
$obj = new \stdClass();
$obj->vid = $this->vid;
$obj->url = $this->urlAlias;
$url[] = $obj;
}
$this->linkUrl = self::taxonomy_facets_prepend_language_prefix() . '/' . variable_get('taxonomy_facets_first_argument', 'items_list');
usort($url, 'taxonomy_facets_sort_by_vid');
foreach ($url as $u) {
$this->linkUrl .= '/' . $u->url;
}
}
public static function taxonomy_facets_prepend_language_prefix() {
global $language;
$alias = '';
$lang_ignore = variable_get('taxonomy_facets_ignore_language_prefix', FALSE);
if ($language->prefix != NULL && $lang_ignore == NULL) {
$alias = '/' . $language->prefix;
}
return $alias;
}
}