Forked from sepiariver/setResourceProps.plugin.php
Created
December 21, 2017 12:13
-
-
Save Burick/67ea583d5f342a5050d6bcb6c1f19683 to your computer and use it in GitHub Desktop.
Sets Resource properties OnDocFormSave. To be used with getResourceProps.snippet.php
This file contains hidden or 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
<?php | |
/** | |
* | |
* @author @sepiariver | |
* | |
**/ | |
if ($modx->context->get('key') !== 'mgr' || $modx->event->name !== 'OnDocFormSave') return; | |
if (!($resource instanceof modResource)) { | |
$modx->log(modX::LOG_LEVEL_ERROR, 'setResourceProps Plugin did not have access to a valid resource object on line: ' . __LINE__); | |
return; | |
} | |
// set default namespace for legacy content from modx.com import | |
$namespace = $modx->getOption('namespace', $scriptProperties, 'customprops'); | |
// This is custom and would be modified per-implementation | |
// Set previously published and next article | |
$pC = $modx->newQuery('modResource'); | |
$pC->select('id'); | |
$pC->where(array( | |
'parent:=' => $resource->get('parent'), | |
'template:=' => $resource->get('template'), | |
'publishedon:<' => $resource->publishedon, | |
'deleted' => 0, | |
)); | |
$pC->sortby('publishedon', 'DESC'); | |
$pC->limit(1); | |
$nC = $modx->newQuery('modResource'); | |
$nC->select('id'); | |
$nC->where(array( | |
'parent:=' => $resource->get('parent'), | |
'template:=' => $resource->get('template'), | |
'publishedon:>' => $resource->publishedon, | |
'deleted' => 0, | |
)); | |
$nC->sortby('publishedon', 'ASC'); | |
$nC->limit(1); | |
$props = array( | |
'prev' => $modx->getValue($pC->prepare()), | |
'next' => $modx->getValue($nC->prepare()), | |
); | |
$resource->setProperties($props, $namespace); | |
$resource->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment