Ejemplo n.º 1
0
 protected function updateBean(SugarBean $bean, ServiceBase $api, $args)
 {
     $id = parent::updateBean($bean, $api, $args);
     //retrieve a Bean created
     if (isset($args['record']) && !empty($args['record'])) {
         $projectBean = BeanFactory::retrieveBean($args['module'], $args['record']);
     } else {
         $projectBean = $bean;
     }
     //Create a Diagram row
     $diagramBean = BeanFactory::getBean('pmse_BpmnDiagram')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($diagramBean)) {
         $diagramBean = BeanFactory::newBean('pmse_BpmnDiagram');
         $diagramBean->dia_uid = PMSEEngineUtils::generateUniqueID();
     }
     $diagramBean->name = $projectBean->name;
     $diagramBean->description = $projectBean->description;
     $diagramBean->assigned_user_id = $projectBean->assigned_user_id;
     $diagramBean->prj_id = $id;
     $dia_id = $diagramBean->save();
     //Create a Process row
     $processBean = BeanFactory::getBean('pmse_BpmnProcess')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($processBean)) {
         $processBean = BeanFactory::newBean('pmse_BpmnProcess');
         $processBean->pro_uid = PMSEEngineUtils::generateUniqueID();
     }
     $processBean->name = $projectBean->name;
     $processBean->description = $projectBean->description;
     $processBean->assigned_user_id = $projectBean->assigned_user_id;
     $processBean->prj_id = $id;
     $processBean->dia_id = $dia_id;
     $pro_id = $processBean->save();
     //Create a ProcessDefinition row
     $processDefinitionBean = BeanFactory::getBean('pmse_BpmProcessDefinition')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($processDefinitionBean)) {
         $processDefinitionBean = BeanFactory::newBean('pmse_BpmProcessDefinition');
         $processDefinitionBean->id = $pro_id;
         $processDefinitionBean->new_with_id = true;
     }
     $processDefinitionBean->prj_id = $id;
     $processDefinitionBean->pro_module = $projectBean->prj_module;
     $processDefinitionBean->pro_status = $projectBean->prj_status;
     $processDefinitionBean->assigned_user_id = $projectBean->assigned_user_id;
     $processDefinitionBean->save();
     $relDepStatus = $projectBean->prj_status == 'ACTIVE' ? 'INACTIVE' : 'ACTIVE';
     while ($relatedDepBean = BeanFactory::getBean('pmse_BpmRelatedDependency')->retrieve_by_string_fields(array('prj_id' => $id, 'pro_status' => $relDepStatus))) {
         $relatedDepBean->pro_status = $projectBean->prj_status;
         $relatedDepBean->save();
     }
     $keysArray = array('prj_id' => $id, 'pro_id' => $pro_id);
     $dynaF = BeanFactory::getBean('pmse_BpmDynaForm')->retrieve_by_string_fields(array('prj_id' => $id, 'pro_id' => $pro_id, 'name' => 'Default'));
     if (empty($dynaF)) {
         $editDyna = false;
     } else {
         $editDyna = true;
     }
     $dynaForm = new PMSEDynaForm();
     $dynaForm->generateDefaultDynaform($processDefinitionBean->pro_module, $keysArray, $editDyna);
     return $id;
 }
 function setup()
 {
     $rel = BeanFactory::getBean('Relationships');
     if (!empty($this->vardef['relationship'])) {
         $rel->retrieve_by_name($this->vardef['relationship']);
     }
     if ($rel->relationship_type == 'many-to-many') {
         if ($rel->lhs_module == $this->module_dir) {
             $this->related_module = $rel->rhs_module;
             $module_dir = $rel->lhs_module;
         } else {
             if ($rel->rhs_module == $this->module_dir) {
                 $this->related_module = $rel->lhs_module;
                 $module_dir = $rel->rhs_module;
             } else {
                 die("this field has no relationships mapped with this module");
             }
         }
         if ($module_dir != $this->module_dir) {
             die('These modules do not match : ' . $this->module_dir . ' and ' . $module_dir);
         }
         $this->bean = BeanFactory::retrieveBean($this->module_dir, $_REQUEST['bean_id']);
         if (empty($this->bean)) {
             die('failed to load the bean');
         }
         if ($this->bean->load_relationship($this->vardef['name'])) {
             $this->retrieve_values();
         } else {
             die('failed to load the relationship');
         }
     } else {
         die("the relationship is not a many-to-many");
     }
 }
Ejemplo n.º 3
0
 public function filterRelatedSetup(ServiceBase $api, array $args)
 {
     // Load the parent bean.
     $record = BeanFactory::retrieveBean($args['module'], $args['record']);
     if (empty($record)) {
         throw new SugarApiExceptionNotFound(sprintf('Could not find parent record %s in module: %s', $args['record'], $args['module']));
     }
     if (!$record->ACLAccess('view')) {
         throw new SugarApiExceptionNotAuthorized('No access to view records for module: ' . $args['module']);
     }
     // Load the relationship.
     $linkName = $args['link_name'];
     if (!$record->load_relationship($linkName)) {
         // The relationship did not load.
         throw new SugarApiExceptionNotFound('Could not find a relationship named: ' . $args['link_name']);
     }
     $linkModuleName = $record->{$linkName}->getRelatedModuleName();
     $linkSeed = BeanFactory::getBean($linkModuleName);
     if (!$linkSeed->ACLAccess('list')) {
         throw new SugarApiExceptionNotAuthorized('No access to list records for module: ' . $linkModuleName);
     }
     $options = $this->parseArguments($api, $args, $linkSeed);
     // If they don't have fields selected we need to include any link fields
     // for this relationship
     if (empty($args['fields']) && is_array($linkSeed->field_defs)) {
         $relatedLinkName = $record->{$linkName}->getRelatedModuleLinkName();
         $options['linkDataFields'] = array();
         foreach ($linkSeed->field_defs as $field => $def) {
             if (empty($def['rname_link']) || empty($def['link'])) {
                 continue;
             }
             if ($def['link'] != $relatedLinkName) {
                 continue;
             }
             // It's a match
             $options['linkDataFields'][] = $field;
             $options['select'][] = $field;
         }
     }
     // In case the view parameter is set, reflect those fields in the
     // fields argument as well so formatBean only takes those fields
     // into account instead of every bean property.
     if (!empty($args['view'])) {
         $args['fields'] = $options['select'];
     }
     $q = self::getQueryObject($linkSeed, $options);
     // Some relationships want the role column ignored
     if (!empty($args['ignore_role'])) {
         $ignoreRole = true;
     } else {
         $ignoreRole = false;
     }
     $q->joinSubpanel($record, $linkName, array('joinType' => 'INNER', 'ignoreRole' => $ignoreRole));
     $q->setJoinOn(array('baseBean' => strtolower($record->object_name), 'baseBeanId' => $record->id));
     if (!isset($args['filter']) || !is_array($args['filter'])) {
         $args['filter'] = array();
     }
     self::addFilters($args['filter'], $q->where(), $q);
     return array($args, $q, $options, $linkSeed);
 }
