*/ /** * Klasa CountriesArea * * @package stCountriesPlugin * @subpackage libs */ class CountriesArea extends BaseCountriesArea { /** * Id przypisanych krajów * * @var array */ protected $countriesIds = null; /** * Pobierania nazwy kraju * * @return string */ public function __toString() { return $this->getName(); } /** * * Metoda dodana na potrzeby admin generator - przypisuje przekazana liste krajow * * @param array $countries Lista krajow (format: array('id1', 'id2', ...)) */ public function setCountriesIds($ids) { foreach($ids as $id) { $cahc = new CountriesAreaHasCountries(); $cahc->setCountriesId($id); $this->addCountriesAreaHasCountries($cahc); } $this->countriesIds = $ids; $this->modifiedColumns[] = 'countries_ids'; } /** * Metoda dodana na potrzeby admin generator - zwraca id przypisanych krajow * * @return array */ public function getCountriesIds() { if (null === $this->countriesIds) { $results = array(); foreach ($this->getCountriesAreaHasCountriess() as $area) { $results[] = $area->getCountriesId(); } $this->countriesIds = $results; } return $this->countriesIds; } public function getAvailableCountries() { $c = new Criteria(); $c->add(CountriesPeer::IS_ACTIVE, true); $c->addJoin(CountriesPeer::ID, CountriesAreaHasCountriesPeer::COUNTRIES_ID, Criteria::LEFT_JOIN); $c1 = $c->getNewCriterion(CountriesAreaHasCountriesPeer::ID, null, Criteria::ISNULL); $c1->addOr($c->getNewCriterion(CountriesAreaHasCountriesPeer::COUNTRIES_AREA_ID, $this->getId())); $c->add($c1); return CountriesPeer::doSelect($c); } public function save($con = null) { if (!$this->isNew() && $this->isColumnModified('countries_ids')) { $c = new Criteria(); $c->add(CountriesAreaHasCountriesPeer::COUNTRIES_AREA_ID, $this->getId()); CountriesAreaHasCountriesPeer::doDelete($c); $this->resetModified('countries_ids'); } return parent::save($con); } }