aliroMenuHandler Class Reference

Inheritance diagram for aliroMenuHandler:

cachedSingleton

List of all members.

Public Member Functions

 getMenuByID ($id)
 getMenuCount ($type, $published=1)
 getCountByTypeComponentID ($type, $sections)
 getMenutypes ()
 getIDByMenutypeQuery ($type, $query)
 getAllMenusByMenutype ($type)
 getAllMenusByType ($type)
 getMenusByIDTypes ($componentid, $types)
 matchURL ($published=true)
 getIDByTypeCid ($type, $componentid, $unpublished=false)
 getGlobalBlogSectionCount ()
getByParentOrder ($menutype, $published=1)
 getHome ()
 setHome ()
 updateNames ($oldname, $newname, $type)
 publishMenus ($ids, $new_publish, $type=null)
 changeOrder ($id, $direction, $menutype)
 updateOrdering ($orders, $menutype)
 setPathway ($Itemid)
 deleteMenus ($cid)
 saveMenu ($menu)

Static Public Member Functions

static getInstance ()

Protected Member Functions

 __construct ()

Static Protected Attributes

static $instance = __CLASS__

Private Member Functions

 getIDLikeQuery ($query_items, $published=false)
 addMenus ($menutype, &$result, $menukeys, $published, $level)

Private Attributes

 $menus = null
 $counts = null
 $byParentOrder = null
 $main_home = null


Detailed Description

Menu handler

Definition at line 112 of file aliroMenuHandler.php.


Constructor & Destructor Documentation

aliroMenuHandler::__construct (  )  [protected]

Constructor - protected to enforce singleton

Definition at line 123 of file aliroMenuHandler.php.

References aliroCoreDatabase::getInstance(), menutype(), and published().

00123                                       {
00124         $sql = "SELECT * FROM #__menu ORDER BY ordering";
00125         $this->menus = aliroCoreDatabase::getInstance()->doSQLget($sql, 'aliroMenuItem', 'id');
00126         foreach ($this->menus as $key=>$menu) {
00127             if (is_null($this->main_home) AND 'mainmenu' == $menu->menutype AND $menu->published AND 0 == $menu->parent) $this->main_home = $menu;
00128              // Ensure that published is always 0 or 1
00129             $this->menus[$key]->published = $menu->published ? 1 : 0;
00130             $this->byParentOrder[$menu->menutype][$menu->parent][] = $key;
00131             if (isset($this->counts[$menu->menutype][$menu->published])) $this->counts[$menu->menutype][$menu->published]++;
00132             else $this->counts[$menu->menutype][$menu->published] = 1;
00133         }
00134     }


Member Function Documentation

static aliroMenuHandler::getInstance (  )  [static]

Singleton accessor with cache

Definition at line 139 of file aliroMenuHandler.php.

Referenced by aliroSEF::__construct(), aliroPathway::__construct(), aliroMenuCreator::__construct(), aliroXMLParams::_form_mos_menu(), aliroSEF::default_revert(), aliroSelectors::menuLinks(), aliroSelectors::menuParent(), aliroExtensionHandler::removeExtensions(), aliroSEF::sefRelToAbs(), aliroSEF::sefRetrieval(), and aliroAbstractRequest::setHandlers().

00139                                           {
00140         return is_object(self::$instance) ? self::$instance : (self::$instance = parent::getCachedSingleton(self::$instance));
00141     }

aliroMenuHandler::getMenuByID ( id  ) 

Definition at line 143 of file aliroMenuHandler.php.

Referenced by changeOrder(), setPathway(), and updateOrdering().

00143                                       {
00144         return isset($this->menus[$id]) ? $this->menus[$id] : null;
00145     }

aliroMenuHandler::getMenuCount ( type,
published = 1 
)

Definition at line 147 of file aliroMenuHandler.php.

00147                                                        {
00148         return isset($this->counts[$type][$published]) ? $this->counts[$type][$published] : 0;
00149     }

aliroMenuHandler::getCountByTypeComponentID ( type,
sections 
)

Definition at line 151 of file aliroMenuHandler.php.

References componentid(), menutype(), and published().

00151                                                                  {
00152         $count = 0;
00153         foreach ($this->menus as $menu) {
00154             if ($menu->menutype == $type AND in_array($menu->componentid, $sections) AND 1 == $menu->published) $count++;
00155         }
00156         return $count;
00157     }

aliroMenuHandler::getMenutypes (  ) 

Definition at line 159 of file aliroMenuHandler.php.

00159                                     {
00160         $types = array();
00161         foreach ($this->menus as $menu) $types[$menu->menutype] = 1;
00162         ksort($types);
00163         if (0 == count($types)) return array('mainmenu');
00164         return array_keys($types);
00165     }

aliroMenuHandler::getIDByMenutypeQuery ( type,
query 
)

Definition at line 167 of file aliroMenuHandler.php.

References menutype(), and published().

00167                                                          {
00168         $query = str_replace('&', '&', $query);
00169         foreach ($this->menus as $menu) {
00170             if ($menu->published == 1 AND ($type == '*' OR $menu->menutype == $type) AND $menu->link == 'index.php?'.$query) return $menu->id;
00171         }
00172         return null;
00173     }

aliroMenuHandler::getAllMenusByMenutype ( type  ) 

Definition at line 175 of file aliroMenuHandler.php.

References $menus, and menutype().

00175                                                   {
00176         $menus = array();
00177         foreach ($this->menus as $menu) if ($menu->menutype == $type) $menus[] = $menu;
00178         return $menus;
00179     }

aliroMenuHandler::getAllMenusByType ( type  ) 

Definition at line 181 of file aliroMenuHandler.php.

References $menus.

00181                                               {
00182         $menus = array();
00183         foreach ($this->menus as $menu) if ($menu->type == $type) $menus[] = $menu;
00184         return $menus;
00185     }

aliroMenuHandler::getMenusByIDTypes ( componentid,
types 
)

Definition at line 187 of file aliroMenuHandler.php.

References $menus, and componentid().

00187                                                              {
00188         $menus = array();
00189         foreach ($this->menus as $menu) {
00190             if ($componentid != $menu->componentid) continue;
00191             foreach ($types as $type) if (false !== strpos($menu->link, $type)) {
00192                 $menus = $menu;
00193                 continue;
00194             }
00195         }
00196         return $menus;
00197     }

aliroMenuHandler::getIDLikeQuery ( query_items,
published = false 
) [private]

Definition at line 199 of file aliroMenuHandler.php.

References menutype(), and published().

Referenced by matchURL().

00199                                                                      {
00200         $min = 999;
00201         $result = 0;
00202         foreach ($this->menus as $menu) {
00203             if (substr($menu->link,0,10) != 'index.php?' OR ($published AND !$menu->published)) continue;
00204             $link = str_replace('&', '&', substr($menu->link,10));
00205             $link_items = explode('&', $link);
00206             $diff = count(array_diff($link_items, $query_items));
00207             if ($diff < $min) {
00208                 $min = $diff;
00209                 $result = $menu->id;
00210             }
00211             elseif ($diff == $min AND $menu->menutype == 'mainmenu') $result = $menu->id;
00212         }
00213         if ($min AND isset($_SESSION['aliro_Itemid'])) $result = $_SESSION['aliro_Itemid'];
00214         return $result;
00215     }

aliroMenuHandler::matchURL ( published = true  ) 

Definition at line 217 of file aliroMenuHandler.php.

References $_REQUEST, getHome(), getIDLikeQuery(), and setHome().

00217                                                {
00218         if (!isset($_REQUEST['option'])) {
00219             $this->setHome();
00220             $result = $this->getHome();
00221         }
00222         else {
00223             if ($_SERVER['QUERY_STRING']) $query_items = explode('&', $_SERVER['QUERY_STRING']);
00224             else $query_items = array();
00225             foreach ($_POST as $name=>$value) $query_items[] = $name.'='.$value;
00226             $link = $this->getIDLikeQuery($query_items, $published);
00227             if ($link) $result = $this->menus[$link];
00228             else $result = null;
00229         }
00230         if ($result) {
00231             $optionstring = 'option='.aliroRequest::getInstance()->getOption();
00232             if (false === strpos($result->link, $optionstring)) return null;
00233             $_SESSION['aliro_Itemid'] = $result->id;
00234         }
00235         return $result;
00236    }

aliroMenuHandler::getIDByTypeCid ( type,
componentid,
unpublished = false 
)

Definition at line 238 of file aliroMenuHandler.php.

References componentid(), and published().

00238                                                                              {
00239         foreach ($this->menus as $menu) {
00240             if (($unpublished OR $menu->published == 1) AND ('*' == $type OR $menu->type == $type) AND $menu->componentid == $componentid) return $menu->id;
00241         }
00242         return null;
00243     }

aliroMenuHandler::getGlobalBlogSectionCount (  ) 

Definition at line 245 of file aliroMenuHandler.php.

References componentid(), and published().

00245                                                  {
00246         $count = 0;
00247         foreach ($this->menus as $menu) {
00248             if ($menu->type == 'content_blog_section' AND $menu->published == 1 AND $menu->componentid == 0) $count++;
00249         }
00250         return $count;
00251     }

aliroMenuHandler::addMenus ( menutype,
&$  result,
menukeys,
published,
level 
) [private]

Definition at line 253 of file aliroMenuHandler.php.

References aliroAuthoriser::getInstance(), and published().

Referenced by getByParentOrder().

00253                                                                                    {
00254         $authoriser = aliroAuthoriser::getInstance();
00255         foreach ($menukeys as $key) {
00256             $menu = $this->menus[$key];
00257             $menu->level = $level;
00258             if ($published AND !$menu->published) continue;
00259             if (!$authoriser->checkUserPermission ('view', 'mosMenuEntry', $menu->id)) continue;
00260             $result[] = $menu;
00261             if (isset($this->byParentOrder[$menutype][$menu->id])) $this->addMenus($menutype, $result, $this->byParentOrder[$menutype][$menu->id], $published, $level+1);
00262         }
00263     }

& aliroMenuHandler::getByParentOrder ( menutype,
published = 1 
)

Definition at line 265 of file aliroMenuHandler.php.

References addMenus().

Referenced by updateOrdering().

00265                                                                 {
00266         $result = array();
00267         if (isset($this->byParentOrder[$menutype][0])) {
00268             $this->addMenus($menutype, $result, $this->byParentOrder[$menutype][0], $published, 0);
00269         }
00270         return $result;
00271     }

aliroMenuHandler::getHome (  ) 

Definition at line 273 of file aliroMenuHandler.php.

Referenced by matchURL().

00273                                {
00274         return $this->main_home;
00275     }

aliroMenuHandler::setHome (  ) 

Definition at line 277 of file aliroMenuHandler.php.

References $_REQUEST.

Referenced by matchURL().

00277                                {
00278         if ($this->main_home) {
00279             $requests = explode ('&', substr($this->main_home->link, 10));
00280             foreach ($requests as $request) {
00281                 $parts = explode ('=', $request);
00282                 if (count($parts == 2)) $_REQUEST[$parts[0]] = $_POST[$parts[0]] = $parts[1];
00283             }
00284         }
00285         return isset($_REQUEST['option']) ? $_REQUEST['option'] : null;
00286     }

aliroMenuHandler::updateNames ( oldname,
newname,
type 
)

Definition at line 288 of file aliroMenuHandler.php.

References cachedSingleton::clearCache(), and aliroCoreDatabase::getInstance().

00288                                                             {
00289         $database = aliroCoreDatabase::getInstance();
00290         $database->doSQL("UPDATE #__menu SET name='$newname' WHERE name='$oldname' AND type='$type'");
00291         $this->clearCache();
00292     }

aliroMenuHandler::publishMenus ( ids,
new_publish,
type = null 
)

Definition at line 294 of file aliroMenuHandler.php.

References cachedSingleton::clearCache(), and aliroCoreDatabase::getInstance().

00294                                                                   {
00295         foreach ($ids as &$id) $id = intval($id);
00296         $new_publish = intval($new_publish);
00297         $idlist = implode (',', $ids);
00298         $database = aliroCoreDatabase::getInstance();
00299         $sql = "UPDATE #__menu SET published = $new_publish WHERE id IN ($idlist)";
00300         if ($type) $sql .= " AND type='$type'";
00301         $database->doSQL ($sql);
00302         $this->clearCache();
00303     }

aliroMenuHandler::changeOrder ( id,
direction,
menutype 
)

Definition at line 305 of file aliroMenuHandler.php.

References getMenuByID(), and updateOrdering().

00305                                                              {
00306         $menu = $this->getMenuByID($id);
00307         $movement = 'down' == $direction ? 15 : -15;
00308         $this->updateOrdering (array($id => $menu->ordering + $movement), $menutype);
00309     }

aliroMenuHandler::updateOrdering ( orders,
menutype 
)

Definition at line 311 of file aliroMenuHandler.php.

References cachedSingleton::clearCache(), getByParentOrder(), aliroCoreDatabase::getInstance(), and getMenuByID().

Referenced by changeOrder().

00311                                                         {
00312         foreach ($orders as $id=>$order) {
00313             $menu =  $this->getMenuByID($id);
00314             if ($menu->ordering != $order) $changes[$id] = $order;
00315         }
00316         foreach ($this->getByParentOrder($menutype, 0) as $menu) {
00317             $ordering = isset($changes[$menu->id]) ? $changes[$menu->id] : $menu->ordering;
00318             $allmenus[$menu->level][$ordering] = $menu->id;
00319         }
00320         $changed = false;
00321         $query = "UPDATE #__menu SET ordering = CASE ";
00322         foreach ($allmenus as $level=>$orderings) {
00323             $order = 10;
00324             ksort($orderings);
00325             foreach ($orderings as $ordering=>$id) {
00326                 $menu = $this->getMenuByID($id);
00327                 if ($order != $menu->ordering) {
00328                     $query .= "WHEN id = $id THEN $order ";
00329                     $changed = true;
00330                 }
00331                 $order += 10;
00332             }
00333         }
00334         if ($changed) {
00335             $query .= 'ELSE ordering END';
00336             aliroCoreDatabase::getInstance()->doSQL ($query);
00337             $this->clearCache();
00338         }
00339     }

aliroMenuHandler::setPathway ( Itemid  ) 

Definition at line 341 of file aliroMenuHandler.php.

References aliroPathway::getInstance(), getMenuByID(), and name.

00341                                          {
00342         if ($Itemid) {
00343             $menu = $this->getMenuByID($Itemid);
00344             if ($menu->parent) $this->setPathway($menu->parent);
00345             $pathway = aliroPathway::getInstance();
00346             $pathway->addItem($menu->name, $menu->link."&Itemid=$Itemid");
00347         }
00348     }

aliroMenuHandler::deleteMenus ( cid  ) 

Definition at line 350 of file aliroMenuHandler.php.

References cachedSingleton::clearCache(), and aliroCoreDatabase::getInstance().

00350                                        {
00351         if (is_array($cid)) {
00352             foreach ($cid as &$id) $id = intval($id);
00353             $idlist = implode(',', $cid);
00354         }
00355         else $idlist = intval($cid);
00356         $database = aliroCoreDatabase::getInstance();
00357         $database->doSQL ("DELETE FROM #__menu WHERE id IN($idlist)");
00358         $this->clearCache();
00359         self::$instance = __CLASS__;
00360     }

aliroMenuHandler::saveMenu ( menu  ) 

Definition at line 362 of file aliroMenuHandler.php.

References cachedSingleton::clearCache(), and aliroCoreDatabase::getInstance().

00362                                      {
00363         if ($menu instanceof aliroMenuItem) {
00364             $database = aliroCoreDatabase::getInstance();
00365             if ($menu->id == 0) {
00366                 $menu->parent = intval($menu->parent);
00367                 $database->setQuery ("SELECT MAX(ordering) FROM `#__menu` WHERE `parent` = $menu->parent GROUP BY `parent`");
00368                 $menu->ordering = $database->loadResult() + 1;
00369             }
00370             if (!$menu->store()) die ('Store menu object failed');
00371             $this->clearCache();
00372             self::$instance = __CLASS__;
00373         }
00374         else die ('Asked to store something not a menu object');
00375     }


Member Data Documentation

aliroMenuHandler::$menus = null [private]

aliroMenuHandler::$counts = null [private]

Definition at line 114 of file aliroMenuHandler.php.

aliroMenuHandler::$byParentOrder = null [private]

Definition at line 115 of file aliroMenuHandler.php.

aliroMenuHandler::$main_home = null [private]

Definition at line 116 of file aliroMenuHandler.php.

aliroMenuHandler::$instance = __CLASS__ [static, protected]

Definition at line 118 of file aliroMenuHandler.php.


The documentation for this class was generated from the following file:

Generated on Thu Apr 17 13:03:30 2008 for ALIRO by  doxygen 1.5.5