function filter($condition) { switch ($condition) { case 'open': $options = array('conditions' => 'progress < 100'); break; case 'closed': $options = array('conditions' => 'progress = 100'); break; } $this->view_data['project'] = Project::all($options); $this->content_view = 'projects/all'; $this->view_data['projects_assigned_to_me'] = ProjectHasWorker::count(array('conditions' => 'user_id = ' . $this->user->id)); $this->view_data['tasks_assigned_to_me'] = ProjectHasTask::count(array('conditions' => 'user_id = ' . $this->user->id . ' and status = "open"')); $now = time(); $beginning_of_week = strtotime('last Monday', $now); // BEGINNING of the week $end_of_week = strtotime('next Sunday', $now) + 86400; // END of the last day of the week $this->view_data['projects_opened_this_week'] = Project::find_by_sql('select count(id) AS "amount", DATE_FORMAT(FROM_UNIXTIME(`datetime`), "%w") AS "date_day", DATE_FORMAT(FROM_UNIXTIME(`datetime`), "%Y-%m-%d") AS "date_formatted" from projects where datetime >= "' . $beginning_of_week . '" AND datetime <= "' . $end_of_week . '" '); }
function view($id = FALSE) { $this->view_data['submenu'] = array(); $this->view_data['project'] = Project::find($id); $this->view_data['project_has_invoices'] = Invoice::all(array('conditions' => array('project_id = ? AND estimate != ?', $id, 1))); if (!isset($this->view_data['project_has_invoices'])) { $this->view_data['project_has_invoices'] = array(); } $tasks = ProjectHasTask::count(array('conditions' => 'project_id = ' . $id)); $this->view_data['alltasks'] = $tasks; $this->view_data['opentasks'] = ProjectHasTask::count(array('conditions' => array('status != ? AND project_id = ?', 'done', $id))); $this->view_data['usercountall'] = User::count(array('conditions' => array('status = ?', 'active'))); $this->view_data['usersassigned'] = ProjectHasWorker::count(array('conditions' => array('project_id = ?', $id))); $this->view_data['assigneduserspercent'] = round($this->view_data['usersassigned'] / $this->view_data['usercountall'] * 100); $this->view_data['time_days'] = round((human_to_unix($this->view_data['project']->end . ' 00:00') - human_to_unix($this->view_data['project']->start . ' 00:00')) / 3600 / 24); $this->view_data['time_left'] = $this->view_data['time_days']; $this->view_data['timeleftpercent'] = 100; if (human_to_unix($this->view_data['project']->start . ' 00:00') < time() && human_to_unix($this->view_data['project']->end . ' 00:00') > time()) { $this->view_data['time_left'] = round((human_to_unix($this->view_data['project']->end . ' 00:00') - time()) / 3600 / 24); $this->view_data['timeleftpercent'] = $this->view_data['time_left'] / $this->view_data['time_days'] * 100; } if (human_to_unix($this->view_data['project']->end . ' 00:00') < time()) { $this->view_data['time_left'] = 0; $this->view_data['timeleftpercent'] = 0; } $this->view_data['mytasks'] = ProjectHasTask::count(array('conditions' => array('status != ? AND project_id = ? AND user_id = ?', 'done', $id, $this->user->id))); $tasks_done = ProjectHasTask::count(array('conditions' => array('status = ? AND project_id = ?', 'done', $id))); $this->view_data['progress'] = $this->view_data['project']->progress; if ($this->view_data['project']->progress_calc == 1) { if ($tasks) { @($this->view_data['progress'] = round($tasks_done / $tasks * 100)); } $attr = array('progress' => $this->view_data['progress']); $this->view_data['project']->update_attributes($attr); } @($this->view_data['opentaskspercent'] = $tasks == 0 ? 0 : $tasks_done / $tasks * 100); $projecthasworker = ProjectHasWorker::all(array('conditions' => array('user_id = ? AND project_id = ?', $this->user->id, $id))); if (!$projecthasworker && $this->user->admin != 1) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_no_access_error')); redirect('projects'); } $tracking = $this->view_data['project']->time_spent; if (!empty($this->view_data['project']->tracking)) { $tracking = time() - $this->view_data['project']->tracking + $this->view_data['project']->time_spent; } $this->view_data['timertime'] = $tracking; $this->view_data['time_spent_from_today'] = time() - $this->view_data['project']->time_spent; $tracking = floor($tracking / 60); $tracking_hours = floor($tracking / 60); $tracking_minutes = $tracking - $tracking_hours * 60; $this->view_data['time_spent'] = $tracking_hours . " " . $this->lang->line('application_hours') . " " . $tracking_minutes . " " . $this->lang->line('application_minutes'); $this->view_data['time_spent_counter'] = sprintf("%02s", $tracking_hours) . ":" . sprintf("%02s", $tracking_minutes); $this->content_view = 'projects/view'; }