~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/ihris-common/modules/TrainingCourse/lib/iHRIS_PageForm_Scheduled_Training_Course.php

  • Committer: litlfred at ibiblio
  • Date: 2009-10-23 12:59:28 UTC
  • Revision ID: litlfred@ibiblio.org-20091023125928-u5lkafz0urm9t8eq
updated ihris-suite to 4.0.1-prerelease -- not debugged

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
* © Copyright 2008 IntraHealth International, Inc.
4
 
5
 
* This File is part of I2CE 
6
 
7
 
* I2CE 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
 
*  iHRIS_PageForm_Scheduled_Training_Course
22
 
* @package I2CE
23
 
* @subpackage Core
24
 
* @author Carl Leitner <litlfred@ibiblio.org>
25
 
* @copyright Copyright &copy; 2008 IntraHealth International, Inc. 
26
 
* This file is part of I2CE. I2CE is free software; you can redistribute it and/or modify it under 
27
 
* the terms of the GNU General Public License as published by the Free Software Foundation; either 
28
 
* version 3 of the License, or (at your option) any later version. I2CE is distributed in the hope 
29
 
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
30
 
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 
31
 
* received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
32
 
* @version 2.1
33
 
* @access public
34
 
*/
35
 
 
36
 
 
37
 
class iHRIS_PageForm_Scheduled_Training_Course extends I2CE_PageForm{
38
 
 
39
 
    /**
40
 
     * @var integer The record id number of the object being edited.
41
 
     */
42
 
    protected $id;
43
 
 
44
 
 
45
 
    /**
46
 
     * @var integer The record id number of the parent of the object being edited.
47
 
     */
48
 
    protected $course_id;
49
 
 
50
 
    /**
51
 
     * Create a new instance of this page.
52
 
     * 
53
 
     * This will call the parent constructor and then setup the base
54
 
     * template pages for the {@link I2CE_Template template}.  It also sets up the values
55
 
     * for the member variables.
56
 
     * @param string $title The title for this page.
57
 
     * @param string $defaultHTMLFile The default HTML file for this page.
58
 
     * @param mixed $access The role required to access this page.
59
 
     * @param array $files The list of template files to load for this page.
60
 
     */
61
 
    public function __construct( $args,$request_remainder) {
62
 
        parent::__construct( $args,$request_remainder);
63
 
        $this->id = 0;
64
 
        $this->course_id = 0;
65
 
        if ( $this->isPost() ) {
66
 
            if ( $this->post_exists( 'id' ) ) {
67
 
                $this->id = $this->post('id');
68
 
            }           
69
 
            if ( $this->post_exists( 'parent' ) ) {
70
 
                $this->course_id = $this->post('parent');
71
 
            }
72
 
        } else {
73
 
            if ( $this->get_exists( 'id' ) ) {
74
 
                $this->id = $this->get('id');
75
 
            }
76
 
            if ( $this->get_exists( 'parent' ) ) {
77
 
                $this->course_id = $this->get('parent');
78
 
            }
79
 
        }
80
 
    }
81
 
 
82
 
 
83
 
    /**
84
 
     * Create and load data for the objects used for this form.
85
 
     * 
86
 
     * Create the list object and if this is a form submission load
87
 
     * the data from the form data.
88
 
     */
89
 
    protected function loadObjects() {
90
 
        $factory = I2CE_FormFactory::instance();
91
 
        $scheduledCourse = $factory->createForm( "scheduled_training_course", $this->id );
92
 
        $this->setObject( $scheduledCourse);
93
 
        if ($this->id > 0) {
94
 
            $scheduledCourse->populate();
95
 
            $this->course_id =  $scheduledCourse->getParent(true);
96
 
        } 
97
 
        $parent = $factory->createForm( "training_course", $this->course_id );
98
 
 
99
 
        if ($parent instanceof I2CE_Form) {
100
 
            $parent->populate();
101
 
            $this->setObject( $parent , I2CE_PageForm::EDIT_PARENT );
102
 
        }
103
 
        parent::loadObjects();
104
 
    }
105
 
 
106
 
    /**
107
 
     * Save the objects to the database.
108
 
     * 
109
 
     * Save the default object being edited and return to the view page.
110
 
     * @global array
111
 
     */
112
 
