-
-
Save Fi1osof/ff3ea018841b1bb1f99b to your computer and use it in GitHub Desktop.
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 | |
| include_once dirname(__FILE__).'/update.class.php'; | |
| /** | |
| * Saves a property set | |
| * | |
| * @package modx | |
| * @subpackage processors.element.propertyset | |
| */ | |
| class modPropertySetUpdateFromElementProcessor extends modPropertySetUpdateProcessor { | |
| public $languageTopics = array('propertyset', 'category', 'element'); | |
| /** | |
| * {@inheritdoc} | |
| * @return bool|null|string | |
| */ | |
| public function initialize() { | |
| /* | |
| Определяем был ли передан ID набора параметров. | |
| Если да, то класс текущего объекта оставляем без изменений modPropertySet | |
| Если нет, то меняем класс на класс обновляемого элемента. | |
| То есть текущий элемент $this->object в зависимости от ситуации будет или modPropertySet или modTemplate|modSnippet и т.п. | |
| */ | |
| if(!$id = (int)$this->getProperty($this->primaryKeyField)){ | |
| if(!$elementType = $this->getProperty('elementType')){ | |
| return "Не был указан класс элемента"; | |
| } | |
| // else | |
| $this->classKey = $elementType; | |
| $id = (int)$this->getProperty('elementId'); | |
| switch($this->classKey){ | |
| } | |
| /* | |
| Здесь надо бы еще подключить соответствующие словари элементов | |
| */ | |
| } | |
| $this->setProperty($this->primaryKeyField, $id); | |
| return parent::initialize(); | |
| } | |
| /** | |
| * Return data as array | |
| * @return mixed | |
| */ | |
| public function getData() { | |
| return $this->modx->fromJSON($this->getProperty('data')); | |
| } | |
| public function beforeSet() { | |
| /* | |
| Необходимо установить эти значения, так как родительский процессор их перетирает, | |
| если не были переданы в параметры | |
| */ | |
| $this->setDefaultProperties(array( | |
| "name" => $this->object->get('name'), | |
| "category" => $this->object->get('category'), | |
| )); | |
| return parent::beforeSet(); | |
| } | |
| /** | |
| * Convert JSON data to array and unset default properties | |
| * @return bool | |
| */ | |
| public function beforeSave() { | |
| $this->object->setProperties($this->getData()); | |
| return parent::beforeSave();; | |
| } | |
| /** | |
| * Log the property set update from element manager action | |
| * @return void | |
| */ | |
| public function logManagerAction() { | |
| $key = $this->object ? $this->object->get($this->primaryKeyField) : | |
| $this->getProperty('elementType') . ' ' . $this->getProperty('elementId') . ' Default'; | |
| $this->modx->logManagerAction($this->objectType.'_update_from_element', $this->classKey, $key); | |
| } | |
| public function cleanup(){ | |
| return $this->success(''); | |
| } | |
| } | |
| return 'modPropertySetUpdateFromElementProcessor'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment