@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | elseif (ModelUtils::gettype($my_doc[$key]) == "array" && $my_model[$key]['_type'] !="array") { |
| 97 | - $my_doc[$key]=$my_model[$key]['_default']; |
|
| 97 | + $my_doc[$key]=$my_model[$key]['_default']; |
|
| 98 | 98 | } |
| 99 | 99 | // If array[key] is not an array and not has same variable type that stated in the model definition. |
| 100 | 100 | else { |
@@ -122,47 +122,47 @@ discard block |
||
| 122 | 122 | // If array does not have this key, set the default value. |
| 123 | 123 | if (! isset($my_doc[$key])) { |
| 124 | 124 | if(isset($my_model[$key]['_input_type'])){ |
| 125 | - switch ($my_model[$key]['_input_type']){ |
|
| 125 | + switch ($my_model[$key]['_input_type']){ |
|
| 126 | 126 | case 'uid': |
| 127 | 127 | $shortid = ShortId::create(); |
| 128 | 128 | $new_doc[$key]=$shortid->generate(); |
| 129 | 129 | break; |
| 130 | - case 'date': |
|
| 131 | - if($my_model[$key]['_default']=='today'){ |
|
| 132 | - $new_doc[$key] = date("Y-m-d"); |
|
| 133 | - } |
|
| 134 | - else{ |
|
| 135 | - $new_doc[$key]=$my_model[$key]['_default']; |
|
| 136 | - } |
|
| 137 | - break; |
|
| 138 | - case 'timestamp': |
|
| 139 | - if(($my_model[$key]['_default']=="now") && ($my_model[$key]['_type'] == "integer")){ |
|
| 140 | - $new_doc[$key] = time(); |
|
| 141 | - } |
|
| 142 | - else if($my_model[$key]['_default']=="now" && ($my_model[$key]['_type']=="string")){ |
|
| 130 | + case 'date': |
|
| 131 | + if($my_model[$key]['_default']=='today'){ |
|
| 132 | + $new_doc[$key] = date("Y-m-d"); |
|
| 133 | + } |
|
| 134 | + else{ |
|
| 135 | + $new_doc[$key]=$my_model[$key]['_default']; |
|
| 136 | + } |
|
| 137 | + break; |
|
| 138 | + case 'timestamp': |
|
| 139 | + if(($my_model[$key]['_default']=="now") && ($my_model[$key]['_type'] == "integer")){ |
|
| 140 | + $new_doc[$key] = time(); |
|
| 141 | + } |
|
| 142 | + else if($my_model[$key]['_default']=="now" && ($my_model[$key]['_type']=="string")){ |
|
| 143 | 143 | |
| 144 | - $new_doc[$key] = date("Y-m-d H:i:s"); |
|
| 145 | - } |
|
| 146 | - else{ |
|
| 147 | - $new_doc[$key]=$my_model[$key]['_default']; |
|
| 148 | - } |
|
| 149 | - break; |
|
| 144 | + $new_doc[$key] = date("Y-m-d H:i:s"); |
|
| 145 | + } |
|
| 146 | + else{ |
|
| 147 | + $new_doc[$key]=$my_model[$key]['_default']; |
|
| 148 | + } |
|
| 149 | + break; |
|
| 150 | 150 | |
| 151 | - default: |
|
| 152 | - $new_doc[$key]=$my_model[$key]['_default']; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - else{ |
|
| 156 | - $new_doc[$key]=$my_model[$key]['_default']; |
|
| 157 | - } |
|
| 151 | + default: |
|
| 152 | + $new_doc[$key]=$my_model[$key]['_default']; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + else{ |
|
| 156 | + $new_doc[$key]=$my_model[$key]['_default']; |
|
| 157 | + } |
|
| 158 | 158 | } |
| 159 | 159 | // If array has this key |
| 160 | 160 | else { |
| 161 | 161 | // If model definition stated this key's default value is not Null and has a wrong variable type, fix it. |
| 162 | 162 | if ($my_model[$key]['_default'] !== null) { |
| 163 | - if(ModelUtils::gettype($my_doc[$key]) != $my_model[$key]['_type'] && ModelUtils::gettype($my_doc[$key]) == "array"){ |
|
| 164 | - $my_doc[$key]=$my_model[$key]['_default']; |
|
| 165 | - } |
|
| 163 | + if(ModelUtils::gettype($my_doc[$key]) != $my_model[$key]['_type'] && ModelUtils::gettype($my_doc[$key]) == "array"){ |
|
| 164 | + $my_doc[$key]=$my_model[$key]['_default']; |
|
| 165 | + } |
|
| 166 | 166 | settype($my_doc[$key], $my_model[$key]['_type']); |
| 167 | 167 | } |
| 168 | 168 | $new_doc[$key] = $my_doc[$key]; |