Created
June 25, 2015 07:31
-
-
Save Dmi3yy/2aa3a8e3add17b59afbb to your computer and use it in GitHub Desktop.
tvs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Получает имена и значения всех TV в одной категории для указанного документа | |
* | |
* version: 0.2 | |
* | |
* Author: | |
* darksmoke from modx.im | |
* [email protected] | |
* | |
* Параметры: | |
* &cat - Название категории в которой хранятся TV | |
* &id_doc - ID документа TV которого хотим получить | |
* ¬v - Исключить вывод TV | |
* | |
* Плейсхолдеры: | |
* [+name+] - Имя TV | |
* [+value+] - Значение TV | |
* [+locked+] - Показывает ограничен ли доступ к редактированию, возвращает 0 - не ограничен, 1 - ограничен | |
* | |
* Пример: [!tvs? &cat=`Фирма` &id_doc=`[+id+]` &tpl=`tvs` ¬v=`photo,email` !] | |
* | |
*/ | |
if(!$modx->getChunk($tpl)) | |
echo '<div style="color: red">Не создан чанк!</div>'; | |
$sql = $modx->db->select("id", $modx->getFullTableName('categories'), "category = '" . $cat ."'", 1); | |
$catID = $modx->db->getRow($sql); | |
$sql2 = $modx->db->query("SELECT * FROM ". $modx->getFullTableName('site_tmplvar_contentvalues') ." JOIN ". $modx->getFullTableName('site_tmplvars') ." ON ". $modx->getFullTableName('site_tmplvar_contentvalues').".`tmplvarid`= ". $modx->getFullTableName('site_tmplvars') .".id WHERE ". $modx->getFullTableName('site_tmplvar_contentvalues') .".`contentid`=". $id_doc ." AND ". $modx->getFullTableName('site_tmplvars') .".category = ".$catID['id']." "); | |
while( $row = $modx->db->getRow($sql2) ) { | |
$docID[] = $row['tmplvarid']; | |
} | |
$tv= $modx->getTemplateVars($docID, '*', $id_doc); | |
if(!empty($notv)){ | |
$notv = explode(',', $notv); | |
if(is_array($notv)){ | |
foreach($notv as $key => $value){ | |
$notv[] = trim($value); | |
} | |
} | |
if(is_array($tv)){ | |
foreach($tv as $k => $el) { | |
if (in_array($el['name'], $notv)) | |
unset($tv[$k]); | |
} | |
$tv = array_values($tv); | |
} | |
} | |
for($i=0; $i<count($tv); $i++){ | |
$output2 .= $modx->parseChunk($tpl, $tv[$i], '[+', '+]' ); | |
} | |
return $output2; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment