/** * Return tasks on which the user has an open timeslot * * @return array */ static function getOpenTimeslotTasks($context, Contact $user, $assigned_to_contact = null, $archived = false) { $archived_cond = " AND `o`.`archived_on` " . ($archived ? "<>" : "=") . " 0 "; $open_timeslot = " AND `e`.`object_id` IN (SELECT `t`.`rel_object_id` FROM " . Timeslots::instance()->getTableName(true) . " `t` WHERE `t`.`contact_id` = " . $user->getId() . " AND `t`.`end_time` = '" . EMPTY_DATETIME . "')"; $assigned_to_str = ""; if ($assigned_to_contact) { if ($assigned_to_contact == -1) { $assigned_to_contact = 0; } $assigned_to_str = " AND `e`.`assigned_to_contact_id` = " . DB::escape($assigned_to_contact) . " "; } $result = self::instance()->listing(array("order" => 'due_date', "order_dir" => "ASC", "extra_conditions" => ' AND `is_template` = false' . $archived_cond . $assigned_to_str . $open_timeslot)); $objects = $result->objects; return $objects; }
private function populateTimeslots($objects_list) { if (is_array($objects_list) && count($objects_list) > 0 && $objects_list[0]->allowsTimeslots() && $objects_list[0] instanceof ProjectDataObject) { $ids = array(); $objects = array(); $manager_name = $objects_list[0]->getObjectManagerName(); for ($i = 0; $i < count($objects_list); $i++) { $ids[] = $objects_list[$i]->getId(); $objects[$objects_list[$i]->getId()] = $objects_list[$i]; $objects_list[$i]->timeslots = array(); $objects_list[$i]->timeslots_count = 0; } if (count($ids > 0)) { $timeslots = Timeslots::findAll(array('conditions' => 'object_manager = \'' . $manager_name . '\' AND object_id in (' . implode(',', $ids) . ')')); for ($i = 0; $i < count($timeslots); $i++) { $object = $objects[$timeslots[$i]->getObjectId()]; $object->timeslots[] = $timeslots[$i]; $object->timeslots_count = count($object->timeslots); } } } }
function getOpenTimeslots() { return Timeslots::getOpenTimeslotsByObject($this); }
function populateTimeslots($objects_list) { if (is_array($objects_list) && count($objects_list) > 0 && $objects_list[0]->allowsTimeslots() && $objects_list[0] instanceof ContentDataObject) { $ids = array(); $objects = array(); for ($i = 0; $i < count($objects_list); $i++) { $ids[] = $objects_list[$i]->getId(); $objects[$objects_list[$i]->getId()] = $objects_list[$i]; $objects_list[$i]->timeslots = array(); $objects_list[$i]->timeslots_count = 0; } if (count($ids > 0)) { $result = Timeslots::instance()->listing(array("extra_conditions" => ' AND `e`.`object_id` in (' . implode(',', $ids) . ')')); $timeslots = $result->objects; for ($i = 0; $i < count($timeslots); $i++) { $object = $objects[$timeslots[$i]->getRelObjectId()]; $object->timeslots[] = $timeslots[$i]; $object->timeslots_count = count($object->timeslots); } } } }
function total_task_times_vs_estimate_comparison($report_data = null, $task = null) { $this->setTemplate('report_wrapper'); if (!$report_data) { $report_data = array_var($_POST, 'report'); } $workspace = Projects::findById(array_var($report_data, 'project_id')); if ($workspace instanceof Project) { if (array_var($report_data, 'include_subworkspaces')) { $workspacesCSV = $workspace->getAllSubWorkspacesQuery(false); } else { $workspacesCSV = $workspace->getId(); } } else { $workspacesCSV = null; } $start = getDateValue(array_var($report_data, 'start_value')); $end = getDateValue(array_var($report_data, 'end_value')); $st = $start->beginningOfDay(); $et = $end->endOfDay(); $st = new DateTimeValue($st->getTimestamp() - logged_user()->getTimezone() * 3600); $et = new DateTimeValue($et->getTimestamp() - logged_user()->getTimezone() * 3600); $timeslots = Timeslots::getTimeslotsByUserWorkspacesAndDate($st, $et, 'ProjectTasks', null, $workspacesCSV, array_var($report_data, 'task_id', 0)); tpl_assign('timeslots', $timeslots); tpl_assign('workspace', $workspace); tpl_assign('start_time', $st); tpl_assign('end_time', $et); tpl_assign('user', $user); tpl_assign('post', $report_data); tpl_assign('template_name', 'total_task_times'); tpl_assign('title', lang('task time report')); }
function total_task_times_by_task_print() { $this->setLayout("html"); $task = ProjectTasks::findById(get_id()); $st = DateTimeValueLib::make(0, 0, 0, 1, 1, 1900); $et = DateTimeValueLib::make(23, 59, 59, 12, 31, 2036); $timeslotsArray = Timeslots::getTaskTimeslots(active_context(), null, null, $st, $et, get_id()); tpl_assign('columns', array()); tpl_assign('user', array()); tpl_assign('group_by', array()); tpl_assign('grouped_timeslots', array()); tpl_assign('template_name', 'total_task_times'); tpl_assign('estimate', $task->getTimeEstimate()); tpl_assign('timeslotsArray', $timeslotsArray); tpl_assign('title', lang('task time report')); tpl_assign('task_title', $task->getTitle()); tpl_assign('start_time', $st); tpl_assign('end_time', $et); $this->setTemplate('report_printer'); }
function delete_project_timeslot() { if (!can_manage_time(logged_user(), true)) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } ajx_current("empty"); $timeslot = Timeslots::findById(get_id()); if (!$timeslot instanceof Timeslot) { flash_error(lang('timeslot dnx')); return; } if (!$timeslot->canDelete(logged_user())) { flash_error(lang('no access permissions')); return; } try { DB::beginWork(); $timeslot->delete(); DB::commit(); ajx_extra_data(array("timeslotId" => get_id())); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } // try }
function getArrayInfo($return_billing = false) { $task_name = ''; $user = Contacts::findById($this->getContactId()); if ($user instanceof Contact) { $displayname = $user->getObjectName(); } else { $displayname = lang("n/a"); } $general_info = $this->getObject()->getArrayInfo(); $result = array( 'id' => $this->getId(), 'date' => $this->getStartTime()->getTimestamp(), 'time' => $this->getSeconds(), 'mids' => $this->getMemberIds(), 'uid' => $this->getContactId(), 'uname' => $displayname, 'lastupdated' => $general_info['dateUpdated'], 'lastupdatedby' => $general_info['updatedBy'], 'memPath' => json_encode($this->getMembersToDisplayPath()), 'otid' => Timeslots::instance()->getObjectTypeId(), ); if ($return_billing) { $result['hourlybilling'] = $this->getHourlyBilling(); $result['totalbilling'] = $this->getFixedBilling(); } if ($this->getDescription() != '') $result['desc'] = $this->getDescription(); if ($task_name != '') $result['tn'] = $task_name; return $result; }
function can_add_timeslots($user, $members) { return can_manage_time($user) || can_access_pgids($user->getPermissionGroupIds(), $members, Timeslots::instance()->getObjectTypeId(), ACCESS_LEVEL_WRITE); }
<input type="hidden" id="<?php echo $genid; ?> tsId" name="timeslot[id]" value=""/> <div style="padding:7px;"> <div class="context-body" style="float: left; margin-bottom: 5px;"> <?php //get skipped dimensions for this view $dimensions_to_show = explode(",", user_config_option("add_timeslot_view_dimensions_combos")); $dimensions_to_show = is_array($dimensions_to_show) ? array_filter($dimensions_to_show) : array(); $dimensions_to_skip = array_diff(get_user_dimensions_ids(), $dimensions_to_show); $listeners = array(); $listeners = array('on_selection_change' => 'ogTimeManager.renderUserCombo("' . $genid . '")'); if (!empty($dimensions_to_show)) { render_member_selectors(Timeslots::instance()->getObjectTypeId(), $genid, null, array('select_current_context' => true, 'listeners' => $listeners, 'horizontal' => true, 'width' => '270'), $dimensions_to_skip, null, true); } ?> </div> <div class="small-member-selector TMTimespanSelectorHeight" style="<?php echo can_manage_time(logged_user()) ? '' : 'display: none;'; ?> "> <?php echo label_tag(lang('user')); ?> <?php $options = array(); foreach ($users as $user) {
/** * Return manager instance * * @access protected * @param void * @return Timeslots */ function manager() { if(!($this->manager instanceof Timeslots)) $this->manager = Timeslots::instance(); return $this->manager; } // manager
<table style="margin-top:10px;"> <?php if (can_manage_time(logged_user())) { echo '<tr><td style="vertical-align:middle;"><span class="bold">' . lang("person") . ': </span></td>'; 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) { $rel_object = $timeslot->getRelObject(); $is_assigned = ($rel_object instanceof ProjectTask && $rel_object->getAssignedToContactId() == $user->getId()); if ($is_assigned || can_add($user, active_context(), Timeslots::instance()->getObjectTypeId())) { $tmp_users[] = $user; } } $users = $tmp_users; $user_options = array(); foreach ($users as $user) { $user_options[] = option_tag($user->getObjectName(), $user->getId(), array_var($timeslot_data, 'contact_id') == $user->getId() ? array("selected" => "selected") : null); } echo '<td>' . select_box("timeslot[contact_id]", $user_options, array('id' => $genid . 'tsUser', 'tabindex' => '15')) . '</td></tr>'; echo '<tr><td> </td></tr>'; } ?> <tr> <td style="vertical-align:middle;"><span class="bold"><?php echo lang("start date") ?>: </span></td>
/** * Empty implementation of static method. * * Add tag permissions are done through ProjectDataObject::canTimeslot() method. This * will return timeslot permissions for specified object * * @param User $user * @param Project $project * @return boolean */ function canAdd(User $user, Project $project) { return can_add($user, $project, get_class(Timeslots::instance())); }
static function countProjectTimeslots($allowedWorkspaceIdsCSV = null, $user = null, $project = null) { $project_sql = ""; if ($allowedWorkspaceIdsCSV != null) { $project_sql .= " AND `object_id` IN ({$allowedWorkspaceIdsCSV})"; } if ($project instanceof Project) { $pids = $project->getAllSubWorkspacesQuery(); $project_sql .= " AND `object_id` IN ({$pids})"; } $user_sql = ""; if ($user instanceof User) { $user_sql = " AND user_id = " . $user->getId(); } return Timeslots::count("object_manager = 'Projects'" . $project_sql . $user_sql); }
/** * This function returns the total amount of seconds worked in this task * * @return integer */ function getTotalSeconds() { $totalSeconds = Timeslots::getTotalSecondsWorkedOnObject($this->getId()); return $totalSeconds; }
function getOpenTimeslots() { return Timeslots::instance()->getOpenTimeslotsByObject($this->getId()); }
static function getTotalSecondsWorkedOnObject($object_id) { //getTotalSecondsWorkedOnObject $totalMinutes = Timeslots::getTotalMinutesWorkedOnObject($object_id); $totalSeconds = $totalMinutes * 60; return $totalSeconds; }
/** * Clear object timeslots * * @param void * @return boolean */ function clearTimeslots() { return Timeslots::dropTimeslotsByObject($this); }
/** * Return entries related to specific object * * If $include_private is set to true private entries will be included in result. If $include_silent is set to true * logs marked as silent will also be included. $limit and $offset are there to control the range of the result, * usually we don't want to pull the entire log but just the few most recent entries. If NULL they will be ignored * * @param ApplicationDataObject $object * @param boolean $include_private * @param boolean $include_silent * @param integer $limit * @param integer $offset * @return array */ static function getObjectLogs($object, $include_private = false, $include_silent = false, $limit = null, $offset = null) { $private_filter = $include_private ? 1 : 0; $silent_filter = $include_silent ? 1 : 0; // User History if ($object instanceof Contact && $object->isUser()){ $private_filter = $include_private ? 1 : 0; $silent_filter = $include_silent ? 1 : 0; $userCond = " AND `taken_by_id` = " . $object->getId(); $conditions = array( '`is_private` <= ? AND `is_silent` <= ? '.$userCond, $private_filter, $silent_filter); return self::findAll(array( 'conditions' => $conditions, 'order' => '`created_on` DESC', 'limit' => $limit, 'offset' => $offset, )); // findAll } else { $logs = self::findAll(array( 'conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND (`rel_object_id`IN (SELECT `object_id` FROM '.Comments::instance()->getTableName(true).' WHERE `rel_object_id` = (?)) OR `rel_object_id`IN (SELECT `object_id` FROM '.Timeslots::instance()->getTableName(true).' WHERE `rel_object_id` = (?)))', $private_filter, $silent_filter, $object->getId(),$private_filter, $silent_filter, $object->getId(), $object->getId()), 'order' => '`created_on` DESC', 'limit' => $limit, 'offset' => $offset, )); // findAll } $next_offset = $offset + $limit; do { // Look for objects that user cannot see $removed = 0; foreach ($logs as $k => $log) { if ($log->getAction() == 'link') { $id = explode(":", $log->getLogData()); $lobj = Objects::findObject($id[1]); if (!$lobj instanceof ApplicationDataObject || !can_access(logged_user(), $lobj->getMembers(), $lobj->getObjectTypeId(), ACCESS_LEVEL_READ)) { $removed++; unset($logs[$k]); } } } // Get more objects to substitute the removed ones if ($limit && $removed > 0) { $other_logs = self::findAll(array( 'conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND (`rel_object_id`IN (SELECT `id` FROM '.Comments::instance()->getTableName(true).' WHERE `rel_object_id` = (?)) AND `rel_object_id`IN (SELECT `object_id` FROM '.Timeslots::instance()->getTableName(true).' WHERE `rel_object_id` = (?)))', $private_filter, $silent_filter, $object->getId(),$private_filter, $silent_filter, $object->getId(), $object->getId()), 'order' => '`created_on` DESC', 'limit' => $next_offset + $removed, 'offset' => $next_offset, )); // findAll $logs = array_merge($logs, $other_logs); $next_offset += $removed; if (count($logs) > $limit) $logs = array_slice($logs, 0, $limit); } } while ($removed > 0); return $logs; } // getObjectLogs
</div> <table style="margin-top:10px;"> <?php if (can_manage_time(logged_user())) { echo '<tr><td style="vertical-align:middle;"><span class="bold">' . lang("person") . ': </span></td>'; 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) { $rel_object = $timeslot->getRelObject(); $is_assigned = $rel_object instanceof ProjectTask && $rel_object->getAssignedToContactId() == $user->getId(); if ($is_assigned || can_add($user, $rel_object->getMembers(), Timeslots::instance()->getObjectTypeId())) { $tmp_users[] = $user; } } $users = $tmp_users; $user_options = array(); foreach ($users as $user) { $user_options[] = option_tag($user->getObjectName(), $user->getId(), array_var($timeslot_data, 'contact_id') == $user->getId() ? array("selected" => "selected") : null); } echo '<td>' . select_box("timeslot[contact_id]", $user_options, array('id' => $genid . 'tsUser', 'tabindex' => '15')) . '</td></tr>'; echo '<tr><td> </td></tr>'; } ?> <tr> <td style="vertical-align:middle;"><span class="bold"><?php echo lang("start date");
/** * Delete specific timeslot * * @param void * @return null */ function delete() { $timeslot = Timeslots::findById(get_id()); if (!$timeslot instanceof Timeslot) { flash_error(lang('timeslot dnx')); ajx_current("empty"); return; } $object = $timeslot->getRelObject(); if (!$object instanceof ContentDataObject) { flash_error(lang('object dnx')); ajx_current("empty"); return; } if (trim($object->getObjectUrl())) { $redirect_to = $object->getObjectUrl(); } if (!$timeslot->canDelete(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } try { $timeslot_delete = $timeslot; DB::beginWork(); $timeslot->delete(); ApplicationLogs::createLog($timeslot, ApplicationLogs::ACTION_DELETE); $object->onDeleteTimeslot($timeslot); DB::commit(); $this->percent_complete_delete($timeslot_delete); flash_success(lang('success delete timeslot')); ajx_current("reload"); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete timeslot')); ajx_current("empty"); } }
function delete_timeslot() { ajx_current("empty"); $timeslot = Timeslots::findById(get_id()); if (!$timeslot instanceof Timeslot) { flash_error(lang('timeslot dnx')); return; } if (!$timeslot->canDelete(logged_user())) { flash_error(lang('no access permissions')); return; } try { DB::beginWork(); $timeslot->delete(); DB::commit(); ApplicationLogs::createLog($timeslot, ApplicationLogs::ACTION_DELETE); ajx_extra_data(array("timeslotId" => get_id())); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } // try }
} $more_content_templates = array(); Hook::fire("more_content_templates", $object, $more_content_templates); foreach ($more_content_templates as $ct) { tpl_assign('genid', $genid); tpl_assign('object', $object); $this->includeTemplate(get_template_path($ct[0], $ct[1], array_var($ct, 2))); } if ($object instanceof ContentDataObject) { echo render_co_view_member_path($object); } if ($object instanceof ApplicationDataObject) { echo render_custom_properties($object); } $logged_user_pgs = logged_user()->getPermissionGroupIds(); if ($object instanceof ContentDataObject && $object->allowsTimeslots() && can_access_pgids($logged_user_pgs, $object->getMembers(), Timeslots::instance()->getObjectTypeId(), ACCESS_LEVEL_READ)) { echo render_object_timeslots($object, $object->getViewUrl()); } $isUser = $object instanceof Contact && $object->isUser(); if ($object instanceof ContentDataObject && $object->canView(logged_user()) || $isUser && (logged_user()->getId() == get_id() || logged_user()->isAdministrator())) { //echo render_object_latest_activity($object); //TODO SE rompe } if (!$isUser && $object instanceof ContentDataObject && $object->isCommentable()) { echo render_object_comments($object, $object->getViewUrl()); } ?> </td> </tr> <tr> <td class="coViewBottomLeft"></td> <td class="coViewBottom" colspan=2></td>
/** * Return manager instance * * @access protected * @param void * @return Timeslots */ function manager() { if (!$this->manager instanceof Timeslots) { $this->manager = Timeslots::instance(); } return $this->manager; }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'Timeslots')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return Timeslots::instance()->paginate($arguments, $items_per_page, $current_page); } // if }
static function getGeneralTimeslots($context, $user = null, $offset = 0, $limit = 20) { $user_sql = ""; if ($user instanceof Contact) { $user_sql = " AND contact_id = " . $user->getId(); } //$result = Timeslots::getContentObjects($context, ObjectTypes::findById(Timeslots::instance()->getObjectTypeId()), array('start_time', 'rel_object_id'), 'DESC', " AND rel_object_id = 0" . $user_sql, null, null, null, $offset, $limit); $result = Timeslots::instance()->listing(array("order" => array('start_time', 'rel_object_id'), "order_dir" => "DESC", "extra_conditions" => " AND rel_object_id = 0" . $user_sql, "start" => $offset, "limit" => $limit)); return $result; }
<div id="<?php echo $genid ?>TMTimespanSubmitEdit" style="display:none"> <?php echo submit_button(lang('save'),'s',array('style'=>'margin-top:0px;margin-left:0px', 'tabindex' => '310', 'onclick' => 'ogTimeManager.SubmitNewTimeslot(\'' .$genid . '\');return false;')) ?><br/> <?php echo submit_button(lang('cancel'),'c',array('style'=>'margin-top:0px;margin-left:0px', 'tabindex' => '320', 'onclick' => 'ogTimeManager.CancelEdit();return false;')) ?> </div> </td> </tr> </table> <div class="context-switcher"> <div class="context-header"> <label><?php echo lang("related to")?></label> </div> <div class="context-body" style="display:<?php echo $display_members ? 'block' : 'none'?>;"> <?php render_member_selectors(Timeslots::instance()->getObjectTypeId(), $genid, null, array('select_current_context' => true)); ?> </div> </div> </div> </div> <div id="<?php echo $genid ?>TMTimespanAddNew" class="TMTimespanAddNew" style="padding: 6px 0;<?php echo (!$draw_inputs ? "" : 'display:none;') ?>"> <?php $names = array(); $context = active_context(); foreach ($context as $dimension) { $names[] = $dimension->getName(); } ?> <span class="desc" style="padding: 0 12px;">* <?php echo lang('select member to add timeslots', implode(", ", $names))?></span> </div>
/** * Clear all project timeslots * * @param void * @return null */ private function clearTimeslots() { if (is_null($this->all_timeslots)) { $this->all_timeslots = Timeslots::getAllProjectTimeslots($this); } if (is_array($this->all_timeslots)) { foreach ($this->all_timeslots as $t) { $t->delete(); } } }
function update_unset_billing_values() { ajx_current("empty"); if (!logged_user()->isAdministrator()) { flash_error(lang("no access permissions")); return; } try { DB::beginWork(); $count = Timeslots::updateBillingValues(); DB::commit(); flash_success(lang("success update billing values", $count)); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } }
?> </div> </td> </tr> </table> <div class="context-switcher"> <div class="context-header"> <label><?php echo lang("related to"); ?> </label> </div> <div class="context-body" style="display:none"> <?php render_dimension_trees(Timeslots::instance()->getObjectTypeId(), $genid, array()); ?> </div> </div> </div> </div> <div id="<?php echo $genid; ?> TMTimespanAddNew" class="TMTimespanAddNew" style="padding: 6px 0;<?php echo !$draw_inputs ? "" : 'display:none;'; ?> "> <?php $names = array();