public function reorderAuthors($em, $articleAuthors, $order = array())
{
// clear current order
foreach ($articleAuthors as $articleAuthor) {
$articleAuthor->setOrder(null);
}
$em->flush();
if (count($order) > 1) {
$counter = 0;
foreach ($order as $item) {
list($authorId, $authorTypeId) = explode("-", $item);
foreach ($articleAuthors as $articleAuthor) {
if ($articleAuthor->getAuthor()->getId() == $authorId && $articleAuthor->getType()->getId() == $authorTypeId) {
$articleAuthor->setOrder($counter + 1);
$counter++;
}
}
}
} else {
$counter = 1;
foreach ($articleAuthors as $articleAuthor) {
$articleAuthor->setOrder($counter);
$counter++;
}
}
$em->flush();
return true;
}