source: branches/1.2/workflow/inc/class.basecontroller.inc.php @ 1349

Revision 1349, 4.3 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * Manage workflow module processes providing support for MVC architecture by controlling the process flow.
4 * @author Carlos Eduardo Nogueira Gonçalves
5 * @version 1.3
6 * @package Workflow
7 * @license http://www.gnu.org/copyleft/gpl.html GPL
8 */
9class BaseController
10{       
11        /* begin attributes declaration */
12
13        /**
14     * @var object $view Holds view layer instance
15     * @access public
16     */         
17        var $view = null;
18
19        /**
20     * @var string $templateFile Template file reference
21     * @access public
22     */
23        var $templateFile = null;       
24
25        /**
26     * @var object $model Holds model layer instance
27     * @access public
28     */
29        var $model = null;
30
31        /* ends attributes declaration */
32        /**
33     * Base controller layer constructor
34     *
35     * @access public
36     * @param object $model Model layer instance for activities business logic
37     * @return void
38     * @param array $env MVC environment settings
39     */
40        function BaseController(&$model , &$env) {
41                /* Gets other layers instances for controlling them */
42                $this->view          =&  $env['view'];
43                $this->templateFile  =&  $env['template_file'];
44                $this->model         =&  $model;
45        }
46        /* begin methods declaration */
47       
48    /**
49     * Shows requested interface (template)
50     * @param string $file Template file to be presented
51     * @return void
52     * @access public
53     */
54        function showForm($file) {
55                $this->templateFile = $file;
56        }
57   /**
58    * Assigns all model's attributes into view layer
59    * @return void.
60    * @access public
61    */
62        function syncVars()     {           
63                /* retrieves only process attributes */         
64                $processVars = $this->model->getAttributes();
65               
66                /* makes synchronization */
67                foreach ( $processVars as $var => $value ) {
68                        $this->assign($var, $value);
69                }
70        }
71       
72   /**
73    * Fills view vars with registered vars from model layer
74    * @return void     
75    * @access public
76    */
77    function loadViewVars() {           
78                foreach ( $this->model->viewData as $var => $value ) {
79                        $this->assign($var, $value);
80                }
81    }
82   
83   /**
84    * Assigns value to a view var
85    * @param string $var Template var name to be assigned
86    * @param mixed $value Value assigned
87    * @return void
88    * @access public
89    */
90        function assign($var, $value) {         
91                if (!empty($this->view))
92                $this->view->assign($var, $value);
93    }   
94   
95   /**
96    * Halts activities execution
97    * @return void
98    * @access public
99    */
100        function cancelar() {           
101                $this->model->setWfProperty($this->model->CANCELAR , true);
102        }   
103
104   /**
105    * Normalizes methods names replacing upper case letters by lower case ones, 
106    * blank spaces by underline chars and non-english chars by english ones. 
107    * @return string normalized method name
108    * @access public
109    */
110        function getNormalizedAction($str) {
111                $ts = array("/[À-Å]/", "/Æ/", "/Ç/", "/[È-Ë]/", "/[Ì-Ï]/", "/Ð/", "/Ñ/", "/[Ò-ÖØ]/", "/×/", "/[Ù-Ü]/", "/Ý/", "/ß/", "/[à-å]/", "/æ/", "/ç/", "/[è-ë]/", "/[ì-ï]/", "/ð/", "/ñ/", "/[ò-öø]/", "/÷/", "/[ù-ü]/", "/[ý-ÿ]/");
112                $tn = array("A", "AE", "C", "E", "I", "D", "N", "O", "X", "U", "Y", "ss", "a", "ae", "c", "e", "i", "d", "n", "o", "x", "u", "y");
113                $output = strtolower(preg_replace($ts, $tn, $str));
114                while ($i = strpos($output, ' '))
115                        $output = substr_replace($output, strtoupper($output[$i+1]), $i, 2);
116                return $output;
117        }
118       
119   /**
120    * Searches and runs requested action's implementation in model layer
121    * @param string $action Requested action
122    * @return void
123    * @access public
124    */
125        function dispatch($action)
126        {
127                $action = $this->getNormalizedAction($action);
128        if (method_exists($this, $action))
129                $this->{$action}();
130        else
131                $this->__default();
132        }
133
134   /**
135    * Default activities action
136    * @return void
137    * @access public
138    */
139        function __default() {}
140       
141   /**
142    * Runs activity. It must be implemented in activities controller classes
143    * @abstract
144    * @param string $action Requested action
145    * @return void
146    * @access public
147    */   
148    function run($action) {}
149
150   /**
151    * Provides constructor access to its subclasses for processes startup settings
152    * @param object $model Model layer instance for activities business logic
153    * @param array $env MVC environment settings
154    * @return void
155    * @access public
156    */
157    function super(&$model , &$env) {
158        BaseController::BaseController(&$model , &$env);
159    }
160        /* ends method declarations */
161}
162
163?>
Note: See TracBrowser for help on using the repository browser.