Вот сделал загрузку рубрикатора из файла csv в меню, модифицировав wayfinder.inc.php
Думаю пригодится, правда работает пока только с двумя уровнями вложенности в файле.
Описание полей файла на примере:
Array (
[id] => 1
[menutitle] => Home
[pagetitle] => Home
[introtext] => Create and do amazing things with MODx
[menuindex] => 1
[published] => 1
[hidemenu] => 0
[parent] => 0
[isfolder] => 0
[description] => Introduction to MODx
[alias] => index
[longtitle] => Welcome to MODx
[type] => document
[content] =>
[template] => 6
[link_attributes] => )
содержимое файла для примера:
100;test;test;;30;1;0;0;0;;test;test;document;;6;
101;test1;test1;;30;1;0;100;0;;test1;test1;document;;6;
102;test2;test2;;30;1;0;100;0;;test2;test2;document;;6;
нужно положить файл rubr.csv в каталог assets\Price
В скрипте wayfinder.inc.php заменяем функцию getData() и добавляем функцию getDataRow
в getData() также включил оптимизацию, подсмотренную на одной из веток форума...
//Get all of the documents from the database
function getData() {
global $modx;
$ids = array();
// Оптимизация
//$ids = $modx->getChildIds($this->_config['id'],$this->_config['level']);
if (!$this->_config['hideSubMenus']) {
$ids = $modx->getChildIds($this->_config['id'],$this->_config['level']);
} else { // then hideSubMenus is checked, we don`t need all children
$parents = $this->parentTree;
//remove parents higher than startId
$parents = array_diff($parents, $modx->getParentIds($this->_config['id']));
foreach($parents as $p)
$ids = $modx->getChildIds($p, 1, $ids);
}
//Get all of the ids for processing
if ($this->_config['displayStart'] && $this->_config['id'] !== 0) {
$ids[] = $this->_config['id'];
}
if (!empty($ids)) {
//Setup the fields for the query
$fields = "sc.id, sc.menutitle, sc.pagetitle, sc.introtext, sc.menuindex, sc.published, sc.hidemenu, sc.parent, sc.isfolder, sc.description, sc.alias, sc.longtitle, sc.type,if(sc.type='reference',sc.content,'') as content, sc.template, sc.link_attributes";
//Get the table names
$tblsc = $modx->getFullTableName("site_content");
$tbldg = $modx->getFullTableName("document_groups");
//Add the ignore hidden option to the where clause
if ($this->_config['ignoreHidden']) {
$menuWhere = '';
} else {
$menuWhere = ' AND sc.hidemenu=0';
}
//add the include docs to the where clause
if ($this->_config['includeDocs']) {
$menuWhere .= " AND sc.id IN ({$this->_config['includeDocs']})";
}
//add the exclude docs to the where clause
if ($this->_config['excludeDocs']) {
$menuWhere .= " AND (sc.id NOT IN ({$this->_config['excludeDocs']}))";
}
//add the limit to the query
if ($this->_config['limit']) {
$sqlLimit = " LIMIT 0, {$this->_config['limit']}";
} else {
$sqlLimit = '';
}
//Determine sorting
if (strtolower($this->_config['sortBy']) == 'random') {
$sort = 'rand()';
$dir = '';
} else {
// modify field names to use sc. table reference
$sort = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$this->_config['sortBy'])));
}
// get document groups for current user
if($docgrp = $modx->getUserDocGroups()) $docgrp = implode(",",$docgrp);
// build query
$access = ($modx->isFrontend() ? "sc.privateweb=0" : "1='{$_SESSION['mgrRole']}' OR sc.privatemgr=0").(!$docgrp ? "" : " OR dg.document_group IN ({$docgrp})");
$sql = "SELECT DISTINCT {$fields} FROM {$tblsc} sc LEFT JOIN {$tbldg} dg ON dg.document = sc.id WHERE sc.published=1 AND sc.deleted=0 AND ({$access}){$menuWhere} AND sc.id IN (".implode(',',$ids).") GROUP BY sc.id ORDER BY {$sort} {$this->_config['sortOrder']} {$sqlLimit};";
//run the query
$result = $modx->dbQuery($sql);
$numResults = @$modx->recordCount($result);
$level = 1;
//Setup startlevel for determining each items level
if ($this->_config['id'] == 0) {
$startLevel = 0;
} else {
$startLevel = count($modx->getParentIds($this->_config['id']));
$startLevel = $startLevel ? $startLevel+1 : 1;
}
$prevParent = -1;
$resourceArray = array();
$resultIds = array();
//loop through the results
for($i=0;$i<$numResults;$i++) {
$tempDocInfo = $modx->fetchRow($result);
$resultIds[] = $tempDocInfo['id'];
$tempDocInfo_ = array_keys ($tempDocInfo);
//determine the level, if parent has changed
if ($prevParent !== $tempDocInfo['parent']) {
$level = count($modx->getParentIds($tempDocInfo['id'])) + 1 - $startLevel;
}
//add parent to hasChildren array for later processing
if (($level > 1 || $this->_config['displayStart']) && !in_array($tempDocInfo['parent'],$this->hasChildren)) {
$this->hasChildren[] = $tempDocInfo['parent'];
}
//set the level
$tempDocInfo['level'] = $level;
$prevParent = $tempDocInfo['parent'];
$this->getDataRow($tempDocInfo,$resourceArray,$tempResults);
}
//add menu from file
$startLevel = 0;
$dir_price = "assets/Price/";
$fp = fopen ($dir_price."rubr.csv","r");
while ($data = fgetcsv ($fp, 1000, ";")) {
$tempDocInfo=array_combine($tempDocInfo_,$data);
$resultIds[] = $tempDocInfo['id'];
if ($prevParent !== $tempDocInfo['parent']) {
$level = 1 + 1 - $startLevel;
$prevParent = $tempDocInfo['parent'];
}
//add parent to hasChildren array for later processing
if (($level > 1 || $this->_config['displayStart']) && !in_array($tempDocInfo['parent'],$this->hasChildren)) {
$this->hasChildren[] = $tempDocInfo['parent'];
}
$tempDocInfo['level'] = $level;
$this->getDataRow($tempDocInfo,$resourceArray,$tempResults);
$row++;
}
fclose ($fp);
//Process the tvs
if (!empty($this->tvList) && !empty($resultIds)) {
$tvValues = array();
//loop through all tvs and get their values for each document
foreach ($this->tvList as $tvName) {
$tvValues = array_merge_recursive($this->appendTV($tvName,$resultIds),$tvValues);
}
//loop through the document array and add the tvar values to each document
foreach ($tempResults as $tempDocInfo) {
if (array_key_exists("#{$tempDocInfo['id']}",$tvValues)) {
foreach ($tvValues["#{$tempDocInfo['id']}"] as $tvName => $tvValue) {
$tempDocInfo[$tvName] = $tvValue;
}
}
$resourceArray[$tempDocInfo['level']][$tempDocInfo['parent']][] = $tempDocInfo;
}
}
}
//return final docs
return $resourceArray;
}
function getDataRow(&$tempDocInfo,&$resourceArray,&$tempResults) {
global $modx;
//Create the link
$linkScheme = $this->_config['fullLink'] ? 'full' : '';
if ($this->_config['useWeblinkUrl'] !== 'FALSE' && $tempDocInfo['type'] == 'reference') {
if (is_numeric($tempDocInfo['content'])) {
$tempDocInfo['link'] = $modx->makeUrl(intval($tempDocInfo['content']),'','',$linkScheme);
} else {
$tempDocInfo['link'] = $tempDocInfo['content'];
}
} elseif ($tempDocInfo['id'] == $modx->config['site_start']) {
$tempDocInfo['link'] = $modx->config['site_url'];
} else {
$tempDocInfo['link'] = $modx->makeUrl($tempDocInfo['id'],'','',$linkScheme);
}
//determine other output options
$useTextField = (empty($tempDocInfo[$this->_config['textOfLinks']])) ? 'pagetitle' : $this->_config['textOfLinks'];
$tempDocInfo['linktext'] = $tempDocInfo[$useTextField];
$tempDocInfo['title'] =$tempDocInfo[$this->_config['titleOfLinks']];
//If tvs were specified keep array flat otherwise array becomes level->parent->doc
if (!empty($this->tvList)) {
$tempResults[] = $tempDocInfo;
} else {
$resourceArray[$tempDocInfo['level']][$tempDocInfo['parent']][] = $tempDocInfo;
}
return;
}
Теперь надо бы универсальный модуль для обработки меню и вывода прайса по выбранной категории
и возможность обновления кэша по некой ссылке...