Example #1
0
 /**
  * Create the lead record and optionally perform post-save actions for Convert Target & Lead from Email cases
  */
 public function createRecord($api, $args)
 {
     //create the lead using the ModuleApi
     $data = parent::createRecord($api, $args);
     $leadId = null;
     if (isset($data['id']) && !empty($data['id'])) {
         $leadId = $data['id'];
     } else {
         //lead not created, can't do post-processes - bail out
         return $data;
     }
     // Handle Lead-Prospect post processing
     if (!empty($args['relate_to']) && $args['relate_to'] === 'Prospects' && !empty($args['relate_id'])) {
         // Save lead_id for display purposes
         $prospectId = $args['relate_id'];
         $prospect = BeanFactory::getBean('Prospects', $prospectId);
         $prospect->lead_id = $leadId;
         $prospect->save();
         // Handle Campaign Log entry creation
         if (!empty($data['campaign_id'])) {
             $lead = BeanFactory::getBean('Leads', $leadId);
             campaign_log_lead_or_contact_entry($data['campaign_id'], $prospect, $lead, 'lead');
         }
     }
     //handle Create Lead from Email use case
     if (isset($args['inbound_email_id']) && !empty($args['inbound_email_id'])) {
         $this->linkLeadToEmail($args['inbound_email_id'], $leadId);
     }
     return $data;
 }
