Example #1
0
 /**
  * Get a list of templates for the specified client
  *
  * @param   integer  $client_id
  * @param   integer  $id
  * @return  object
  */
 public function getTemplate($client_id = 0, $id = 0)
 {
     if (!$this->app->has('cache.store') || !($cache = $this->app['cache.store'])) {
         $cache = new \Hubzero\Cache\Storage\None();
     }
     $templates = $cache->get('com_templates.templates' . $client_id . $this->lang);
     if (!$templates || empty($templates)) {
         try {
             $db = $this->app['db'];
             $s = '#__template_styles';
             $e = '#__extensions';
             $query = new Query($db);
             $query->select($s . '.id')->select($s . '.home')->select($s . '.template')->select($s . '.params')->select($e . '.protected')->from($s)->join($e, $e . '.element', $s . '.template')->whereEquals($s . '.client_id', (int) $client_id)->whereEquals($e . '.enabled', 1)->whereEquals($e . '.type', 'template')->whereRaw($e . '.`client_id` = `' . $s . '`.`client_id`');
             if ($id) {
                 $query->whereEquals($s . '.id', $id);
             }
             $query->order('home', 'desc');
             $db->setQuery($query->toString());
             $templates = $db->loadObjectList('id');
             foreach ($templates as $i => $template) {
                 $template->params = new Registry($template->params);
                 $template->path = $this->determinePath($template->protected) . DIRECTORY_SEPARATOR . $template->template;
                 $templates[$i] = $template;
                 // Create home element
                 if ($template->home && !isset($templates[0])) {
                     $templates[0] = clone $template;
                 }
             }
             $cache->put('com_templates.templates' . $client_id . $this->lang, $templates, $this->app['config']->get('cachetime', 15));
         } catch (Exception $e) {
             $templates = array();
         }
     }
     $tmpl = null;
     if (isset($templates[$id])) {
         $tmpl = $templates[$id];
     } else {
         if (isset($templates[0])) {
             $tmpl = $templates[0];
         }
     }
     if ($tmpl && file_exists($tmpl->path . DIRECTORY_SEPARATOR . 'index.php')) {
         return $tmpl;
     }
     return $this->getSystemTemplate();
 }