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
 protected function addCampaignLog($campaignId, $lead, $contact, $moduleName)
 {
     return campaign_log_lead_or_contact_entry($campaignId, $lead, $contact, $moduleName);
 }
Example #3
0
 /**
  * Saves a new Contact as well as any related items passed in.
  *
  * @return null
  */
 protected function handleSave()
 {
     require_once 'modules/Campaigns/utils.php';
     require_once "include/formbase.php";
     $lead = false;
     if (!empty($_REQUEST['record'])) {
         $lead = new Lead();
         $lead->retrieve($_REQUEST['record']);
     }
     global $beanList;
     $this->loadDefs();
     $beans = array();
     $selectedBeans = array();
     $selects = array();
     // Make sure the contact object is availible for relationships.
     $beans['Contacts'] = new Contact();
     // Contacts
     if (!empty($_REQUEST['selectedContact'])) {
         $beans['Contacts']->retrieve($_REQUEST['selectedContact']);
         if (!empty($beans['Contacts']->id)) {
             $beans['Contacts']->new_with_id = false;
             unset($_REQUEST["convert_create_Contacts"]);
             unset($_POST["convert_create_Contacts"]);
         }
     } elseif (!empty($_REQUEST["convert_create_Contacts"]) && $_REQUEST["convert_create_Contacts"] != "false" && !isset($_POST['ContinueContact'])) {
         require_once 'modules/Contacts/ContactFormBase.php';
         $contactForm = new ContactFormBase();
         $duplicateContacts = $contactForm->checkForDuplicates('Contacts');
         if (isset($duplicateContacts)) {
             echo $contactForm->buildTableForm($duplicateContacts, 'Contacts');
             return;
         }
         $this->new_contact = true;
     } elseif (isset($_POST['ContinueContact'])) {
         $this->new_contact = true;
     }
     // Accounts
     if (!empty($_REQUEST['selectedAccount'])) {
         $_REQUEST['account_id'] = $_REQUEST['selectedAccount'];
         unset($_REQUEST["convert_create_Accounts"]);
         unset($_POST["convert_create_Accounts"]);
     } elseif (!empty($_REQUEST["convert_create_Accounts"]) && $_REQUEST["convert_create_Accounts"] != "false" && empty($_POST['ContinueAccount'])) {
         require_once 'modules/Accounts/AccountFormBase.php';
         $accountForm = new AccountFormBase();
         $duplicateAccounts = $accountForm->checkForDuplicates('Accounts');
         if (isset($duplicateAccounts)) {
             echo $accountForm->buildTableForm($duplicateAccounts);
             return;
         }
     }
     foreach ($this->defs as $module => $vdef) {
         //Create a new record if "create" was selected
         if (!empty($_REQUEST["convert_create_{$module}"]) && $_REQUEST["convert_create_{$module}"] != "false") {
             //Save the new record
             $bean = $beanList[$module];
             if (empty($beans[$module])) {
                 $beans[$module] = new $bean();
             }
             $this->populateNewBean($module, $beans[$module], $beans['Contacts'], $lead);
             // when creating a new contact, create the id for linking with other modules
             // and do not populate it with lead's old account_id
             if ($module == 'Contacts') {
                 $beans[$module]->id = create_guid();
                 $beans[$module]->new_with_id = true;
                 $beans[$module]->account_id = '';
             }
         } else {
             if (!empty($vdef['ConvertLead']['select'])) {
                 //Save the new record
                 $select = $vdef['ConvertLead']['select'];
                 $fieldDef = $beans['Contacts']->field_defs[$select];
                 if (!empty($fieldDef['id_name']) && !empty($_REQUEST[$fieldDef['id_name']])) {
                     $beans['Contacts']->{$fieldDef}['id_name'] = $_REQUEST[$fieldDef['id_name']];
                     $selects[$module] = $_REQUEST[$fieldDef['id_name']];
                     if (!empty($_REQUEST[$select])) {
                         $beans['Contacts']->{$select} = $_REQUEST[$select];
                     }
                     // Bug 39268 - Add the existing beans to a list of beans we'll potentially add the lead's activities to
                     $bean = loadBean($module);
                     $bean->retrieve($_REQUEST[$fieldDef['id_name']]);
                     $selectedBeans[$module] = $bean;
                     // If we selected the Contact, just overwrite the $beans['Contacts']
                     if ($module == 'Contacts') {
                         $beans[$module] = $bean;
                     }
                 }
             }
         }
     }
     $this->handleActivities($lead, $beans);
     // Bug 39268 - Add the lead's activities to the selected beans
     $this->handleActivities($lead, $selectedBeans);
     //link selected account to lead if it exists
     if (!empty($selectedBeans['Accounts'])) {
         $lead->account_id = $selectedBeans['Accounts']->id;
     }
     // link account to contact, if we picked an existing contact and created a new account
     if (!empty($beans['Accounts']->id) && !empty($beans['Contacts']->account_id) && $beans['Accounts']->id != $beans['Contacts']->account_id) {
         $beans['Contacts']->account_id = $beans['Accounts']->id;
     }
     // Saving beans with priorities.
     // Contacts and Accounts should be saved before lead activities to create correct relations
     $saveBeanPriority = array('Contacts', 'Accounts');
     $tempBeans = array();
     foreach ($saveBeanPriority as $name) {
         if (isset($beans[$name])) {
             $tempBeans[$name] = $beans[$name];
         }
     }
     $beans = array_merge($tempBeans, $beans);
     unset($tempBeans);
     //Handle non-contacts relationships
     foreach ($beans as $bean) {
         if (!empty($lead)) {
             if (empty($bean->assigned_user_id)) {
                 $bean->assigned_user_id = $lead->assigned_user_id;
             }
             $leadsRel = $this->findRelationship($bean, $lead);
             if (!empty($leadsRel)) {
                 $bean->load_relationship($leadsRel);
                 $relObject = $bean->{$leadsRel}->getRelationshipObject();
                 if ($relObject->relationship_type == "one-to-many" && $bean->{$leadsRel}->_get_bean_position()) {
                     $id_field = $relObject->rhs_key;
                     $lead->{$id_field} = $bean->id;
                 } else {
                     $bean->{$leadsRel}->add($lead->id);
                 }
             }
         }
         //Special case code for opportunities->Accounts
         if ($bean->object_name == "Opportunity" && empty($bean->account_id)) {
             if (isset($beans['Accounts'])) {
                 $bean->account_id = $beans['Accounts']->id;
                 $bean->account_name = $beans['Accounts']->name;
             } else {
                 if (!empty($selects['Accounts'])) {
                     $bean->account_id = $selects['Accounts'];
                 }
             }
         }
         //create meetings-users relationship
         if ($bean->object_name == "Meeting") {
             $bean = $this->setMeetingsUsersRelationship($bean);
         }
         $this->copyAddressFields($bean, $beans['Contacts']);
         $bean->save();
         //if campaign id exists then there should be an entry in campaign_log table for the newly created contact: bug 44522
         if (isset($lead->campaign_id) && $lead->campaign_id != null && $bean->object_name == "Contact") {
             campaign_log_lead_or_contact_entry($lead->campaign_id, $lead, $beans['Contacts'], 'contact');
         }
     }
     if (!empty($lead)) {
         //Mark the original Lead converted
         $lead->status = "Converted";
         $lead->converted = '1';
         $lead->in_workflow = true;
         $lead->save();
     }
     $this->displaySaveResults($beans);
 }
Example #4
0
 /**
     *
     * This method is deprecated
     * @deprecated 62_Joneses - June 24, 2011
     * @see campaign_log_lead_or_contact_entry()
     */
function campaign_log_lead_entry($campaign_id, $parent_bean,$child_bean,$activity_type){
    campaign_log_lead_or_contact_entry($campaign_id, $parent_bean,$child_bean,$activity_type);
}
 /**
  * Saves a new Contact as well as any related items passed in.
  *
  * @return null
  */
 protected function handleSave()
 {
     require_once 'modules/Campaigns/utils.php';
     require_once "include/formbase.php";
     $lead = false;
     if (!empty($_REQUEST['record'])) {
         $lead = new Lead();
         $lead->retrieve($_REQUEST['record']);
     }
     global $beanList;
     $this->loadDefs();
     $beans = array();
     $selectedBeans = array();
     $selects = array();
     //Make sure the contact object is availible for relationships.
     $beans['Contacts'] = new Contact();
     $beans['Contacts']->id = create_guid();
     $beans['Contacts']->new_with_id = true;
     // Bug 39287 - Check for Duplicates on selected modules before save
     if (!empty($_REQUEST['selectedContact'])) {
         $beans['Contacts']->retrieve($_REQUEST['selectedContact']);
         if (!empty($beans['Contacts']->id)) {
             $beans['Contacts']->new_with_id = false;
             unset($_REQUEST["convert_create_Contacts"]);
             unset($_POST["convert_create_Contacts"]);
         }
     } elseif (!empty($_REQUEST["convert_create_Contacts"]) && $_REQUEST["convert_create_Contacts"] != "false" && !isset($_POST['ContinueContact'])) {
         require_once 'modules/Contacts/ContactFormBase.php';
         $contactForm = new ContactFormBase();
         $duplicateContacts = $contactForm->checkForDuplicates('Contacts');
         if (isset($duplicateContacts)) {
             echo $contactForm->buildTableForm($duplicateContacts, 'Contacts');
             return;
         }
         $this->new_contact = true;
     }
     if (!empty($_REQUEST['selectedAccount'])) {
         $_REQUEST['account_id'] = $_REQUEST['selectedAccount'];
         unset($_REQUEST["convert_create_Accounts"]);
         unset($_POST["convert_create_Accounts"]);
     } elseif (!empty($_REQUEST["convert_create_Accounts"]) && $_REQUEST["convert_create_Accounts"] != "false" && empty($_POST['ContinueAccount'])) {
         require_once 'modules/Accounts/AccountFormBase.php';
         $accountForm = new AccountFormBase();
         $duplicateAccounts = $accountForm->checkForDuplicates('Accounts');
         if (isset($duplicateAccounts)) {
             echo $accountForm->buildTableForm($duplicateAccounts);
             return;
         }
     }
     foreach ($this->defs as $module => $vdef) {
         //Create a new record if "create" was selected
         if (!empty($_REQUEST["convert_create_{$module}"]) && $_REQUEST["convert_create_{$module}"] != "false") {
             //Save the new record
             $bean = $beanList[$module];
             if (empty($beans[$module])) {
                 $beans[$module] = new $bean();
             }
             $this->populateNewBean($module, $beans[$module], $beans['Contacts'], $lead);
         } else {
             if (!empty($vdef['ConvertLead']['select'])) {
                 //Save the new record
                 $select = $vdef['ConvertLead']['select'];
                 $fieldDef = $beans['Contacts']->field_defs[$select];
                 if (!empty($fieldDef['id_name']) && !empty($_REQUEST[$fieldDef['id_name']])) {
                     $beans['Contacts']->{$fieldDef}['id_name'] = $_REQUEST[$fieldDef['id_name']];
                     $selects[$module] = $_REQUEST[$fieldDef['id_name']];
                     if (!empty($_REQUEST[$select])) {
                         $beans['Contacts']->{$select} = $_REQUEST[$select];
                     }
                     // Bug 39268 - Add the existing beans to a list of beans we'll potentially add the lead's activities to
                     $bean = loadBean($module);
                     $bean->retrieve($_REQUEST[$fieldDef['id_name']]);
                     $selectedBeans[$module] = $bean;
                 }
             }
         }
     }
     $this->handleActivities($lead, $beans);
     // Bug 39268 - Add the lead's activities to the selected beans
     $this->handleActivities($lead, $selectedBeans);
     //link selected account to lead if it exists
     if (!empty($selectedBeans['Accounts'])) {
         $lead->account_id = $selectedBeans['Accounts']->id;
     }
     //Handle non-contacts relationships
     foreach ($beans as $bean) {
         if (!empty($lead)) {
             if (empty($bean->assigned_user_id)) {
                 $bean->assigned_user_id = $lead->assigned_user_id;
             }
             $leadsRel = $this->findRelationship($bean, $lead);
             if (!empty($leadsRel)) {
                 $bean->load_relationship($leadsRel);
                 if (!$bean->{$leadsRel}->isParentRelationship()) {
                     $bean->{$leadsRel}->add($lead);
                 }
             }
         }
         //Special case code for opportunities->Accounts
         if ($bean->object_name == "Opportunity" && empty($bean->account_id)) {
             if (isset($beans['Accounts'])) {
                 $bean->account_id = $beans['Accounts']->id;
                 $bean->account_name = $beans['Accounts']->name;
             } else {
                 if (!empty($selects['Accounts'])) {
                     $bean->account_id = $selects['Accounts'];
                 }
             }
         }
         $this->copyAddressFields($bean, $beans['Contacts']);
         $bean->save();
         //if campaign id exists then there should be an entry in campaign_log table for the newly created contact: bug 44522
         if (isset($lead->campaign_id) && $lead->campaign_id != null && $bean->object_name == "Contact") {
             campaign_log_lead_or_contact_entry($lead->campaign_id, $lead, $beans['Contacts'], 'contact');
         }
     }
     if (!empty($lead)) {
         //Mark the original Lead converted
         $lead->status = "Converted";
         $lead->converted = '1';
         $lead->in_workflow = true;
         $lead->save();
     }
     $this->displaySaveResults($beans);
 }