/** * Returns all the user data to be sent in the REST API call for a normal * `/me` call. * * This data is dependent on the platform used. Each own platform has a * different data set to be sent in the response. * * @param string $platform The platform of the request. * @param array $options A list of options like `category` to retrieve the * basic user info. Will use `global` if no `category` is supplied. * @return array The user's data to be used in a `/me` request. */ protected function getUserData($platform, array $options) { $current_user = $this->getUserBean(); // Get the basics $category = isset($options['category']) ? $options['category'] : 'global'; $user_data = $this->getBasicUserInfo($platform, $category); // Fill in the rest $user_data['type'] = self::TYPE_USER; if ($current_user->isAdmin()) { $user_data['type'] = self::TYPE_ADMIN; } $user_data['show_wizard'] = $this->shouldShowWizard($category); $user_data['id'] = $current_user->id; $current_user->_create_proper_name_field(); $user_data['full_name'] = $current_user->full_name; $user_data['user_name'] = $current_user->user_name; $user_data['roles'] = ACLRole::getUserRoles($current_user->id); $user_data = $this->setExpiredPassword($user_data); $user_data['picture'] = $current_user->picture; $user_data['acl'] = $this->getAcls($platform); $user_data['is_manager'] = User::isManager($current_user->id); $user_data['is_top_level_manager'] = false; $user_data['reports_to_id'] = $current_user->reports_to_id; $user_data['reports_to_name'] = $current_user->reports_to_name; if ($user_data['is_manager']) { $user_data['is_top_level_manager'] = User::isTopLevelManager($current_user->id); } // Address information $user_data['address_street'] = $current_user->address_street; $user_data['address_city'] = $current_user->address_city; $user_data['address_state'] = $current_user->address_state; $user_data['address_country'] = $current_user->address_country; $user_data['address_postalcode'] = $current_user->address_postalcode; require_once 'modules/Teams/TeamSetManager.php'; $teams = $current_user->get_my_teams(); $my_teams = array(); foreach ($teams as $id => $name) { $my_teams[] = array('id' => $id, 'name' => $name); } $user_data['my_teams'] = $my_teams; $defaultTeams = TeamSetManager::getTeamsFromSet($current_user->team_set_id); foreach ($defaultTeams as $id => $team) { $defaultTeams[$id]['primary'] = false; if ($team['id'] == $current_user->team_id) { $defaultTeams[$id]['primary'] = true; } } $user_data['preferences']['default_teams'] = $defaultTeams; // Send back a hash of this data for use by the client $user_data['_hash'] = $current_user->getUserMDHash(); return array('current_user' => $user_data); }
/** * Returns the Quota for a given timeperiod_id, user_id, and quota_type * * @param $api * @param $args * @return array * @throws SugarApiExceptionNotAuthorized */ public function getQuota($api, $args) { if (!SugarACL::checkAccess('Quotas', 'access')) { throw new SugarApiExceptionNotAuthorized(); } /* @var $quotaBean Quota */ $quotaBean = BeanFactory::getBean('Quotas'); $isRollup = $args['quota_type'] == 'rollup'; // add the manager's rollup quota to the data returned $data = $quotaBean->getRollupQuota($args['timeperiod_id'], $args['user_id'], $isRollup); // add if the manager is a top-level manager or not $data['is_top_level_manager'] = User::isTopLevelManager($args['user_id']); return $data; }
/** * Utility method to build out a tree node array * @param User $user * @param string $rel * @return array */ protected function getTreeArray(User $user, $rel = 'rep') { global $locale; $fullName = $locale->formatName($user); $qa_id = 'jstree_node_'; if ($rel == "my_opportunities") { $qa_id .= 'myopps_'; } $state = ''; if ($rel == 'rep' && User::isManager($user->id)) { // check if the user is a manager and if they are change the rel to be 'manager' $rel = 'manager'; $state = 'closed'; } return array('data' => $fullName, 'children' => array(), 'metadata' => array('id' => $user->id, 'user_name' => $user->user_name, 'full_name' => $fullName, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'picture' => $user->picture, 'reports_to_id' => $user->reports_to_id, 'reports_to_name' => $user->reports_to_name, 'title' => $user->title, 'is_manager' => User::isManager($user->id), 'is_top_level_manager' => User::isTopLevelManager($user->id)), 'state' => $state, 'attr' => array('rel' => $rel, 'id' => $qa_id . $user->user_name)); }
/** * If the user is the top level manager, set their rollup quota value correctly * * @param string $user_id * @param string $timeperiod_id * @throws SugarQueryException */ protected function fixTopLevelManagerQuotaRollup($user_id, $timeperiod_id) { if (User::isTopLevelManager($user_id)) { $sq = new SugarQuery(); $sq->select(array())->fieldRaw('sum(quota * base_rate)', 'quota'); $sq->from($this); $sq->where()->equals('assigned_user_id', $user_id)->equals('timeperiod_id', $timeperiod_id)->equals('draft', 1); $quota = $sq->getOne(); $this->commitQuota($quota, $user_id, $timeperiod_id, 'Rollup'); } }