Skip to content

Commit b830ab2

Browse files
author
Ilyas Ronef
committed
Version 1.2
2 parents f8355ec + e64ca94 commit b830ab2

4 files changed

Lines changed: 179 additions & 125 deletions

File tree

ddselectdocuments/ddselectdocuments.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@
2525
color: #FFFFFF;
2626
}
2727

28-
.ui-helper-hidden-accessible {display: none;}
28+
.ui-helper-hidden-accessible {display: none;}
29+
30+
.ddMultipleInput > span {
31+
overflow: hidden;
32+
vertical-align: middle;
33+
}
34+
.ddMultipleInput_dropPlaceholder {
35+
display: inline-block !important;
36+
overflow: hidden;
37+
vertical-align: middle;
38+
}
Lines changed: 145 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,147 @@
1-
<?php
2-
/**
3-
* mm_ddSelectDocuments
4-
* @version 1.1b (2013-08-09)
5-
*
6-
* @desc A widget for ManagerManager that makes selection of documents ids easier.
7-
*
8-
* @uses ManagerManager 0.5.1.
9-
*
10-
* @param $tvs {comma separated string} - TVs names that the widget is applied to. @required
11-
* @param $roles {comma separated string} - Roles that the widget is applied to (when this parameter is empty then widget is applied to the all roles). Default: ''.
12-
* @param $templates {comma separated string} - Templates IDs for which the widget is applying (empty value means the widget is applying to all templates). Default: ''.
13-
* @param $parentIds {comma separated string} - Parent documents IDs. @required
14-
* @param $depth {integer} - Depth of search. Default: 1.
15-
* @param $filter {separated string} - Filter clauses, separated by '&' between pairs and by '=' between keys and values. For example, 'template=15&published=1' means to choose the published documents with template id=15. Be advised that you can't filter by TVs values. Default: ''.
16-
* @param $max {integer} - The largest number of elements that can be selected by user (“0” means selection without a limit). Default: 0.
17-
*
18-
* @link http://code.divandesign.biz/modx/mm_ddselectdocuments/1.1b
19-
*
20-
* @copyright 2013, DivanDesign
21-
* http://www.DivanDesign.ru
22-
*/
23-
24-
function mm_ddSelectDocuments($tvs = '', $roles = '', $templates = '', $parentIds, $depth = 1, $filter = '', $max = 0){
25-
global $modx, $mm_current_page;
26-
$e = &$modx->Event;
27-
28-
if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates) && !empty($parentIds)){
29-
$output = '';
30-
31-
$tvs = tplUseTvs($mm_current_page['template'], $tvs);
32-
if ($tvs == false){return;}
33-
1+
<?php
2+
/**
3+
* mm_ddSelectDocuments
4+
* @version 1.2 (2013-12-11)
5+
*
6+
* @desc A widget for ManagerManager that makes selection of documents ids easier.
7+
*
8+
* @uses ManagerManager 0.6.
9+
* @uses ddTools 0.10.
10+
*
11+
* @param $tvs {comma separated string} - TVs names that the widget is applied to. @required
12+
* @param $roles {comma separated string} - Roles that the widget is applied to (when this parameter is empty then widget is applied to the all roles). Default: ''.
13+
* @param $templates {comma separated string} - Templates IDs for which the widget is applying (empty value means the widget is applying to all templates). Default: ''.
14+
* @param $parentIds {comma separated string} - Parent documents IDs. @required
15+
* @param $depth {integer} - Depth of search. Default: 1.
16+
* @param $filter {separated string} - Filter clauses, separated by '&' between pairs and by '=' between keys and values. For example, 'template=15&published=1' means to choose the published documents with template id=15. Default: ''.
17+
* @param $max {integer} - The largest number of elements that can be selected by user (“0” means selection without a limit). Default: 0.
18+
* @param $labelMask {string} - Template to be used while rendering elements of the document selection list. It is set as a string containing placeholders for document fields and TVs. Also, there is the additional placeholder “[+title+]” that is substituted with either “menutitle” (if defined) or “pagetitle”. Default: '[+title+] ([+id+])'.
19+
*
20+
* @event OnDocFormPrerender
21+
* @event OnDocFormRender
22+
*
23+
* @link http://code.divandesign.biz/modx/mm_ddselectdocuments/1.2
24+
*
25+
* @copyright 2013, DivanDesign
26+
* http://www.DivanDesign.ru
27+
*/
28+
29+
function mm_ddSelectDocuments($tvs = '', $roles = '', $templates = '', $parentIds, $depth = 1, $filter = '', $max = 0, $labelMask = '[+title+] ([+id+])'){
30+
if (empty($parentIds) || !useThisRule($roles, $templates)){return;}
31+
32+
global $modx;
33+
$e = &$modx->Event;
34+
35+
$output = '';
36+
37+
if ($e->name == 'OnDocFormPrerender'){
38+
$pluginDir = $modx->config['site_url'].'assets/plugins/managermanager/';
39+
$widgetDir = $pluginDir.'widgets/ddselectdocuments/';
40+
41+
$output .= includeJsCss($widgetDir.'ddselectdocuments.css', 'html');
42+
$output .= includeJsCss($pluginDir.'js/jquery-ui-1.10.3.min.js', 'html', 'jquery-ui', '1.10.3');
43+
$output .= includeJsCss($widgetDir.'jquery.ddMultipleInput-1.2.min.js', 'html', 'jquery.ddMultipleInput', '1.2');
44+
45+
$e->output($output);
46+
}else if ($e->name == 'OnDocFormRender'){
47+
global $mm_current_page;
48+
49+
$tvs = tplUseTvs($mm_current_page['template'], $tvs);
50+
if ($tvs == false){return;}
51+
3452
$filter = ddTools::explodeAssoc($filter, '&', '=');
35-
36-
//Рекурсивно получает все необходимые документы
37-
if (!function_exists('ddGetDocs')){function ddGetDocs($parentIds = array(0), $filter = array(), $depth = 1){
38-
//Получаем дочерние документы текущего уровня
39-
$docs = array();
40-
41-
//Перебираем всех родителей
42-
foreach ($parentIds as $parent){
43-
//Получаем документы текущего родителя
44-
$tekDocs = ddTools::getDocumentChildren($parent, false);
45-
46-
//Если что-то получили
47-
if (is_array($tekDocs)){
48-
//Запомним
49-
$docs = array_merge($docs, $tekDocs);
50-
}
51-
}
52-
53-
$result = array();
54-
55-
//Если что-то есть
56-
if (count($docs) > 0){
57-
//Перебираем полученные документы
58-
foreach ($docs as $val){
59-
//Если фильтр пустой, либо не пустой и документ удовлетворяет всем условиям
60-
if (empty($filter) || count(array_intersect_assoc($filter, $val)) == count($filter)){
61-
//Записываем результат
62-
$result[] = array('label' => $val['pagetitle'].' ('.$val['id'].')', 'value' => $val['id']);
63-
}
64-
65-
//Если ещё надо двигаться глубже
66-
if ($depth > 1){
67-
//Сливаем результат с дочерними документами
68-
$result = array_merge($result, ddGetDocs(array($val['id']), $filter, $depth - 1));
69-
}
70-
}
71-
}
72-
73-
return $result;
74-
}}
75-
76-
//Получаем все дочерние документы
77-
$docs = ddGetDocs(explode(',', $parentIds), $filter, $depth);
78-
79-
if (count($docs) == 0){return;}
80-
81-
$pluginDir = $modx->config['site_url'].'assets/plugins/managermanager/';
82-
$widgetDir = $pluginDir.'widgets/ddselectdocuments/';
83-
84-
$output .= "// ---------------- mm_ddSelectDocuments :: Begin ------------- \n";
85-
//General functions
86-
$output .= '
87-
'.includeCss($widgetDir.'ddselectdocuments.css').'
88-
'.includeJs($pluginDir.'js/jquery.ddTools-1.8.1.min.js', 'js', 'jquery.ddTools', '1.8.1').'
89-
'.includeJs($pluginDir.'js/jquery-ui-1.10.3.min.js', 'js', 'jquery-ui', '1.10.3').'
90-
'.includeJs($widgetDir.'jquery.ddMultipleInput-1.1.min.js', 'js', 'jquery.ddMultipleInput', '1.1').'
91-
';
92-
93-
foreach ($tvs as $tv){
94-
$output .= '
95-
$j("#tv'.$tv['id'].'").ddMultipleInput({source: $j.parseJSON(\''.json_encode($docs).'\'), max: '.$max.'});
96-
';
97-
}
98-
99-
$output .= "\n// ---------------- mm_ddSelectDocuments :: End -------------";
100-
101-
$e->output($output."\n");
102-
}
103-
}
53+
54+
//Необходимые поля
55+
preg_match_all('~\[\+([^\+\]]*?)\+\]~', $labelMask, $matchField);
56+
57+
$fields = array_unique(array_merge(array_keys($filter), array('pagetitle', 'id'), $matchField[1]));
58+
59+
if (($title_pos = array_search('title', $fields)) !== false){
60+
unset($fields[$title_pos]);
61+
$fields = array_unique(array_merge($fields, array('menutitle')));
62+
}
63+
64+
//Рекурсивно получает все необходимые документы
65+
if (!function_exists('ddGetDocs')){function ddGetDocs($parentIds = array(0), $filter = array(), $depth = 1, $labelMask = '[+pagetitle+] ([+id+])', $fields = array('pagetitle', 'id')){
66+
//Получаем дочерние документы текущего уровня
67+
$docs = array();
68+
69+
//Перебираем всех родителей
70+
foreach ($parentIds as $parent){
71+
//Получаем документы текущего родителя
72+
$tekDocs = ddTools::getDocumentChildrenTVarOutput($parent, $fields, false);
73+
74+
//Если что-то получили
75+
if (is_array($tekDocs)){
76+
//Запомним
77+
$docs = array_merge($docs, $tekDocs);
78+
}
79+
}
80+
81+
$result = array();
82+
83+
//Если что-то есть
84+
if (count($docs) > 0){
85+
//Перебираем полученные документы
86+
foreach ($docs as $val){
87+
//Если фильтр пустой, либо не пустой и документ удовлетворяет всем условиям
88+
if (empty($filter) || count(array_intersect_assoc($filter, $val)) == count($filter)){
89+
$val['title'] = empty($val['menutitle']) ? $val['pagetitle'] : $val['menutitle'];
90+
91+
//Записываем результат
92+
$tmp = ddTools::parseText($labelMask, $val, '[+', '+]', false);
93+
94+
if (strlen(trim($tmp)) == 0){
95+
$tmp = ddTools::parseText('[+pagetitle+] ([+id+])', $val, '[+', '+]', false);
96+
}
97+
98+
$result[] = array(
99+
'label' => $tmp,
100+
'value' => $val['id']
101+
);
102+
}
103+
104+
//Если ещё надо двигаться глубже
105+
if ($depth > 1){
106+
//Сливаем результат с дочерними документами
107+
$result = array_merge($result, ddGetDocs(array($val['id']), $filter, $depth - 1, $labelMask, $fields));
108+
}
109+
}
110+
}
111+
112+
return $result;
113+
}}
114+
115+
//Получаем все дочерние документы
116+
$docs = ddGetDocs(explode(',', $parentIds), $filter, $depth, $labelMask, $fields);
117+
118+
if (count($docs) == 0){return;}
119+
120+
if (version_compare(PHP_VERSION, '5.4.0') >= 0){
121+
$jsonDocs = json_encode($docs, JSON_UNESCAPED_UNICODE);
122+
}else{
123+
$jsonDocs = preg_replace_callback(
124+
'/\\\\u([0-9a-f]{4})/i',
125+
function ($matches){
126+
$sym = mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
127+
return $sym;
128+
},
129+
json_encode($docs)
130+
);
131+
}
132+
133+
$output .= "//---------- mm_ddSelectDocuments :: Begin -----\n";
134+
135+
foreach ($tvs as $tv){
136+
$output .=
137+
'
138+
$j("#tv'.$tv['id'].'").ddMultipleInput({source: '.$jsonDocs.', max: '.$max.'});
139+
';
140+
}
141+
142+
$output .= "//---------- mm_ddSelectDocuments :: End -----\n";
143+
144+
$e->output($output);
145+
}
146+
}
104147
?>

ddselectdocuments/jquery.ddMultipleInput-1.1.min.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

ddselectdocuments/jquery.ddMultipleInput-1.2.min.js

Lines changed: 23 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)