Skip to content

Commit bf165d0

Browse files
author
Ilyas Ronef
committed
Initial commit
0 parents  commit bf165d0

5 files changed

Lines changed: 147 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# mm_ddSelectDocuments
2+
3+
Visit the following [link](http://code.divandesign.biz/modx/mm_ddselectdocuments) to read the documentation, instructions & changelog.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.ui-autocomplete {
2+
display: block;
3+
max-height: 300px;
4+
padding: 0;
5+
z-index: 3;
6+
border: 1px solid #C8C8C8;
7+
margin: 0;
8+
overflow-x: hidden;
9+
overflow-y: scroll;
10+
position: absolute;
11+
background: #FFFFFF;
12+
}
13+
14+
.ui-autocomplete li {list-style: none;}
15+
16+
.ui-autocomplete a {
17+
display: block;
18+
padding: 0 3px 1px;
19+
text-decoration: none;
20+
cursor: pointer;
21+
}
22+
23+
.ui-autocomplete a:hover, .ui-autocomplete .ui-state-focus {
24+
background: #007CC3;
25+
color: #FFFFFF;
26+
}
27+
28+
.ui-helper-hidden-accessible {display: none;}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* mm_ddSelectDocuments
4+
* @version 1.0b (2013-05-30)
5+
*
6+
* @description Виджет для выбора id определённых документов в удобном виде.
7+
*
8+
* @uses ManagerManager 0.5.
9+
*
10+
* @param $tvs {comma separated string} - Имена TV, для которых необходимо применить виджет. @required
11+
* @param $roles {comma separated string} - Роли, для которых необходимо применить виждет, пустое значение — все роли. По умолчанию: ''.
12+
* @param $templates {comma separated string} - Id шаблонов, для которых необходимо применить виджет, пустое значение — все шаблоны. По умолчанию: ''.
13+
* @param $parentId {integer} - Id родительского документа, дочерние документы которого необходимо выбирать. @required
14+
* @param $depth {integer} - Глубина поиска дочерних документов. По умолчанию: 1.
15+
* @param $filter {separated string} - Условия фильтрации документов (чем-то похож на фильтр Ditto), разделённые через '&' между парами и через '=' между ключом и значением. Например: 'template=15&published=1', — получим только опубликованные документы с id шаблона 15. В фильтрации могут участвовать только поля документа (без TV). По умолчанию: ''.
16+
* @param $max {integer} - Максимальное количество документов, которое пользователь может выбрать (при == 0 — без ограничений). По умолчанию: 0.
17+
*
18+
* @link http://code.divandesign.biz/modx/mm_ddselectdocuments/1.0b
19+
*
20+
* @copyright 2013, DivanDesign
21+
* http://www.DivanDesign.ru
22+
*/
23+
24+
function mm_ddSelectDocuments($tvs = '', $roles = '', $templates = '', $parentId, $depth = 1, $filter = '', $max = 0){
25+
global $modx, $mm_current_page;
26+
$e = &$modx->Event;
27+
28+
if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates) && is_numeric($parentId)){
29+
$output = '';
30+
31+
$tvs = tplUseTvs($mm_current_page['template'], $tvs);
32+
if ($tvs == false){return;}
33+
34+
$filter = ddTools::explodeAssoc($filter, '&', '=');
35+
36+
//Рекурсивно получает все необходимые документы
37+
if (!function_exists('ddGetDocs')){function ddGetDocs($parentId = 0, $filter = array(), $depth = 1){
38+
//Получаем дочерние документы текущего уровня
39+
$docs = ddTools::getDocumentChildren($parentId, false);
40+
41+
$result = array();
42+
43+
//Если что-то есть
44+
if ($docs && count($docs) > 0){
45+
//Перебираем полученные документы
46+
foreach ($docs as $val){
47+
//Если фильтр пустой, либо не пустой и документ удовлетворяет всем условиям
48+
if (empty($filter) || count(array_intersect_assoc($filter, $val)) == count($filter)){
49+
//Записываем результат
50+
$result[] = array('label' => $val['pagetitle'].' ('.$val['id'].')', 'value' => $val['id']);
51+
}
52+
53+
//Если ещё надо двигаться глубже
54+
if ($depth > 1){
55+
//Сливаем результат с дочерними документами
56+
$result = array_merge($result, ddGetDocs($val['id'], $filter, $depth - 1));
57+
}
58+
}
59+
}
60+
61+
return $result;
62+
}}
63+
64+
//Получаем все дочерние документы
65+
$docs = ddGetDocs($parentId, $filter, $depth);
66+
67+
if (count($docs) == 0){return;}
68+
69+
$pluginDir = $modx->config['site_url'].'assets/plugins/managermanager/';
70+
$widgetDir = $pluginDir.'widgets/ddselectdocuments/';
71+
72+
$output .= "// ---------------- mm_ddSelectDocuments :: Begin ------------- \n";
73+
//General functions
74+
$output .= '
75+
'.includeCss($widgetDir.'ddselectdocuments.css').'
76+
'.includeJs($pluginDir.'js/jquery.ddTools-1.8.1.min.js', 'js', 'jquery.ddTools', '1.8.1').'
77+
'.includeJs($pluginDir.'js/jquery-ui-1.10.3.min.js', 'js', 'jquery-ui', '1.10.3').'
78+
'.includeJs($widgetDir.'jquery.ddMultipleInput-1.1.min.js', 'js', 'jquery.ddMultipleInput', '1.1').'
79+
';
80+
81+
foreach ($tvs as $tv){
82+
$output .= '
83+
$j("#tv'.$tv['id'].'").ddMultipleInput({source: $j.parseJSON(\''.json_encode($docs).'\'), max: '.$max.'});
84+
';
85+
}
86+
87+
$output .= "\n// ---------------- mm_ddSelectDocuments :: End -------------";
88+
89+
$e->output($output."\n");
90+
}
91+
}
92+
?>

ddselectdocuments/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h2>Unauthorized access</h2>
2+
You're not allowed to access file folder

ddselectdocuments/jquery.ddMultipleInput-1.1.min.js

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)