/** * {@inheritDoc} * @param string $qty * @param array $filterComponents * @param int Bitmask fo class constants * @return Bond\Container */ public function findByFilterComponents($qty, array $filterComponents, $source = null) { $source = $this->findByFilterComponentsSourceSetup($source); $output = $this->makeNewContainer(); $profiler = new Profiler(__FUNCTION__); $profiler->log("setup"); if ($source & self::UNPERSISTED) { $output->add($this->findByFilterComponentsMultiton($filterComponents, $source)); } $profiler->log("multiton"); if ($source & self::PERSISTED) { $cannotMatch = function ($entity) { return $entity instanceof Base ? $entity->isNew() : false; }; // If all of the filter components can't match - that is return true - there isn't any point in going to the db $checkDatabase = !\Bond\array_check(function ($filterComponent) use($cannotMatch) { return $filterComponent->getCannotMatch($cannotMatch); }, $filterComponents, false); if ($checkDatabase) { $output->add($this->findByFilterComponentsDatabase($filterComponents, $source)); } } $profiler->log("database"); return $this->findByFilterComponentsFormatReturnValue($qty, $output); }
/** * Standard getter $cannotMatch * @return bool */ public function getCannotMatch(callable $cannotMatch) { return \Bond\array_check($cannotMatch, $this->findFilterComponents); }
/** * Helper function. Get dataTypes for this Entity. * @return array */ public function dataTypesGet($filter = null) { // array of string if (func_num_args() > 1 and \Bond\array_check('is_string', func_get_args())) { $filter = func_get_args(); } // filter constants if (is_int($filter)) { $dataTypes = array(); if ($filter & DataType::PRIMARY_KEYS) { $dataTypes += array_filter($this->dataTypes, function ($dataType) { return $dataType->isPrimaryKey(); }); } if ($filter & DataType::FORM_CHOICE_TEXT) { $dataTypes += array_filter($this->dataTypes, function ($dataType) { return $dataType->isFormChoiceText(); }); } if ($filter & DataType::AUTOCOMPLETE) { $dataTypes += array_filter($this->dataTypes, function ($dataType) { return $dataType->isAutoComplete(); }); } // todo. build a datatype from the $this->links et al if ($filter & DataType::LINKS) { } return $dataTypes; } if (is_string($filter)) { $filter = array($filter); } if (is_array($filter)) { $result = array_intersect_key($this->dataTypes, array_flip($filter)); if (count($result) != count($filter)) { throw new \InvalidArgumentException(sprintf('Unknown columns "%s" passed to %s->dataTypesGet()', implode('","', array_diff($filter, array_keys($result))), $this->entity)); } return $result; } if ($filter instanceof \Closure) { return array_filter($this->dataTypes, $filter); } return $this->dataTypes; }