/** * Returns a new HolidayDomainQuery object. * * @param string $modelAlias The alias of a model in the query * @param HolidayDomainQuery|Criteria $criteria Optional Criteria to build the query from * * @return HolidayDomainQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof HolidayDomainQuery) { return $criteria; } $query = new HolidayDomainQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(HolidayDomainPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = HolidayDomainQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Holiday is new, it will return * an empty collection; or if this Holiday has previously * been saved, it will retrieve related HolidayDomains from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Holiday. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|HolidayDomain[] List of HolidayDomain objects */ public function getHolidayDomainsJoinDomain($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = HolidayDomainQuery::create(null, $criteria); $query->joinWith('Domain', $join_behavior); return $this->getHolidayDomains($query, $con); }
/** * Updates a holiday * * @param int $intId The holiday ID * @param array $arrData * @return int The holiday ID */ public function do_update($intId, $arrData) { $user = $this->requireUser(); // Validate input data $validator = new KickstartValidator(); $locale = Localizer::getInstance(); $warnings = $validator->filterErrors($arrData, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { return array('result' => false, 'warnings' => $warnings); } if ($intId) { if (!($holiday = HolidayQuery::create()->findOneById($intId))) { throw new Exception('Holiday with ID ' . $intId . ' not found!'); } } else { $holiday = new Holiday(); } $con = Propel::getConnection(HolidayPeer::DATABASE_NAME); $con->beginTransaction(); try { $holiday->setName($arrData['Name'])->setDate($arrData['Date'])->setAccount($user->getAccount())->save($con); // Assign the domains if (!(isset($arrData['Domains']) && is_array($arrData['Domains']))) { $arrData['Domains'] = array(); } $sub = array(); foreach (HolidayDomainQuery::create()->filterByHoliday($holiday)->find() as $link) { if (in_array($link->getDomainId(), $arrData['Domains'])) { $sub[] = $link->getDomainId(); } else { $link->delete($con); } } $diff = array_diff($arrData['Domains'], $sub); if (sizeof($diff) > 0) { // Get the account's domains $domainFilter = DomainQuery::create()->filterByAccount($user->getAccount())->add(DomainPeer::ID, $arrData['Domains'], Criteria::IN)->find(); if (sizeof($domainFilter) != sizeof($arrData['Domains'])) { // Obviously there are some domains the user does not belong to } foreach (array_diff($arrData['Domains'], $sub) as $domainId) { $link = new HolidayDomain(); $link->setHoliday($holiday)->setDomainId($domainId)->save($con); } } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } return array('result' => $holiday->getId(), 'test' => $diff); // return $holiday->getId(); }