/** * Creates the basic entity for DatastoreComment, with properties "created" * "name", and "body" */ public function createEntity(\Google_Service_Datastore_Key $key, $name, $body) { $entity = new \Google_Service_Datastore_Entity(); $entity->setKey($key); $nameProp = new \Google_Service_Datastore_Property(); $nameProp->setStringValue($name); $bodyProp = new \Google_Service_Datastore_Property(); $bodyProp->setStringValue($body); $createdProp = new \Google_Service_Datastore_Property(); $createdProp->setDateTimeValue(date('c')); $properties = ['name' => $nameProp, 'body' => $bodyProp, 'created' => $createdProp]; $entity->setProperties($properties); return $entity; }
/** * Create date property. */ protected function createDateProperty($date, $indexed = false) { $prop = new Google_Service_Datastore_Property(); $dateValue = new DateTime($date); $prop->setDateTimeValue($dateValue->format(DateTime::ATOM)); $prop->setIndexed($indexed); return $prop; }
/** * 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; }
/** * Creates the basic entity for PubSubMessage, with properties "created" * and "message" */ public function createEntity(\Google_Service_Datastore_Key $key, $message) { $entity = new \Google_Service_Datastore_Entity(); $entity->setKey($key); $messageProp = new \Google_Service_Datastore_Property(); $messageProp->setStringValue($message); $createdProp = new \Google_Service_Datastore_Property(); $createdProp->setDateTimeValue(date('c')); $properties = ['message' => $messageProp, 'created' => $createdProp]; $entity->setProperties($properties); return $entity; }
protected function createProperty($input, $indexed = false, $type = null) { $prop = new \Google_Service_Datastore_Property(); if (is_string($input)) { $prop->setStringValue($input); $prop->setIndexed($indexed); } elseif ($type == self::TYPE_DATE) { $date = new DateTime($input); $prop->setDateTimeValue($date->format(DateTime::ATOM)); $prop->setIndexed($indexed); } else { if (is_array($input)) { $values = []; foreach ($input as $s) { $value = new \Google_Service_Datastore_Value(); $value->setStringValue($s); $value->setIndexed($indexed); $values[] = $value; } $prop->setListValue($values); } } return $prop; }