~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/OneDay/lib/iHRIS_Module_One_Day.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
class iHRIS_Module_One_Day extends I2CE_Module {
 
3
    public static function getMethods() {
 
4
        return array(
 
5
            'iHRIS_PageView->action_person_one_day' => 'action_person_one_day'
 
6
            
 
7
            );
 
8
    }
 
9
 
 
10
 
 
11
    public function action_person_one_day($obj) {
 
12
        if (!$obj instanceof iHRIS_PageView) {
 
13
            return;
 
14
        }
 
15
        return $obj->addChildForms('person_one_day');
 
16
    }
 
17
 
 
18
 public static function getHooks() {
 
19
        return array(
 
20
                'validate_form_person_one_day' => 'validate_form_person_one_day',
 
21
                );
 
22
    }
 
23
 
 
24
 
 
25
 public function validate_form_person_one_day( $form ) {
 
26
        if ( $form->training_date->isValid()  ) {
 
27
    
 
28
             $form->getField( 'training_date' )->setInvalid( 'Please enter a correct date.' );
 
29
            }
 
30
        
 
31
 
 
32
          
 
33
         $personID = $form->getParent();
 
34
         $ids = I2CE_FormStorage::search('person_one_day', $personID );
 
35
        //which would get the ids of the trainings for the person with id 'person|23123'.
 
36
 
 
37
        //You can then loop through each of these ids....
 
38
          $form_factory = I2CE_FormFactory::instance();
 
39
          $success = true;
 
40
          foreach($ids as $id) {
 
41
              $trainingObj = $form_factory->createContainer('person_one_day|' . $id);
 
42
              if (!$trainingObj instanceof iHRIS_PersonOne_Day) {
 
43
                  continue;
 
44
              }
 
45
              $trainingObj->populate();
 
46
 
 
47
              //do the checks for the dates here.
 
48
                if ( $form->training_date->compare( $trainingObj->training_date ) == 0 )   {
 
49
                   $success = false;
 
50
                   break; 
 
51
                
 
52
           }
 
53
      
 
54
 
 
55
          if (!$success) {
 
56
             $form->getField( "training_date" )->setInvalid( "Person cannot attend same training on same day" );
 
57
          }
 
58
        }
 
59
    }
 
60
}
 
61
?>