Exemple #1
0
 public function setAssignment($value)
 {
     $options = $this->assignmentOptions();
     if (!isset($options[$value])) {
         throw new \RuntimeException('Invalid value for default assignment!', 400);
     }
     $style = StyleHelper::getStyle($this->style_id);
     $style->home = $value;
     if (!$style->check() || !$style->store()) {
         throw new \RuntimeException($style->getError());
     }
     // Clean the cache.
     CacheHelper::cleanTemplates();
 }
Exemple #2
0
 public function setMenu($data)
 {
     $active = array_keys(array_filter($data, function ($value) {
         return $value == 1;
     }));
     // Detect disabled template.
     $extension = \JTable::getInstance('Extension');
     $template = static::gantry()['theme.name'];
     if ($extension->load(array('enabled' => 0, 'type' => 'template', 'element' => $template, 'client_id' => 0))) {
         throw new \RuntimeException(\JText::_('COM_TEMPLATES_ERROR_SAVE_DISABLED_TEMPLATE'));
     }
     $style = \JTable::getInstance('Style', 'TemplatesTable');
     if (!$style->load($this->style_id) || $style->client_id != 0) {
         throw new \RuntimeException('Template style does not exist');
     }
     $user = \JFactory::getUser();
     $n = 0;
     if ($user->authorise('core.edit', 'com_menus')) {
         $db = \JFactory::getDbo();
         $user = \JFactory::getUser();
         if (!empty($active) && is_array($active)) {
             ArrayHelper::toInteger($active);
             // Update the mapping for menu items that this style IS assigned to.
             $query = $db->getQuery(true)->update('#__menu')->set('template_style_id = ' . (int) $style->id)->where('id IN (' . implode(',', $active) . ')')->where('template_style_id != ' . (int) $style->id)->where('checked_out IN (0,' . (int) $user->id . ')');
             $db->setQuery($query);
             $db->execute();
             $n += $db->getAffectedRows();
         }
         // Remove style mappings for menu items this style is NOT assigned to.
         // If unassigned then all existing maps will be removed.
         $query = $db->getQuery(true)->update('#__menu')->set('template_style_id = 0');
         if (!empty($active)) {
             $query->where('id NOT IN (' . implode(',', $active) . ')');
         }
         $query->where('template_style_id = ' . (int) $style->id)->where('checked_out IN (0,' . (int) $user->id . ')');
         $db->setQuery($query);
         $db->execute();
         $n += $db->getAffectedRows();
     }
     // Clean the cache.
     CacheHelper::cleanTemplates();
     return $n > 0;
 }