3
* © Copyright 2007, 2008 IntraHealth International, Inc.
5
* This File is part of iHRIS
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.
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.
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/>.
23
* @author Luke Duncan <lduncan@intrahealth.org>
24
* @copyright Copyright © 2007, 2008 IntraHealth International, Inc.
29
* Object for dealing with positions.
35
class iHRIS_Position extends I2CE_List {
38
* The main field name used for display a description of a record.
40
const MAIN_FIELD = "code";
42
* The secondary field name used for displaying a description of a record in combination with the MAIN_FIELD.
44
const SEC_FIELD = "title";
46
* Constant value for open position status.
48
const STATUS_OPEN = 1;
50
* Constant value for closed position status.
52
const STATUS_CLOSED = 2;
54
* Constant value for discontinued position status.
56
const STATUS_DISCONTINUED = 3;
59
* @var array The list of position status.
61
static private $status = array( self::STATUS_OPEN => 'Open', self::STATUS_CLOSED => 'Closed',
62
self::STATUS_DISCONTINUED => 'Discontinued' );
65
* Create a new instance of a position.
67
* @param string $form The name of this form
70
public function __construct( $form, $id = 0 ) {
71
parent::__construct( $form, $id );
73
$this->fields['type']->setValue( $form );
78
* Remove all fields except for the status and type for when only dealing with status updates.
80
public function statusOnly() {
81
$this->clearFields( array( 'status', 'type' ) );
85
* Lookup the given value from the status array.
87
* @param string $form Not used for this method.
90
static public function lookupStatus( $id, $form="" ) {
91
return I2CE_Form::lookupArray( $id, self::$status );
94
* List all the options from the status array.
95
* @param string $form The form we wish to lookup by
98
static public function listStatusOptions($form ) {
102
* List all options except closed for the status arra
103
* @param string $form The form we wish to lookup byy.
106
static public function listDepartureOptions($form ) {
107
$status = self::$status;
108
unset( $status[self::STATUS_CLOSED] );
113
* List all positions by status (the linked form for this object).
115
* This will return an array that includes all status codes with all positions that
116
* are in that status.
119
static public function getOptionsByLink() {
120
$factory = I2CE_FormFactory::instance();
121
return parent::_getOptionsByLink( $factory->getFormName( get_class() ), self::MAIN_FIELD, "status", self::SEC_FIELD );
125
* List all open positions
126
* @param string $form The class being listed.
129
static public function listOpen ( $form="position" ) {
130
return I2CE_List::listOptions( $form, "status", 1 );
134
* Update the status for this position.
135
* @param integer $status
137
public function setStatus( $status ) {
138
$this->fields['status']->setValue( $status );
142
* Mark this position as closed and remove it from any applications.
144
* The person being assigned the position will have all application positions removed.
145
* @param I2CE_User &$user The user performing this action.
146
* @param integer $person_id The person being assigned this position.
148
public function closePosition( &$user, $person_id ) {
149
$factory = I2CE_FormFactory::instance();
150
$this->setStatus( self::STATUS_CLOSED );
151
$this->save( $user );
152
if ( I2CE_ModuleFactory::instance()->isEnabled( "ihris-manage-Application" ) ) {
153
$apps = $factory->callStatic( "person", "findApplicants", array( $this->id ) );
154
if ( count( $apps ) > 0 ) {
155
foreach ( $apps as $per_id => $per_name ) {
156
$app_per = $factory->createForm( "person", $per_id );
157
$app_per->populateChildren( array( "application" ) );
158
if( array_key_exists( 'application', $app_per->children ) &&
159
count( $app_per->children['application'] ) > 0 ) {
160
foreach( $app_per->children['application'] as $app ) {
161
$app->removePosition( $this->getId() );
167
$form_id = I2CE_Form::getFormId( "application" );
168
$sth = $this->db->prepare( "SELECT id,parent FROM record WHERE parent IN ( "
169
. implode( ",", array_keys( $apps ) ) . " ) ", null, MDB2_PREPARE_RESULT );
170
if ( !I2CE::pearError( $sth, "Error preparing statement to close a position: " ) ) {
171
$app_ids = $sth->execute();
172
if ( !I2CE::pearError( $app_ids, "Error executing statement to close a position: " ) ) {
173
while( $data = $app_ids->fetchRow() ) {
174
$app = $factory->createForm( "application", $data->id );
176
$app->removePosition( $this->id );
187
* Return the list of record ids that have this position as supervisor.
190
public function getSupervised() {
191
$sup_det = I2CE_FormField::getFormFieldIdAndType( "position", "supervisor" );
192
if ( !$sup_det ) return array();
193
$supervised = array();
195
$db = MDB2::singleton();
196
if ( !I2CE::pearError( $db, "Error getting database connection: " ) ) {
198
$sth = $db->prepare( "SELECT record FROM last_entry WHERE form_field = ? AND " . $sup_det['type'] . "_value = ?",
199
array('integer', 'integer' ), MDB2_PREPARE_RESULT );
200
if ( !I2CE::pearError( $sth, "Error preparing statement to get supervised positions: " ) ) {
201
$results = $sth->execute( array( $sup_det['id'], $this->id ) );
202
if ( !I2CE::pearError( $results, "Error executing statement to get supervised positions: " ) ) {
203
while( $row = $results->fetchRow() ) {
204
$supervised[] = $row->record;
220
# c-default-style: "bsd"
221
# indent-tabs-mode: nil