- // 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;
- global $user;
- $this->team_id = $user->team_id;
+ 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'));