Transforms Collection entities to json ([{id: 123, name: "Slurms MacKenzie"}, {id: 555, name: "Bob Hoskins"}])
@param Collection $collection
@return string (JSON)
6793
public function transform($collection)
    {
        if (null === $collection) {
            return null;
        }

        if (!($collection instanceof Collection)) {
            throw new UnexpectedTypeException($collection, 'Doctrine\Common\Collection\Collection');
        }

        $results = array();
        foreach ($collection as $entity) {
            $results[] = array(
                $this->arrayIdentifierName => $this->displayValue(
                    $this->accessor->getValue($entity, $this->identifier)
                ),
                $this->arrayLabelName => $this->displayValue($this->extractLabel($entity)),
            );
        }

        //Here, do not put the result in the cache because we must check the value in
        //reverseTransform (by QueryBuilder)
        return json_encode($results);
    }
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;
    }
635125
public function deserializeCollection(string $json): CollectionWrapperInterface
    {
        try {
            /** @var CollectionWrapperInterface $collectionWrapper */
            $collectionWrapper = $this->jms()->deserialize(
                $json,
                $this->collectionWrapperClass(),
                'json'
            );
        } catch (\Exception $e) {
            throw new \RuntimeException('Error while deserialize "' . $json . '"', 0, $e);
        }


        return $collectionWrapper;
    }
282177
public static function toJson($features)
	{
		if (is_null($features) || count($features) == 0) {
			return null;
		}

		return Collection::make($features)->filter(function ($item) {
			return trim($item) != '';
		})->toJson();
	}
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();
    }
949327
public function deleteBrands($collection)
	{
		$timeStamp = time();
		if (!is_array($collection)) {
			return $this->createException('InvalidParameterValueException', 'Invalid parameter value. Parameter must be an array collection', 'E:S:001');
		}
		$countDeleted = 0;
		foreach ($collection as $entry) {
			if ($entry instanceof BundleEntity\Brand) {
				$this->em->remove($entry);
				$countDeleted++;
			} else {
				$response = $this->getBrand($entry);
				if (!$response->error->exist) {
					$this->em->remove($response->result->set);
					$countDeleted++;
				}
			}
		}
		if ($countDeleted < 0) {
			return new ModelResponse(null, 0, 0, null, true, 'E:E:001', 'Unable to delete all or some of the selected entries.', $timeStamp, time());
		}
		$this->em->flush();
		return new ModelResponse(null, 0, 0, null, false, 'S:D:001', 'Selected entries have been successfully removed from database.', $timeStamp, time());
	}
589383
public static function get_metadata(collection $collection) : collection {

        $sessionfields = [
                'userid' => 'privacy:metadata:mnet_session:userid',
                'username' => 'privacy:metadata:mnet_session:username',
                'token' => 'privacy:metadata:mnet_session:token',
                'mnethostid' => 'privacy:metadata:mnet_session:mnethostid',
                'useragent' => 'privacy:metadata:mnet_session:useragent',
                'expires' => 'privacy:metadata:mnet_session:expires'
        ];

        $collection->add_database_table('mnet_session', $sessionfields, 'privacy:metadata:mnet_session');

        $logfields = [
                'hostid' => 'privacy:metadata:mnet_log:hostid',
                'remoteid' => 'privacy:metadata:mnet_log:remoteid',
                'time' => 'privacy:metadata:mnet_log:time',
                'userid' => 'privacy:metadata:mnet_log:userid',
                'ip' => 'privacy:metadata:mnet_log:ip',
                'course' => 'privacy:metadata:mnet_log:course',
                'coursename' => 'privacy:metadata:mnet_log:coursename',
                'module' => 'privacy:metadata:mnet_log:module',
                'cmid' => 'privacy:metadata:mnet_log:cmid',
                'action' => 'privacy:metadata:mnet_log:action',
                'url' => 'privacy:metadata:mnet_log:url',
                'info' => 'privacy:metadata:mnet_log:info'
        ];

        $collection->add_database_table('mnet_log', $logfields, 'privacy:metadata:mnet_log');

        $externalfields = [
                'address' => 'privacy:metadata:mnet_external:address',
                'aim' => 'privacy:metadata:mnet_external:aim',
                'alternatename' => 'privacy:metadata:mnet_external:alternatename',
                'autosubscribe' => 'privacy:metadata:mnet_external:autosubscribe',
                'calendartype' => 'privacy:metadata:mnet_external:calendartype',
                'city' => 'privacy:metadata:mnet_external:city',
                'country' => 'privacy:metadata:mnet_external:country',
                'currentlogin' => 'privacy:metadata:mnet_external:currentlogin',
                'department' => 'privacy:metadata:mnet_external:department',
                'description' => 'privacy:metadata:mnet_external:description',
                'email' => 'privacy:metadata:mnet_external:email',
                'emailstop' => 'privacy:metadata:mnet_external:emailstop',
                'firstaccess' => 'privacy:metadata:mnet_external:firstaccess',
                'firstname' => 'privacy:metadata:mnet_external:firstname',
                'firstnamephonetic' => 'privacy:metadata:mnet_external:firstnamephonetic',
                'icq' => 'privacy:metadata:mnet_external:icq',
                'id' => 'privacy:metadata:mnet_external:id',
                'idnumber' => 'privacy:metadata:mnet_external:idnumber',
                'imagealt' => 'privacy:metadata:mnet_external:imagealt',
                'institution' => 'privacy:metadata:mnet_external:institution',
                'lang' => 'privacy:metadata:mnet_external:lang',
                'lastaccess' => 'privacy:metadata:mnet_external:lastaccess',
                'lastlogin' => 'privacy:metadata:mnet_external:lastlogin',
                'lastname' => 'privacy:metadata:mnet_external:lastname',
                'lastnamephonetic' => 'privacy:metadata:mnet_external:lastnamephonetic',
                'maildigest' => 'privacy:metadata:mnet_external:maildigest',
                'maildisplay' => 'privacy:metadata:mnet_external:maildisplay',
                'middlename' => 'privacy:metadata:mnet_external:middlename',
                'msn' => 'privacy:metadata:mnet_external:msn',
                'phone1' => 'privacy:metadata:mnet_external:phone1',
                'pnone2' => 'privacy:metadata:mnet_external:phone2',
                'picture' => 'privacy:metadata:mnet_external:picture',
                'policyagreed' => 'privacy:metadata:mnet_external:policyagreed',
                'skype' => 'privacy:metadata:mnet_external:skype',
                'suspended' => 'privacy:metadata:mnet_external:suspended',
                'timezone' => 'privacy:metadata:mnet_external:timezone',
                'trackforums' => 'privacy:metadata:mnet_external:trackforums',
                'trustbitmask' => 'privacy:metadata:mnet_external:trustbitmask',
                'url' => 'privacy:metadata:mnet_external:url',
                'username' => 'privacy:metadata:mnet_external:username',
                'yahoo' => 'privacy:metadata:mnet_external:yahoo',
        ];

        $collection->add_external_location_link('moodle', $externalfields, 'privacy:metadata:external:moodle');

        $collection->add_external_location_link('mahara', $externalfields, 'privacy:metadata:external:mahara');

        return $collection;
    }
