Created
May 5, 2017 06:29
-
-
Save vgrish/0e1e11fb7c5d2011dcbdae1d0b3438ee to your computer and use it in GitHub Desktop.
msOptionsColor
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 modX $modx */ | |
/** @var array $scriptProperties */ | |
switch ($modx->event->name) { | |
case 'OnDocFormSave': | |
/* | |
id ресурса откуда копируем | |
ключ опции которую копируем | |
*/ | |
$rid = 11984; | |
$key = 'memory'; | |
$mode = $modx->getOption('mode', $scriptProperties); | |
$resource = $modx->getOption('resource', $scriptProperties); | |
if ($mode != modSystemEvent::MODE_NEW) { | |
return; | |
} | |
$fqn = $modx->getOption('msoptionscolor_class', null, 'msoptionscolor.msoptionscolor', true); | |
$path = $modx->getOption('msoptionscolor_core_path', null, | |
$modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/msoptionscolor/'); | |
$msoptionscolor = $modx->getService( | |
$fqn, | |
'', | |
$path . 'model/', | |
array('core_path' => $path) | |
); | |
if (!$msoptionscolor) { | |
return; | |
} | |
$msoptionscolor->initialize($modx->context->key); | |
if (!$msoptionscolor->isWorkingClassKey($resource) | |
OR | |
!$msoptionscolor->isWorkingTemplates($resource) | |
) { | |
return; | |
} | |
$class = 'msocColor'; | |
$q = $modx->newQuery($class); | |
$q->where(array('rid' => $rid, 'key' => $key)); | |
/** @var xPDOObject|$color */ | |
foreach ($modx->getIterator($class, $q) as $color) { | |
$msoptionscolor->setProductOptions($resource->get('id'), array($key => $color->get('value'))); | |
/** @var xPDOObject $o */ | |
$o = $modx->newObject($class); | |
$o->fromArray($color->toArray(), '', true); | |
$o->set('rid', $resource->get('id')); | |
$o->save(); | |
} | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment