content added; look modifications; side box content
[living-lab-site.git] / application / core / Article_Controller.php
1 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2 /**
3  * Library Article_Controller can be extended by a controller to be used for 
4  * content pages that depend on the language.
5  *
6  * The page views are usually located in
7  * "application/views/article/$language/$method".
8  * Parameters:
9  * <ul>
10  *      <li><strong>Article Title:</strong> in language file 'article_lang.php':
11  * an entry named "article_$method".
12  * If not present "$method" is used as a name.</li>
13  *      <li><strong>Article Meta Description:</strong> in language file..:
14  * an entry "article_${method}_description"</li>
15  *      <li><strong>Helpers, Libraries:</strong> in config file 'article.php':
16  * an entry named "article_${method}_helpers" or "article_${method}_libraries"
17  * respectively with an array of helpers or libraries to be loaded for the
18  * article.</li>
19  * </ul> 
20  *
21  * @category    Base Controller Library
22  * @author              Călin-Andrei Burloiu
23  */
24 class Article_Controller extends CI_Controller {
25         
26         protected $title = NULL;
27         protected $metaDescription = NULL;
28         protected $helpers = array();
29         protected $libraries = array();
30         
31         function __construct()
32         {
33                 parent::__construct();
34                 
35                 // Language, title and description
36                 $this->lang->load('article');
37                 
38                 // Helpers and libraries.
39                 $this->config->load('article');
40         }
41         
42         /**
43          * Extend this with site specific information (header, menus...) and call
44          * $this->_load which is a generic method that loads the article.
45          * Both parameters must be passed to $this->_load.
46          */
47         public function _remap($method, $params = array())
48         {
49                 // Title
50                 $this->title = $this->lang->line("article_$method");
51                 if ($this->title === FALSE)
52                         $this->title = $method;
53
54                 // Meta Description
55                 $this->metaDescription = $this->lang->line("article_${method}_description");
56                 if ($this->metaDescription === FALSE)
57                         $this->metaDescription = '';
58                 
59                 // Helpers
60                 $this->helpers = $this->config->item("article_${method}_helpers");
61                 if ($this->helpers !== FALSE)
62                         $this->load->helper($this->helpers);
63                 
64                 // Libraries
65                 $this->libraries = $this->config->item("article_${method}_library");
66                 if ($this->libraries !== FALSE)
67                         $this->load->library($libraries);
68         }
69         
70         /**
71          * Returns the article based on the language from
72          * "application/views/article/$language/$method".
73          * 
74          * @param       string $method  defines article name
75          * @param       array $params   odd elements are keys and even elements are
76          * their values (eg.: [0] => key, [1] => value etc.). This are going to
77          * be converted to an associative array that is passed to the view if 
78          * $assoc parameter is FALSE. Otherwise this parameter is already an
79          * associative array.
80          * @param       bool $assoc     states whether or not $params is associative
81          */
82         public function _load($method, $params = array(), $assoc = FALSE)
83         {
84                 if (! $assoc)
85                 {
86                         $alt = 0;
87                         $params_assoc = array();
88                         $prev_val = NULL;
89                         foreach ($params as $i => $val)
90                         {
91                                 if ($alt == 0)
92                                         $prev_val = $val;
93                                 else if ($alt == 1)
94                                         $params_assoc[$prev_val] = $val;
95                                 
96                                 $alt = ($alt + 1) % 2;
97                         }
98                 }
99                 else
100                         $params_assoc = $params;
101                 
102                 return $this->load->view('article/'. $this->config->item('language')
103                         . '/' . $method, $params_assoc, TRUE);
104         }
105 }
106
107 /* End of file Article_Controller.php */
108 /* Location: ./application/core/Article_Controller.php */