Ejemplo n.º 1
0
 function index()
 {
     $tasksUserId = array_var($_GET, 'tu');
     if (is_null($tasksUserId)) {
         $tasksUserId = user_config_option('TM tasks user filter', logged_user()->getId());
     } else {
         if (user_config_option('TM tasks user filter') != $tasksUserId) {
             set_user_config_option('TM tasks user filter', $tasksUserId, logged_user()->getId());
         }
     }
     $timeslotsUserId = array_var($_GET, 'tsu');
     if (is_null($timeslotsUserId)) {
         $timeslotsUserId = user_config_option('TM user filter', 0);
     } else {
         if (user_config_option('TM user filter') != $timeslotsUserId) {
             set_user_config_option('TM user filter', $timeslotsUserId, logged_user()->getId());
         }
     }
     $showTimeType = array_var($_GET, 'stt');
     if (is_null($showTimeType)) {
         $showTimeType = user_config_option('TM show time type', 0);
     } else {
         if (user_config_option('TM show time type') != $showTimeType) {
             set_user_config_option('TM show time type', $showTimeType, logged_user()->getId());
         }
     }
     $start = array_var($_GET, 'start', 0);
     $limit = 20;
     $tasksUser = Contacts::findById($tasksUserId);
     $timeslotsUser = Contacts::findById($timeslotsUserId);
     //Active tasks view
     $open_timeslots = Timeslots::instance()->listing(array("extra_conditions" => " AND end_time = '" . EMPTY_DATETIME . "' AND contact_id = " . $tasksUserId))->objects;
     $tasks = array();
     foreach ($open_timeslots as $open_timeslot) {
         $task = ProjectTasks::findById($open_timeslot->getRelObjectId());
         if ($task instanceof ProjectTask && !$task->isCompleted() && !$task->isTrashed() && !$task->isArchived()) {
             $tasks[] = $task;
         }
     }
     ProjectTasks::populateTimeslots($tasks);
     //Timeslots view
     $total = 0;
     switch ($showTimeType) {
         case 0:
             //Show only timeslots added through the time panel
             $result = Timeslots::getGeneralTimeslots(active_context(), $timeslotsUser, $start, $limit);
             $timeslots = $result->objects;
             $total = $result->total;
             break;
         default:
             throw new Error('Unrecognised TM show time type: ' . $showTimeType);
     }
     //Get Users Info
     $users = array();
     $context = active_context();
     if (!can_manage_time(logged_user())) {
         if (can_add(logged_user(), $context, Timeslots::instance()->getObjectTypeId())) {
             $users = array(logged_user());
         }
     } else {
         if (logged_user()->isMemberOfOwnerCompany()) {
             $users = Contacts::getAllUsers();
         } else {
             $users = logged_user()->getCompanyId() > 0 ? Contacts::getAllUsers(" AND `company_id` = " . logged_user()->getCompanyId()) : array(logged_user());
         }
         $tmp_users = array();
         foreach ($users as $user) {
             if (can_add($user, $context, Timeslots::instance()->getObjectTypeId())) {
                 $tmp_users[] = $user;
             }
         }
         $users = $tmp_users;
     }
     //Get Companies Info
     if (logged_user()->isMemberOfOwnerCompany() || logged_user()->isAdminGroup()) {
         $companies = Contacts::getCompaniesWithUsers();
     } else {
         $companies = array();
         if (logged_user()->getCompanyId() > 0) {
             $companies[] = logged_user()->getCompany();
         }
     }
     $required_dimensions = DimensionObjectTypeContents::getRequiredDimensions(Timeslots::instance()->getObjectTypeId());
     $draw_inputs = !$required_dimensions || count($required_dimensions) == 0;
     if (!$draw_inputs) {
         $ts_ots = DimensionObjectTypeContents::getDimensionObjectTypesforObject(Timeslots::instance()->getObjectTypeId());
         $context = active_context();
         foreach ($context as $sel) {
             if ($sel instanceof Member) {
                 foreach ($ts_ots as $ts_ot) {
                     if ($sel->getDimensionId() == $ts_ot->getDimensionId() && $sel->getObjectTypeId() == $ts_ot->getDimensionObjectTypeId()) {
                         $draw_inputs = true;
                         break;
                     }
                 }
                 if ($draw_inputs) {
                     break;
                 }
             }
         }
     }
     tpl_assign('draw_inputs', $draw_inputs);
     tpl_assign('selected_user', logged_user()->getId());
     tpl_assign('timeslots', $timeslots);
     tpl_assign('tasks', $tasks);
     if (count($tasks) > 0) {
         tpl_assign('all_users', Contacts::getAllUsers());
     }
     tpl_assign('users', $users);
     tpl_assign('start', $start);
     tpl_assign('limit', $limit);
     tpl_assign('total', $total);
     tpl_assign('companies', $companies);
     ajx_set_no_toolbar(true);
 }
Ejemplo n.º 2
0
 function getDimensionObjectTypes()
 {
     return DimensionObjectTypeContents::getDimensionObjectTypesforObject($this->getObjectTypeId());
 }