/** * Вспомагательная функция для сортировки виджетов: * - первыми идут с приоритетом 'top' * - потом те, у кого выше приоритет * - потом те, которые были раньше добавлены * * @param ModuleWidget_EntityWidget $oW1 * @param ModuleWidget_EntityWidget $oW2 * * @return int */ protected function _SortWidgetsCompare($oW1, $oW2) { if ($oW1->getPriority() === $oW2->getPriority()) { return $oW1->getOrder() - $oW2->getOrder(); } elseif ($oW1->isTop()) { return 1; } elseif ($oW2->isTop()) { return -1; } if ($oW1->getPriority() < $oW2->getPriority()) { return -1; } return 1; }
/** * @param ModuleWidget_EntityWidget $oWidget */ public function _eventWidgetsEdit($oWidget) { if ($this->GetPost()) { $aConfig = array(); $sPrefix = 'widget.' . $oWidget->GetId() . '.config.'; if ($xVal = $this->GetPost('widget_group')) { $aConfig[$sPrefix . 'wgroup'] = $xVal; } $aConfig[$sPrefix . 'active'] = (bool) $this->GetPost('widget_active'); $xVal = strtolower($this->GetPost('widget_priority')); $aConfig[$sPrefix . 'priority'] = $xVal == 'top' ? 'top' : intval($xVal); if ($this->GetPost('widget_display') == 'period') { if ($sFrom = $this->GetPost('widget_period_from')) { $aConfig[$sPrefix . 'display.date_from'] = date('Y-m-d', strtotime($sFrom)); } if ($sUpto = $this->GetPost('widget_period_upto')) { $aConfig[$sPrefix . 'display.date_upto'] = date('Y-m-d', strtotime($sUpto)); } } $xVal = strtolower($this->GetPost('widget_visitors')); $aConfig[$sPrefix . 'visitors'] = in_array($xVal, array('users', 'admins')) ? $xVal : null; Config::WriteCustomConfig($aConfig); R::Location('admin/site-widgets'); } $this->_setTitle(E::ModuleLang()->Get('action.admin.widget_edit_title')); $this->SetTemplateAction('site/widgets_add'); E::ModuleViewer()->Assign('oWidget', $oWidget); }