Ejemplo n.º 4
0
 public function filterRelated(ServiceBase $api, array $args)
 {
     if (empty($args['include_child_items']) || !in_array($args['link_name'], array('calls', 'meetings'))) {
         return parent::filterRelated($api, $args);
     }
     $api->action = 'list';
     $record = BeanFactory::retrieveBean($args['module'], $args['record']);
     if (empty($record)) {
         throw new SugarApiExceptionNotFound(sprintf('Could not find parent record %s in module: %s', $args['record'], $args['module']));
     }
     if (!$record->ACLAccess('view')) {
         throw new SugarApiExceptionNotAuthorized(sprintf('No access to view records for module: %s', $args['module']));
     }
     $linkName = $args['link_name'];
     if (!$record->load_relationship($linkName)) {
         throw new SugarApiExceptionNotFound(sprintf('Could not find a relationship named: %s', $args['link_name']));
     }
     $linkModuleName = $record->{$linkName}->getRelatedModuleName();
     $linkSeed = BeanFactory::getBean($linkModuleName);
     if (!$linkSeed->ACLAccess('list')) {
         throw new SugarApiExceptionNotAuthorized(sprintf('No access to list records for module: %s', $linkModuleName));
     }
     $options = $this->parseArguments($api, $args, $linkSeed);
     $q = self::getQueryObject($linkSeed, $options);
     if (!isset($args['filter']) || !is_array($args['filter'])) {
         $args['filter'] = array();
     }
     self::addFilters($args['filter'], $q->where(), $q);
     // FIXME: this informations should be dynamically retrieved
     if ($linkModuleName === 'Meetings') {
         $linkToContacts = 'contacts';
         $childModuleTable = 'meetings';
         $childRelationshipTable = 'meetings_contacts';
         $childRelationshipAlias = 'mc';
         $childLhsColumn = $childModuleTable . '.id';
         $childRhsColumn = $childRelationshipAlias . '.meeting_id';
     } else {
         $linkToContacts = 'contacts';
         $childModuleTable = 'calls';
         $childRelationshipTable = 'calls_contacts';
         $childRelationshipAlias = 'cc';
         $childLhsColumn = $childModuleTable . '.id';
         $childRhsColumn = $childRelationshipAlias . '.call_id';
     }
     // Join contacts if not already requested.
     $contactJoin = $q->join($linkToContacts, array('joinType' => 'LEFT'));
     // FIXME: there should be the ability to specify from which related module
     // the child items should be loaded
     $q->joinTable('accounts_contacts', array('alias' => 'ac', 'joinType' => 'LEFT', 'linkingTable' => true))->on()->equalsField('ac.contact_id', $contactJoin->joinName() . '.id')->equals('ac.deleted', 0);
     $q->joinTable('accounts', array('alias' => 'a', 'joinType' => 'LEFT', 'linkingTable' => true))->on()->equalsField('a.id', 'ac.account_id')->equals('a.deleted', 0);
     $where = $q->where()->queryOr();
     $where->queryAnd()->equals('ac.account_id', $record->id);
     $where->queryAnd()->equals($childModuleTable . '.parent_type', 'Accounts')->equals($childModuleTable . '.parent_id', $record->id);
     return $this->runQuery($api, $args, $q, $options, $linkSeed);
 }
Ejemplo n.º 5
0
 /**
  * Restore should merely look for Restore property to be set on the model. Restored is the boolean field to be checked after restore is complete, but simply set Restore (no d) on the model and pass it to the standard PUT request for Recycler module.
  */
 public function restore($api, $args)
 {
     global $app_strings;
     $bean = BeanFactory::retrieveBean("dm_Recycler", $args['id']);
     $result = $bean->restore();
     if ($result) {
         $data = array('message' => $app_strings['LBL_DM_DATAMANAGER_RECORD_RESTORE_SUCCESS']);
     } else {
         $data = array('error' => "1", 'error_message' => $app_strings['LBL_DM_DATAMANAGER_RECORD_RESTORE_FAILURE']);
     }
     return $data;
 }
