~ihris+botswana/ihris-botswana/ihs-aris

« back to all changes in this revision

Viewing changes to modules/IHSLecturers/lib/IHS_PageFormLecturer.php

  • Committer: Ally Shaban
  • Date: 2014-06-18 05:45:40 UTC
  • Revision ID: allyshaban5@gmail.com-20140618054540-droncso01hp9npig
Added Lecturer Module And Department Module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * © Copyright 2006, 2007, 2008, 2009 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
 * @author Ally Shaban <allyshaban5@yahoo.com>
 
22
 * @since v4.1.0
 
23
 * @version v4.1.0
 
24
 */
 
25
/**
 
26
 * iHRIS_Person class for the person form.
 
27
 *
 
28
 * @package iHRIS
 
29
 * @subpackage ihris-train
 
30
 */
 
31
class IHS_PageFormLecturer extends I2CE_PageForm {
 
32
        
 
33
protected function loadObjects() {
 
34
        $factory = I2CE_FormFactory::instance();
 
35
        
 
36
        if ($this->isPost())
 
37
        {
 
38
        if($this->post["submit_type"]=="confirm")
 
39
        {
 
40
                $lecturer=$factory->createContainer("lecturer");                                
 
41
                $this->applyLimits($lecturer);
 
42
                $lecturer->load($this->post);
 
43
                $this->setObject($lecturer);
 
44
        }
 
45
        else if($this->post["submit_type"]=="save")
 
46
        {
 
47
        $this->setObject($lecturer,I2CE_PageForm::EDIT_PRIMARY);
 
48
        parent::save();
 
49
        $this->userMessage("Lecturer Added Successfully!!!");
 
50
        $this->setRedirect("add_lecturer");
 
51
        }
 
52
        }
 
53
        
 
54
        else
 
55
        {
 
56
                $id="lecturer|0";
 
57
                $lecturer=$factory->createContainer($id);
 
58
                $this->applyLimits($lecturer);
 
59
                $lecturer->populate();  
 
60
                $this->setObject( $lecturer);
 
61
        }
 
62
                        
 
63
                }
 
64
                
 
65
        protected function applyLimits($lecturer)
 
66
        {
 
67
        $username=$this->getUser()->username;
 
68
        $where_users=array(
 
69
                                                "operator"=>"FIELD_LIMIT",
 
70
                                                "field"=>"identification_number",
 
71
                                                "style"=>"equals",
 
72
                                                "data"=>array("value"=>$username)
 
73
                                                );
 
74
        $insts=I2CE_FormStorage::listFields("lecturer",array("institution"),false,$where_users);
 
75
        foreach ($insts as $inst)
 
76
        $inst_id=$inst["institution"];
 
77
        
 
78
        $where=array(   "operator"=>"FIELD_LIMIT",
 
79
                                                "fields"=>"institution",
 
80
                                                "style"=>"equals",
 
81
                                                "data"=>array("value"=>$inst_id)
 
82
                                         );
 
83
        $dep_field=$lecturer->getField("department");           
 
84
        $dep_field->setOption(array("meta","limits","default","department"),$where);
 
85
 
 
86
        $where=array( "operator"=>"OR",
 
87
                                                "operand"=>array(0=>array( "operator"=>"FIELD_LIMIT",
 
88
                                                                                                                        "field"=>"id",
 
89
                                                                                                                        "style"=>"equals",
 
90
                                                                                                                        "data"=>array("value"=>"role|lecturer")
 
91
                                                                                                                  ),
 
92
                                                                                          1=>array( "operator"=>"FIELD_LIMIT",
 
93
                                                                                                                        "field"=>"id",
 
94
                                                                                                                        "style"=>"equals",
 
95
                                                                                                                        "data"=>array("value"=>"role|hod")
 
96
                                                                                                                  ),
 
97
                                                                                          2=>array( "operator"=>"FIELD_LIMIT",
 
98
                                                                                                                        "field"=>"id",
 
99
                                                                                                                        "style"=>"equals",
 
100
                                                                                                                        "data"=>array("value"=>"role|principal")
 
101
                                                                                                                  ),
 
102
                                                                                         )
 
103
                               );
 
104
        $role_field=$lecturer->getField("role");                
 
105
        $role_field->setOption(array("meta","limits","default","role"),$where); 
 
106
        }
 
107
 
 
108
}
 
 
b'\\ No newline at end of file'