~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/BaylorMentorship/lib/iHRIS_Module_Baylor_Mentorship.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_Baylor_Mentorship extends I2CE_Module {
 
3
    public static function getMethods() {
 
4
        return array(
 
5
            'iHRIS_PageView->action_person_baylor_mentorship' => 'action_person_baylor_mentorship'
 
6
            
 
7
            );
 
8
    }
 
9
 
 
10
    public static function getHooks() {
 
11
        return array(
 
12
                'validate_form_person_baylor_mentorship' => 'validate_form_person_baylor_mentorship'
 
13
                );
 
14
    }
 
15
    public function action_person_baylor_mentorship($obj) {
 
16
        if (!$obj instanceof iHRIS_PageView) {
 
17
            return;
 
18
        }
 
19
        return $obj->addChildForms('person_baylor_mentorship', 'end_date');
 
20
    }
 
21
    /**
 
22
     * Checks to make sure the end date is after the start date for the person position.
 
23
     * @param I2CE_Form $form
 
24
     */
 
25
    public function validate_form_person_baylor_mentorship( $form ) {
 
26
        if ( $form->start_date->isValid() && $form->end_date->isValid() ) {
 
27
            if ( $form->start_date->compare( $form->end_date ) < 0 ) {
 
28
                $form->getField('end_date')->setInvalid( "The end date must be after the start date." );
 
29
            }
 
30
        }
 
31
 
 
32
        $personID = $form->getParent();
 
33
        $ids = I2CE_FormStorage::search('person_baylor_mentorship', $personID );
 
34
        //which would get the ids of the trainings for the person with id 'person|23123'.
 
35
 
 
36
        //You can then loop through each of these ids....
 
37
          $form_factory = I2CE_FormFactory::instance();
 
38
          $success = true;
 
39
          foreach($ids as $id) {
 
40
              $mentorshipObj = $form_factory->createContainer('person_baylor_mentorship|' . $id);
 
41
              if (!$mentorshipObj instanceof iHRIS_PersonBaylor_Mentorship) {
 
42
                  continue;
 
43
              }
 
44
              $mentorshipObj->populate();
 
45
 
 
46
              //do the checks for the dates here.
 
47
                if (( $form->start_date->compare( $mentorshipObj->start_date ) > 0 ) || ( $form->start_date->compare( $mentorshipObj->end_date ) < 0 )) {
 
48
                   $success = false;
 
49
                   break; 
 
50
                } else if (( $form->end_date->compare( $mentorshipObj->start_date ) > 0 ) || ( $form->end_date->compare( $mentorshipObj->end_date ) < 0 )) {
 
51
                   $success = false;
 
52
                   break; 
 
53
                }else if(( $form->start_date->compare( $mentorshipObj->start_date ) < 0 ) && ( $form->end_date->compare( $mentorshipObj->end_date ) > 0 )) {
 
54
                   $success = false;
 
55
                   break; 
 
56
                }
 
57
           }
 
58
      
 
59
 
 
60
          if (!$success) {
 
61
             $form->getField( "end_date" )->setInvalid( "The dates of the training overlap with another training" );
 
62
          }
 
63
     
 
64
 
 
65
}
 
66
   }
 
67
 
 
68
 
 
69
?>