-
- var $db;
- var $holidays;
- // Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code.
- function __construct() {
- $this->db = getConnection();
- $i18n = $GLOBALS['I18N'];
- $this->holidays = $i18n->holidays;
- }
-
- public function update($year, $month, $quota) {
- $deleteSql = "DELETE FROM tt_monthly_quota WHERE year = $year AND month = $month";
- $this->db->exec($deleteSql);
- $insertSql = "INSERT INTO tt_monthly_quota (year, month, quota) values ($year, $month, $quota)";
- $affected = $this->db->exec($insertSql);
- return (!is_a($affected, 'PEAR_Error'));
- }
-
- public function get($year, $month) {
-
- if (is_null($month)){
- return $this->getMany($year);
- }
-
- return $this->getSingle($year, $month);
- }
-
- private function getSingle($year, $month) {
-
- $sql = "SELECT quota FROM tt_monthly_quota WHERE year = $year AND month = $month";
- $reader = $this->db->query($sql);
- if (is_a($reader, 'PEAR_Error')) {
- return false;
- }
-
- $row = $reader->fetchRow();
-
- // if we don't find a record, return calculated monthly quota
- if (is_null($row)){
-
- $holidaysWithYear = array();
- foreach ($this->holidays as $day) {
- $parts = explode("/", $day);
- $holiday = "$year-$parts[0]-$parts[1]";
- array_push($holidaysWithYear, $holiday);
- }
-
- $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
- return $this->getWorkingDays("$year-$month-01", "$year-$month-$daysInMonth", $holidaysWithYear) * 8;
- }
-
- return $row["quota"];
+
+ var $db; // Database connection.
+ var $team_id; // Team id.
+
+ // Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code.
+ function __construct() {
+ $this->db = getConnection();
+ global $user;
+ $this->team_id = $user->team_id;
+ }
+
+ // update - deletes a quota, then inserts a new one.
+ public function update($year, $month, $quota) {
+ $teamId = $this->team_id;
+ $deleteSql = "DELETE FROM tt_monthly_quotas WHERE year = $year AND month = $month AND team_id = $teamId";
+ $this->db->exec($deleteSql);
+ if ($quota){
+ $insertSql = "INSERT INTO tt_monthly_quotas (team_id, year, month, quota) values ($teamId, $year, $month, $quota)";
+ $affected = $this->db->exec($insertSql);
+ return (!is_a($affected, 'PEAR_Error'));