    protected function save() {
113
 
        parent::save();
114
 
        $this->setRedirect(  "view_list?type=training_course&id=" . $this->getParent()->getId() );
115
 
    }
116
 
 
117
 
    protected function action() {
118
 
        if ($this->permissionParser->hasTask('can_edit_scheduled_training_course') || $this->permissionParser->hasTask('can_edit_all_database_lists')) {
119
 
            parent::action();
120
 
        } else {
121
 
            $this->userMessage("You do not have permission to add or edit a scheduled training course",'notice');
122
 
            $this->setRedirect('noaccess');
123
 
        }
124
 
    }
125
 
 
126
 
    /**
127
 
     * Display the save or confirm button templates as needed.
128
 
     * @param boolean $save Flag to show the save button.
129
 
     * @param boolean $show_edit (defaults to true)
130
 
     */
131
 
    protected function displayControls( $save = false, $show_edit = true ) {
132
 
        if ( $save ) {
133
 
            $this->template->addFile( "button_save.html" );
134
 
        } elseif ( $this->getPrimary()->getId() > 0 ) {
135
 
            $this->template->addFile( "button_confirm.html" );     
136
 
        } else {
137
 
            $node = $this->template->addFile( "button_save_return.html" );     
138
 
            $buttonNode = $this->template->getElementById('button_return',$node);
139
 
            if ($buttonNode instanceof DOMElement) {
140
 
                $buttonNode->setAttribute('href','view_list?type=training_course&id=' );
141
 
            }
142
 
        }
143
 
    }
144
 
 
145
 
 
146
 
 
147
 
    public function loadHTMLTemplates() {
148
 
        parent::loadHTMLTemplates();
149
 
        $studentListNode = $this->template->getElementById('list_students');
150
 
        if (!$studentListNode instanceof DOMNode) {
151
 
            $this->template->setDisplayDataImmediate('has_enrolled_students','');
152
 
            return;
153
 
        }
154
 
        $scheduledCourse = $this->getPrimary();
155
 
        if (!$scheduledCourse instanceof iHRIS_Scheduled_Training_Course) {
156
 
            $this->template->setDisplayDataImmediate('has_enrolled_students','');
157
 
            return;
158
 
        }
159
 
        if ($scheduledCourse->getID() < 1) {
160
 
            $this->template->setDisplayDataImmediate('has_enrolled_students','');
161
 
            return;
162
 
        }
163
 
        $personIds = $scheduledCourse->getEnrolledStudents();
164
 
        if (count($personIds) == 0) {
165
 
            $this->template->setDisplayDataImmediate('has_enrolled_students','');
166
 
            return;
167
 
        }
168
 
        $factory = I2CE_FormFactory::instance();
169
 
        $enrolled = false;
170
 
        foreach ($personIds as $personID) {
171
 
            if ($personID < 1) {
172
 
                continue;
173
 
            }
174
 
            $person = $factory->createForm('person',$personID);
175
 
            if (!$person instanceof iHRIS_Person) {
176
 
                continue;
177
 
            }
178
 
            $person->populate();
179
 
            $personNode = $this->template->appendFileByNode("scheduled_course_list_person.html", 'li',$studentListNode);
180
 
            if (!$personNode instanceof DOMNode) {
181
 
                continue;
182
 
            }
183
 
            $enrolled  = true;
184
 
            $this->template->setDisplayDataImmediate('person_surname', $person->surname,$personNode);
185
 
            $this->template->setDisplayDataImmediate('person_firstname',$person->firstname,$personNode);
186
 
            $this->template->setDisplayDataImmediate('person_id','id=' .$personID,$personNode);
187
 
        }
188
 
        if ($enrolled) {
189
 
            $this->template->setDisplayDataImmediate('has_enrolled_students','1');
190
 
        } else {
191
 
            $this->template->setDisplayDataImmediate('has_enrolled_students','');
192
 
        }
193
 
        
194
 
    }
195
 
 
196
 
 
197
 
}
198
 
# Local Variables:
199
 
# mode: php
200
 
# c-default-style: "bsd"
201
 
# indent-tabs-mode: nil
202
 
# c-basic-offset: 4
203
 
# End: