示例#1
0
 function _setModelState()
 {
     $state = parent::_setModelState();
     $app = JFactory::getApplication();
     $model = $this->getModel($this->get('suffix'));
     $ns = $this->getNamespace();
     $state['order'] = $app->getUserStateFromRequest($ns . '.filter_order', 'filter_order', 'tbl.ordering', 'cmd');
     $state['direction'] = $app->getUserStateFromRequest($ns . '.filter_direction', 'filter_direction', 'ASC', 'word');
     foreach (@$state as $key => $value) {
         $model->setState($key, $value);
     }
     return $state;
 }
示例#2
0
 function _setModelState()
 {
     $state = parent::_setModelState();
     $app = JFactory::getApplication();
     $model = $this->getModel($this->get('suffix'));
     $ns = $this->getNamespace();
     $state['filter_parent'] = $app->getUserStateFromRequest($ns . 'parent', 'filter_parent', '', '');
     $state['filter_enabled'] = $app->getUserStateFromRequest($ns . 'enabled', 'filter_enabled', '', '');
     $state['filter_menutype'] = $app->getUserStateFromRequest($ns . 'menutype', 'filter_menutype', '', '');
     $state['filter_levellimit'] = $app->getUserStateFromRequest($ns . 'levellimit', 'filter_levellimit', '', '');
     $state['filter_itemid'] = $app->getUserStateFromRequest($ns . 'filter_itemid', 'filter_itemid', '', '');
     foreach (@$state as $key => $value) {
         $model->setState($key, $value);
     }
     return $state;
 }
示例#3
0
 /**
  * constructor
  */
 function __construct()
 {
     parent::__construct();
     $this->set('suffix', 'config');
 }
示例#4
0
 function boolean()
 {
     $do = parent::boolean();
     $cids = JRequest::getVar('cid', array(0), 'post', 'array');
     $task = JRequest::getVar('task');
     $vals = explode('.', $task);
     $field = $vals['0'];
     $action = $vals['1'];
     switch (strtolower($action)) {
         case "switch":
             $switch = '1';
             break;
         case "disable":
             $enable = '0';
             $switch = '0';
             break;
         case "enable":
             $enable = '1';
             $switch = '0';
             break;
         default:
             $this->messagetype = 'notice';
             $this->message = JText::_("Invalid Task");
             $this->setRedirect($redirect, $this->message, $this->messagetype);
             return;
             break;
     }
     $db =& JFactory::getDBO();
     $config = Mysite::getInstance();
     $limit = $config->get('tree_depth', '0');
     if (!empty($limit)) {
         if (version_compare(JVERSION, '1.6.0', 'ge')) {
             // Joomla! 1.6+ code here
             $limit_query = "AND menu.level <= '{$limit}'";
         } else {
             // Joomla! 1.5 code here
             $limit_query = "AND menu.sublevel <= '{$limit}'";
         }
     }
     // parent was changed to parent_id in 1.6
     // name was changed to title in 1.6
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6+ code here
         $parent_key = 'parent_id';
         $title_key = 'title';
     } else {
         // Joomla! 1.5 code here
         $parent_key = 'parent_id';
         $title_key = 'title';
     }
     // if a menu is enabled after being disabled, first regenerate items for it
     foreach (@$cids as $cid) {
         $db->setQuery("SELECT * FROM #__mysite_menus WHERE `menu_id` = '{$cid}'");
         $thismenu = $db->loadObject();
         if ($thismenu->enabled == 1 && $enable) {
             $db->setQuery("SELECT * FROM #__mysite_menus WHERE `menu_id` = '{$cid}'");
             $thismenu = $db->loadObject();
             $menutype = $thismenu->menutype;
             //delete all the items created from a this menu
             $db->setQuery("SELECT item_id FROM #__mysite_items WHERE menutype = '{$menutype}'");
             $items = $db->loadObjectList();
             $countItems = count($items);
             if ($countItems) {
                 //update the menu
                 $db->setQuery("\n\t\t\t\t\t    SELECT menu.* \n\t\t                FROM #__menu AS menu \n\t\t                LEFT JOIN #__mysite_menus AS menutypes ON menu.menutype = menutypes.menutype \n\t\t                WHERE menutypes.enabled = '1' \n\t\t                AND menu.menutype = '{$menutype}' \n\t\t\t\t\t    AND menu.published >= '0'\n\t\t\t\t\t    {$limit_query} \n\t\t                ORDER BY menu.{$parent_key} ASC, menu.ordering DESC \n\t\t                ");
                 $menus = $db->loadObjectList();
                 foreach ($menus as $menu) {
                     $db->setQuery("UPDATE #__mysite_items SET url='" . $menu->link . "', enabled='" . $menu->published . "' WHERE itemid=" . $menu->id);
                     $db->query();
                 }
                 $updated++;
             } else {
                 //rebuild the menu
                 // first create the parent sitemap item for the menu
                 unset($parent);
                 $parent = JTable::getInstance('Items', 'MysiteTable');
                 $parent->menutype = $thismenu->menutype;
                 $parent->title = $thismenu->title;
                 $parent->url = "";
                 $parent->itemid = "";
                 $parent->parent = 0;
                 $parent->save();
                 $db->setQuery("\n\t\t\t\t\t    SELECT menu.* \n\t\t                FROM #__menu AS menu \n\t\t                LEFT JOIN #__mysite_menus AS menutypes ON menu.menutype = menutypes.menutype \n\t\t                WHERE menutypes.enabled = '1' \n\t\t                AND menu.menutype = '{$menutype}'\n\t\t                AND menu.published >= '0' \n\t\t\t\t\t    {$limit_query} \n\t\t                ORDER BY menu.{$parent_key} ASC, menu.ordering DESC \n\t\t                ");
                 $menus = $db->loadObjectList();
                 $parentMap = array();
                 $parentMap[$parent->item_id] = array();
                 $fix = array();
                 foreach ($menus as $menu) {
                     $parent_id = !empty($menu->{$parent_key}) ? $parentMap[$parent->item_id][$menu->{$parent_key}] : $parent->item_id;
                     if (empty($parentMap[$parent->item_id][$menu->{$parent_key}])) {
                         // the mysite item for the parent hasn't been created yet,
                         // so we need to fix this one after all others are finished
                         $fix[$menu->id] = $menu->{$parent_key};
                     }
                     $table = JTable::getInstance('Items', 'MysiteTable');
                     $table->menutype = $menu->menutype;
                     $table->title = $menu->{$title_key};
                     $table->url = $menu->link;
                     $table->itemid = $menu->id;
                     $table->enabled = $menu->published;
                     $table->parent = $parent_id;
                     $table->save();
                     $parentMap[$parent->item_id][$menu->id] = $table->id;
                 }
                 // select all mysite_items where parent = 0
                 // foreach one, set the parent if it exists
                 // to correct for ones created before their parent existed
                 $model = JModel::getInstance('Items', 'MysiteModel');
                 $model->setState('filter_parent', '0');
                 if ($list = $model->getList()) {
                     foreach ($list as $item) {
                         $parent_itemid = $fix[$item->itemid];
                         if (!empty($parentMap[$parent->item_id][$parent_itemid])) {
                             $table = JTable::getInstance('Items', 'MysiteTable');
                             $table->load(array('itemid' => $item->itemid));
                             $table->{$parent_key} = $parentMap[$parent->item_id][$parent_itemid];
                             $table->store();
                         }
                     }
                 }
                 JPluginHelper::importPlugin('mysite');
                 $dispatcher =& JDispatcher::getInstance();
                 $data = array($menutype);
                 $dispatcher->trigger('onGenerateItems', $data);
             }
         }
     }
     // if a menu is disabled after being enabled, disable all of its menu items in the sitemap
     foreach (@$cids as $cid) {
         $db->setQuery("SELECT menutype FROM #__mysite_menus WHERE menu_id = {$cid}");
         if ($menutype = $db->loadResult()) {
             $db->setQuery("UPDATE #__mysite_items SET enabled = '{$enable}' WHERE menutype = '{$menutype}'");
             $db->query();
         }
     }
 }