Ejemplo n.º 6
0
 public static function setQuotaSubscriptions(Quota $bean, $event, $args)
 {
     if ($event !== 'before_save') {
         return false;
     }
     // Subscribe the user making the quota change
     global $current_user;
     Subscription::subscribeUserToRecord($current_user, $bean);
     // Subscribe the user whose quota is getting changed
     $assignee = BeanFactory::retrieveBean('Users', $bean->user_id);
     Subscription::subscribeUserToRecord($assignee, $bean);
     return true;
 }
 public function run()
 {
     if (version_compare($this->from_version, '7.6.0', '>=')) {
         $this->log('ACL role sets should be already registered, skipping');
         return;
     }
     require_once 'modules/ACLRoles/AclRoleSetRegistrar.php';
     $registrar = new AclRoleSetRegistrar();
     $result = $this->db->query("SELECT id FROM users where deleted = 0");
     while ($row = $this->db->fetchByAssoc($result)) {
         $user = BeanFactory::retrieveBean('Users', $row['id']);
         if ($user) {
             $this->log('Registering ACL role sets for user ' . $user->id);
             $registrar->registerAclRoleSet($user);
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Get summary text
  */
 public function get_summary_text()
 {
     /**
      * @var TimePeriod
      */
     $timeperiod = BeanFactory::retrieveBean("TimePeriods", $this->timeperiod_id);
     // make sure we have the full name before display happens
     if (empty($this->user_full_name) && !empty($this->user_id)) {
         $user = BeanFactory::getBean('Users', $this->user_id);
         $this->user_full_name = $user->full_name;
     }
     $mod_strings = return_module_language($GLOBALS['current_language'], $this->module_name);
     // get the quota type as a label
     $quota_type = '';
     if (!empty($this->quota_type)) {
         $quota_type = $mod_strings['LBL_' . strtoupper($this->quota_type)] . ' ' . $mod_strings['LBL_MODULE_NAME_SINGULAR'] . ' ';
     }
     return "{$timeperiod->name} {$quota_type}- {$this->user_full_name}";
 }
Ejemplo n.º 9
0
 public function unsubscribeFromRecord(ServiceBase $api, array $args)
 {
     $this->requireArgs($args, array('module', 'record'));
     $bean = BeanFactory::retrieveBean($args['module'], $args['record']);
     if (empty($bean)) {
         throw new SugarApiExceptionNotFound('Could not find parent record ' . $args['record'] . ' in module ' . $args['module']);
     }
     if (!$bean->ACLAccess('view')) {
         $moduleName = null;
         if (isset($args['module'])) {
             $failed_module_strings = return_module_language($GLOBALS['current_language'], $args['module']);
             $moduleName = $failed_module_strings['LBL_MODULE_NAME'];
         }
         $args = null;
         if (!empty($moduleName)) {
             $args = array('moduleName' => $moduleName);
         }
         throw new SugarApiExceptionNotAuthorized('EXCEPTION_SUBSCRIBE_MODULE_NOT_AUTHORIZED', $args);
     }
     return Subscription::unsubscribeUserFromRecord($api->user, $bean);
 }
Ejemplo n.º 10
0
 /**
  * Look up the supplied oauth_token from download token storage.
  *
  * @param $oauth_token
  * oauth_token to be check with.
  *
  * @return
  * An associative array as below, and return NULL if the supplied oauth_token
  * is invalid:
  * - client_id: Stored client identifier.
  * - expires: Stored expiration in unix timestamp.
  * - scope: (optional) Stored scope values in space-separated string.
  *
  * @ingroup oauth2_section_7
  */
 public function getDownloadToken($oauth_token)
 {
     $tokenSeed = BeanFactory::newBean('OAuthTokens');
     $token = $tokenSeed->retrieve_by_string_fields(array('download_token' => $oauth_token));
     if (empty($token->id)) {
         return NULL;
     }
     $clientBean = BeanFactory::retrieveBean('OAuthKeys', $token->consumer);
     if (empty($token->id) || empty($clientBean->id)) {
         return NULL;
     }
     $clientAllowed = $this->isClientAllowed($clientBean);
     if (!$clientAllowed) {
         return NULL;
     }
     if (session_id()) {
         // The session here could be unrelated to the actual user attached to the
         // download token, so let's just close it.
         session_write_close();
         $_SESSION = array();
     }
     $tokenData = array('client_id' => $clientBean->c_key, 'user_id' => $token->assigned_user_id, 'expires' => $token->expire_ts);
     return $this->getPlatformStore()->getDownloadTokenData($tokenData, $token, $clientBean);
 }
Ejemplo n.º 11
0
 function get_invite_calls($user)
 {
     // First, get the list of IDs.
     $query = "SELECT calls_users.required, calls_users.accept_status, calls_users.call_id from calls_users where calls_users.user_id='{$user->id}' AND ( calls_users.accept_status IS NULL OR  calls_users.accept_status='none') AND calls_users.deleted=0";
     $GLOBALS['log']->debug("Finding linked records {$this->object_name}: " . $query);
     $result = $this->db->query($query, true);
     $list = array();
     while ($row = $this->db->fetchByAssoc($result)) {
         $record = BeanFactory::retrieveBean($this->module_dir, $row['call_id']);
         if (empty($record)) {
             continue;
         }
         $record->required = $row['required'];
         $record->accept_status = $row['accept_status'];
         $list[] = $record;
     }
     return $list;
 }
Ejemplo n.º 12
0
 /**
  * Handles failed reports by deactivating them and sending email notifications to owner and subscribed user
  */
 public function handleFailedReports()
 {
     /** @var LoggerManager */
     global $log;
     $schedules_to_deactivate = $this->getSchedulesToDeactivate();
     foreach ($schedules_to_deactivate as $schedule) {
         $log->info('Deactivating report schedule ' . $schedule['id']);
         $this->deactivate($schedule['id']);
         $owner = BeanFactory::retrieveBean('Users', $schedule['owner_id']);
         $subscriber = BeanFactory::retrieveBean('Users', $schedule['subscriber_id']);
         require_once 'modules/Reports/utils.php';
         $utils = new ReportsUtilities();
         $utils->sendNotificationOfDisabledReport($schedule['report_id'], $owner, $subscriber);
     }
 }
Ejemplo n.º 13
0
 /**
  * Relates existing records to related bean.
  *
  * @param ServiceBase $api The API class of the request.
  * @param array $args The arguments array passed in from the API.
  * @param string $securityTypeLocal What ACL to check on the near side of the link
  * @param string $securityTypeRemote What ACL to check on the far side of the link
  * @return array Array of formatted fields.
  * @throws SugarApiExceptionInvalidParameter If wrong arguments are passed
  * @throws SugarApiExceptionNotFound If bean can't be retrieved.
  */
 public function createRelatedLinks($api, $args, $securityTypeLocal = 'view', $securityTypeRemote = 'view')
 {
     $this->requireArgs($args, array('ids'));
     $ids = $this->normalizeLinkIds($args['ids']);
     $result = array('related_records' => array());
     $primaryBean = $this->loadBean($api, $args);
     list($linkName) = $this->checkRelatedSecurity($api, $args, $primaryBean, $securityTypeLocal, $securityTypeRemote);
     $relatedModuleName = $primaryBean->{$linkName}->getRelatedModuleName();
     foreach ($ids as $id => $additionalValues) {
         $relatedBean = BeanFactory::retrieveBean($relatedModuleName, $id);
         if (!$relatedBean || $relatedBean->deleted) {
             throw new SugarApiExceptionNotFound('Could not find the related bean');
         }
         $primaryBean->{$linkName}->add(array($relatedBean), $additionalValues);
         $result['related_records'][] = $this->formatBean($api, $args, $relatedBean);
     }
     //Clean up any hanging related records.
     SugarRelationship::resaveRelatedBeans();
     $result['record'] = $this->formatBean($api, $args, $primaryBean);
     return $result;
 }
Ejemplo n.º 14
0
 /**
  *
  * @param type $flowData
  * @param type $createThread
  * @param type $bean
  * @param type $externalAction
  * @param type $arguments
  * @return boolean
  * @codeCoverageIgnore
  */
 public function runEngine($flowData, $createThread = false, $bean = null, $externalAction = '', $arguments = array())
 {
     // Load the bean if the request comes from a RESUME_EXECUTION related origin
     // like for example: a timer event execution.
     if (is_null($bean)) {
         $bean = BeanFactory::retrieveBean($flowData['cas_sugar_module'], $flowData['cas_sugar_object_id']);
     }
     // Validating unreferenced elements when cron jobs are executed, after MACAROON-518 shouldn't have
     // unreferenced elements. This will validate previous records created before this fix.
     if ($externalAction == 'WAKE_UP') {
         $elementBean = BeanFactory::getBean('pmse_BpmnEvent', $flowData['bpmn_id']);
         if (!isset($elementBean->id)) {
             // Setting active flow to deleted
             $fd = BeanFactory::getBean('pmse_BpmFlow', $flowData['id']);
             $fd->cas_flow_status = 'DELETED';
             $fd->save();
             // Updating process to error
             $cf = new PMSECaseFlowHandler();
             $cf->changeCaseStatus($flowData['cas_id'], 'TERMINATED');
             // Exiting without errors
             return true;
         }
     }
     $preparedData = $this->caseFlowHandler->prepareFlowData($flowData, $createThread);
     $this->logger->debug("Begin process Element {$flowData['bpmn_type']}");
     try {
         $executionData = $this->processElement($preparedData, $bean, $externalAction, $arguments);
         if (isset($executionData['process_bean']) && !empty($executionData['process_bean'])) {
             $bean = $executionData['process_bean'];
         }
         $this->validateFailSafes($flowData, $executionData);
         $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread);
     } catch (PMSEElementException $e) {
         $this->logger->warning($e->getMessage());
         $element = $e->getElement();
         $flow = $e->getFlowData();
         $state = empty($flow['id']) ? 'CREATE' : 'UPDATE';
         $executionData = $element->prepareResponse($flow, 'ERROR', $state);
         // If the status is put into error then the Inbox record should be updated as well
         $this->caseFlowHandler->changeCaseStatus($executionData['flow_data']['cas_id'], 'ERROR');
         $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread);
     } catch (Exception $e) {
         $this->logger->warning($e->getMessage());
         $element = $this->retrievePMSEElement('');
         $status = $e->getCode() == 0 ? 'QUEUE' : 'ERROR';
         $preparedData['cas_flow_status'] = $status;
         $executionData = $element->prepareResponse($preparedData, $status, 'CREATE');
         // If the status is put into error then the Inbox record should be updated as well
         if ($status == 'ERROR') {
             $this->caseFlowHandler->changeCaseStatus($executionData['flow_data']['cas_id'], 'ERROR');
         }
         $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread);
     }
     if ($this->caseFlowHandler->numberOfCasesByStatus($flowData, 'ERROR') <= 0 && $externalAction == 'RESUME_EXECUTION') {
         $this->caseFlowHandler->changeCaseStatus($flowData['cas_id'], 'IN PROGRESS');
     }
     if (!empty($routeData['next_elements'])) {
         $createThread = sizeof($routeData['next_elements']) > 1;
         if ($createThread) {
             $startTime = ($this->maxExecutionTimeout - $this->executionTime) / sizeof($routeData['next_elements']);
         }
         foreach ($routeData['next_elements'] as $elementData) {
             //reset execution time if the derivation is in parallel
             $this->executionTime = $createThread ? $startTime : $this->executionTime;
             $this->runEngine($elementData, $createThread, $bean);
         }
     } else {
         // Quick fix to the 0 output printed by some element,
         // TODO: Don't remove until the fix to the element is commited
         ob_get_clean();
         return true;
     }
     return true;
 }
