~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/Instance/lib/iHRIS_Module_Instance.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
class iHRIS_Module_Instance extends I2CE_Module {
 
4
 
 
5
 
 
6
    public static function getMethods() {
 
7
        return array(
 
8
            'iHRIS_PageView->action_instance' => 'action_instance'
 
9
            );
 
10
    }
 
11
 
 
12
    /**
 
13
     * Return the array of hooks available in this module.
 
14
     * @return array
 
15
     */
 
16
    public static function getHooks() {
 
17
        return array(
 
18
                'validate_form_instance' => 'validate_form_instance',
 
19
                );
 
20
    }
 
21
 
 
22
     public function action_instance( $page ) {
 
23
        if ( !$page instanceof iHRIS_PageView ) {
 
24
            I2CE::raiseError("invalid call");
 
25
            return false;
 
26
        }
 
27
        return $page->addLastChildForm( 'instance', 'baylor_training_type' );
 
28
    }
 
29
/*
 
30
    public function action_person_baylor_training($obj) {
 
31
        if (!$obj instanceof iHRIS_PageView) {
 
32
            I2CE::raiseError("invalid call");
 
33
            return false;;
 
34
        }
 
35
        //do nothing so that an warning message is avoided
 
36
        return true;
 
37
    }
 
38
*/
 
39
 
 
40
    /**
 
41
     * Checks to make sure the end of applicability is after the start of applicability.
 
42
     * @param I2CE_Form $form
 
43
     
 
44
    public function validate_form_baylor_training_instance( $form ) {
 
45
        if ( $form->actual_start_date->isValid() && $form->actual_end_date->isValid() ) {
 
46
            if ($form->actual_start_date->compare( $form->actual_end_date ) < 0 ) {
 
47
                //$form->getField( 'end_date' )->setInvalid( $form->start_date );
 
48
                $form->getField( 'actual_end_date' )->setInvalid( 'The end date must be after the start date.' );
 
49
            }
 
50
        }
 
51
 
 
52
         /* 
 
53
         $personID = $form->getParent();
 
54
        $ids = I2CE_FormStorage::search('person_baylor_training', $personID );
 
55
     
 
56
          $form_factory = I2CE_FormFactory::instance();
 
57
    
 
58
          foreach($ids as $id) {
 
59
              $trainingObj = $form_factory->createContainer('person_baylor_training|' . $id);
 
60
               
 
61
              if (!$trainingObj instanceof iHRIS_PersonBaylor_Training) {
 
62
                  continue;
 
63
           
 
64
             }
 
65
             
 
66
                $trainingObj->populate();
 
67
     
 
68
               if (( $form->start_date->compare( $trainingObj->start_date ) < 0 ) && ( $form->start_date->compare( $trainingObj->end_date ) > 0 )){                
 
69
                       $form->getField( "end_date" )->setInvalid( "The dates of the training overlap with another training, One cannot attend two trainings within the same period of time" ); 
 
70
                       break;
 
71
           }else if (( $form->end_date->compare( $trainingObj->start_date ) < 0 ) && ( $form->end_date->compare( $trainingObj->end_date ) > 0 )){                
 
72
                       $form->getField( "end_date" )->setInvalid( "The dates of the training overlap with another training, One cannot attend two trainings within the same period of time" ); 
 
73
                       break;
 
74
          // }else if (( $form->start_date->compare( $trainingObj->end_date ) > 0 ) && ( $form->end_date->compare( $trainingObj->end_date ) > 0 )){                
 
75
             //          $form->getField( "end_date" )->setInvalid( "The dates of the training overlap with another training" ); 
 
76
               //        break;
 
77
           }
 
78
    
 
79
 }*/
 
80
 
 
81
 
 
82
//}
 
83
}
 
84