[FORM] Implement ActorArrayTransformer

This commit is contained in:
Daniel 2020-10-14 21:43:44 +01:00 committed by Hugo Sales
parent 279cfcd058
commit c3aa2ae400
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -32,27 +32,37 @@
namespace App\Util\Form;
use App\Entity\GSActor;
class ActorArrayTransformer extends ArrayTransformer
{
/**
* Transforms array of GSActors into string of usernames
*
* @param array $a
*
* @return string
*/
public function transform($a)
{
// TODO convert each to string
$s = parent::transform($a);
return parent::transform(array_map(
function ($actor) { return $actor->getNickname(); },
$a)
);
}
/**
* Transforms string of usernames into GSActors
*
* @param string $s
*
* @return array
*/
public function reverseTransform($s)
{
$a = parent::reverseTransform($s);
// TODO convert each to profile
return array_map(
function ($nickmame) { return GSActor::getFromNickname($nickmame); },
parent::reverseTransform($s)
);
}
}