Last active
October 7, 2019 07:26
-
-
Save sidor1989/f046ef6dd38e948062b162edec7d2686 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
<? | |
[[+phx:input=`now`:strtotime:el=`[[+publishedon:add=`7776000`]]`:then=` <span style="color: #46a546;" >NEW</span>`:else=``]] | |
//меняем шаблон всем русурсам у указанного родителя | |
$parent = 1840; //укажите ID родителя | |
$template = 83; //укажите ID нового шаблона | |
foreach ($modx->getIterator('modResource', array('parent' => $parent)) as $resource) { | |
$resource->set('template', $template); | |
$resource->save(); | |
} | |
//преносим значение тв у указанного родителя | |
$parent = 18; //укажите ID родителя | |
foreach ($modx->getIterator('modResource', array('parent' => $parent)) as $resource) { | |
$date1tv = $resource->getTVValue('datestart'); | |
$date2tv = $resource->getTVValue('datestop'); | |
$resource->set('date1', $date1tv); | |
$resource->set('date2', $date2tv); | |
$resource->save(); | |
} | |
// Считаем всех детей контейнера с id 1815, глубина 10 | |
$parent = 1815; //укажите ID родителя | |
$template = 83; //укажите ID нового шаблона | |
$child = $modx->getChildIds($parent, 10, array('context' => 'web')); | |
$collection = $modx->getCollection('modResource', array( | |
'id:IN' => $child, | |
)); | |
if ($collection) { | |
foreach ($collection as $resource) { | |
$resource->set('template', $template); | |
$resource->save(); | |
} | |
} | |
//********************************************** | |
//делаем свое событие на примере сохранения продукта минишопа | |
//регистрируем событие | |
$Event = $modx->newObject('modEvent'); | |
$Event->set('name', 'msOnAfterSaveProduct'); | |
$Event->set('service',6); | |
$Event->set('groupname', 'Custom'); | |
//далее пишем в методе событие | |
/** | |
* @param null $cacheFlag | |
* | |
* @return bool | |
*/ | |
public function save($cacheFlag = null) | |
{ | |
if (!$this->isNew() && parent::get('class_key') != 'msProduct') { | |
$this->loadData()->remove(); | |
parent::set('show_in_tree', true); | |
} else { | |
$this->loadData(); | |
} | |
$saved = parent::save($cacheFlag); | |
$this->xpdo->invokeEvent('msOnAfterSaveProduct', array( | |
'msProduct' => &$this, | |
)); | |
return $saved; | |
} | |
///********************************************************** | |
//метод для процессора очищающий тип поля datetime в обход объекта | |
/** | |
* @return bool | |
*/ | |
public function afterSave() | |
{ | |
if (empty($this->getProperty('date2'))) { | |
$table = $this->modx->getTableName('msProductData'); | |
$update = $this->modx->prepare("UPDATE {$table} SET date2 = NULL WHERE id = ?"); | |
$update->execute(array($this->object->get('id'))); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment