public function add($item)
 {
     try {
         return parent::add($item);
     } catch (\UnderflowException $e) {
         // ignore
     } catch (\OverflowException $e) {
         // ignore
     }
     $factory = $this->factory;
     $this->attach($factory($this));
     return $this->add($item);
 }
Esempio n. 2
0
 /**
  * Flush the cached results for all relations (has_one, has_many, many_many)
  * Also clears any cached aggregate data.
  *
  * @param boolean $persistent When true will also clear persistent data stored in the Cache system.
  *                            When false will just clear session-local cached data 
  *
  */
 public function flushCache($persistent = true)
 {
     if ($persistent) {
         Aggregate::flushCache($this->class);
     }
     if ($this->class == 'DataObject') {
         DataObject::$_cache_get_one = array();
         return;
     }
     $classes = ClassInfo::ancestry($this->class);
     foreach ($classes as $class) {
         if (isset(DataObject::$_cache_get_one[$class])) {
             unset(DataObject::$_cache_get_one[$class]);
         }
     }
     $this->extend('flushCache');
     $this->components = array();
 }
 /**
  * Constructor
  * 
  * @param DataObject $object The object that has_many somethings that we're calculating the aggregate for 
  * @param string $relationship The name of the relationship
  * @param string $filter (optional) An SQL filter to apply to the relationship rows before calculating the
  *                       aggregate
  */
 public function __construct($object, $relationship, $filter = '')
 {
     $this->object = $object;
     $this->relationship = $relationship;
     $this->has_many = $object->has_many($relationship);
     $this->many_many = $object->many_many($relationship);
     if (!$this->has_many && !$this->many_many) {
         user_error("Could not find relationship {$relationship} on object class {$object->class} in" . " Aggregate Relationship", E_USER_ERROR);
     }
     parent::__construct($this->has_many ? $this->has_many : $this->many_many[1], $filter);
 }
Esempio n. 4
0
 /**
  * Add match clause to match all parts of the aggregate that needs to be updated
  *
  * @param IdentityInterface $identity
  * @param obkect $entity
  * @param Aggregate $meta
  * @param CollectionInterface $changeset
  * @param Query $query
  *
  * @return Query
  */
 private function matchAggregate(IdentityInterface $identity, $entity, Aggregate $meta, CollectionInterface $changeset, Query $query) : Query
 {
     $name = $this->name->sprintf(md5($identity->value()));
     $query = $query->match((string) $name, $meta->labels()->toPrimitive())->withProperty($meta->identity()->property(), (string) $name->prepend('{')->append('_identity}'))->withParameter((string) $name->append('_identity'), $identity->value());
     $this->variables = $this->variables->put($name, $this->buildProperties($changeset, $meta->properties()));
     $meta->children()->foreach(function (string $property, ValueObject $child) use(&$query, $changeset, $name) {
         if (!$changeset->hasKey($property)) {
             return;
         }
         $changeset = $changeset->get($property);
         $childName = null;
         $relName = $name->append('_')->append($property);
         $this->variables = $this->variables->put($relName, $this->buildProperties($changeset, $child->relationship()->properties()));
         if ($changeset->hasKey($child->relationship()->childProperty())) {
             $childName = $relName->append('_')->append($child->relationship()->childProperty());
             $this->variables = $this->variables->put($childName, $changeset->get($child->relationship()->childProperty()));
         }
         $query = $query->match((string) $name)->linkedTo($childName ? (string) $childName : null, $child->labels()->toPrimitive())->through((string) $child->relationship()->type(), (string) $relName);
     });
     return $query;
 }
Esempio n. 5
0
 public function doSomething(Aggregate $aggregate)
 {
     $iterator = $aggregate->createIterator();
     $iterator->next();
     return $iterator;
 }
Esempio n. 6
0
 protected function aggregate(Aggregate $aggregate)
 {
     $sql = strtoupper($aggregate->getFunction());
     $sql .= '(';
     if ($aggregate->isDistinct()) {
         $sql .= 'DISTINCT ';
     }
     $sql .= $this->columns($aggregate->getColumns());
     $sql .= ')';
     return $sql;
 }
Esempio n. 7
0
 public function __construct()
 {
     parent::__construct();
     $this->range = "today";
 }
 public function flushCache($persistent = true)
 {
     if ($persistent) {
         Aggregate::flushCache($this->class);
     }
     if ($this->class == 'ExternalDataObject') {
         ExternalDataObject::$_cache_get_one = array();
         return $this;
     }
     $classes = class_parents($this->class) + array($this->class => $this->class);
     foreach ($classes as $class) {
         if (isset(ExternalDataObject::$_cache_get_one[$class])) {
             unset(ExternalDataObject::$_cache_get_one[$class]);
         }
     }
     $this->extend('flushCache');
     return $this;
 }