Skip to content

Instantly share code, notes, and snippets.

@vgrish
Last active January 11, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrish/97db0f633e9bbe390f367ea148dfa0b3 to your computer and use it in GitHub Desktop.
Save vgrish/97db0f633e9bbe390f367ea148dfa0b3 to your computer and use it in GitHub Desktop.
<?php
/* @var array $scriptProperties */
/* @var payandsee $payandsee */
if (!function_exists('explodeAndClean')) {
function explodeAndClean($array, $delimiter = ',')
{
$array = explode($delimiter, $array); // Explode fields to array
$array = array_map('trim', $array); // Trim array's values
$array = array_keys(array_flip($array)); // Remove duplicate fields
$array = array_filter($array); // Remove empty values from array
return $array;
}
}
$input = $modx->getOption('input', $scriptProperties);
$options = $modx->getOption('options', $scriptProperties, '', true);
parse_str($options, $options);
foreach ((array)$options as $k => $v) {
$scriptProperties[$k] = $v;
}
$user = explodeAndClean($modx->getOption('user', $scriptProperties, $modx->user->id, true));
$resource = explodeAndClean($modx->getOption('resource', $scriptProperties, $modx->resource->id, true));
$active = $modx->getOption('active', $scriptProperties, true, true);
$date = $modx->getOption('date', $scriptProperties, true, true);
$class = 'PaySeeList';
$q = $modx->newQuery('PaySeeList', array(
'resource_id:IN' => $resource,
'user_id:IN' => $user,
'active' => $active,
));
$q->select("{$class}.resource_id");
if ($date) {
$q->where(array('NOW() BETWEEN startdate AND stopdate'));
}
$check = (int)$modx->getCount($class, $q);
if (!empty($options)) {
return $check ? $input : ' ';
}
return $check;
@vgrish
Copy link
Author

vgrish commented Jan 11, 2017

вызов сниппета, можно указать resource,user,date,active

[[!psCheck? &resource=`15,6` &date=`1`]]

вызов как модификатора

[[*pagetitle:psCheck=`resource=15,6&date=1`]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment