Example #1
0
 /**
  * Sync template object
  */
 public final function sync()
 {
     $modTemplate = parent::_sync('modTemplate', array('templatename' => $this->getName()));
     if ($modTemplate) {
         $this->assignVariables();
         /* @var $tv ModSync\Element\Template\Variable\IsVariableInterface */
         foreach ($this->getVariables() as $tv) {
             $tvt = self::getModX()->getObject('modTemplateVarTemplate', array('tmplvarid' => $tv->getModTemplateVar()->get('id'), 'templateid' => $modTemplate->get('id')));
             if (!$tvt) {
                 $tvt = self::getModX()->newObject('modTemplateVarTemplate');
                 $tvt->set('tmplvarid', $tv->getModTemplateVar()->get('id'));
                 $tvt->set('templateid', $modTemplate->get('id'));
                 $tvt->set('rank', $tv->getModTemplateVar()->get('rank'));
                 $tvt->save();
             }
         }
     }
 }
Example #2
0
 /**
  * Syncs an element with modx
  */
 public final function sync()
 {
     $modTemplateVar = parent::_sync('modTemplateVar', array('name' => $this->getName()));
     if ($this->getSource() > 0) {
         if (!$modTemplateVar) {
             $modTemplateVar = self::getModTemplateVar();
         }
         $sourceElements = self::getModX()->getCollection('sources.modMediaSourceElement', array('object' => $modTemplateVar->get('id'), 'object_class' => 'modTemplateVar'));
         /** @var modMediaSourceElement $sourceElement */
         foreach ($sourceElements as $sourceElement) {
             $sourceElement->remove();
         }
         $contextElements = self::getModX()->getCollection('modContext', array('key:!=' => 'mgr'));
         foreach ($contextElements as $context) {
             /** @var modMediaSourceElement $sourceElement */
             $sourceElement = self::getModX()->newObject('sources.modMediaSourceElement');
             $sourceElement->set('object', $modTemplateVar->get('id'));
             $sourceElement->set('object_class', 'modTemplateVar');
             $sourceElement->set('context_key', $context->get('key'));
             $sourceElement->set('source', $this->getSource());
             $sourceElement->save();
         }
     }
 }
Example #3
0
 public function __construct($args = array())
 {
     parent::__construct();
     $this->_args = $args;
 }