/** * Looks up an hour_report to edit. * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_edit($handler_id, array $args, array &$data) { $this->_hour_report = new org_openpsa_projects_hour_report_dba($args[0]); $this->_load_schemadb(); $this->_controller = midcom_helper_datamanager2_controller::create('simple'); $this->_controller->schemadb =& $this->_schemadb; $this->_controller->set_storage($this->_hour_report); if (!$this->_controller->initialize()) { throw new midcom_error("Failed to initialize a DM2 controller instance for hour_report {$this->_hour_report->id}."); } switch ($this->_controller->process_form()) { case 'save': $this->_hour_report->modify_hours_by_time_slot(); // *** FALL-THROUGH *** // *** FALL-THROUGH *** case 'cancel': $task = new org_openpsa_projects_task_dba($this->_hour_report->task); return new midcom_response_relocate("hours/task/" . $task->guid . "/"); } $this->_prepare_request_data(); // Add toolbar items org_openpsa_helpers::dm2_savecancel($this); $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "hours/delete/{$this->_hour_report->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('delete'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png', MIDCOM_TOOLBAR_ACCESSKEY => 'd')); $parent = $this->_hour_report->get_parent(); $this->_add_toolbar_items($parent); $this->_view_toolbar->bind_to($this->_hour_report); midcom::get('metadata')->set_request_metadata($this->_hour_report->metadata->revised, $this->_hour_report->guid); midcom::get('head')->set_pagetitle($this->_l10n->get($handler_id)); $this->_update_breadcrumb_line($handler_id); }
/** * Report hours based on time used * * @return boolean */ private function _report_hours($description, $invoiceable = false) { $hour_report = new org_openpsa_projects_hour_report_dba(); $hour_report->invoiceable = $invoiceable; $hour_report->date = $this->start; $hour_report->person = $this->person->id; $hour_report->task = $this->task->id; $hour_report->description = $description; $hour_report->hours = $this->time / 3600; $stat = $hour_report->create(); if (!$stat) { midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.mypage', 'org.openpsa.mypage'), sprintf(midcom::get('i18n')->get_string('reporting %d hours to task %s failed, reason %s', 'org.openpsa.mypage'), $hour_report->hours, $this->task->title, midcom_connection::get_error_string()), 'error'); return false; } //apply minimum_time_slot $hour_report->modify_hours_by_time_slot(); midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.mypage', 'org.openpsa.mypage'), sprintf(midcom::get('i18n')->get_string('successfully reported %d hours to task %s', 'org.openpsa.mypage'), $hour_report->hours, $this->task->title), 'ok'); return true; }