protected function hook_preStore() { parent::hook_preStore(); if (!$this->event_recurs) { $this->event_times_recuring = 0; } else { //If the event recurs then set the end date day to be equal to the start date day and keep the hour:minute of the end date //so that the event starts recurring from the start day onwards n times after the start date for the period given //Meaning: The event end date day is useless as far as recurring events are concerned. $start_date = new w2p_Utilities_Date($this->event_start_date); $end_date = new w2p_Utilities_Date($this->event_end_date); $hour = $end_date->getHour(); $minute = $end_date->getMinute(); $end_date->setDate($start_date->getDate()); $end_date->setHour($hour); $end_date->setMinute($minute); $this->event_end_date = $end_date->format(FMT_DATETIME_MYSQL); } // ensure changes to check boxes and select lists are honoured $this->event_private = (int) $this->event_private; $this->event_type = (int) $this->event_type; $this->event_cwd = (int) $this->event_cwd; $this->event_creator = (int) $this->event_creator ? $this->event_creator : $this->_AppUI->user_id; $this->event_owner = (int) $this->event_owner ? $this->event_owner : $this->_AppUI->user_id; $q = $this->_getQuery(); $this->event_updated = $q->dbfnNowWithTZ(); }
public function store(CAppUI $AppUI) { $perms = $AppUI->acl(); $stored = false; if (!$this->event_recurs) { $this->event_times_recuring = 0; } else { //If the event recurs then set the end date day to be equal to the start date day and keep the hour:minute of the end date //so that the event starts recurring from the start day onwards n times after the start date for the period given //Meaning: The event end date day is useless as far as recurring events are concerned. $start_date = new w2p_Utilities_Date($this->event_start_date); $end_date = new w2p_Utilities_Date($this->event_end_date); $hour = $end_date->getHour(); $minute = $end_date->getMinute(); $end_date->setDate($start_date->getDate()); $end_date->setHour($hour); $end_date->setMinute($minute); $this->event_end_date = $end_date->format(FMT_DATETIME_MYSQL); } // ensure changes to check boxes and select lists are honoured $this->event_private = (int) $this->event_private; $this->event_type = (int) $this->event_type; $this->event_cwd = (int) $this->event_cwd; $this->_error = $this->check(); if (count($this->_error)) { return $this->_error; } $this->event_start_date = $AppUI->convertToSystemTZ($this->event_start_date); $this->event_end_date = $AppUI->convertToSystemTZ($this->event_end_date); /* * TODO: I don't like the duplication on each of these two branches, but I * don't have a good idea on how to fix it at the moment... */ if ($this->event_id && $perms->checkModuleItem('events', 'edit', $this->event_id)) { if ($msg = parent::store()) { return $msg; } $stored = true; } if (0 == $this->event_id && $perms->checkModuleItem('events', 'add')) { if ($msg = parent::store()) { return $msg; } $stored = true; } if ($stored) { // TODO: I *really* don't like using the POST inside here.. $this->updateAssigned(explode(',', $_POST['event_assigned'])); $custom_fields = new w2p_Core_CustomFields('calendar', 'addedit', $this->event_id, 'edit'); $custom_fields->bind($_POST); $sql = $custom_fields->store($this->event_id); // Store Custom Fields } return $stored; }
/** * Calculating a future date considering a given duration * * Respects non-working days and the working hours and the begining and end of days * SantosDiez - Credit for better variable names * * @param $duration Duration to be added to the date * @param $durationType Duration Type: 1=hours, 24=days * @return w2p_Utilities_Date The w2p_Utilities_Date object of the finish date */ public function calcFinish($duration, $durationType) { // since one will alter the date ($this) one better copies it to a new instance $finishDate = new w2p_Utilities_Date(); $finishDate->copy($this); // get w2P time constants $day_start_hour = (int) w2PgetConfig('cal_day_start'); $day_end_hour = (int) w2PgetConfig('cal_day_end'); $work_hours = (int) w2PgetConfig('daily_working_hours'); $min_increment = (int) w2PgetConfig('cal_day_increment'); $duration_in_minutes = $durationType == 24 ? $duration * $work_hours * 60 : $duration * 60; // Jump to the first working day while (!$finishDate->isWorkingDay()) { $finishDate->addDays(1); } $first_day_minutes = min($day_end_hour * 60 - $finishDate->getHour() * 60 - $finishDate->getMinute(), $work_hours * 60, $duration_in_minutes); $finishDate->addSeconds($first_day_minutes * 60); $duration_in_minutes -= $first_day_minutes; $minutes = $finishDate->getMinute(); $mod = $minutes % $min_increment; if ($mod > $min_increment / 2) { $multiplier = (int) (1 + $minutes / $min_increment); } else { $multiplier = (int) ($minutes / $min_increment); } $finishDate->setMinute($multiplier * $min_increment); while ($duration_in_minutes != 0) { // Jump to the next day $finishDate->addDays(1); // Reset date's time to the first hour in the morning $finishDate->setTime($day_start_hour); // Jump all non-working days while (!$finishDate->isWorkingDay()) { $finishDate->addDays(1); } $day_work_minutes = min($work_hours * 60, $duration_in_minutes); $finishDate->addSeconds($day_work_minutes * 60); $duration_in_minutes -= $day_work_minutes; } return $finishDate; }
} // @todo convert to template // @todo remove database query global $AppUI, $w2Pconfig, $cal_df, $cf; // check permissions for this module $perms =& $AppUI->acl(); $canView = canView($m); $canAddProjects = $perms->checkModuleItem('projects', 'add'); if (!$canView) { $AppUI->redirect(ACCESS_DENIED); } $AppUI->getTheme()->loadCalendarJS(); $today = new w2p_Utilities_Date(); $today->addDays(1); $today->setHour($w2Pconfig['cal_day_start']); $today->setMinute(0); $view_options = __extract_from_projectdesigner1($AppUI); $project_id = (int) w2PgetParam($_POST, 'project_id', 0); $project_id = (int) w2PgetParam($_GET, 'project_id', $project_id); $extra = array('where' => 'project_active = 1'); $project = new CProject(); $projects = $project->getAllowedRecords($AppUI->user_id, 'projects.project_id,project_name', 'project_name', null, $extra, 'projects'); $idx_companies = __extract_from_projectdesigner2(); foreach ($projects as $prj_id => $prj_name) { $projects[$prj_id] = $idx_companies[$prj_id] . ': ' . $prj_name; } asort($projects); $projects = arrayMerge(array('0' => $AppUI->_('(None)', UI_OUTPUT_RAW)), $projects); $extra = array(); $task = new CTask(); $tasks = $task->getAllowedRecords($AppUI->user_id, 'task_id,task_name', 'task_name', null, $extra);
public function store() { $stored = false; $q = $this->_getQuery(); if (!$this->event_recurs) { $this->event_times_recuring = 0; } else { //If the event recurs then set the end date day to be equal to the start date day and keep the hour:minute of the end date //so that the event starts recurring from the start day onwards n times after the start date for the period given //Meaning: The event end date day is useless as far as recurring events are concerned. $start_date = new w2p_Utilities_Date($this->event_start_date); $end_date = new w2p_Utilities_Date($this->event_end_date); $hour = $end_date->getHour(); $minute = $end_date->getMinute(); $end_date->setDate($start_date->getDate()); $end_date->setHour($hour); $end_date->setMinute($minute); $this->event_end_date = $end_date->format(FMT_DATETIME_MYSQL); } // ensure changes to check boxes and select lists are honoured $this->event_private = (int) $this->event_private; $this->event_type = (int) $this->event_type; $this->event_cwd = (int) $this->event_cwd; $this->event_start_date = $this->_AppUI->convertToSystemTZ($this->event_start_date); $this->event_end_date = $this->_AppUI->convertToSystemTZ($this->event_end_date); /* * TODO: I don't like the duplication on each of these two branches, but I * don't have a good idea on how to fix it at the moment... */ if ($this->{$this->_tbl_key} && $this->canEdit()) { $this->event_updated = $q->dbfnNowWithTZ(); $stored = parent::store(); } if (0 == $this->{$this->_tbl_key} && $this->canCreate()) { $this->event_created = $q->dbfnNowWithTZ(); $this->event_updated = $this->event_created; $stored = parent::store(); } return $stored; }
$time = strtotime($bulk_task_start_date); $upd_task->task_start_date = date('Y-m-d H:i:s', $time); if ($add_task_bulk_time_keep) { $tmp_start_date = new w2p_Utilities_Date($upd_task->task_start_date, $userTZ); $tmp_start_date->setHour($start_date_old->getHour()); $tmp_start_date->setMinute($start_date_old->getMinute()); $upd_task->task_start_date = $tmp_start_date->format(FMT_DATETIME_MYSQL); } } if ($bulk_task_end_date) { $time = strtotime($bulk_task_end_date); $upd_task->task_end_date = date('Y-m-d H:i:s', $time); if ($add_task_bulk_time_keep) { $tmp_end_date = new w2p_Utilities_Date($upd_task->task_end_date, $userTZ); $tmp_end_date->setHour($end_date_old->getHour()); $tmp_end_date->setMinute($end_date_old->getMinute()); $upd_task->task_end_date = $tmp_end_date->format(FMT_DATETIME_MYSQL); } } $result = $upd_task->store(); } //Action: Modify Duration if (isset($_POST['bulk_task_duration']) && $bulk_task_duration != '' && is_numeric($bulk_task_duration)) { if ($upd_task->task_id) { $upd_task->task_duration = $bulk_task_duration; //set duration type to hours (1) $upd_task->task_duration_type = $bulk_task_durntype ? $bulk_task_durntype : 1; $result = $upd_task->store(); if (!$result) { break; }
/** * Updates the variable information on the task. * * @param int $notUsed not used * @param int $task_id that task id of task this task log is for * * @return void * * @access protected */ protected function updateTaskSummary($notUsed = null, $task_id) { $task = new CTask(); $task->overrideDatabase($this->_query); $task->load($task_id); $q = $this->_getQuery(); if ($this->_perms->checkModuleItem('tasks', 'edit', $task_id)) { if ($this->task_log_percent_complete <= 100) { $q->addQuery('task_log_percent_complete, task_log_date'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); $q->addOrder('task_log_date DESC, task_log_id DESC'); $q->setLimit(1); $results = $q->loadHash(); $percentComplete = $results['task_log_percent_complete']; } else { $percentComplete = 100; } $old_end_date = new w2p_Utilities_Date($task->task_end_date); $new_end_date = new w2p_Utilities_Date($this->task_log_task_end_date); $new_end_date->setHour($old_end_date->getHour()); $new_end_date->setMinute($old_end_date->getMinute()); $task_end_date = $new_end_date->format(FMT_DATETIME_MYSQL); /* * We're using a database update here instead of store() because a * bunch of other things happen when you call store().. like the * processing of contacts, departments, etc. */ $q = $this->_getQuery(); $q->addTable('tasks'); $q->addUpdate('task_percent_complete', $percentComplete); $q->addUpdate('task_end_date', $task_end_date); $q->addWhere('task_id = ' . (int) $task_id); $success = $q->exec(); if (!$success) { $this->_AppUI->setMsg($task->getError(), UI_MSG_ERROR, true); } $task->pushDependencies($task_id, $task_end_date); } $q->addQuery('SUM(task_log_hours)'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); $totalHours = $q->loadResult(); $task->updateHoursWorked2($task_id, $totalHours); $task->updateDynamics(); }