Offers can be changed in the backend
This commit is contained in:
@@ -61,9 +61,14 @@ class CommonClubsModelClub extends AbstractCommonClubsModel
|
||||
return $this->fetchAssociatedElements(new CommonClubsModelFactoryPlace(), 'clubid');
|
||||
}
|
||||
|
||||
private function getOfferAssocs()
|
||||
{
|
||||
return $this->fetchAssociatedElements(new CommonClubsModelFactoryOfferassoc(), 'clubid');
|
||||
}
|
||||
|
||||
public function getOffers()
|
||||
{
|
||||
$assocs = $this->fetchAssociatedElements(new CommonClubsModelFactoryOfferassoc(), 'clubid');
|
||||
$assocs = $this->getOfferAssocs();
|
||||
|
||||
$offersFactory = new CommonClubsModelFactoryOffer();
|
||||
$allOffers = $offersFactory->loadElements();
|
||||
@@ -92,6 +97,41 @@ class CommonClubsModelClub extends AbstractCommonClubsModel
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
*/
|
||||
public function setOfferIds($ids)
|
||||
{
|
||||
$dbo = $this->getFactory()->loadById($this->getId());
|
||||
$currentOffersAssocs = $dbo->getOfferAssocs();
|
||||
$currentIds = array_map(function($obj){
|
||||
return $obj->getOffer()->getId();
|
||||
}, $currentOffersAssocs);
|
||||
|
||||
$newIds = array_diff($ids, $currentIds);
|
||||
$delIds = array_diff($currentIds, $ids);
|
||||
|
||||
$offerAssocFactory = new CommonClubsModelFactoryOfferassoc();
|
||||
$offerFactory = new CommonClubsModelFactoryOffer();
|
||||
|
||||
foreach($delIds as $id)
|
||||
{
|
||||
$delId = (int) $id;
|
||||
$delObjs = $offerAssocFactory->loadElements("clubid = {$this->getId()} AND offerid = $delId");
|
||||
foreach($delObjs as $o)
|
||||
$o->delete();
|
||||
}
|
||||
|
||||
foreach($newIds as $id)
|
||||
{
|
||||
$newId = (int) $id;
|
||||
$o = $offerAssocFactory->createNew();
|
||||
$o->setOffer($offerFactory->loadById($newId));
|
||||
$o->setClub($this);
|
||||
$o->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function getUsers()
|
||||
{
|
||||
return $this->fetchAssociatedElements(new CommonClubsModelFactoryUserassoc(), 'clubid');
|
||||
|
||||
Reference in New Issue
Block a user