221 lines
5.1 KiB
PHP
221 lines
5.1 KiB
PHP
<?php
|
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
// No direct access.
|
|
defined('_JEXEC') or die;
|
|
|
|
class CommonClubsModelClub extends AbstractCommonClubsModel
|
|
{
|
|
|
|
protected function getFactory()
|
|
{
|
|
return new CommonClubsModelFactoryClub();
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
return $this->getValues()['name'];
|
|
}
|
|
|
|
public function setName($name)
|
|
{
|
|
$this->setValue('name', $name);
|
|
}
|
|
|
|
public function getAddress()
|
|
{
|
|
return $this->getValues()['address'];
|
|
}
|
|
|
|
public function setAddress($address)
|
|
{
|
|
$this->setValue('address', $address);
|
|
}
|
|
|
|
public function getCity()
|
|
{
|
|
return $this->getValues()['city'];
|
|
}
|
|
|
|
public function setCity($city)
|
|
{
|
|
$this->setValue('city', $city);
|
|
}
|
|
|
|
public function getHomepage()
|
|
{
|
|
return $this->getValues()['homepage'];
|
|
}
|
|
|
|
public function setHomepage($homepage)
|
|
{
|
|
$this->setValue('homepage', $homepage);
|
|
}
|
|
|
|
public function getMail()
|
|
{
|
|
return $this->getValues()['mail'];
|
|
}
|
|
|
|
public function setMail($mail)
|
|
{
|
|
$this->setValue('mail', $mail);
|
|
}
|
|
|
|
public function getIban()
|
|
{
|
|
return $this->getValues()['iban'];
|
|
}
|
|
|
|
public function setIban($iban)
|
|
{
|
|
$this->setValue('iban', $iban);
|
|
}
|
|
|
|
public function getBic()
|
|
{
|
|
return $this->getValues()['bic'];
|
|
}
|
|
|
|
public function setBic($bic)
|
|
{
|
|
$this->setValue('bic', $bic);
|
|
}
|
|
|
|
public function isCharitable()
|
|
{
|
|
return $this->getValues()['charitable'];
|
|
}
|
|
|
|
public function setCharitable($charitable)
|
|
{
|
|
$this->setValue('charitable', $charitable);
|
|
}
|
|
|
|
public function getPresident()
|
|
{
|
|
return $this->getValues()['president'];
|
|
}
|
|
|
|
public function setPresident($user)
|
|
{
|
|
$this->setValue('president', $user);
|
|
}
|
|
|
|
public function getPlaces()
|
|
{
|
|
return $this->fetchAssociatedElements(new CommonClubsModelFactoryPlace(), 'clubid');
|
|
}
|
|
|
|
private function getOfferAssocs()
|
|
{
|
|
return $this->fetchAssociatedElements(new CommonClubsModelFactoryOfferassoc(), 'clubid');
|
|
}
|
|
|
|
public function getOffers()
|
|
{
|
|
$assocs = $this->getOfferAssocs();
|
|
|
|
$offersFactory = new CommonClubsModelFactoryOffer();
|
|
$allOffers = $offersFactory->loadElements();
|
|
|
|
$ret = array();
|
|
foreach($allOffers as $offer)
|
|
{
|
|
$arr = array(
|
|
'offer' => $offer,
|
|
'valid' => false
|
|
);
|
|
|
|
$id = $offer->getId();
|
|
foreach($assocs as $a)
|
|
{
|
|
$oid = $a->getOffer()->getId();
|
|
if($id === $oid)
|
|
{
|
|
$arr['valid'] = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$ret[] = $arr;
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* @param int[] $ids
|
|
*/
|
|
public function setOfferIds($ids)
|
|
{
|
|
if(empty($ids))
|
|
$ids = array();
|
|
|
|
$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();
|
|
|
|
$db = Factory::getDbo();
|
|
$db->transactionStart(true);
|
|
|
|
try
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
catch (Exception $ex)
|
|
{
|
|
$db->transactionRollback(true);
|
|
throw $ex;
|
|
}
|
|
|
|
$db->transactionCommit(true);
|
|
}
|
|
|
|
public function getUsers()
|
|
{
|
|
return $this->fetchAssociatedElements(new CommonClubsModelFactoryUserassoc(), 'clubid');
|
|
}
|
|
|
|
protected function prepareDelete($db)
|
|
{
|
|
$q = $db->getQuery(true);
|
|
$q->delete('#__club_user_assocs')->where("clubid = {$this->getId()}");
|
|
$db->setQuery($q);
|
|
$db->execute();
|
|
|
|
$q = $db->getQuery(true);
|
|
$q->delete('#__club_places')->where("clubid = {$this->getId()}");
|
|
$db->setQuery($q);
|
|
$db->execute();
|
|
|
|
$q = $db->getQuery(true);
|
|
$q->delete('#__club_offer_assocs')->where("clubid = {$this->getId()}");
|
|
$db->setQuery($q);
|
|
$db->execute();
|
|
}
|
|
}
|