Ejemplo n.º 15
0
/*
 * Your installation or use of this SugarCRM file is subject to the applicable
 * terms available at
 * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/.
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */
global $mod_strings;
global $app_strings;
global $app_list_strings;
global $focus, $support_coming_due, $support_expired;
if (!empty($_REQUEST['record'])) {
    $focus = BeanFactory::retrieveBean('WorkFlow', $_REQUEST['record']);
    if (empty($focus)) {
        sugar_die($app_strings['LBL_UNAUTH_ADMIN']);
    }
} else {
    header("Location: index.php?module=WorkFlow&action=index");
}
if (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
    $focus->id = "";
}
echo getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_MODULE_TITLE'], $focus->name), true);
$GLOBALS['log']->info("WorkFlow detail view");
$xtpl = new XTemplate('modules/WorkFlow/DetailView.html');
$xtpl->assign("MOD", $mod_strings);
$xtpl->assign("APP", $app_strings);
$xtpl->assign("GRIDLINE", $gridline);
Ejemplo n.º 16
0
 /**
  * Used by the dependency manager to pre-load all the related fields required
  * to load an entire view.
  */
 public function action_getRelatedValues()
 {
     /** @var LoggerManager */
     global $log;
     $ret = array();
     if (empty($_REQUEST['tmodule']) || empty($_REQUEST['fields'])) {
         return;
     }
     $fields = json_decode(html_entity_decode($_REQUEST['fields']), true);
     if (!is_array($fields)) {
         $log->fatal('"fields" is not a valid JSON string');
         $this->display($ret);
         return;
     }
     $module = $_REQUEST['tmodule'];
     $id = empty($_REQUEST['record_id']) ? null : $_REQUEST['record_id'];
     $focus = BeanFactory::retrieveBean($module, $id);
     if (!$focus) {
         $log->fatal('Unable to load bean');
         $this->display($ret);
         return;
     }
     foreach ($fields as $rfDef) {
         if (!isset($rfDef['link'], $rfDef['type'])) {
             $log->fatal('At least one of "link" and "type" attributes is not specified');
             continue;
         }
         $link = $rfDef['link'];
         $type = $rfDef['type'];
         if (!isset($ret[$link])) {
             $ret[$link] = array();
         }
         if (empty($ret[$link][$type])) {
             $ret[$link][$type] = array();
         }
         switch ($type) {
             //The Related function is used for pulling a sing field from a related record
             case "related":
                 if (!isset($rfDef['relate'])) {
                     $log->fatal('"relate" attribute of related expression is not specified');
                     break;
                 }
                 //Default it to a blank value
                 $ret[$link]['related'][$rfDef['relate']] = "";
                 //If we have neither a focus id nor a related record id, we can't retrieve anything
                 if (!empty($id) || !empty($rfDef['relId'])) {
                     $relBean = null;
                     if (empty($rfDef['relId']) || empty($rfDef['relModule'])) {
                         //If the relationship is invalid, just move onto another field
                         if (!$focus->load_relationship($link)) {
                             break;
                         }
                         $beans = $focus->{$link}->getBeans(array("enforce_teams" => true));
                         //No related beans means no value
                         if (empty($beans)) {
                             break;
                         }
                         //Grab the first bean on the list
                         reset($beans);
                         $relBean = current($beans);
                     } else {
                         $relBean = BeanFactory::getBean($rfDef['relModule'], $rfDef['relId']);
                     }
                     //If we found a bean and the current user has access to the related field, grab a value from it
                     if (!empty($relBean) && ACLField::hasAccess($rfDef['relate'], $relBean->module_dir, $GLOBALS['current_user']->id, true)) {
                         $validFields = FormulaHelper::cleanFields($relBean->field_defs, false, true, true);
                         if (isset($validFields[$rfDef['relate']])) {
                             $ret[$link]['relId'] = $relBean->id;
                             $ret[$link]['related'][$rfDef['relate']] = FormulaHelper::getFieldValue($relBean, $rfDef['relate']);
                         }
                     }
                 }
                 break;
             case "count":
                 if (!empty($id) && $focus->load_relationship($link)) {
                     $ret[$link][$type] = count($focus->{$link}->get());
                 } else {
                     $ret[$link][$type] = 0;
                 }
                 break;
             case "rollupSum":
             case "rollupAve":
             case "rollupMin":
             case "rollupMax":
                 //If we are going to calculate one rollup, calculate all the rollups since there is so little cost
                 if (!isset($rfDef['relate'])) {
                     $log->fatal('"relate" attribute of rollup expression is not specified');
                     break;
                 }
                 $rField = $rfDef['relate'];
                 if (!empty($id) && $focus->load_relationship($link)) {
                     $relBeans = $focus->{$link}->getBeans(array("enforce_teams" => true));
                     $sum = 0;
                     $count = 0;
                     $min = false;
                     $max = false;
                     if (!empty($relBeans)) {
                         //Check if the related record vardef has banned this field from formulas
                         $relBean = reset($relBeans);
                         $validFields = FormulaHelper::cleanFields($relBean->field_defs, false, true, true);
                         if (!isset($validFields[$rField])) {
                             break;
                         }
                     }
                     foreach ($relBeans as $bean) {
                         if (isset($bean->{$rField}) && is_numeric($bean->{$rField}) && ACLField::hasAccess($rField, $bean->module_dir, $GLOBALS['current_user']->id, true)) {
                             $count++;
                             $sum += floatval($bean->{$rField});
                             if ($min === false || $bean->{$rField} < $min) {
                                 $min = floatval($bean->{$rField});
                             }
                             if ($max === false || $bean->{$rField} > $max) {
                                 $max = floatval($bean->{$rField});
                             }
                         }
                     }
                     if ($type == "rollupSum") {
                         $ret[$link][$type][$rField] = $sum;
                     }
                     if ($type == "rollupAve") {
                         $ret[$link][$type][$rField] = $count == 0 ? 0 : $sum / $count;
                     }
                     if ($type == "rollupMin") {
                         $ret[$link][$type][$rField] = $min;
                     }
                     if ($type == "rollupMax") {
                         $ret[$link][$type][$rField] = $max;
                     }
                 } else {
                     $ret[$link][$type][$rField] = 0;
                 }
                 break;
         }
     }
     $this->display($ret);
 }
