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); } } } }
/** * This function sets the selected billing values for all timeslots which lack any type of billing values (value set to 0). * This function is used when users start to use billing in the system. * * @return unknown_type */ static function updateBillingValues() { $timeslots = Timeslots::findAll(array('conditions' => '`end_time` > 0 AND billing_id = 0 AND is_fixed_billing = 0', 'join' => array('table' => Objects::instance()->getTableName(true), 'jt_field' => 'id', 'e_field' => 'rel_object_id'))); $users = Contacts::getAllUsers(); $usArray = array(); foreach ($users as $u) { $usArray[$u->getId()] = $u; } $pbidCache = array(); $count = 0; $categories_cache = array(); foreach ($timeslots as $ts) { /* @var $ts Timeslot */ $user = $usArray[$ts->getContactId()]; if ($user instanceof Contact) { $billing_category_id = $user->getDefaultBillingId(); if ($billing_category_id > 0) { $hours = $ts->getMinutes() / 60; $billing_category = array_var($categories_cache, $billing_category_id); if (!$billing_category instanceof BillingCategory) { $billing_category = BillingCategories::findById($billing_category_id); $categories_cache[$billing_category_id] = $billing_category; } if ($billing_category instanceof BillingCategory) { $hourly_billing = $billing_category->getDefaultValue(); $ts->setBillingId($billing_category_id); $ts->setHourlyBilling($hourly_billing); $ts->setFixedBilling(round($hourly_billing * $hours, 2)); $ts->setIsFixedBilling(false); $ts->save(); $count++; } } } else { $ts->setIsFixedBilling(true); $ts->save(); } } return $count; }
function resumeTimeslots(User $user) { $manager_class = get_class($this->manager()); $object_id = $this->getObjectId(); $timeslots = Timeslots::findAll(array('conditions' => 'user_id = ' . $user->getId() . ' AND object_manager = "' . $manager_class . '" AND object_id = ' . $object_id . ' AND end_time = "' . EMPTY_DATETIME . '" AND paused_on != "' . EMPTY_DATETIME . '"')); if ($timeslots) { foreach ($timeslots as $timeslot) { $timeslot->resume(); $timeslot->save(); } } }
function resumeTimeslots(Contact $user) { $timeslots = Timeslots::findAll(array('conditions' => 'contact_id = ' . $user->getId() . ' AND rel_object_id = ' . $this->getObjectId() . ' AND end_time = "' . EMPTY_DATETIME . '" AND paused_on != "' . EMPTY_DATETIME . '"')); if ($timeslots) { foreach ($timeslots as $timeslot) { $timeslot->resume(); $timeslot->save(); } } }
static function getProjectTimeslots($allowedWorkspaceIdsCSV = null, $user = null, $project = null, $offset = 0, $limit = 20) { $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::findAll(array('conditions' => "object_manager = 'Projects'" . $project_sql . $user_sql, 'order' => 'start_time DESC, id DESC', 'offset' => $offset, 'limit' => $limit)); }