Serialize a collection of conditions

@param ConditionCollection $collection A collection of conditions

@return string A ready to be stored Condition collection
545289
public function serializeConditionCollection(ConditionCollection $collection)
    {
        if ($collection->count() == 0) {
            /** @var ConditionInterface $conditionNone */
            $conditionNone = $this->container->get(
                'thelia.condition.match_for_everyone'
            );
            $collection[] = $conditionNone;
        }
        $serializableConditions = [];
        /** @var $condition ConditionInterface */
        foreach ($collection as $condition) {
            $serializableConditions[] = $condition->getSerializableCondition();
        }

        return base64_encode(json_encode($serializableConditions));
    }
934407
public function match(RecordCollection $collection, RecordCollection $recordsLoaded)
    {
        $dictionary = $this->buildDictionary($recordsLoaded);

        foreach ($collection as $record) {
            /** @var Record $record */
            $results = $this->getResultsFromCollectionDictionary($dictionary, $collection, $record);
            /** @noinspection PhpUnhandledExceptionInspection */
            $record->getRelation($this->getName())->setResults($results);
        }

        return $recordsLoaded;
    }
1141014
protected function dispatchCollection($collection)
    {
        // find and send group variables
        $group = isset($collection['group']) ? $collection['group'] : null;
        // dispatch action dispatcher
        $content = $this->getActionDispatcher()->dispatch($collection['action'], $group);
        if (is_string($content)) {
            $this->sendContentString($content, $this->getRequest());
        }
    }
1084248
public function prepareCollection(ProductCollection $collection)
    {
        $terms = $this->getQueryText();

        $collection->setSearchQuery($terms);

        return $collection;
    }
637039
public function put_version($collection, $version)
    {
        if ($version) {
            $this->get_versions();
            $this->versions[$collection] = $version;
            $version_path = $this->get_path('versions');
            return $this->write_cache($version_path, $this->versions);
        }
    }
484075
public function union( common_Collection $collection)
    {
        $returnValue = null;

        
        $returnValue = new core_kernel_classes_ContainerCollection($this);     
        $returnValue->sequence = array_merge($this->sequence, $collection->sequence );      
        

        return $returnValue;
    }
736
public function get($condition)
    {
        $result = null;
        $this->hook->attach('collection.get.before', $condition, $result, $this);

        if (isset($result)) {
            return $result;
        }

        if (!is_array($condition)) {
            $condition = array('collection_id' => $condition);
        }

        $condition['limit'] = array(0, 1);
        $list = (array) $this->getList($condition);
        $result = empty($list) ? array() : reset($list);

        $this->hook->attach('collection.get.after', $condition, $result, $this);
        return $result;
    }
9352
public function unserializeCollection($collection)
    {
        if (is_array($collection)) {
            return array_map(function ($value) {
                return maybe_unserialize(reset($value));
            }, $collection);
        }

        return maybe_unserialize($collection);
    }
461657
public function renderTemplate(Collection $collection)
    {
        $escapeHtmlAttribHelper = $this->getEscapeHtmlAttrHelper();
        $fieldSetHelper = $this->getFieldsetHelper();

        $templateMarkup = '';

        $elementOrFieldSet = $collection->getTemplateElement();

        if ($elementOrFieldSet instanceof AbstractLineFieldSet) {
            $templateMarkup .= sprintf(
                $this->rowWrap,
                $this->getLineType(),
                $fieldSetHelper($elementOrFieldSet, $this->shouldWrap()),
                ucfirst($this->getLineType())
            );
        }

        return sprintf(
            $this->getTemplateWrapper(),
            $this->getLineType(),
            $escapeHtmlAttribHelper($templateMarkup)
        );
    }