4008
protected function getDeleteRowSQL(PersistentCollection $collection)
    {
        $mapping     = $collection->getMapping();
        $class       = $this->em->getClassMetadata($mapping['sourceEntity']);
        $targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
        $columns     = array();
        $types       = array();

        foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
            $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
            $types[]   = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $class, $this->em);
        }

        foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
            $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform);
            $types[]   = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em);
        }

        return array(
            'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform)
            . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?',
            $types,
        );
    }
550616
public function getDictionary($collection)
	{
		$dictionary = array();

		foreach ($collection as $value)
		{
			$dictionary[$value->getKey()] = $value;
		}

		return $dictionary;
	}
663703
public function transform($id)
    {
        if (null === $id) {
            return null;
        } else if (is_string($id)) {
            /** @var Group|null $entity */
            $entity = $this->om->getRepository('FOMUserBundle:Group')
                ->findOneBy(array('id' => $id));
            return $entity;
        } elseif (is_array($id)) {
            if (count($id) === 0) {
                return null;
            }
            $result = new ArrayCollection();
            foreach($id as $value) {
                $group = $this->om->getRepository('FOMUserBundle:Group')
                    ->findOneBy(array('id' => $value));
                if ($group !== null) {
                    $result->add($group);
                }
            }
            return $result;
        } else {
            return null;
        }
    }
1014258
private function writeGeometryCollection(GeometryCollection $collection) : string
    {
        $result = [];

        foreach ($collection as $geometry) {
            $result[] = $this->doWrite($geometry);
        }

        return implode(',' . $this->prettyPrintSpace, $result);
    }
452594
protected function getDeleteSQL(PersistentCollection $collection)
    {
        $columns    = array();
        $mapping    = $collection->getMapping();
        $class      = $this->em->getClassMetadata(get_class($collection->getOwner()));
        $joinTable  = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform);

        foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
            $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
        }

        return 'DELETE FROM ' . $joinTable
            . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?';
    }
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;
    }
334196
public function unmapCollection(Entity\Collection $collection)
    {
        $data = [];
        foreach ($collection as $index => $entity) {
            $data[$index] = $this->unmapEntity($entity);
        }
        return $data;
    }
566964
public function newObject($collection)
    {
        /** @var MongoObject $obj */
        $obj =$this->container->get($this->classMap->getClassForResult($collection, []));
        $obj->setCollection($collection);

        return $obj;
    }
9352
public function unserializeCollection($collection)
    {
        if (is_array($collection)) {
            return array_map(function ($value) {
                return maybe_unserialize(reset($value));
            }, $collection);
        }

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

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

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

                ->field('name')
                ->field('permissions')

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

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }