Skip to content

Commit 1f02a33

Browse files
author
Andrey Demchenko
committed
Version 1.5
2 parents ae47549 + dc183a8 commit 1f02a33

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

ddselectdocuments/ddselectdocuments.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
22
/**
33
* mm_ddSelectDocuments
4-
* @version 1.4 (2016-11-04)
4+
* @version 1.5 (2016-12-20)
55
*
66
* @desc A widget for ManagerManager that makes selection of documents ids easier.
77
*
88
* @uses PHP >= 5.4.
99
* @uses MODXEvo.plugin.ManagerManager >= 0.7.
1010
*
1111
* @param $params {array_associative|stdClass} — The object of params. @required
12-
* @param $params['fields'] {string_commaSeparated} — TVs names that the widget is applied to. @required
13-
* @param $params['parentIds'] {string_commaSeparated} — Parent documents IDs. Default: '0'.
12+
* @param $params['fields'] {string_commaSeparated|array} — TVs names that the widget is applied to. @required
13+
* @param $params['parentIds'] {string_commaSeparated|array} — Parent documents IDs. Default: '0'.
14+
* @param $params['parentIds'][i] {integer|'current'} — IDs or current document Id. Default: '0'.
1415
* @param $params['depth'] {integer} — Depth of search. Default: 1.
1516
* @param $params['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: ''.
1617
* @param $params['listItemLabelMask'] {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+])'.
@@ -22,7 +23,7 @@
2223
* @event OnDocFormPrerender
2324
* @event OnDocFormRender
2425
*
25-
* @link http://code.divandesign.biz/modx/mm_ddselectdocuments/1.4
26+
* @link http://code.divandesign.biz/modx/mm_ddselectdocuments/1.5
2627
*
2728
* @copyright 2013–2016 DivanDesign {@link http://www.DivanDesign.biz }
2829
*/
@@ -88,6 +89,24 @@ function mm_ddSelectDocuments($params){
8889
$params->fields = tplUseTvs($mm_current_page['template'], $params->fields);
8990
if ($params->fields == false){return;}
9091

92+
$params->parentIds = makeArray($params->parentIds);
93+
//Если используется current, то сделаем id текущего документа
94+
foreach ($params->parentIds as $key => $id){
95+
if ($id == 'current'){
96+
if (
97+
is_array($e->params) &&
98+
isset($e->params['id']) &&
99+
is_numeric($e->params['id'])
100+
){
101+
$params->parentIds[$key] = $e->params['id'];
102+
}else{
103+
unset($params->parentIds[$key]);
104+
}
105+
}
106+
}
107+
//Может быть пустым если указан current и создаем новый документ
108+
if (count($params->parentIds) == 0){return;}
109+
91110
$params->filter = ddTools::explodeAssoc($params->filter, '&', '=');
92111

93112
//Необходимые поля
@@ -108,7 +127,7 @@ function mm_ddSelectDocuments($params){
108127

109128
//Получаем все дочерние документы
110129
$listDocs = mm_ddSelectDocuments_getDocsList([
111-
'parentIds' => explode(',', $params->parentIds),
130+
'parentIds' => $params->parentIds,
112131
'filter' => $params->filter,
113132
'depth' => $params->depth,
114133
'listItemLabelMask' => $params->listItemLabelMask,

0 commit comments

Comments
 (0)