Ejemplo n.º 17
0
 /**
  * Determines a user's access to the current bean, taking both team security
  * and ACLs into consideration.
  * @param  User $user
  * @return bool       True if $user has access, false otherwise.
  */
 public function checkUserAccess(User $user = null)
 {
     $userHasAccess = false;
     if (is_null($user)) {
         $user = $GLOBALS['current_user'];
     }
     $save_user = $GLOBALS['current_user'];
     $GLOBALS['current_user'] = $user;
     if (!empty($this->id) && empty($this->new_with_id)) {
         $newBean = BeanFactory::retrieveBean($this->module_name, $this->id, array('use_cache' => false));
         if (!empty($newBean)) {
             $context = array('user' => $user);
             $userHasAccess = $this->ACLAccess('view', $context);
         }
     }
     $GLOBALS['current_user'] = $save_user;
     return $userHasAccess;
 }
Ejemplo n.º 18
0
 /**
  * Fetches data from the $args array and updates the bean with that data
  * @param $api ServiceBase The API class of the request, used in cases where the API changes how the bean is retrieved
  * @param $args array The arguments array passed in from the API
  * @param $aclToCheck string What kind of ACL to verify when loading a bean. Supports: view,edit,create,import,export
  * @param $options Options array to pass to the retrieveBean method
  * @return SugarBean The loaded bean
  */
 protected function loadBean(ServiceBase $api, $args, $aclToCheck = 'view', $options = array())
 {
     $this->requireArgs($args, array('module', 'record'));
     $bean = BeanFactory::retrieveBean($args['module'], $args['record'], $options);
     if ($api->action == 'save' && ($bean == false || $bean->deleted == 1)) {
         throw new SugarApiExceptionNotAuthorized('SUGAR_API_EXCEPTION_RECORD_NOT_AUTHORIZED', array('save'));
     }
     if ($bean == FALSE || $bean->deleted == 1) {
         // Couldn't load the bean
         throw new SugarApiExceptionNotFound('Could not find record: ' . $args['record'] . ' in module: ' . $args['module']);
     }
     if (SugarACLStatic::fixUpActionName($aclToCheck) != 'view' && !$bean->ACLAccess(SugarACLStatic::fixUpActionName($aclToCheck))) {
         throw new SugarApiExceptionNotAuthorized('SUGAR_API_EXCEPTION_RECORD_NOT_AUTHORIZED', array($aclToCheck));
     }
     return $bean;
 }
