~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/ihris-manage/lib/iHRIS_PersonPosition.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 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
 
 * @package iHRIS
22
 
 * @subpackage Manage
23
 
 * @author Luke Duncan <lduncan@intrahealth.org>
24
 
 * @copyright Copyright &copy; 2007, 2008 IntraHealth International, Inc. 
25
 
 * @since v1.0.0
26
 
 * @version v2.0.0
27
 
 */
28
 
/**
29
 
 * Object for dealing with positions assigned to people.
30
 
 * 
31
 
 * @package iHRIS
32
 
 * @subpackage Manage
33
 
 * @access public
34
 
 */
35
 
class iHRIS_PersonPosition extends I2CE_Form {
36
 
 
37
 
    /**
38
 
     * Create a new instance of a person position.
39
 
     * 
40
 
     * @param string $form The name of this form
41
 
     * @param integer $id
42
 
     */
43
 
    public function __construct( $form, $id = 0 ) {
44
 
        parent::__construct( $form, $id );
45
 
        $this->start_date = I2CE_Date::now();
46
 
        $this->end_date = I2CE_Date::blank();
47
 
        
48
 
    }
49
 
    
50
 
    /**
51
 
     * Return the record id and the parent id for the person position record
52
 
     * for the given position.
53
 
     * @param integer $position
54
 
     * @return array
55
 
     */
56
 
    static public function getIds( $position ) {
57
 
        $pos_det = I2CE_FormField::getFormFieldIdAndType( "person_position", "position" );
58
 
        $end_det = I2CE_FormField::getFormFieldIdAndType( "person_position", "end_date" );
59
 
        if ( !$pos_det || !$end_det ) return array();
60
 
        
61
 
        $db = MDB2::singleton();
62
 
        if ( !I2CE::pearError( $db, "Error getting database connection: " ) ) {
63
 
        
64
 
            $row = $db->getRow( "SELECT e1.record FROM last_entry e1 JOIN last_entry e2 ON e1.record = e2.record WHERE e1.form_field = ? AND e2.form_field = ? AND e1." 
65
 
                                . $pos_det['type'] . "_value = ? AND e2." . $end_det['type'] . "_value IS NULL", array('integer'),
66
 
                                array( $pos_det['id'], $end_det['id'], $position ), array( 'integer', 'integer', 'integer' ) );
67
 
                
68
 
            if ( !I2CE::pearError( $row, "Errr getting person position ids: " ) ) {
69
 
                $record = $row->record;
70
 
                
71
 
                $form_data = I2CE_Form::getFormData( $record );
72
 
        
73
 
                return array( 'record' => $record, 'parent' => $form_data['parent'] );
74
 
            }
75
 
        }
76
 
        return array();
77
 
        
78
 
    }
79
 
 
80
 
 
81
 
 
82
 
    public function getSalaryGradeID() {
83
 
        $pos_det = I2CE_FormField::getFormFieldIdAndType( "person_position", "position" );
84
 
        $job_det = I2CE_FormField::getFormFieldIdAndType( "position", "job" );
85
 
        $sg_det = I2CE_FormField::getFormFieldIdAndType( "job", "salary_grade" );
86
 
        $qry =
87
 
            "SELECT e2.integer_value FROM last_entry e2 " .
88
 
            "JOIN last_entry e3 ON e2.record = e3.integer_value " . 
89
 
            "JOIN last_entry e4 on e3.record = e4.integer_value " . 
90
 
            "WHERE   e2.form_field= ? AND e3.form_field = ? ".
91
 
            "  AND e4.form_field = ? AND e4.record = ?";
92
 
        $db =& MDB2::singleton(); 
93
 
        $row =& $db->getRow($qry, 
94
 
                            array('integer'), 
95
 
                            array($sg_det['id'],$job_det['id'],$pos_det['id'],$this->getId()),
96
 
                            array('integer','integer','integer','integer'));  
97
 
            
98
 
        return  $row->integer_value;
99
 
    }
100
 
 
101
 
 
102
 
 
103
 
    /**
104
 
     * Constant value for employed
105
 
     */
106
 
    const STATUS_EMPLOYED =1;
107
 
    /**
108
 
     * Constant value for not employed
109
 
     */
110
 
    const STATUS_NOT_EMPLOYED = 2;
111
 
    /**
112
 
     * @var array Employment Status
113
 
     */
114
 
    static public $stati = array( self::STATUS_EMPLOYED => 'Employed', self::STATUS_NOT_EMPLOYED => 'Not Employed' );
115
 
 
116
 
 
117
 
    /**
118
 
     * Lookup the given value from the gender array.
119
 
     * @param integer $id
120
 
     * @param string $form Not used for this method.
121
 
     * @return string
122
 
     */
123
 
    static public function lookupStatus( $id, $form="" ) {
124
 
        return I2CE_Form::lookupArray( $id, self::$stati );
125
 
    }
126
 
    /**
127
 
     * List all the options from the gender array.
128
 
     * @param string $form The  form we wish to lookup by
129
 
     * @returns array
130
 
     */
131
 
    static public function listStatusOptions($form ) {
132
 
        return  self::$stati ;
133
 
    }
134
 
        
135
 
}
136
 
 
137
 
# Local Variables:
138
 
# mode: php
139
 
# c-default-style: "bsd"
140
 
# indent-tabs-mode: nil
141
 
# c-basic-offset: 4
142
 
# End: