article engine for static pages was integrated
[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  * Several language specific parameters can be coded in language files.
7  * Non language specific parameters can be putted in config files.
8  *
9  * @category    Library
10  * @author              Călin-Andrei Burloiu
11  */
12 class Article_Controller extends CI_Controller {
13         
14         function __construct()
15         {
16                 parent::__construct();
17         }
18         
19         /**
20          * Override this with site specific information (header, menus...) and call
21          * $this->_load which is a generic method that loads the article.
22          * Both parameters must be passed to $this->_load.
23          */
24         public function _remap($method, $params = array())
25         {
26                 $this->load->view('echo', 
27                         array('output' => $this->_load($method, $params),
28                                 'clear' => TRUE)
29                         );
30         }
31         
32         /**
33          * Returns the article based on the language from
34          * "application/views/article/$language/$method".
35          * 
36          * @param       string $method  defines article name
37          * @param       array $params   odd elements are keys and even elements are
38          * their values (eg.: [0] => key, [1] => value etc.). This are going to
39          * be converted to an associative array that is passed to the view if 
40          * $assoc parameter is FALSE. Otherwise this parameter is already an
41          * associative array.
42          * @param       bool $assoc     states whether or not $params is associative
43          */
44         public function _load($method, $params = array(), $assoc = FALSE)
45         {
46                 if (! $assoc)
47                 {
48                         $alt = 0;
49                         $params_assoc = array();
50                         $prev_val = NULL;
51                         foreach ($params as $i => $val)
52                         {
53                                 if ($alt == 0)
54                                         $prev_val = $val;
55                                 else if ($alt == 1)
56                                         $params_assoc[$prev_val] = $val;
57                                 
58                                 $alt = ($alt + 1) % 2;
59                         }
60                 }
61                 else
62                         $params_assoc = $params;
63                 
64                 return $this->load->view('article/'. $this->config->item('language')
65                         . '/' . $method, $params_assoc, TRUE);
66         }
67 }
68
69 /* End of file Article_Controller.php */
70 /* Location: ./application/core/Article_Controller.php */