Ejemplo n.º 19
0
 /**
  * Gets file info for a bean and field type file
  *
  * @param SugarBean $bean The bean to get the info for
  * @param string $field The field name to get the file information for
  * @return array|bool
  */
 public function getFileInfo($bean, $field)
 {
     if ($this->validateBeanAndField($bean, $field, 'file')) {
         // Default the file id and url
         $fileid = $bean->id;
         $fileurl = '';
         // Handle special cases, like Documents and KBDocumentRevisions
         if (isset($bean->object_name)) {
             if ($bean->object_name == 'Document') {
                 // Documents store their file information in DocumentRevisions
                 $revision = BeanFactory::retrieveBean('DocumentRevisions', $bean->id);
                 if (!empty($revision)) {
                     $fileid = $revision->id;
                     $name = $revision->filename;
                     $fileurl = empty($revision->doc_url) ? '' : $revision->doc_url;
                 } else {
                     // The id is not a revision id, try the actual document revision id
                     $revision = BeanFactory::retrieveBean('DocumentRevisions', $bean->document_revision_id);
                     if (!empty($revision)) {
                         // Revision will hold the file id AND the file name
                         $fileid = $revision->id;
                         $name = $revision->filename;
                         $fileurl = empty($revision->doc_url) ? '' : $revision->doc_url;
                     } else {
                         // Nothing to find
                         return false;
                     }
                 }
             } elseif ($bean->object_name == 'KBDocument') {
                 // Sorta the same thing with KBDocuments
                 $revision = BeanFactory::getBean('KBDocumentRevisions', $bean->id);
                 if (!empty($revision)) {
                     $revision = BeanFactory::getBean('DocumentRevisions', $revision->document_revision_id);
                     // Last change to fail, if nothing found, return false
                     if (empty($revision)) {
                         return false;
                     }
                     $fileid = $revision->id;
                     $name = $revision->filename;
                     $fileurl = empty($revision->doc_url) ? '' : $revision->doc_url;
                 } else {
                     // Try the kbdoc revision
                     $revision = BeanFactory::getBean('KBDocumentRevisions', $bean->kbdocument_revision_id);
                     if (!empty($revision)) {
                         $revision = BeanFactory::getBean('DocumentRevisions', $revision->document_revision_id);
                         // Last change to fail, if nothing found, return false
                         if (empty($revision)) {
                             return false;
                         }
                         $fileid = $revision->id;
                         $name = $revision->filename;
                         $fileurl = empty($revision->doc_url) ? '' : $revision->doc_url;
                     } else {
                         return false;
                     }
                 }
             }
         } else {
             $fileid = $bean->id;
             $fileurl = '';
         }
         $filepath = $this->getFilePathFromId($fileid);
         // Quick existence check to make sure we are actually working
         // on a real file
         if (!file_exists($filepath) && ($bean->doc_type == "Sugar" || empty($bean->doc_type))) {
             return false;
         }
         if (empty($fileurl) && !empty($bean->doc_url)) {
             $fileurl = $bean->doc_url;
         }
         // Get our filename if we don't have it already
         if (empty($name)) {
             $name = $bean->getFileName();
         }
         return array('content-type' => $this->getMimeType($filepath), 'content-length' => filesize($filepath), 'name' => $name, 'uri' => $fileurl, 'path' => $filepath, 'doc_type' => $bean->doc_type);
     } else {
         return null;
     }
 }
Ejemplo n.º 20
0
<?php

if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}
/*
 * Your installation or use of this SugarCRM file is subject to the applicable
 * terms available at
 * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/.
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */
/*********************************************************************************
 * Description:
 ********************************************************************************/
