/** * * Counts holidays per week for a given timeframe. * @param int $domain * @param int $start * @param int $end * @return multitype:number */ public static function getCountPerWeek($domain, $start, $end) { $holidays = HolidayQuery::create()->filterByDomain($domain)->filterByDate($start, Criteria::GREATER_EQUAL)->filterByDate($end, Criteria::LESS_EQUAL)->find(); $holidaysWeeks = array(); foreach ($holidays as $holiday) { $date = createDate($holiday->getDate()); $key = $date->format('W-Y'); if (array_key_exists($key, $holidaysWeeks)) { $holidaysWeeks[$key] = $holidaysWeeks[$key] + 1; } else { $holidaysWeeks[$key] = 1; } } return $holidaysWeeks; }
public function calcClockings(&$list, $userid, $start, $end) { $this->employee = UserQuery::create()->filterById($userid)->findOne(); $domain = $this->employee->getDomain(); $vacationDays = HolidayQuery::create()->filterByDomain($domain)->filterByDate($start, Criteria::GREATER_EQUAL)->filterByDate($end, Criteria::LESS_EQUAL)->find(); $this->holidays = array(); foreach ($vacationDays as $day) { $key = dayKey($day->getDate()); $this->holidays[$key] = $day; } // Get flexitime $this->flexitime = ClockingQuery::create()->filterByUserId($userid)->filterByStart($start, Criteria::LESS_THAN)->filterByVisibility(0)->withColumn('SUM(flexitime)', 'flexitimeSum')->findOne()->getFlexitimeSum(); $this->holidaysWeeks = Holiday::getCountPerWeek($domain, $start, $end); // Calculate weektime for first item $first = $list->getFirst(); if ($first == null) { // No items at all, stop here return; } $weekday = date('N', $first->getStart()); $currentWeek = date('W', $first->getStart()); $currentYear = date('Y', $first->getStart()); // Count any holiday as 'work done' $weekKey = $currentWeek . '-' . $currentYear; if (!array_key_exists($weekKey, $this->holidaysWeeks)) { $this->holidaysWeeks[$weekKey] = 0; } $this->worktime = $this->holidaysWeeks[$weekKey] * $this->employee->getDailyTime(); if ($weekday > 1) { $weekstart = createDate($first->getStart()); $weekstart->modify('midnight this week'); $weekend = createDate($first->getStart()); $weekend->modify('midnight this week +7 days'); $week = ClockingQuery::create()->filterByStart($weekstart->getTimestamp(), Criteria::GREATER_THAN)->filterByStart($weekend->getTimestamp(), Criteria::LESS_THAN)->filterByUser($this->employee)->filterByVisibility(0)->find(); $this->calcList($week); } $connection = Propel::getConnection(ClockingPeer::DATABASE_NAME); $connection->beginTransaction(); try { $this->calcList($list); $connection->commit(); } catch (Exception $e) { $connection->rollBack(); throw $e; } }
/** * Returns the number of related Holiday objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Holiday objects. * @throws PropelException */ public function countHolidays(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { $partial = $this->collHolidaysPartial && !$this->isNew(); if (null === $this->collHolidays || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collHolidays) { return 0; } if ($partial && !$criteria) { return count($this->getHolidays()); } $query = HolidayQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByAccount($this)->count($con); } return count($this->collHolidays); }
/** * Get the associated Holiday object * * @param PropelPDO $con Optional Connection object. * @param $doQuery Executes a query to get the object if required * @return Holiday The associated Holiday object. * @throws PropelException */ public function getHoliday(PropelPDO $con = null, $doQuery = true) { if ($this->aHoliday === null && $this->holiday_id !== null && $doQuery) { $this->aHoliday = HolidayQuery::create()->findPk($this->holiday_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aHoliday->addHolidayDomains($this); */ } return $this->aHoliday; }
/** * 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(HolidayPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = HolidayQuery::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; } }
/** * Loads a single holiday and checks the user's permissions * * @param int $intId * @throws Exception * @return Holiday */ private function getHolidayById($intId) { $user = $this->requireUser(); $holiday = HolidayQuery::create()->findOneById($intId); if (!$holiday) { throw new Exception('Holiday with ID ' . $intId . ' not found!'); } // Check, if the holiday belongs to the user's account if ($holiday->getAccountId() != $user->getAccount()->getId()) { throw new Exception('Permission denied for Holiday ID "' . $intId . '"; Object belongs to another Account.'); } return $holiday; }