~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/common/modules/Person/modules/Contact/lib/iHRIS_Module_PersonContact.php

  • Committer: litlfred at ibiblio
  • Date: 2009-10-26 13:55:16 UTC
  • Revision ID: litlfred@ibiblio.org-20091026135516-7er0260tad01febt
ihris suite updated to 4.0.1 pre-release...
follows that did not get added on the last attempt did this time... the problem is that bzr does not like to include branches in a sub-directory even if you add them in which 
  is how ihris-suite/lib/* was structed.  so i had to move ihris-suite/lib/*/.bzr to ihris-suite/lib/*/.bzr_dir to trick it
the site will now succesfully install.  have not attempted change the root drive letter yet

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
    /**
 
50
     * Upgrades the modules
 
51
     * @param string $old_vers
 
52
     * @param string $new_vers
 
53
     * @returns boolean
 
54
     */
 
55
    public function upgrade($old_vers,$new_vers) {
 
56
        if (I2CE_Validate::checkVersion($old_vers,'<','3.2.6') || I2CE_Validate::checkVersion($old_vers,'=','3.2.10')) {
 
57
            if (!$this->updateContacts()) {
 
58
                return false;
 
59
            }
 
60
        }
 
61
        return true;
 
62
    }
 
63
 
 
64
    public function post_update($old_vers,$new_vers) {        
 
65
        if (I2CE_Validate::checkVersion($old_vers,'=','0')) { 
 
66
            //this module is new to 3.2, we may need to update contacts from 3.1
 
67
            //only fixup contact on a new installation
 
68
            if (!$this->updateContacts()) {
 
69
                return false;
 
70
            }
 
71
        }
 
72
        return true;
 
73
    }
 
74
 
 
75
    protected function updateContacts() {
 
76
        foreach (self::$contacts as $contact) {
 
77
            I2CE::raiseError("Changing contact child form of type $contact  of person to person_contact_$contact");
 
78
            if (! iHRIS_Module_Contact::changeContactForm('person', "contact_type|$contact","person_contact_$contact",true,false)) {
 
79
                I2CE::raiseError("Could not upgrade training funder contacts");
 
80
                return false;
 
81
            }
 
82
        }
 
83
        iHRIS_Module_Contact::removeContactForm('person');
 
84
        return true;
 
85
    }
 
86
 
 
87
 
 
88
 
 
89
 
 
90
 
 
91
 
 
92
 
 
93
    public function action_person_contact_work($page) {
 
94
        return $this->action_contact($page, 'work');
 
95
    }
 
96
    public function action_person_contact_personal($page) {
 
97
        return $this->action_contact($page, 'personal');
 
98
    }
 
99
    public function action_person_contact_emergency($page) {
 
100
        return $this->action_contact($page, 'emergency');
 
101
    }
 
102
    public function action_person_contact_other($page) {
 
103
        return $this->action_contact($page, 'other');
 
104
    }
 
105
 
 
106
    
 
107
 
 
108
    protected function action_contact($page,$contact) {
 
109
        if (!$page instanceof iHRIS_PageView) {
 
110
            return false;
 
111
        }
 
112
        $person = $page->getPerson();
 
113
        if (!$person instanceof iHRIS_Person) {
 
114
            return false;
 
115
        }
 
116
        $page->addChildForms('person_contact_' . $contact);
 
117
        $template = $page->getTemplate();
 
118
        $contactObjs = $person->getChildren('person_contact_' . $contact);
 
119
        if (count($contactObjs) == 1) {
 
120
            return true;
 
121
        }  else if (count($contactObjs) > 1) {
 
122
            I2CE::raiseError("Too many contacts of type " . $contact . " for " . $person->getId());
 
123
            return false;
 
124
        } else if ($page->hasPermission("task(person_can_edit_child_form_person_contact_$contact)")) {
 
125
            $template->appendFileById("add_person_contact_" . $contact . ".html", 'span','contact_links');
 
126
        }
 
127
        return true;
 
128
    }
 
129
 
 
130
 
 
131
 
 
132
}
 
133
# Local Variables:
 
134
# mode: php
 
135
# c-default-style: "bsd"
 
136
# indent-tabs-mode: nil
 
137
# c-basic-offset: 4
 
138
# End: