-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ilyas Ronef
committed
Nov 5, 2014
0 parents
commit e5d2293
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# ddGetParentId | ||
|
||
Gets the parent ID of the required level. | ||
___ | ||
Visit the following [link](http://code.divandesign.biz/modx/ddgetparentid) to read the documentation, instructions & changelog. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* ddGetParentId.php | ||
* @version 1.0 (2011-12-18) | ||
* | ||
* @desc Gets the parent ID of the required level. | ||
* | ||
* @param $id {integer} - Document Id. Default: [*id*]. | ||
* @param $level {integer; string} - Parent level (1 — the immediate parent, 'ultimate' — the last). Default: 1. | ||
* @param $tpl {string} - Template (chunk name) for output. Available placeholders: [+id+]. Default: —. | ||
* @param $toPlaceholder {0; 1} - Returns value to the placeholder. Default: 0. | ||
* @param $placeholderName {string} - Placeholder name. Default: 'ddParent'. | ||
* | ||
* @link http://code.divandesign.biz/modx/ddgetparentid/1.0 | ||
* | ||
* @copyright 2011, DivanDesign | ||
* http://www.DivanDesign.biz | ||
*/ | ||
|
||
$id = isset($id) ? $id : $modx->documentIdentifier; | ||
$level = isset($level) ? $level : 1; | ||
$toPlaceholder = (isset($toPlaceholder) && $toPlaceholder == '1') ? true : false; | ||
$placeholderName = isset($placeholderName) ? $placeholderName : 'ddParent'; | ||
|
||
//Если нужно получить самый последний, задаём глубину 10 | ||
if ($level == 'ultimate'){$level = 10;} | ||
|
||
//Получаем последнего родителя | ||
$parent = array_pop($modx->getParentIds($id, $level)); | ||
|
||
//Если задан шаблон, выводим по шаблону | ||
if (isset($tpl)){$parent = $modx->parseChunk($tpl, array('id' => $parent),'[+','+]');} | ||
|
||
//Если надо, выводим в плэйсхолдер, или просто возвращаем | ||
if ($toPlaceholder){ | ||
$modx->setPlaceholder($placeholderName, $parent); | ||
}else{ | ||
return $parent; | ||
} | ||
?> |