Get formated datas for a collection.

@param \Subbly\Model\Collection $collection

@return \Illuminate\Support\Collection
335547
public function collection(Collection $collection)
    {
        $entries = new Entries();

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

            $entry
                ->conditionalField('id', function () {
                    return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth');
                })

                ->field('position')
                ->field('name')
                ->field('description')
                ->field('sku')
                ->field('status')
                ->field('price')
                ->field('sale_price')
                ->field('quantity')

                ->relationshipField('images', 'Subbly\\Presenter\\V1\\ProductImagePresenter')
                ->relationshipField('options', 'Subbly\\Presenter\\V1\\ProductOptionPresenter')
                ->relationshipField('categories', 'Subbly\\Presenter\\V1\\ProductCategoryPresenter')

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

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
1133092
protected function collection_to_array($collection)
    {
        if ($collection instanceof self) {
            return $collection->toArray();

        } else if ($collection instanceof \Traversable) {
            return iterator_to_array($collection);

        } else if ($collection instanceof Arrayable) {
            return $collection->toArray();

        } else if ($collection instanceof Jsonable) {
            return json_decode($collection->toJson(), true);

        } else if (is_object($collection) || is_array($collection)) {
            return (array)$collection;

        } else {
            throw new \InvalidArgumentException(sprintf(
                '$collection has type %s, which is not collection-like',
                gettype($collection)
            ));
        }
    }
572712
public function collection(Collection $collection)
    {
        $entries = new Entries();

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

            $entry
                ->field('id')
                ->field('firstname')
                ->field('lastname')
                ->field('address1')
                ->field('address2')
                ->field('zipcode')
                ->field('city')
                ->field('country')
                ->field('phone_work')
                ->field('phone_home')
                ->field('phone_mobile')
                ->field('other_informations')
            ;

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
245516
protected function addPreview(Collection $collection)
    {
        return $collection->setPreview(
            $this->getPreview($collection->getId(), $collection->getLocale())
        );
    }
283386
public static function get_metadata(collection $collection) : collection {
        $completedfields = [
            'userid' => 'privacy:metadata:completed:userid',
            'timemodified' => 'privacy:metadata:completed:timemodified',
            'anonymous_response' => 'privacy:metadata:completed:anonymousresponse',
        ];

        $collection->add_database_table('feedback_completed', $completedfields, 'privacy:metadata:completed');
        $collection->add_database_table('feedback_completedtmp', $completedfields, 'privacy:metadata:completedtmp');

        $valuefields = [
            'value' => 'privacy:metadata:value:value'
        ];

        $collection->add_database_table('feedback_value', $valuefields, 'privacy:metadata:value');
        $collection->add_database_table('feedback_valuetmp', $valuefields, 'privacy:metadata:valuetmp');

        return $collection;
    }
1290858
public static function getCollectionTopics(Collection $collection) {
		$url = self::getTopicsUrl($collection);

		$response = Client::GET($url, self::getHeaders($collection));

		$body = self::getDataFromResponse($response);
		if (!property_exists($body, "topicIds")) {
			return null;
		}

		return $body->{"topicIds"};
	}
211923
public static function get_metadata(collection $collection) : collection {
        $collection->add_database_table(
            'tool_dataprivacy_request',
            [
                'comments' => 'privacy:metadata:request:comments',
                'userid' => 'privacy:metadata:request:userid',
                'requestedby' => 'privacy:metadata:request:requestedby',
                'dpocomment' => 'privacy:metadata:request:dpocomment',
                'timecreated' => 'privacy:metadata:request:timecreated'
            ],
            'privacy:metadata:request'
        );

        $collection->add_user_preference(tool_helper::PREF_REQUEST_FILTERS,
            'privacy:metadata:preference:tool_dataprivacy_request-filters');
        $collection->add_user_preference(tool_helper::PREF_REQUEST_PERPAGE,
            'privacy:metadata:preference:tool_dataprivacy_request-perpage');

        return $collection;
    }
791879
public function collection(Collection $collection)
    {
        $entries = new Entries();

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

            $entry
                ->conditionalField('id', function () {
                    return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth');
                })

                ->field('uid')
                ->field('email')
                ->field('firstname')
                ->field('lastname')
                ->compositeField('displayName', 'firstname', 'lastname')

                ->relationshipField('addresses', 'Subbly\\Presenter\\V1\\UserAddressPresenter')
                ->integer('orders_total', $user->countOrders())
                ->relationshipField('orders', 'Subbly\\Presenter\\V1\\OrderPresenter')
                ->relationshipField('groups', 'Subbly\\Presenter\\V1\\GroupPresenter')

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

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
9352
public function unserializeCollection($collection)
    {
        if (is_array($collection)) {
            return array_map(function ($value) {
                return maybe_unserialize(reset($value));
            }, $collection);
        }

        return maybe_unserialize($collection);
    }
79449
public function haveInCollection($collection, array $data)
    {
        $collection = $this->driver->getDbh()->selectCollection($collection);
        if ($this->driver->isLegacy()) {
            $collection->insert($data);
            return $data['_id'];
        }

        $response = $collection->insertOne($data);
        return (string) $response->getInsertedId();
    }
691959
public function getCollectionId($collection)
    {
        if ($collection instanceof Collection) {
            $collectionId = $collection->getId();

            return $collectionId;
        }

        $collectionId = $collection;

        return $collectionId;
    }
851076
public static function get_metadata(collection $collection) : collection {
        $messageemailmessages = [
            'useridto' => 'privacy:metadata:message_email_messages:useridto',
            'conversationid' => 'privacy:metadata:message_email_messages:conversationid',
            'messageid' => 'privacy:metadata:message_email_messages:messageid',
        ];
        // Note - this data gets deleted once the scheduled task runs.
        $collection->add_database_table('message_email_messages',
            $messageemailmessages, 'privacy:metadata:message_email_messages');

        $collection->link_external_location('smtp', [
                'recipient' => 'privacy:metadata:recipient',
                'userfrom' => 'privacy:metadata:userfrom',
                'subject' => 'privacy:metadata:subject',
                'fullmessage' => 'privacy:metadata:fullmessage',
                'fullmessagehtml' => 'privacy:metadata:fullmessagehtml',
                'attachment' => 'privacy:metadata:attachment',
                'attachname' => 'privacy:metadata:attachname',
                'replyto' => 'privacy:metadata:replyto',
                'replytoname' => 'privacy:metadata:replytoname'
        ], 'privacy:metadata:externalpurpose');

        return $collection;
    }
617094
public function intersect($collection)
    {
        $intersection = new DefaultCollection();
        /** @var ModelInterface $localModel */
        foreach ($this as $localModel) {
            /** @var ModelInterface $otherModel */
            foreach ($collection as $otherModel) {
                if (($localModel->getProviderName() === $otherModel->getProviderName())
                    && ($localModel->getId() === $otherModel->getId())
                ) {
                    $intersection->push($localModel);
                }
            }
        }

        return $intersection;
    }
141832
public function transform($collection)
    {
        if ($collection && !is_array($collection) && !($collection instanceof \ArrayAccess)) {
            // in case of single entity, we have to make sure it's managed
            if (!$this->er->getManager()->contains($collection)) {
                $collection = $this->er->getManager()->merge($collection);
            }
        }
        return $collection;
    }
158690
public function transform($collection)
    {
        if (null === $collection) {
            return [];
        }

        if (!$collection instanceof Collection) {
            throw new TransformationFailedException(sprintf('Expected a %s object.', Collection::class));
        }

        $values = [];
        foreach ($collection as $field) {
            $values[$field->getId()] = $field;
        }

        return $values;
    }
889201
public function format(Collection $record)
    {
        return json_encode($this->prepare($record), ($this->prettyPrint ? JSON_PRETTY_PRINT : 0));
    }
260938
protected function filterCurrentItems(Collection $collection)
    {
        $endDate    = new DateTime();
        $format     = $this->configuration->getGroupByDateFormat();
        $identifier = $endDate->format($format);

        return $collection->filter(function (ReportRow $row) use ($identifier) {
            return $row->getIdentifier() === $identifier;
        });
    }