~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/Trainer/modules/Contact/lib/iHRIS_Module_PrivateFacilityContact.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 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
* @package iHRIS
 
21
* @subpackage Common
 
22
* @author Carl Leitner <litlfred@ibiblio.org>
 
23
* @version v3.2
 
24
* @since v3.2
 
25
* @filesource
 
26
*/
 
27
/**
 
28
* Class iHRIS_Module_PersonContact
 
29
*
 
30
* @access public
 
31
*/
 
32
 
 
33
 
 
34
class iHRIS_Module_PersonContact extends I2CE_Module {
 
35
 
 
36
    public static function getMethods() {
 
37
        return array(
 
38
            'iHRIS_PageView->action_person_contact_work' => 'action_person_contact_work',
 
39
            'iHRIS_PageView->action_person_contact_personal' => 'action_person_contact_personal',
 
40
            'iHRIS_PageView->action_person_contact_other' => 'action_person_contact_other',
 
41
            'iHRIS_PageView->action_person_contact_emergency' => 'action_person_contact_emergency'
 
42
            );
 
43
    }
 
44
 
 
45
 
 
46
    protected static $contacts = array("personal","work","emergency","other"); 
 
47
 
 
48
    /**
 
49
     * Return the array of hooks available in this module.
 
50
     * @return array
 
51
     */
 
52
    public static function getHooks() {
 
53
        $hooks = array();
 
54
        foreach ( self::$contacts as $type ) {
 
55
            $hooks["validate_form_person_contact_${type}_field_email"] = "validate_form_contact_field_email";
 
56
        }
 
57
        return $hooks;
 
58
    }
 
59
 
 
60
    /**
 
61
     * Validate the email field for contact forms.
 
62
     * @param I2CE_FormField $formfield
 
63
     */
 
64
    public function validate_form_contact_field_email( $formfield ) {
 
65
        $value = $formfield->getValue();
 
66
        if ( I2CE_Validate::checkString( $value ) 
 
67
                && !I2CE_Validate::checkEmail( $value ) ) {
 
68
            $formfield->setInvalid( "Please enter a valid email address." );
 
69
        } 
 
70
    }
 
71
 
 
72
    /**
 
73
     * Upgrades the modules
 
74
     * @param string $old_vers
 
75
     * @param string $new_vers
 
76
     * @returns boolean
 
77
     */
 
78
    public function upgrade($old_vers,$new_vers) {
 
79
        if (I2CE_Validate::checkVersion($old_vers,'<','3.2.6') || I2CE_Validate::checkVersion($old_vers,'=','3.2.10')) {
 
80
            if (!$this->updateContacts()) {
 
81
                return false;
 
82
            }
 
83
        }
 
84
        return true;
 
85
    }
 
86
 
 
87
    public function post_update($old_vers,$new_vers) {        
 
88
        if (I2CE_Validate::checkVersion($old_vers,'=','0')) { 
 
89
            //this module is new to 3.2, we may need to update contacts from 3.1
 
90
            //only fixup contact on a new installation
 
91
            if (!$this->updateContacts()) {
 
92
                return false;
 
93
            }
 
94
        }
 
95
        return true;
 
96
    }
 
97
 
 
98
    protected function updateContacts() {
 
99
        foreach (self::$contacts as $contact) {
 
100
            I2CE::raiseError("Changing contact child form of type $contact  of person to person_contact_$contact");
 
101
            if (! iHRIS_Module_Contact::changeContactForm('person', "contact_type|$contact","person_contact_$contact",true,false)) {
 
102
                I2CE::raiseError("Could not upgrade training funder contacts");
 
103
                return false;
 
104
            }
 
105
        }
 
106
        iHRIS_Module_Contact::removeContactForm('person');
 
107
        return true;
 
108
    }
 
109
 
 
110
 
 
111
 
 
112
 
 
113
 
 
114
 
 
115
 
 
116
    public function action_person_contact_work($page) {
 
117
        return $this->action_contact($page, 'work');
 
118
    }
 
119
    public function action_person_contact_personal($page) {
 
120
        return $this->action_contact($page, 'personal');
 
121
    }
 
122
    public function action_person_contact_emergency($page) {
 
123
        return $this->action_contact($page, 'emergency');
 
124
    }
 
125
    public function action_person_contact_other($page) {
 
126
        return $this->action_contact($page, 'other');
 
127
    }
 
128
 
 
129
    
 
130
 
 
131
    protected function action_contact($page,$contact) {
 
132
        if (!$page instanceof iHRIS_PageView) {
 
133
            return false;
 
134
        }
 
135
        $person = $page->getPerson();
 
136
        if (!$person instanceof iHRIS_Person) {
 
137
            return false;
 
138
        }
 
139
        $page->addChildForms('person_contact_' . $contact);
 
140
        $template = $page->getTemplate();
 
141
        $contactObjs = $person->getChildren('person_contact_' . $contact);
 
142
        if (count($contactObjs) == 1) {
 
143
            return true;
 
144
        }  else if (count($contactObjs) > 1) {
 
145
            I2CE::raiseError("Too many contacts of type " . $contact . " for " . $person->getId());
 
146
            return false;
 
147
        } else if ($page->hasPermission("task(person_can_edit_child_form_person_contact_$contact)")) {
 
148
            $template->appendFileById("add_person_contact_" . $contact . ".html", 'span','contact_links');
 
149
        }
 
150
        return true;
 
151
    }
 
152
 
 
153
 
 
154
 
 
155
}
 
156
# Local Variables:
 
157
# mode: php
 
158
# c-default-style: "bsd"
 
159
# indent-tabs-mode: nil
 
160
# c-basic-offset: 4
 
161
# End: