/** * 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; }
static function getGeneralTimeslots($context, $user = null, $offset = 0, $limit = 20, $only_count_result = false) { $user_sql = ""; if ($user instanceof Contact) { $user_sql = " AND contact_id = " . $user->getId(); } $result = Timeslots::instance()->listing(array("order" => array('start_time', 'updated_on'), "order_dir" => "DESC", "extra_conditions" => " AND rel_object_id = 0" . $user_sql, 'only_count_results' => $only_count_result, "start" => $offset, "limit" => $limit)); return $result; }
function getOpenTimeslots() { return Timeslots::instance()->getOpenTimeslotsByObject($this->getId()); }
function getBillingTotalByUsers(User $user, $user_id = null) { //$project_ids = $this->getAllSubWorkspacesQuery($user); $user_cond = ''; if (isset($user_id)) { $user_cond = ' AND timeslots.user_id = ' . $user_id; } $rows = DB::executeAll('SELECT SUM(timeslots.fixed_billing) as total_billing, timeslots.user_id as user from ' . Timeslots::instance()->getTableName() . ' as timeslots, ' . ProjectTasks::instance()->getTableName() . ' as tasks WHERE ((tasks.' . trim(ProjectTasks::getWorkspaceString($this->getId())) . ' AND timeslots.object_id = tasks.id AND timeslots.object_manager = \'ProjectTasks\')' . ' OR (timeslots.object_manager = \'Project\' AND timeslots.object_id = ' . $this->getId() . '))' . $user_cond . ' GROUP BY user'); if (!is_array($rows) || !count($rows)) { return null; } else { for ($i = 0; $i < count($rows); $i++) { if ($rows[$i]['total_billing'] == 0) { unset($rows[$i]); } } return $rows; } }
?> </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();
<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>
function delete_timeslot() { if (!can_delete(logged_user(), active_context(), Timeslots::instance()->getObjectTypeId())) { 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 }
<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) {
function can_add_timeslots($user, $members) { return can_manage_time($user) || can_access_pgids($user->getPermissionGroupIds(), $members, Timeslots::instance()->getObjectTypeId(), ACCESS_LEVEL_WRITE); }
<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>
/** * Return manager instance * * @access protected * @param void * @return Timeslots */ function manager() { if(!($this->manager instanceof Timeslots)) $this->manager = Timeslots::instance(); return $this->manager; } // manager
/** * 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())); }
/** * Returns timeslots based on the set query parameters * * @param User $user * @param string $workspacesCSV * @param DateTimeValue $start_date * @param DateTimeValue $end_date * @param string $object_manager * @param string $object_id * @param array $group_by * @param array $order_by * @return array */ static function getTaskTimeslots($workspace = null, $user = null, $workspacesCSV = null, $start_date = null, $end_date = null, $object_id = 0, $group_by = null, $order_by = null, $limit = 0, $offset = 0, $timeslot_type = 0, $custom_conditions = null, $object_subtype = null) { $wslevels = 0; foreach ($group_by as $gb) { if ($gb == "project_id") { $wslevels++; } } $wsDepth = 0; if ($workspace instanceof Project) { $wsDepth = $workspace->getDepth(); } $wslevels = min(array($wslevels, 10 - $wsDepth)); if ($wslevels < 0) { $wslevels = 0; } $select = "SELECT `ts`.*"; for ($i = 0; $i < $wslevels; $i++) { $select .= ", `ws" . $i . "`.`name` AS `wsName" . $i . "`, `ws" . $i . "`.`id` AS `wsId" . $i . "`"; } $preFrom = " FROM "; for ($i = 0; $i < $wslevels; $i++) { $preFrom .= "("; } $postFrom = ""; for ($i = 0; $i < $wslevels; $i++) { $postFrom .= ") LEFT OUTER JOIN `" . TABLE_PREFIX . "projects` AS `ws" . $i . "` ON `pr`.`p" . ($wsDepth + $i + 1) . "` = `ws" . $i . "`.`id`"; } $commonConditions = ""; if ($start_date) { $commonConditions .= DB::prepareString(' AND `ts`.`start_time` >= ? ', array($start_date)); } if ($end_date) { $commonConditions .= DB::prepareString(' AND (`ts`.`paused_on` <> 0 OR `ts`.`end_time` <> 0) AND `ts`.`end_time` < ? ', array($end_date)); } //$commonConditions .= DB::prepareString(' AND (`ts`.`paused_on` <> 0 OR `ts`.`end_time` <> 0) AND `ts`.`end_time` > 0 AND `ts`.`end_time` < ? ', array($end_date)); -- another fix reported by a user, but we have to test it yet //User condition $commonConditions .= $user ? ' AND `ts`.`user_id` = ' . $user->getId() : ''; //Object condition $commonConditions .= $object_id > 0 ? ' AND `ts`.`object_manager` = "ProjectTasks" AND `ts`.`object_id` = ' . $object_id : ''; //Only applies to tasks $sql = ''; //Custom properties conditions $custom_cond = ''; $custom = false; if (count($custom_conditions) > 0) { $custom = true; foreach ($custom_conditions as $condCp) { //array_var($condCp, 'custom_property_id'); $cp = CustomProperties::getCustomProperty(array_var($condCp, 'custom_property_id')); //$skip_condition = false; $dateFormat = 'm/d/Y'; if (isset($params[array_var($condCp, 'id') . "_" . $cp->getName()])) { $value = $params[array_var($condCp, 'id') . "_" . $cp->getName()]; if ($cp->getType() == 'date') { $dateFormat = user_config_option('date_format'); } } else { $value = array_var($condCp, 'value'); } $custom_cond .= ' AND `pt`.id IN ( SELECT object_id as id FROM ' . TABLE_PREFIX . 'custom_property_values cpv WHERE '; $custom_cond .= ' cpv.custom_property_id = ' . array_var($condCp, 'custom_property_id'); if (array_var($condCp, 'condition') == 'like' || array_var($condCp, 'condition') == 'not like') { $value = '%' . $value . '%'; } if ($cp->getType() == 'date') { $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value); $value = $dtValue->format('Y-m-d H:i:s'); } if (array_var($condCp, 'condition') != '%') { if ($cp->getType() == 'numeric') { $custom_cond .= ' AND cpv.value ' . array_var($condCp, 'condition') . ' ' . mysql_real_escape_string($value); } else { $custom_cond .= ' AND cpv.value ' . array_var($condCp, 'condition') . ' "' . mysql_real_escape_string($value) . '"'; } } else { $custom_cond .= ' AND cpv.value like "%' . mysql_real_escape_string($value) . '"'; } $custom_cond .= ')'; } } switch ($timeslot_type) { case 0: //Task timeslots $from = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "project_tasks` AS `pt`, `" . TABLE_PREFIX . "projects` AS `pr`, `" . TABLE_PREFIX . "workspace_objects` AS `wo`"; $conditions = " WHERE `ts`.`object_manager` = 'ProjectTasks' AND `pt`.`id` = `ts`.`object_id` AND `pt`.`trashed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `pt`.`archived_by_id` = 0 AND `wo`.`object_manager` = 'ProjectTasks' AND `wo`.`object_id` = `ts`.`object_id` AND `wo`.`workspace_id` = `pr`.`id`"; //Project condition $conditions .= $workspacesCSV ? ' AND `pr`.`id` IN (' . $workspacesCSV . ')' : ''; if ($custom) { $commonConditions .= $custom_cond; } if ($object_subtype) { $conditions .= " AND `pt`.`object_subtype`={$object_subtype}"; } $sql = $select . $preFrom . $from . $postFrom . $conditions . $commonConditions; break; case 1: //Time timeslots $from = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "projects` AS `pr`"; $conditions = " WHERE `ts`.`object_manager` = 'Projects'"; $conditions .= $workspacesCSV ? ' AND `ts`.`object_id` IN (' . $workspacesCSV . ") AND `ts`.`object_id` = `pr`.`id`" : " AND `ts`.`object_id` = `pr`.`id`"; $sql = $select . $preFrom . $from . $postFrom . $conditions . $commonConditions; break; case 2: //All timeslots $from1 = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "project_tasks` AS `pt`, `" . TABLE_PREFIX . "projects` AS `pr`, `" . TABLE_PREFIX . "workspace_objects` AS `wo`"; $from2 = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "projects` AS `pr`"; $conditions1 = " WHERE `ts`.`object_manager` = 'ProjectTasks' AND `pt`.`id` = `ts`.`object_id` AND `pt`.`trashed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `pt`.`archived_by_id` = 0 AND `wo`.`object_manager` = 'ProjectTasks' AND `wo`.`object_id` = `ts`.`object_id` AND `wo`.`workspace_id` = `pr`.`id`"; //Project condition $conditions1 .= $workspacesCSV ? ' AND `pr`.`id` IN (' . $workspacesCSV . ')' : ''; if ($object_subtype) { $conditions1 .= " AND `pt`.`object_subtype`={$object_subtype}"; } $conditions2 = " WHERE `object_manager` = 'Projects'"; $conditions2 .= $workspacesCSV ? ' AND `ts`.`object_id` IN (' . $workspacesCSV . ") AND `ts`.`object_id` = `pr`.`id`" : " AND `ts`.`object_id` = `pr`.`id`"; $sql = $select . $preFrom . $from1 . $postFrom . $conditions1 . $commonConditions . $custom_cond . ' UNION ' . $select . $preFrom . $from2 . $postFrom . $conditions2 . $commonConditions; break; default: throw new Error("Timeslot type not recognised: " . $timeslot_type); } //Group by $wsCount = 0; $sql .= ' ORDER BY '; if (is_array($group_by)) { foreach ($group_by as $gb) { switch ($gb) { case 'project_id': $sql .= "`wsName" . $wsCount . "` ASC, "; $wsCount++; break; case 'id': case 'priority': case 'milestone_id': case 'state': if ($timeslot_type == 0) { $sql .= "`pt`.`{$gb}` ASC, "; } break; default: if (is_string($gb) && trim($gb) != '') { $sql .= "`{$gb}` ASC, "; } break; } } } //Order by if (is_array($order_by)) { foreach ($order_by as $ob) { if (is_string($ob) && trim($ob) != '') { $sql .= "`{$ob}` ASC, "; } } } $sql .= " `start_time`"; if ($limit > 0 && $offset > 0) { $sql .= " LIMIT {$offset}, {$limit}"; } $timeslots = array(); $rows = DB::executeAll($sql); if (is_array($rows)) { foreach ($rows as $row) { $tsRow = array("ts" => Timeslots::instance()->loadFromRow($row)); for ($i = 0; $i < $wslevels; $i++) { $tsRow["wsId" . $i] = $row["wsId" . $i]; } $timeslots[] = $tsRow; } // foreach } // if return count($timeslots) ? $timeslots : null; }
function canAddTimeslot($user) { return $this->canChangeStatus($user) || can_manage_time($user) || can_access_pgids($user->getPermissionGroupIds(), $this->getMembers(), Timeslots::instance()->getObjectTypeId(), ACCESS_LEVEL_WRITE); }
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; }
</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");
/** * 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
function edit_timeslot() { ajx_current("empty"); $timeslot_data = array_var($_POST, 'timeslot'); $timeslot = Timeslots::findById(array_var($timeslot_data, 'id', 0)); if (!$timeslot instanceof Timeslot) { flash_error(lang('timeslot dnx')); return; } //context permissions or members $member_ids = json_decode(array_var($_POST, 'members', array())); // clean member_ids $tmp_mids = array(); foreach ($member_ids as $mid) { if (!is_null($mid) && trim($mid) != "") { $tmp_mids[] = $mid; } } $member_ids = $tmp_mids; if (empty($member_ids)) { if (!can_add(logged_user(), active_context(), Timeslots::instance()->getObjectTypeId())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } } else { if (count($member_ids) > 0) { $enteredMembers = Members::findAll(array('conditions' => 'id IN (' . implode(",", $member_ids) . ')')); } else { $enteredMembers = array(); } if (!can_add(logged_user(), $enteredMembers, Timeslots::instance()->getObjectTypeId())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } } try { $hoursToAdd = array_var($timeslot_data, 'hours', 0); $minutes = array_var($timeslot_data, 'minutes', 0); if (strpos($hoursToAdd, ',') && !strpos($hoursToAdd, '.')) { $hoursToAdd = str_replace(',', '.', $hoursToAdd); } if (strpos($hoursToAdd, ':') && !strpos($hoursToAdd, '.')) { $pos = strpos($hoursToAdd, ':') + 1; $len = strlen($hoursToAdd) - $pos; $minutesToAdd = substr($hoursToAdd, $pos, $len); if (!strlen($minutesToAdd) <= 2 || !strlen($minutesToAdd) > 0) { $minutesToAdd = substr($minutesToAdd, 0, 2); } $mins = $minutesToAdd / 60; $hours = substr($hoursToAdd, 0, $pos - 1); $hoursToAdd = $hours + $mins; } if ($minutes) { $min = str_replace('.', '', $minutes / 6); $hoursToAdd = $hoursToAdd + ("0." . $min); } if ($hoursToAdd <= 0) { flash_error(lang('time has to be greater than 0')); return; } $startTime = getDateValue(array_var($timeslot_data, 'date')); $startTime = $startTime->add('h', 8 - logged_user()->getTimezone()); $endTime = getDateValue(array_var($timeslot_data, 'date')); $endTime = $endTime->add('h', 8 - logged_user()->getTimezone() + $hoursToAdd); $timeslot_data['start_time'] = $startTime; $timeslot_data['end_time'] = $endTime; $timeslot_data['name'] = $timeslot_data['description']; //Only admins can change timeslot user if (!array_var($timeslot_data, 'contact_id') && !logged_user()->isAdministrator()) { $timeslot_data['contact_id'] = $timeslot->getContactId(); } $timeslot->setFromAttributes($timeslot_data); $user = Contacts::findById($timeslot_data['contact_id']); $billing_category_id = $user->getDefaultBillingId(); $bc = BillingCategories::findById($billing_category_id); if ($bc instanceof BillingCategory) { $timeslot->setBillingId($billing_category_id); $hourly_billing = $bc->getDefaultValue(); $timeslot->setHourlyBilling($hourly_billing); $timeslot->setFixedBilling($hourly_billing * $hoursToAdd); $timeslot->setIsFixedBilling(false); } DB::beginWork(); $timeslot->save(); $member_ids = json_decode(array_var($_POST, 'members', '')); $object_controller = new ObjectController(); $object_controller->add_to_members($timeslot, $member_ids); DB::commit(); ApplicationLogs::createLog($timeslot, ApplicationLogs::ACTION_EDIT); ajx_extra_data(array("timeslot" => $timeslot->getArrayInfo())); } 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; }
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 get_object_column_list() { $allowed_columns = $this->get_allowed_columns(array_var($_GET, 'object_type')); $columns = array_var($_GET, 'columns', array()); if (array_var($_GET, 'object_type') == Timeslots::instance()->getObjectTypeId()) { $task_ot = ObjectTypes::findByName('task'); $task_columns = $this->get_allowed_columns($task_ot->getId()); $columns = array_var($_GET, 'columns', array()); foreach ($task_columns as $t) { if (str_starts_with($t['id'], 'dim_') || str_starts_with($t['id'], 'repeat_')) { continue; } $allowed_columns[] = $t; } } tpl_assign('allowed_columns', $allowed_columns); tpl_assign('columns', explode(',', $columns)); tpl_assign('order_by', array_var($_GET, 'orderby')); tpl_assign('order_by_asc', array_var($_GET, 'orderbyasc')); tpl_assign('genid', array_var($_GET, 'genid')); $this->setLayout("html"); $this->setTemplate("column_list"); }