Esempio n. 1
0
 public static function getApplication()
 {
     // check if application object already exists
     if (isset(self::$_application)) {
         return self::$_application;
     }
     // get joomla and application table
     $joomla = JFactory::getApplication();
     $table = YTable::getInstance('application');
     // handle admin
     if ($joomla->isAdmin()) {
         // create application from user state, or search for default
         $id = $joomla->getUserState('com_zooapplication');
         $apps = $table->all(array('order' => 'name'));
         if (isset($apps[$id])) {
             self::$_application = $apps[$id];
         } else {
             if (!empty($apps)) {
                 self::$_application = array_shift($apps);
             }
         }
         return self::$_application;
     }
     // handle site
     if ($joomla->isSite()) {
         // get component params
         $params = $joomla->getParams();
         // create application from menu item params / request
         if ($item_id = YRequest::getInt('item_id')) {
             if ($item = YTable::getInstance('item')->get($item_id)) {
                 self::$_application = $item->getApplication();
             }
         } else {
             if ($category_id = YRequest::getInt('category_id')) {
                 if ($category = YTable::getInstance('category')->get($category_id)) {
                     self::$_application = $category->getApplication();
                 }
             } else {
                 if ($id = YRequest::getInt('app_id')) {
                     self::$_application = $table->get($id);
                 } else {
                     if ($id = $params->get('application')) {
                         self::$_application = $table->get($id);
                     } else {
                         // try to get application from default menu item
                         $menu = JSite::getMenu(true);
                         $default = $menu->getDefault();
                         if (isset($default->component) && $default->component == 'com_zoo') {
                             if ($app_id = $menu->getParams($default->id)->get('application')) {
                                 self::$_application = $table->get($app_id);
                             }
                         }
                     }
                 }
             }
         }
         return self::$_application;
     }
     return null;
 }