~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/Mentor/lib/iHRIS_Module_PrivateFacility.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-common
 
21
* @author Carl Leitner <litlfred@ibiblio.org>
 
22
* @version v3.2
 
23
* @since v3.2
 
24
* @filesource
 
25
*/
 
26
/**
 
27
* Class iHRIS_Module_PrivateFacility
 
28
*
 
29
* @access public
 
30
*/
 
31
 
 
32
 
 
33
class iHRIS_Module_PrivateFacility extends I2CE_Module {
 
34
 
 
35
 
 
36
 
 
37
    /**
 
38
     * Return the array of hooks available in this module.
 
39
     * @return array
 
40
     */
 
41
    public static function getHooks() {
 
42
        return array(
 
43
                'validate_form_privatefacility' => 'validate_form_privatefacility',
 
44
                );
 
45
    }
 
46
 
 
47
    /**
 
48
     * Perform extra validation for the privatefacility form.
 
49
     * A new privatefacility record needs to verify there aren't any existing 
 
50
     * records with the same name.
 
51
     * @param I2CE_Form $form
 
52
     */
 
53
    public function validate_form_privatefacility( $form ) {
 
54
 
 
55
        $search = array();
 
56
        $name_ignore = false;
 
57
        if ( isset( $form->name_ignore ) ) {
 
58
            $name_ignore = $form->name_ignore;
 
59
        }
 
60
        if ( I2CE_ModuleFactory::instance()->isEnabled('forms-storage') 
 
61
             && $form->getId() == 0 && !$name_ignore
 
62
             && I2CE_Validate::checkString( $form->name )) {
 
63
            $where = array(
 
64
                'operator' => 'AND',
 
65
                'operand'=>array(
 
66
                    0=>array(
 
67
                        'operator'=>'FIELD_LIMIT',
 
68
                        'field'=>'name',
 
69
                        'style'=>'lowerequals',
 
70
                        'data'=>array('value'=>strtolower($form->name))
 
71
                        )
 
72
                    )
 
73
                );
 
74
            $results = I2CE_FormStorage::listFields('privatefacility',array('name'),false,$where,array('name'));
 
75
            if( count($results) > 0 ) {
 
76
                foreach ($results as $id=>&$data) {
 
77
                    $data = implode(', ', $data);
 
78
                }
 
79
                $form->getField('name')->setInvalid( "Duplicate records match this record's name:",
 
80
                        array( "view?id=" => $results ) );
 
81
            }
 
82
        }
 
83
        
 
84
    }
 
85
 
 
86
 
 
87
}
 
88
# Local Variables:
 
89
# mode: php
 
90
# c-default-style: "bsd"
 
91
# indent-tabs-mode: nil
 
92
# c-basic-offset: 4
 
93
# End: