~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/i2ce/modules/Forms/lib/fields/I2CE_FormField_DB_DATE.php

  • Committer: litlfred at ibiblio
  • Date: 2009-10-23 12:59:28 UTC
  • Revision ID: litlfred@ibiblio.org-20091023125928-u5lkafz0urm9t8eq
updated ihris-suite to 4.0.1-prerelease -- not debugged

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
/*
3
 
 * © Copyright 2007, 2008 IntraHealth International, Inc.
4
 
 * 
5
 
 * This File is part of iHRIS
6
 
 * 
7
 
 * iHRIS is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU General Public License as published by
 
2
/**
 
3
 * @copyright © 2007, 2008, 2009 Intrahealth International, Inc.
 
4
 * This File is part of I2CE
 
5
 *
 
6
 * I2CE is free software; you can redistribute it and/or modify it
 
7
 * under the terms of the GNU General Public License as published by
9
8
 * the Free Software Foundation; either version 3 of the License, or
10
9
 * (at your option) any later version.
11
10
 * 
16
15
 * 
17
16
 * You should have received a copy of the GNU General Public License
18
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
 *//**
20
18
    * @package I2CE
21
19
    * @author Luke Duncan <lduncan@intrahealth.org>
22
 
    * @copyright Copyright &copy; 2007, 2008 IntraHealth International, Inc. 
23
20
    * @since v2.0.0
24
21
    * @version v2.0.0
25
22
    */
31
28
abstract class I2CE_FormField_DB_DATE extends I2CE_FormField { 
32
29
        
33
30
    /**
 
31
     * A string type for the field 
 
32
     */
 
33
    const FIELD_TYPE_I2CE = 'date';
 
34
    /**
 
35
     * The database type for the field
 
36
     */
 
37
    const FIELD_TYPE_DB = 'datetime default NULL';
 
38
    /**
 
39
     * The MDB2 type for the field.
 
40
     */
 
41
    const FIELD_TYPE_MDB2 = 'timestamp';
 
42
 
 
43
 
 
44
   /**
34
45
     * Return the value of this field from the database format for the given type
35
46
     * @param integer $type The type of the field to be returned.
36
47
     * @param mixed $value
56
67
     */
57
68
    public function __construct( $name, $options ) {
58
69
        parent::__construct($name, $options);
59
 
        $this->field_type_string = 'date';
60
 
        $this->field_type_report_db = 'DATETIME';
61
 
        $this->field_type_db = 'datetime';
62
 
        $this->field_type_mdb2 = 'timestamp';
63
70
        $this->start_year = 0;
64
71
        $this->end_year = 0;
65
72
    }
72
79
     * @return mixed
73
80
     */
74
81
    public function getDBValue() {
75
 
        return $this->getValue()->dbFormat();
 
82
        $date = $this->getValue();
 
83
        if (!$date instanceof I2CE_DatE) {
 
84
            return null;
 
85
        }
 
86
        return $date->dbFormat();
76
87
    }
77
88
 
78
89
        
95
106
        }
96
107
    }
97
108
 
 
109
 
 
110
    /**
 
111
     * Checks to see if the value has been set.
 
112
     * @return boolean
 
113
     */
 
114
    public function issetValue() {
 
115
        return ($this->value instanceof I2CE_Date);
 
116
    }
98
117
        
99
118
        
100
119
    /**
113
132
     * @param mixed $value
114
133
     * @return boolean
115
134
     */
116
 
    public function isSameValue( $db_value ) {
117
 
        $check_date = I2CE_Date::fromDB( $db_value );
118
 
        if ( $this->getValue()->compare( $check_date ) == 0 ) {
119
 
            return true;
120
 
        } else {
121
 
            return false;
122
 
        }
 
135
    public function isSameValue( $db_value ) {        
 
136
        return ($this->compare($db_value) == 0);
123
137
    }   
124
138
 
 
139
        /**
 
140
     * Compares this form field agains the given form field.
 
141
     * @param mixed $db_value Either a DB Value or an I2CE_FormField
 
142
     * @returns -1,0,1
 
143
     */
 
144
    public function compare($db_value) {
 
145
        if (is_string($db_value)) {
 
146
            $db_value = I2CE_Date::fromDB($db_value);
 
147
        } else if ($db_value instanceof I2CE_FormField_DB_Date) {
 
148
            $db_value = $db_value->getValue();
 
149
        }
 
150
        if (!$db_value instanceof I2CE_Date) {
 
151
            if ( $this->isValid() ) {
 
152
                return 1;
 
153
            } else {
 
154
                return 0;
 
155
            }
 
156
        } elseif(!$this->getValue() instanceof I2CE_Date) {
 
157
            I2CE::raiseError("Trying to compare a non-set date");
 
158
            return -1;
 
159
        }
 
160
        return $this->getValue()->compare($db_value);
 
161
    }
 
162
 
 
163
 
125
164
    public function setYearRange( $start, $end=0 ) {
126
165
        $this->start_year = $start;
127
166
        $this->end_year = $end;