~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/Trainer/lib/iHRIS_PageViewTrainer.php

  • Committer: Dennis Kibiye
  • Date: 2012-08-15 12:39:06 UTC
  • Revision ID: kibsden@gmail.com-20120815123906-ckmfgnpgi8xqiz9o
First Initialisation of In Service Baylor Training System Based on iHRIS Manage

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * © Copyright 2007, 2008 IntraHealth International, Inc.
 
4
 * 
 
5
 * This File is part of iHRIS
 
6
 * 
 
7
 * iHRIS is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 * 
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
/**
 
21
 * View a person's record.
 
22
 * @package iHRIS
 
23
 * @subpackage Qualify
 
24
 * @access public
 
25
 * @author Luke Duncan <lduncan@intrahealth.org>
 
26
 * @copyright Copyright &copy; 2007, 2008 IntraHealth International, Inc. 
 
27
 * @since v2.0.0
 
28
 * @version v2.0.0
 
29
 */
 
30
 
 
31
/**
 
32
 * The page class for displaying the a person's record.
 
33
 * @package iHRIS
 
34
 * @subpackage Qualify
 
35
 * @access public
 
36
 */
 
37
class iHRIS_PageView extends I2CE_Page{ 
 
38
    protected $person;
 
39
 
 
40
    /**
 
41
     * Perform the main actions of the page.
 
42
     */
 
43
    protected function action() {
 
44
        parent::action();
 
45
        if (!$this->hasPermission("task(person_can_view)")) {
 
46
            $this->userMessage("You do not have permission to view this person");
 
47
            return false;
 
48
        }
 
49
        $this->template->addHeaderLink("view.js");
 
50
        $this->template->appendFileById( "menu_view.html", "li", "navBarUL", true );
 
51
        $this->template->appendFileById( "menu_view_trainer.html", "ul", "menuView" );
 
52
        $factory = I2CE_FormFactory::instance();
 
53
        if (!$this->request_exists('id')) {
 
54
            $this->userMessage("Invalid Person Requested");
 
55
            return false;
 
56
        }
 
57
        if ($this->request_exists('id')) {
 
58
            $id = $this->request('id');
 
59
            if (strpos($id,'|')=== false) {
 
60
                I2CE::raiseError("Deprecated use of id variable");
 
61
                $id = 'trainer|' . $id;
 
62
            }
 
63
        } else {
 
64
            $id = 'trainer|0';
 
65
        }
 
66
        $person = $factory->createContainer( $id);
 
67
        if (!$person instanceof iHRIS_Trainer) {
 
68
            return false;
 
69
        }
 
70
 
 
71
        $this->person = $person;
 
72
        $this->person->populate();
 
73
        $this->template->setForm( $this->person );
 
74
        $child_forms = $this->person->getChildForms();
 
75
        foreach($child_forms as $form) {
 
76
            if (!$this->hasPermission("task(person_can_view_child_forms|person_can_view_child_form_{$form})")) {
 
77
                continue;
 
78
            }
 
79
            $method = 'action_' . $form;
 
80
            if ($this->_hasMethod($method)) {
 
81
                if (!$this->$method()) {
 
82
                    I2CE::raiseError("Could not do action for $form");
 
83
                }
 
84
            }
 
85
        }
 
86
        return true;
 
87
    }
 
88
    
 
89
    public function getPerson() {
 
90
        return $this->person;
 
91
    }
 
92
 
 
93
    public function hasChildForm($form, $populate = false) {
 
94
        if ($populate) {
 
95
            $this->person->populateChildren($form);
 
96
        }
 
97
        return (array_key_exists($form,$this->person->children) && is_array($this->person->children[$form]) && count($this->person->children[$form]) > 0);
 
98
    }
 
99
 
 
100
    public function addChildForms($form, $set_on_node = null , $template = false, $tag = 'div', $append_node = null) {
 
101
        $this->person->populateChildren($form);
 
102
        return $this->appendChildTemplate($form,$set_on_node,$template,$tag, $append_node );
 
103
    }
 
104
 
 
105
 
 
106
    public function addLastChildForm($form, $field,  $set_on_node = null,  $template = false, $tag = 'div', $append_node = null) {
 
107
        $this->person->populateLast(array($form=> $field));
 
108
        return $this->appendChildTemplate($form,$set_on_node,$template,$tag, $append_node );
 
109
    }
 
110
 
 
111
 
 
112
 
 
113
 
 
114
    public function appendChildTemplate($form,$set_on_node = null, $template = false, $tag = 'div', $appendNode = null) {
 
115
        if (!array_key_exists($form,$this->person->children) || !is_array($this->person->children[$form])) {
 
116
            return true;
 
117
        }
 
118
        if (!is_string($template)) {
 
119
            $template = 'view_' . $form . '.html';
 
120
        }
 
121
        if ($appendNode === null) {
 
122
            $appendNode = $form;
 
123
        }
 
124
        if (is_string($appendNode)) {
 
125
            $appendNode = $this->template->getElementById($appendNode);
 
126
        }        
 
127
        if (! $appendNode instanceof DOMNode) {
 
128
            I2CE::raiseError("Do not know where to add child form $form ");
 
129
            return false;
 
130
        }
 
131
        foreach ($this->person->children[$form] as $child) {
 
132
            I2CE_ModuleFactory::callHooks( 'pre_add_child_form_' . $form, 
 
133
                    array( 'form' => $child, 
 
134
                        'page' => $this, 'set_on_node' => $set_on_node, 
 
135
                        'append_node' => $appendNode ) );
 
136
            $node = $this->template->appendFileByNode($template, $tag,  $appendNode );
 
137
            if (!$node instanceof DOMNode) {
 
138
                I2CE::raiseError("Could not find template $template for child form $form of person");
 
139
                return false;
 
140
            }
 
141
            $this->template->setForm($child,$node);
 
142
            if ($set_on_node !== null) {
 
143
                $this->template->setForm($child,$set_on_node);
 
144
            }
 
145
            I2CE_ModuleFactory::callHooks( 'post_add_child_form_' . $form, 
 
146
                    array( 'form' => $child, 'node' => $node,
 
147
                        'page' => $this, 'set_on_node' => $set_on_node, 
 
148
                        'append_node' => $appendNode ) );
 
149
        }
 
150
        return true;
 
151
    }
 
152
 
 
153
 
 
154
  }
 
155
 
 
156
 
 
157
 
 
158
# Local Variables:
 
159
# mode: php
 
160
# c-default-style: "bsd"
 
161
# indent-tabs-mode: nil
 
162
# c-basic-offset: 4
 
163
# End: