/** * Create a property object * * @param array $arr_field_def * @param $mix_value * @return mixed */ protected function createProperty(array $arr_field_def, $mix_value) { $obj_property = new \Google_Service_Datastore_Property(); // Indexed? $bol_index = TRUE; if (isset($arr_field_def['index']) && FALSE === $arr_field_def['index']) { $bol_index = FALSE; } $obj_property->setIndexed($bol_index); switch ($arr_field_def['type']) { case Schema::PROPERTY_STRING: $obj_property->setStringValue((string) $mix_value); break; case Schema::PROPERTY_INTEGER: $obj_property->setIntegerValue((int) $mix_value); break; case Schema::PROPERTY_DATETIME: if ($mix_value instanceof \DateTime) { $obj_dtm = $mix_value; } else { $obj_dtm = new \DateTime($mix_value); } $obj_property->setDateTimeValue($obj_dtm->format(\DateTime::ATOM)); break; case Schema::PROPERTY_DOUBLE: case Schema::PROPERTY_FLOAT: $obj_property->setDoubleValue(floatval($mix_value)); break; case Schema::PROPERTY_BOOLEAN: $obj_property->setBooleanValue((bool) $mix_value); break; case Schema::PROPERTY_STRING_LIST: $obj_property->setIndexed(null); // Ensure we only index the values, not the list $arr_values = []; foreach ((array) $mix_value as $str) { $obj_value = new \Google_Service_Datastore_Value(); $obj_value->setStringValue($str); $obj_value->setIndexed($bol_index); $arr_values[] = $obj_value; } $obj_property->setListValue($arr_values); break; default: throw new \RuntimeException('Unable to process field type: ' . $arr_field_def['type']); } return $obj_property; }
/** * Create date property. */ protected function createIntegerProperty($intValue, $indexed = false) { $prop = new Google_Service_Datastore_Property(); $prop->setIntegerValue($intValue); $prop->setIndexed($indexed); return $prop; }