Last active
January 11, 2017 17:07
-
-
Save vgrish/97db0f633e9bbe390f367ea148dfa0b3 to your computer and use it in GitHub Desktop.
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
<?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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
вызов сниппета, можно указать resource,user,date,active
вызов как модификатора