/**
  * Create a query filter on a date property.
  * @param $name property name
  * @param $value property value
  * @param $operator filter operator
  */
 protected static function createDateFilter($name, $value, $operator = 'greaterThan')
 {
     $date_value = new Google_Service_Datastore_Value();
     $date_time = new DateTime($value);
     $date_value->setDateTimeValue($date_time->format(DateTime::ATOM));
     $property_ref = new Google_Service_Datastore_PropertyReference();
     $property_ref->setName($name);
     $property_filter = new Google_Service_Datastore_PropertyFilter();
     $property_filter->setProperty($property_ref);
     $property_filter->setValue($date_value);
     $property_filter->setOperator($operator);
     $filter = new Google_Service_Datastore_Filter();
     $filter->setPropertyFilter($property_filter);
     return $filter;
 }
示例#2
0
 /**
  * @return \Google_Service_Datastore_Filter
  * @throws MissingFieldsException
  */
 public function build()
 {
     $propertyFilter = new \Google_Service_Datastore_PropertyFilter();
     $missing = [];
     if (empty($this->property)) {
         $missing[] = '$propertyName';
     }
     if (empty($this->operator)) {
         $missing[] = '$operator';
     }
     if (empty($this->value)) {
         $missing[] = '$value';
     }
     if (!empty($missing)) {
         throw new MissingFieldsException(self::class, $missing);
     }
     $propertyFilter->setProperty($this->property);
     $propertyFilter->setOperator($this->operator->value());
     $propertyFilter->setValue($this->value);
     $filter = new \Google_Service_Datastore_Filter();
     $filter->setPropertyFilter($propertyFilter);
     return $filter;
 }