Salve, ho adattato, in modo se vogliamo poco ortodosso ma efficace, il modulo per la visualizzazione delle categorie di phocadownload in stile filesystem.
In sostanza il componente ora non lavora più con le sezioni e le categorie ma solo con categorie ed, eventualmente, categorie figlie quindi ho dovuto adattere il suddetto modulo perchè potesse lavorare con questa nuova versione.
Quello che ho fatto è stato di aggiungere la classe del componente nel modulo e richamarne poi il metodo che ritorna l'array delle categorie e subcategorie.
Importo la classe:
require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'models'.DS.'categories.php' );
La istanzio:
$categorie = new PhocaDownloadModelCategories;
richiamo il metodo che ci serve :
$sections = $categorie->getCategoriesList();
poi ho cambiato alcuni riferimenti nei cicli foreach e alcune attributi che venivano richiamati per la costruzione dei link, alcuni metodi richiamati dal modulo non più presenti nel nuovo componente ed alcune condizioni, mi dispiace non essere più dettagliato ma non ho molto tempo, se siete curiosi fate un diff con il file originale.
Per ora elenca solamente le categorie e la prima sottocategoria, come prima per sezione/categoria, se quelli di phoca non lo aggiornano a breve vedrò di cercare una soluzione momentanea fino alla sua uscita.
Ho lasciato tutto il codice inutile commentato così forse si capisce meglio cosa ho eliminato.
PS ricordatevi di fare prima un backup del file originale!
Il file da modificare è " mod_phocadownload_tree.php ", incollo di seguito il contenuto del file modificato.
<?php
/*
* @package Joomla 1.5
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*
* @module Phoca - Phoca Module
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @based on javascript: dTree 2.05 www.destroydrop.com/javascript/tree/
* @copyright (c) 2002-2003 Geir Landrˆ
*/
defined('_JEXEC') or die('Restricted access');// no direct access
if (!JComponentHelper::isEnabled('com_phocadownload', true)) {
return JError::raiseError(JText::_('Phoca Download Error'), JText::_('Phoca Download is not installed on your system'));
}
require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'phocadownload.php' );
require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'route.php' );
require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'phocadownload.php' );
require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'models'.DS.'categories.php' );
$user = &JFactory::getUser();
$db = &JFactory::getDBO();
$menu = &JSite::getMenu();
$document = &JFactory::getDocument();
// Start CSS
$document->addStyleSheet(JURI::base(true).'/modules/mod_phocadownload_tree/assets/dtree.css');
$document->addScript( JURI::base(true) . '/modules/mod_phocadownload_tree/assets/dtree.js' );
$imgPath = JURI::base(true) . '/modules/mod_phocadownload_tree/assets/';
//Unique id for more modules
$treeId = "d".uniqid( "tree_" );
// Current category info
$id = JRequest::getVar( 'id', 0, '', 'int' );
$option = JRequest::getVar( 'option', 0, '', 'string' );
$view = JRequest::getVar( 'view', 0, '', 'string' );
$categorie = new PhocaDownloadModelCategories;
// Params
$hideC = $params->get( 'hide_categories', '');
$hideS = $params->get( 'hide_sections', '' );
$aid = $user->get('aid', 0);
/*
// SQL, QUERY
$wheres = array();
if (count($hideS) > 1) {
JArrayHelper::toInteger($hideS);
$hideSString = implode(',', $hideS);
$wheres[] = ' s.id NOT IN ( '.$hideSString.' ) ';
} else if ((int)$hideS > 0) {
$wheres[] = ' s.id NOT IN ( '.$hideS.' ) ';
}
$wheres[] = " s.published = 1";
$wheres[] = " s.access <= ". (int)$aid;
$where = ( count( $wheres ) ? ' WHERE '. implode( ' AND ', $wheres ) : '' );
// All Sections - - - - - - -
$query = 'SELECT s.title AS text, s.id AS id, s.alias as alias, s.access as access,'
. ' CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(\':\', s.id, s.alias) ELSE s.id END as secslug '
. ' FROM #__phocadownload_categories AS s'
. $where
. ' ORDER BY s.ordering';
$db->setQuery( $query );
*/
$sections = $categorie->getCategoriesList();
/*
// SQL, QUERY
$wheres = array();
if (count($hideC) > 1) {
JArrayHelper::toInteger($hideC);
$hideCString = implode(',', $hideC);
$wheres[] = ' cc.id NOT IN ( '.$hideCString.' ) ';
} else if ((int)$hideC > 0) {
$wheres[] = ' cc.id NOT IN ( '.$hideC.' ) ';
}
// Add Access check - codejunkie 2009-10-07
$aid = $user->get('aid', 0);
$wheres[] = " cc.published = 1";
$wheres[] = " cc.access <= ". $aid;
$where = ( count( $wheres ) ? ' WHERE '. implode( ' AND ', $wheres ) : '' );
// All Categories - - - - -
$query = 'SELECT cc.title AS text, cc.id AS id, cc.parent_id as parentid, cc.section as section, cc.alias as alias, cc.access as access, cc.accessuserid as cataccessuserid, '
. ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as catslug '
. ' FROM #__phocadownload_categories AS cc'
. $where
. ' ORDER BY cc.ordering';
$db->setQuery( $query );
$categories = $db->loadObjectList();
*/
// Tree
$i = 1;
$tree = array();
$newIdSec = array();
$newIdCat = array();
$userAID = $user->get('aid', 0);
$userID = $user->get('id', 0);
foreach ($sections as $valueSec) {
$link = JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($valueSec->id, $valueSec->alias));
$tree[] = $treeId.'.add('.$i.',0,\''.addslashes($valueSec->title).'\',\''.$link.'\');'."\n";
$newIdSec[$valueSec->id] = $i;
$j = $i;$i++;
foreach ($valueSec->subcategories as $valueCat) {
//if ((int)$valueCat->section == (int)$valueSec->id) {
// USER RIGHT - Access of categories (if file is included in some not accessed category) - - - - -
// ACCESS is handled in SQL query, ACCESS USER ID is handled here (specific users)
$rightDisplay = 1;
/*
if (!empty($valueCat)) {
$rightDisplay = PhocaDownloadHelper::getUserRight('accessuserid', $valueCat->cataccessuserid, $valueCat->access, $userAID, $userID, 0);
}
* */
// - - - - - - - - - - - - - - - - - - - - - -
if ($rightDisplay == 1) {
$link = JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($valueCat->id, $valueCat->alias, $valueSec->id));
$tree[] = $treeId.'.add('.$i.','.$j.',\''.addslashes($valueCat->title).'\',\''.$link.'\');'."\n";
$newIdCat[$valueCat->id] = $i;
$i++;
}
//}
}
}
// We added unique numbers to categories and sections (because section can have the same id as category we must to add other ids)
if ( $option == 'com_phocadownload' && $view == 'section' ) {
if (isset($newIdSec[$id])) {
$catAndSecId = (int)$newIdSec[$id];
} else {
$catAndSecId = 0;
}
} else if ( $option == 'com_phocadownload' && $view == 'category' ) {
if (isset($newIdCat[$id])) {
$catAndSecId = (int)$newIdCat[$id];
} else {
$catAndSecId = 0;
}
} else {
$catAndSecId = 0;
}
// Categories (Head)
$linkSections = JRoute::_(PhocaDownloadHelperRoute::getCategoriesRoute());
// Create javascript code
$jsTree = '';
foreach($tree as $key => $value) {
$jsTree .= $value ;
}
// Output
$output ='<div style="text-align:left;">';
$output.='<div class="dtree">';
$output.='<script type="text/javascript">'."\n";
$output.='<!--'."\n";
$output.=''."\n";
$output.=''.$treeId.' = new dTree2568(\''.$treeId.'\', \''.$imgPath.'\');'."\n";
$output.=''."\n";
$output.=''.$treeId.'.add(0,-1,\''.JText::_( 'Documenti' ).'\',\''.$linkSections.'\');'."\n";
$output.=$jsTree;
$output.=''."\n";
$output.='document.write('.$treeId.');'."\n";
$output.=''.$treeId.'.openTo('. (int) $catAndSecId.',\'true\');'. "\n";
$output.=''."\n";
$output.='//-->'."\n";
$output.='</script>';
$output.='</div></div>';
require(JModuleHelper::getLayoutPath('mod_phocadownload_tree'));
?>