~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/Trainer/lib/iHRIS_Module_Trainer.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
 
 
4
class iHRIS_Module_Trainer extends I2CE_Module {
 
5
 
 
6
 
 
7
 
 
8
    /**
 
9
     * Return the array of hooks available in this module.
 
10
     * @return array
 
11
     */
 
12
    public static function getHooks() {
 
13
        return array(
 
14
                'validate_form_trainer' => 'validate_form_trainer',
 
15
                );
 
16
    }
 
17
 
 
18
    /**
 
19
     * Perform extra validation for the trainer form.
 
20
     * A new trainer record needs to verify there aren't any existing 
 
21
     * records with the same name.
 
22
     * @param I2CE_Form $form
 
23
     */
 
24
    public function validate_form_trainer( $form ) {
 
25
 
 
26
        $search = array();
 
27
        $surname_ignore = false;
 
28
        if ( isset( $form->surname_ignore ) ) {
 
29
            $surname_ignore = $form->surname_ignore;
 
30
        }
 
31
        if ( I2CE_ModuleFactory::instance()->isEnabled('forms-storage') 
 
32
             && $form->getId() == 0 && !$surname_ignore
 
33
             && I2CE_Validate::checkString( $form->surname ) 
 
34
             && I2CE_Validate::checkString( $form->firstname ) ) {
 
35
            $where = array(
 
36
                'operator' => 'AND',
 
37
                'operand'=>array(
 
38
                    0=>array(
 
39
                        'operator'=>'FIELD_LIMIT',
 
40
                        'field'=>'surname',
 
41
                        'style'=>'lowerequals',
 
42
                        'data'=>array('value'=>strtolower($form->surname))
 
43
                        ),
 
44
                    1=>array(
 
45
                        'operator'=>'FIELD_LIMIT',
 
46
                        'field'=>'firstname',
 
47
                        'style'=>'lowerequals',
 
48
                        'data'=>array('value'=>strtolower($form->firstname))                        
 
49
                        )
 
50
                    )
 
51
                );
 
52
            $results = I2CE_FormStorage::listFields('trainer',array('surname','firstname'),false,$where,array('surname','firstname'));
 
53
            if( count($results) > 0 ) {
 
54
                foreach ($results as $id=>&$data) {
 
55
                    $data = implode(', ', $data);
 
56
                }
 
57
                $form->getField('surname')->setInvalid( "Duplicate records match this record's name:",
 
58
                        array( "viewtrainer?id=" => $results ) );
 
59
            }
 
60
        }
 
61
        
 
62
    }
 
63
 
 
64
 
 
65
   
 
66
 
 
67
}
 
68
# Local Variables:
 
69
# mode: php
 
70
# c-default-style: "bsd"
 
71
# indent-tabs-mode: nil
 
72
# c-basic-offset: 4
 
73
# End: