function create_entity()
{
    $entity = new Google_Service_Datastore_Entity();
    $entity->setKey(createKeyForTestItem());
    $string_prop = new Google_Service_Datastore_Property();
    $string_prop->setStringValue("test field string value");
    $property_map = [];
    $property_map["testfield"] = $string_prop;
    $entity->setProperties($property_map);
    return $entity;
}
 /**
  * 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;
 }
Exemple #3
0
function create_entity($hashkey, $text)
{
    $entity = new Google_Service_Datastore_Entity();
    $entity->setKey(createKeyForTestItem());
    $string_prop_hash = new Google_Service_Datastore_Property();
    $string_prop_hash->setStringValue($hashkey);
    $string_prop_text = new Google_Service_Datastore_Property();
    $string_prop_text->setStringValue($text);
    $property_map = [];
    $property_map["hash"] = $string_prop_hash;
    $property_map["text"] = $string_prop_text;
    $entity->setProperties($property_map);
    return $entity;
}
 /**
  * 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 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;
 }
 /**
  * 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;
 }
 /**
  * @param mixed $value
  * @param Type|string $type
  * @param boolean $indexed
  * @return \Google_Service_Datastore_Property
  */
 public static function newProperty($value, $type, $indexed = true)
 {
     $property = new \Google_Service_Datastore_Property();
     if ($value instanceof \DateTime) {
         $value = $value->format(DateTime::ATOM);
     } else {
         if ($value instanceof BaseEntityModel) {
             $value = $value->exportEntity();
         }
     }
     call_user_func([$property, Type::get($type)->getFuncName('set')], $value);
     if ($indexed === true) {
         $property->setIndexed($indexed);
     }
     return $property;
 }
 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;
 }
Exemple #9
0
 /**
  * Create boolean property.
  */
 protected function createBooleanProperty($b, $indexed = false)
 {
     $prop = new Google_Service_Datastore_Property();
     $prop->setBooleanValue($b);
     $prop->setIndexed($indexed);
     return $prop;
 }