require_once 'include/ListView/ProcessView.php';
global $mod_strings;
$focus = BeanFactory::getBean('WorkFlowTriggerShells');
if (empty($_REQUEST['record'])) {
    sugar_die($mod_strings['ERR_DELETE_RECORD']);
}
$focus = BeanFactory::retrieveBean('WorkFlowTriggerShells', $_REQUEST['record']);
if (empty($focus)) {
    sugar_die($mod_strings['ERR_DELETE_EMPTY']);
}
$focus->mark_deleted($_REQUEST['record']);
header("Location: index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id']);
Ejemplo n.º 21
0
 * Your installation or use of this SugarCRM file is subject to the applicable
 * terms available at
 * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/.
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */
// $Id: Popup_picker.php 56510 2010-05-17 18:54:49Z jenny $
require_once "include/upload_file.php";
require_once 'include/utils/db_utils.php';
require_once 'modules/Audit/Audit.php';
global $currentModule, $focus, $action, $app_strings, $app_list_strings, $current_language, $timedate, $mod_strings;
//we don't want the parent module's string file, but rather the string file specific to this subpanel
$focus = BeanFactory::retrieveBean($_REQUEST['module_name'], $_REQUEST['record']);
class Popup_Picker
{
    /*
     *
     */
    function Popup_Picker()
    {
    }
    /**
     *
     */
    function process_page()
    {
        global $theme;
        global $focus;
Ejemplo n.º 22
0
 public function purge()
 {
     $GLOBALS['log']->info("Purging " . $this->bean_module . " record: " . $this->bean_id);
     $ModuleBean = BeanFactory::retrieveBean($this->bean_module, $this->bean_id, array('disable_row_level_security' => true, 'deleted' => true));
     if (!($ModuleBean === null)) {
         $this->db->query("DELETE FROM {$ModuleBean->table_name} WHERE id = '{$this->bean_id}'");
         $this->db->query("DELETE FROM {$this->table_name} WHERE id='{$this->id}'");
     }
     unset($ModuleBean);
 }
Ejemplo n.º 23
0
}
if (!empty($_REQUEST['load_id']) && !empty($beanList[$_REQUEST['load_module']])) {
    $contact = BeanFactory::retrieveBean($_REQUEST['load_module'], $_REQUEST['load_id']);
    if (!empty($contact)) {
        $link_id = $class_name . '_id';
        $focus->{$link_id} = $_REQUEST['load_id'];
        $focus->contact_name = isset($contact->full_name) ? $contact->full_name : $contact->name;
        $focus->to_addrs_names = $focus->contact_name;
        $focus->to_addrs_ids = $_REQUEST['load_id'];
        //Retrieve the email address.
        //If Opportunity or Case then Oppurtinity/Case->Accounts->(email_addr_bean_rel->email_addresses)
        //If Contacts, Leads etc.. then Contact->(email_addr_bean_rel->email_addresses)
        $sugarEmailAddress = BeanFactory::getBean('EmailAddresses');
        if ($contact->object_name == 'Opportunity' || $contact->object_name == 'aCase') {
            if (!empty($contact->account_id)) {
                $account = BeanFactory::retrieveBean('Accounts', $contact->account_id);
                if (!empty($account)) {
                    $sugarEmailAddress->handleLegacyRetrieve($account);
                    if (isset($account->email1)) {
                        $focus->to_addrs_emails = $account->email1;
                        $focus->to_addrs = "{$focus->contact_name} <{$account->email1}>";
                    }
                }
            }
        } else {
            $sugarEmailAddress->handleLegacyRetrieve($contact);
            if (isset($contact->email1)) {
                $focus->to_addrs_emails = $contact->email1;
                $focus->to_addrs = "{$focus->contact_name} <{$contact->email1}>";
            }
        }
Ejemplo n.º 24
0
 /**
  * Get Team Name given a team_id
  *
  * @param  $teamId
  * @return string name of the team or empty string if not found
  */
 protected function getTeamNameFromId($teamId)
 {
     $bean = BeanFactory::retrieveBean('Teams', $teamId);
     if (!empty($bean)) {
         return $bean->name;
     }
     return '';
 }
Ejemplo n.º 25
0
 /**
 * Use with caution as if you have a large list of beans in the relationship,
 * it can cause the app to timeout or run out of memory.
 *
 * @param array $params An array that can contain the following parameters:<br/>
 * <ul><li><b>where:</b> An array with 3 key/value pairs.
 *  lhs_field: The name of the field to check search.
 *  operator: The operator to use in the search.
 *  rhs_value: The value to search for.<br/>
 *  Example:<pre>
 *  'where' => array(
         'lhs_field' => 'source',
         'operator' => '=',
         'rhs_value' => 'external'
     )</pre>
 *  </li>
 * <li><b>limit:</b> The maximum number of beans to load.</li>
 * <li><b>offset:</b> Offset to pass to the database query when loading.</li>
 * <li><b>order_by:</b> field to order the result set by</li>
 * <li><b>deleted:</b> If deleted is set to 1, only deleted records related to the current record will be returned.</li></ul>
 * @return array of SugarBeans related through this link.
 */
 function getBeans($params = array())
 {
     //Some depricated code attempts to pass in the old format to getBeans with a large number of useless paramters.
     //reset the parameters if they are not in the new array format.
     if (!is_array($params)) {
         $params = array();
     }
     if (!$this->loaded && empty($params)) {
         $this->load();
     }
     $rows = $this->rows;
     //If params is set, we are doing a query rather than a complete load of the relationship
     if (!empty($params)) {
         $data = $this->query($params);
         $rows = $data['rows'];
     }
     $result = array();
     if (!$this->beansAreLoaded() || !empty($params)) {
         if (!is_array($this->beans)) {
             $this->beans = array();
         }
         $rel_module = $this->getRelatedModuleName();
         //First swap in the temp loaded beans, only if we are doing a complete load (no params)
         if (empty($params)) {
             $result = $this->tempBeans;
             $this->tempBeans = array();
         }
         //If there are any relationship fields, we need to figure out the mapping from the relationship fields to the
         //fields in the related module
         $relationshipFields = array();
         $seed = BeanFactory::getBean($rel_module);
         if ($seed !== false) {
             // Deprecated: This format of relationship fields will be removed
             // please use the rname_link format instead
             $relationshipFields = $this->getRelationshipFieldMapping($seed);
             if (!empty($this->def['rel_fields'])) {
                 //Find the field in the related module that maps to this
                 foreach ($this->def['rel_fields'] as $rfName => $rfDef) {
                     //This is pretty badly designed, but there is no mapping stored for fields in the relationship table
                     //to the fields to be populated in the related record.
                     foreach ($seed->field_defs as $f => $d) {
                         if (!empty($d['relationship_fields'][$rfName])) {
                             $relationshipFields[$rfName] = $d['relationship_fields'][$rfName];
                             break;
                         }
                     }
                 }
             }
             if ($seed && is_array($seed->field_defs)) {
                 foreach ($seed->field_defs as $fieldName => $def) {
                     if (empty($def['rname_link'])) {
                         continue;
                     }
                     $relationshipFields[$def['rname_link']] = $fieldName;
                 }
             }
         }
         //now load from the rows
         foreach ($rows as $id => $vals) {
             if (empty($this->beans[$id])) {
                 $tmpBean = BeanFactory::retrieveBean($rel_module, $id);
                 if ($tmpBean) {
                     $result[$id] = $tmpBean;
                 }
             } else {
                 $result[$id] = $this->beans[$id];
             }
             //Populate any relationship fields
             foreach ($relationshipFields as $rfName => $field) {
                 if (isset($vals[$rfName])) {
                     if (!empty($result[$id])) {
                         $result[$id]->{$field} = $vals[$rfName];
                     }
                 }
             }
         }
         //If we did a compelte load, cache the result in $this->beans
         if (empty($params)) {
             $this->beans = $result;
             foreach ($result as $id => $bean) {
                 if (!isset($this->rows[$id])) {
                     $this->rows[$id] = array("id" => $id);
                 }
             }
         }
     } else {
         $result = $this->beans;
     }
     return $result;
 }
Ejemplo n.º 26
0
 function getAllProjectTasks()
 {
     $projectTasks = array();
     $query = "SELECT * FROM project_task WHERE project_id = '" . $this->id . "' AND deleted = 0 ORDER BY project_task_id";
     $result = $this->db->query($query, true, "Error retrieving project tasks");
     while (($row = $this->db->fetchByAssoc($result)) != null) {
         $projectTaskBean = BeanFactory::retrieveBean('ProjectTask', $row['id']);
         if (empty($projectTaskBean)) {
             continue;
         }
         array_push($projectTasks, $projectTaskBean);
     }
     return $projectTasks;
 }
Ejemplo n.º 27
0
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */
require_once 'include/workflow/workflow_utils.php';
global $theme;
global $app_strings;
global $app_list_strings;
global $mod_strings;
global $urlPrefix;
global $currentModule;
$log = LoggerManager::getLogger('workflow_alerts');
if (!empty($_REQUEST['workflow_id'])) {
    $workflow_object = BeanFactory::retrieveBean('WorkFlow', $_REQUEST['workflow_id']);
}
if (empty($workflow_object)) {
    sugar_die("You shouldn't be here");
}
$focus = BeanFactory::getBean('WorkFlowTriggerShells');
if (!empty($_REQUEST['record'])) {
    $focus->retrieve($_REQUEST['record']);
}
if (!empty($_REQUEST['rel_module'])) {
    $focus->rel_module = $_REQUEST['rel_module'];
}
if (!empty($_REQUEST['type'])) {
    $focus->type = $_REQUEST['type'];
}
////////////////////////////////////////////////////////
Ejemplo n.º 28
0
 /**
  *  Update records.
  *
  * @param $data array of job data
  */
 public function runUpdate($data)
 {
     // Get the data down to just the list of fields
     $module = $data['module'];
     unset($data['module']);
     $action = $data['action'];
     unset($data['action']);
     $ids = is_array($data['uid']) ? $data['uid'] : array();
     unset($data['uid']);
     unset($data['filter']);
     unset($data['entire']);
     $prospectLists = isset($data['prospect_lists']) ? $data['prospect_lists'] : array();
     unset($data['prospect_lists']);
     $seed = BeanFactory::newBean($module);
     $fakeApi = new RestService();
     $fakeApi->user = $GLOBALS['current_user'];
     $helper = ApiHelper::getHelper($fakeApi, $seed);
     $failed = 0;
     foreach ($ids as $id) {
         // Doing a full retrieve because we are writing we may need dependent fields for workflow that we don't know about
         $bean = BeanFactory::retrieveBean($module, $id);
         if ($bean == null) {
             // Team permissions may have changed, or a deletion, we won't hold it against them
             continue;
         }
         if (!$bean->aclAccess($action)) {
             // ACL's might not let them modify this bean, but we should still do the rest
             continue;
         }
         if ($action == 'delete') {
             $bean->mark_deleted($id);
             continue;
         }
         try {
             $errors = $helper->populateFromApi($bean, $data, array('massUpdate' => true));
             $check_notify = $helper->checkNotify($bean);
             $bean->save($check_notify);
         } catch (SugarApiExceptionNotAuthorized $e) {
             // ACL's might not let them modify this bean, but we should still do the rest
             $failed++;
             continue;
         }
     }
     if (count($prospectLists) > 0) {
         $massupdate = new MassUpdate();
         foreach ($prospectLists as $listId) {
             if ($action == 'save') {
                 $success = $massupdate->add_prospects_to_prospect_list($module, $listId, $ids);
             } else {
                 $success = $massupdate->remove_prospects_from_prospect_list($module, $listId, $ids);
             }
         }
         if (!$success) {
             $GLOBALS['log']->error("Could not add prospects to prospect list, could not find a relationship to the ProspectLists module.");
         }
     }
     return array('failed' => $failed);
 }
Ejemplo n.º 29
0
 /**
  * Utility Method to create the filter for the filer API to use
  *
  * @param ServiceBase $api                  Service Api Class
  * @param mixed $user_id                    Passed in User ID, if false, it will use the current use from $api->user
  * @param mixed $timeperiod_id              TimePeriod Id, if false, the current time period will be found an used
  * @param string $forecast_type             Type of forecast to return, direct or rollup
  * @return array                            The Filer array to be passed back into the filerList Api
  * @throws SugarApiExceptionNotAuthorized
  * @throws SugarApiExceptionInvalidParameter
  */
 protected function createFilter(ServiceBase $api, $user_id, $timeperiod_id, $forecast_type)
 {
     $filter = array();
     // if we did not find a user in the filters array, set it to the current user's id
     if ($user_id == false) {
         // use the current user, since on one was passed in
         $user_id = $api->user->id;
     } else {
         // make sure that the passed in user is a valid user
         /* @var $user User */
         // we use retrieveBean so it will return NULL and not an empty bean if the $args['user_id'] is invalid
         $user = BeanFactory::retrieveBean('Users', $user_id);
         if (is_null($user) || is_null($user->id)) {
             throw new SugarApiExceptionInvalidParameter('Provided User is not valid');
         }
         # if they are not a manager, don't show them committed number for others
         global $mod_strings, $current_language;
         $mod_strings = return_module_language($current_language, 'Forecasts');
         if ($user_id != $api->user->id && !User::isManager($api->user->id)) {
             throw new SugarApiExceptionNotAuthorized(string_format($mod_strings['LBL_ERROR_NOT_MANAGER'], array($api->user->id, $user_id)));
         }
     }
     // set the assigned_user_id
     array_push($filter, array('user_id' => $user_id));
     if ($forecast_type !== false) {
         // make sure $forecast_type is valid (e.g. Direct or Rollup)
         switch (strtolower($forecast_type)) {
             case 'direct':
             case 'rollup':
                 break;
             default:
                 throw new SugarApiExceptionInvalidParameter('Forecast Type of ' . $forecast_type . ' is not valid. Valid options Direct or Rollup.');
         }
         // set the forecast type, make sure it's always capitalized
         array_push($filter, array('forecast_type' => ucfirst($forecast_type)));
     }
     // if we didn't find a time period, set the time period to be the current time period
     if ($timeperiod_id == false) {
         $timeperiod_id = TimePeriod::getCurrentId();
     }
     // fix up the timeperiod filter
     /* @var $tp TimePeriod */
     // we use retrieveBean so it will return NULL and not an empty bean if the $args['timeperiod_id'] is invalid
     $tp = BeanFactory::retrieveBean('TimePeriods', $timeperiod_id);
     if (is_null($tp) || is_null($tp->id)) {
         throw new SugarApiExceptionInvalidParameter('Provided TimePeriod is not valid');
     }
     array_push($filter, array('timeperiod_id' => $tp->id));
     return $filter;
 }
Ejemplo n.º 30
0
 /**
  * Adds an activities_users relationship between the activity and all users specified in the data array
  * @param array $data
  */
 public static function addActivitySubscriptions(array $data)
 {
     $activity = BeanFactory::retrieveBean('Activities', $data['act_id']);
     $userIds = array();
     foreach ($data['user_partials'] as $userPartial) {
         $userIds[] = $userPartial['created_by'];
     }
     $activity->processUserRelationships($userIds);
 }