Example #2
0
 /**
  * Create the bug record and optionally perform post-save actions for Portal
  */
 public function createRecord($api, $args)
 {
     //create the bug using the ModuleApi
     $contact = null;
     if (isset($_SESSION['type']) && $_SESSION['type'] == 'support_portal') {
         $contact = BeanFactory::getBean('Contacts', $_SESSION['contact_id'], array('strict_retrieve' => true));
         if (!empty($contact)) {
             $args['assigned_user_id'] = $contact->assigned_user_id;
             $args['team_id'] = $contact->fetched_row['team_id'];
             $args['team_set_id'] = $contact->fetched_row['team_set_id'];
         }
     }
     $data = parent::createRecord($api, $args);
     $bugId = null;
     if (isset($data['id']) && !empty($data['id'])) {
         $bugId = $data['id'];
     } else {
         //bug not created, can't do post-processes - bail out
         return $data;
     }
     if (!empty($bugId) && !empty($contact)) {
         $bug = BeanFactory::getBean('Bugs', $bugId);
         $bug->load_relationship('contacts');
         $bug->contacts->add($contact->id);
         $bug->load_relationship('accounts');
         $bug->accounts->add($contact->account_id);
     }
     return $data;
 }
 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;
 }
 /**
  * Create either a single event record or a set of recurring events if record is a recurring event
  * @param ServiceBase $api
  * @param array $args API arguments
  * @param array $additionalProperties Additional properties to be set on the bean
  * @return SugarBean
  */
 public function createBean(ServiceBase $api, array $args, array $additionalProperties = array())
 {
     $this->requireArgs($args, array('module'));
     $this->getCalendarEvents()->setOldAssignedUser($args['module'], null);
     $bean = parent::createBean($api, $args, $additionalProperties);
     if (!empty($bean->id)) {
         if ($this->shouldAutoInviteParent($bean, $args)) {
             $this->getCalendarEvents()->inviteParent($bean, $args['parent_type'], $args['parent_id']);
         }
         if ($this->getCalendarEvents()->isEventRecurring($bean)) {
             $this->generateRecurringCalendarEvents($bean);
         } else {
             $this->getCalendarEvents()->rebuildFreeBusyCache($GLOBALS['current_user']);
         }
     }
     return $bean;
 }
 public function getEnumValues($api, $args)
 {
     // if the field is not opps_view_by, go up to the parent
     if ($args['field'] !== 'opps_view_by') {
         return parent::getEnumValues($api, $args);
     } else {
         global $app_list_strings, $app_strings, $current_language;
         $value = $app_list_strings['opps_config_view_by_options_dom'];
         $value['Opportunities'] = $app_list_strings['moduleList']['Opportunities'];
         $value['RevenueLineItems'] = $app_list_strings['moduleList']['Opportunities'] . ' ' . $app_strings['LBL_DNB_AND'] . ' ';
         if (isset($app_list_strings['moduleList']['RevenueLineItems'])) {
             $value['RevenueLineItems'] .= $app_list_strings['moduleList']['RevenueLineItems'];
         } else {
             // when it's not enabled, the RLI module is not in the moduleList, so we need to
             // pull it from the module lang file
             $moduleLang = return_module_language($current_language, 'RevenueLineItems');
             $value['RevenueLineItems'] .= $moduleLang['LBL_MODULE_NAME'];
         }
         generateEtagHeader(md5(serialize($value)), 3600);
         return $value;
     }
     // opps_view_by
 }
 /**
  * Retrieve list of fields
  * @param string $filter
  * @param array $additionalArgs
  * @return object
  * @codeCoverageIgnore
  */
 public function retrieveFields($filter = '', ModuleApi $moduleApi, $type = '', $baseModule = '')
 {
     global $beanList;
     if (isset($beanList[$filter])) {
         $newModuleFilter = $filter;
     } else {
         $newModuleFilter = $this->pmseRelatedModule->getRelatedModuleName($baseModule, $filter);
     }
     $res = array();
     new stdClass();
     $res['name'] = $newModuleFilter;
     //$module = explode('_', $filter);// pull the related module out.
     //$filter = ucfirst(isset($module[1])?$module[1]:$module[0]);
     //$primal_module = ucfirst(isset($module[0])?$module[0]:'');
     $res['search'] = $filter;
     $res['success'] = true;
     $module_strings = return_module_language('en_us', 'ModuleBuilder');
     $fieldTypes = $module_strings['fieldTypes'];
     //add datetimecombo type field from the vardef overrides to point to Datetime type
     $fieldTypes['datetime'] = $fieldTypes['datetimecombo'];
     $fieldTypes['name'] = "Name";
     global $app_list_strings;
     $output = array();
     $moduleBean = $this->getModuleFilter($newModuleFilter);
     $fieldsData = isset($moduleBean->field_defs) ? $moduleBean->field_defs : array();
     foreach ($fieldsData as $field) {
         //$retrieveId = isset($additionalArgs['retrieveId']) && !empty($additionalArgs['retrieveId']) && $field['name'] == 'id' ? $additionalArgs['retrieveId'] : false;
         if (isset($field['vname']) && PMSEEngineUtils::isValidField($field, $type)) {
             if (PMSEEngineUtils::specialFields($field, $type)) {
                 $field = array_merge($field, $this->replaceItemsValues($field));
             }
             $tmpField = array();
             $tmpField['value'] = $field['name'];
             $tmpField['text'] = str_replace(':', '', translate($field['vname'], $newModuleFilter));
             // Handle field typing, starting with the vardef type for this field
             $tmpField['type'] = $field['type'];
             // If there is a known type for this type, use THAT
             if (isset($fieldTypes[$field['type']])) {
                 $tmpField['type'] = $fieldTypes[$field['type']];
             }
             $tmpField['optionItem'] = 'none';
             if ($field['type'] == 'enum' || $field['type'] == 'radioenum') {
                 if (!isset($field['options']) || !isset($app_list_strings[$field['options']])) {
                     if (PMSEEngineUtils::specialFields($field, $type)) {
                         $tmpField['optionItem'] = $this->gatewayModulesMethod($field);
                     } else {
                         $tmpField['optionItem'] = $moduleApi->getEnumValues(array(), array("module" => $newModuleFilter, "field" => $field["name"]));
                     }
                 } else {
                     $tmpField['optionItem'] = $app_list_strings[$field['options']];
                 }
             }
             if ($field['type'] == 'bool') {
                 $tmpField['optionItem'] = array("TRUE" => true, "FALSE" => false);
             }
             if (isset($field['required'])) {
                 $tmpField['required'] = $field['required'];
             }
             if (isset($field['len'])) {
                 $tmpField['len'] = $field['len'];
             }
             $output[] = $tmpField;
         }
     }
     $text = array();
     foreach ($output as $key => $row) {
         $text[$key] = strtolower($row['text']);
     }
     array_multisort($text, SORT_ASC, $output);
     $res['result'] = $output;
     return $res;
 }