$modx->getParentIds($id);
<?php
/**
* create pdf doc on save from resource
*
* only toplevel resources are used as child resources will be sub items pulled in by getResources
*
*/
///get proper url to build pdf from
$url = $modx->makeUrl($id);
$parentIds = implode('-', $modx->getParentIds($id));
//$parentId = $resource->get('parent');
///get alias to name pdf file
$name = $resource->get('alias');
///build shell command
$cmd = '/usr/local/bin/wkhtmltopdf -q --margin-bottom 18mm --footer-html http://domain.tld/control/footer.html '.$url.' /var/www/vhosts/domain.tld/httpdocs/control/pdf/'.$name.'-'.$parentIds.'_'.$id.'.pdf';
///run the command
shell_exec($cmd);
<?php
/* will tell you if it's a child or not */
if ($resource->get('parent'))
/* get the parent object */
parentObj->getOne('Parent');
/* is there a grandparent? */
($parentObj->get('parent'))
//etc.
so went for the two stage check as this case is unlikely the have any third level documents.<?php
/**
* create pdf doc on save from resource systemEvent:OnDocFormSave
*
* only toplevel resources are used as child resources will be sub items pulled in by getResources
*
* does not work for NEW documents!?
*
*/
/**
* check if resource is a top level doc or a child
*
* @param $res $modx->resource:object
* @return top resourse id:int
*/
function topparentid($res)
{
if($res->get('parent') < 1)
{
return $res->get('id');
}
else
{
$parent = $res->getOne('Parent');
if($parent->get('parent') < 1)
{
return $parent->get('id');
}
else
{
$grandparent = $parent->getOne('Parent');
return $grandparent->get('id');
}
}
}
$resId = topparentid($resource);
///get proper url to build pdf from
$url = $modx->makeUrl($resId);
//$parentIds = implode('-', $modx->getParentIds($id));
//$parentId = $resource->get('parent');
///get alias to name pdf file
$name = $modx->getObject('modResource', $resId)->get('alias');
///build shell command
//$cmd = '/usr/local/bin/wkhtmltopdf -q --margin-bottom 18mm --footer-html http://domain.tld/control/footer.html '.$url.' /var/www/vhosts/domain.tld/httpdocs/control/pdf/'.$name.'-'.$resId.'_'.$id.'.pdf';
$cmd = '/usr/local/bin/wkhtmltopdf -q --margin-bottom 18mm --footer-html http://domain.tld/control/footer.html '.$url.' /var/www/vhosts/domain.tld/httpdocs/control/pdf/'.$name.'.pdf';
///run the command
shell_exec($cmd);$modx->getParentIds($id, 10, array('context' => 'web'));