Back to top

Autore Topic: modulo phocadownload tree  (Letto 3541 volte)

Offline webbati

  • Esploratore
  • **
  • Post: 116
    • Mostra profilo
modulo phocadownload tree
« il: 13 Feb 2011, 16:37:01 »
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:
Codice: [Seleziona]
require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'models'.DS.'categories.php' );
La istanzio:
Codice: [Seleziona]
$categorie = new PhocaDownloadModelCategories;
richiamo il metodo che ci serve :
Codice: [Seleziona]
$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.

Codice: [Seleziona]

<?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->addScriptJURI::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'));
?>



« Ultima modifica: 14 Feb 2011, 09:45:58 da webbati »

Offline webbati

  • Esploratore
  • **
  • Post: 116
    • Mostra profilo
Re:modulo phocadownload tree [aggiornamento]
« Risposta #1 il: 21 Feb 2011, 14:16:23 »
Ok, visto che alla fine mi serviva ho scritto anche le modifiche perchè non si fermi al secondo livello ma che inserisca nell'albero tutte le categorie e subcategorie.
Se a qualcuno serve appeno a 5 min. posto le modifiche.

Offline webbati

  • Esploratore
  • **
  • Post: 116
    • Mostra profilo
Re:modulo phocadownload tree
« Risposta #2 il: 21 Feb 2011, 17:30:39 »
ok. allora, ho modificato il modulo in modo che mostri tutte le  categorie e relative sottocategorie.
Ho creato una nuova directory in   (modules/mod_phocadownload_tree/helpers) ed all'interno ho creato un file chiamato "mod_phocadownload_tree.php" contenente il seguente codice:

Codice: [Seleziona]
<?php
defined
('_JEXEC') or die();



class 
PhocaDownloadTree

{


function getCats(){


$db =& JFactory::getDBO();

$query "SELECT * FROM #__phocadownload_categories ORDER BY parent_id";

$db->setQuery($query);

$cats $db->loadObjectList();

return $cats;
}


function getSubCats$pid ) {

$db =& JFactory::getDBO();

$query "SELECT * FROM #__phocadownload_categories WHERE parent_id = '".$pid."' ORDER BY id";

$subCats $db->loadObjectList();

return $subCats;


}

}
?>






ed ho modificao il file d'entrata del modulo "mod_phocadownload_tree.php" in "modules/mod_phocadownload_tree/" in:

Codice: [Seleziona]

<?php
/*
 * @package Joomla 1.5
 * 
 * modified version for Joomla 1.6 by webbati 
 * 
 * @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.'modules'.DS.'mod_phocadownload_tree'.DS.'helpers'.DS.'mod_phocadownload_tree.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->addScriptJURI::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 PhocaDownloadTree

// Params
$hideC $params->get'hide_categories''');
$hideS $params->get'hide_sections''' );


$aid  $user->get('aid'0);


$miecats $categorie->getCats();

$tree  = array();
$newIdSec = array();
$newIdCat = array();
$userAID $user->get('aid'0);
$userID $user->get('id'0);


foreach (
$miecats as $miecat){



if ($miecat->parent_id == '0'){

$link JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($miecat->id$miecat->alias));
$tree[] =  $treeId.'.add('.$miecat->id.', 0 ,\''.addslashes($miecat->title).'\',\''.$link.'\');'."\n";
$newIdSec[$miecat->id] = $miecat->id;


$subcats $categorie->getSubCats($miecat->id);

foreach ($subcats as $subcat){
if ($subcat->parent_id != '0'){

$link JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($subcat->id$subcat->alias$subcat->id));
$tree[] =  $treeId.'.add('.$subcat->id.','.$subcat->parent_id .',\''.addslashes($subcat->title).'\',\''.$link.'\');'."\n";
$newIdCat[$subcat->id] = $subcat->id;



// fine if subcat


// fine foreach subcats

// fine if 

// fine foreach  miecats

// 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 == 'categories' ) {
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::_'Download' ).'\',\''.$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'));
?>






spero serva a qualcuno,
ciao ciao

« Ultima modifica: 22 Feb 2011, 09:23:16 da webbati »

 



Web Design Bolzano Kreatif