516939
public function collection(Collection $collection)
    {
        $entries = new Entries();

        foreach ($collection as $product) {
            $entry = new Entry($product);

            $entry
                ->field('id')
                ->field('name')
                ->field('description')
                ->field('sku')
                ->field('status')
                ->field('price')
                ->field('sale_price')
                ->field('quantity')

                ->value('image', $product->product->defaultImage())
                // ->relationshipField('product', 'Subbly\\Presenter\\V1\\ProductPresenter')

                ->dateField('created_at')
                ->dateField('updated_at')
            ;

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
645949
public function newCollectionUpdateStruct(?Collection $collection = null): CollectionUpdateStruct
    {
        $collectionUpdateStruct = new CollectionUpdateStruct();

        if ($collection !== null) {
            $collectionUpdateStruct->offset = $collection->getOffset();
            $collectionUpdateStruct->limit = $collection->getLimit() ?? 0;
        }

        return $collectionUpdateStruct;
    }
348378
private function _collection($collection) {
    return (!is_array($collection) && !is_object($collection)) ? str_split((string) $collection) : $collection;
  }
748008
public function listCollections($condition = [], $options = [])
    {
        $this->document = $this->db->getQueryBuilder()->listCollections($condition, $options);
        $cursor = $this->execute();

        return $cursor->toArray();
    }
1198575
protected function cleanup($entityName, array $collection, array $conditions)
    {
        if (!$existing = $this->isCleanupNecessary($entityName, $conditions)) {
            return;
        }

        $identifiers = [];
        foreach ($collection as $instance) {
            $identifiers[] = $this->identifyEntity($instance, $entityName);
        }

        foreach ($existing as $instance) {
            if (in_array($this->identifyEntity($instance, $entityName), $identifiers)) {
                continue;
            }

            $this->storage->delete($instance, $entityName)->execute();
        }

        return;
    }
821504
private function prepareProductCollection(ProductCollection $collection)
    {
        foreach ($this->collectionProcessors as $processor) {
            $collection = $processor->prepareCollection($collection);
        }

        return $collection;
    }
482700
protected function aggregate(ConditionInterface $condition)
    {
        if (!$condition->getParameters()) {
            return '';
        }

        $this->aggNumber++;
        $prefix = str_repeat('_', $this->aggNumber);
        $qb = $this->cloneQb($this->queryBuilder);

        $this->resetSqlParts($qb)
            ->select(sprintf('DISTINCT %s%s', $prefix, $this->aliasDotPrimary()))
            ->addGroupBy(sprintf('%s%s', $prefix, $this->aliasDotPrimary()));
        /** @var From $fromPart */
        foreach ($this->getSqlPart($this->queryBuilder, 'from') as $fromPart) {
            /** @var Base $newFrom */
            $newFrom = new From($fromPart->getFrom(), $prefix.$fromPart->getAlias());
            $qb->add('from', $newFrom, true);
        }
        foreach ($this->getSqlPart($this->queryBuilder, 'join') as $rootAlias => $joinPart) {
            /** @var Join $subPart */
            foreach ($joinPart as $subPart) {
                $join = new Join(
                    $subPart->getJoinType(),
                    $prefix.$subPart->getJoin(),
                    $prefix.$subPart->getAlias()
                );
                /** @var Base $newJoin */
                $newJoin = [$prefix.$rootAlias => $join];
                $qb->add('join', $newJoin, true);
            }
        }

        $newParameters = [];
        foreach ($condition->getParameters() as $paramName => $paramValue) {
            $newParameters[str_replace(':', ':'.$prefix, $paramName)] = $paramValue;
        }

        if (count($newParameters) === 2 && stripos($condition->getComparisonOperator(), Condition::BETWEEN) !== false) {
            $newParameterName = implode(' AND ', array_keys($newParameters));
        } else {
            $newParameterName = key($newParameters);
        }

        $qb->andHaving($condition->getSqlFunctionDefinition($newParameterName, $prefix))->setParameters([]);

        foreach ($newParameters as $paramName => $paramValue) {
            $parameter = new Parameter($paramName, $paramValue);
            $this->parameters->add($parameter);
        }

        return sprintf('%s IN(%s)', $this->aliasDotPrimary(), $qb->getDQL());
    }
495194
public function onPreHandleRequestWithCollection(Collection $collection) {
        $output = new ArrayCollection();
        foreach ($collection as $current) {
            $output->add($current);
        }
        return $output;
    }