/
ManyAssociationSaveHandler.php
42 lines (37 loc) · 1.54 KB
/
ManyAssociationSaveHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Concrete\Core\Express\Form\Control\SaveHandler;
use Concrete\Core\Entity\Express\Control\Control;
use Concrete\Core\Express\Association\Applier;
use Concrete\Core\Support\Facade\Application;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\Request;
abstract class ManyAssociationSaveHandler implements ManySaveHandlerInterface
{
protected $entityManager;
protected $applier;
public function __construct(Applier $applier, EntityManager $manager)
{
$this->entityManager = $manager;
$this->applier = $applier;
}
public function getAssociatedEntriesFromRequest(Control $control, Request $request)
{
$r = $this->entityManager->getRepository('Concrete\Core\Entity\Express\Entry');
$entryIDs = $request->request->get('express_association_' . $control->getId());
$vals = Application::getFacadeApplication()->make('helper/validation/strings');
if (!is_array($entryIDs) && $vals->notempty($entryIDs)) {
$entryIDs = explode(',', $entryIDs);
}
$associatedEntries = [];
if (is_array($entryIDs)) {
foreach ($entryIDs as $entryID) {
$associatedEntry = $r->findOneById($entryID);
$target = $control->getAssociation()->getTargetEntity();
if (is_object($associatedEntry) && $associatedEntry->getEntity()->getID() == $target->getID()) {
$associatedEntries[] = $associatedEntry;
}
}
}
return $associatedEntries;
}
}