/**
  * 'view' is deprecated because it's reserved db word.
  * Some old API (before 7.2.0) can use 'view'.
  * Because of that API will use 'view' as 'view_name' if 'view_name' isn't present.
  *
  * @param SugarBean $bean
  * @param array     $submittedData
  * @param array     $options
  *
  * @return array
  */
 public function populateFromApi(SugarBean $bean, array $submittedData, array $options = array())
 {
     if (isset($submittedData['view']) && !isset($submittedData['view_name'])) {
         $submittedData['view_name'] = $submittedData['view'];
     }
     return parent::populateFromApi($bean, $submittedData, $options);
 }
 public function populateFromApi(SugarBean $bean, array $submittedData, array $options = array())
 {
     parent::populateFromApi($bean, $submittedData, $options);
     if (!$bean->new_with_id && !empty($bean->id)) {
         return true;
     }
     if (empty($submittedData) || empty($submittedData['user_name'])) {
         throw new SugarApiExceptionMissingParameter("Missing username");
     }
     return true;
 }
 /**
  * This function checks the sync_contact var and does the appropriate actions
  * @param SugarBean $bean
  * @param array $submittedData
  * @param array $options
  * @return array
  */
 public function populateFromApi(SugarBean $bean, array $submittedData, array $options = array())
 {
     global $current_user;
     $data = parent::populateFromApi($bean, $submittedData, $options);
     if ($data) {
         if (!empty($bean->emailAddress) && $bean->emailAddress->addresses != $bean->emailAddress->fetchedAddresses) {
             $bean->emailAddress->populateLegacyFields($bean);
         }
         if (isset($submittedData['sync_contact'])) {
             $bean->sync_contact = $submittedData['sync_contact'];
         }
     }
     return $data;
 }
 public function populateFromApi(SugarBean $bean, array $submittedData, array $options = array())
 {
     foreach ($submittedData as $fieldName => $data) {
         if (isset($bean->field_defs[$fieldName])) {
             $properties = $bean->field_defs[$fieldName];
             $type = !empty($properties['custom_type']) ? $properties['custom_type'] : $properties['type'];
             /* Field with name=email is the only field of type=email supported at this time */
             if ($type === 'email') {
                 if ($fieldName !== 'email') {
                     unset($submittedData[$fieldName]);
                 }
             }
         }
     }
     parent::populateFromApi($bean, $submittedData, $options);
     return true;
 }
 /**
  * This function sets the team & assigned user and sets up the contact & account relationship
  * for new Notes submitted via portal users.
  *
  * @param SugarBean $bean
  * @param array $submittedData
  * @param array $options
  * @return array
  */
 public function populateFromApi(SugarBean $bean, array $submittedData, array $options = array())
 {
     //TODO: need a more generic way to deal with file types
     if (isset($submittedData['file_mime_type'])) {
         unset($submittedData['file_mime_type']);
     }
     $data = parent::populateFromApi($bean, $submittedData, $options);
     //Only needed for Portal sessions
     if (isset($_SESSION['type']) && $_SESSION['type'] == 'support_portal') {
         if (empty($bean->id)) {
             $bean->id = create_guid();
             $bean->new_with_id = true;
         }
         $contact = BeanFactory::getBean('Contacts', $_SESSION['contact_id']);
         $account = $contact->account_id;
         $bean->assigned_user_id = $contact->assigned_user_id;
         $bean->team_id = $contact->fetched_row['team_id'];
         $bean->team_set_id = $contact->fetched_row['team_set_id'];
         $bean->account_id = $account;
         $bean->contact_id = $contact->id;
     }
     return $data;
 }
 /**
  * This function sets up shipping and billing address for new Quote.
  *
  * @param SugarBean|Quote $quote The current SugarBean that is being worked with
  * @param array $submittedData The data from the request
  * @param array $options Any Options that may have been passed in.
  * @return array|boolean An array of validation errors if any occurred, otherwise `true`.
  */
 public function populateFromApi(SugarBean $quote, array $submittedData, array $options = array())
 {
     parent::populateFromApi($quote, $submittedData, $options);
     // valid relate modules
     $valid_relate_modules = array('Contacts', 'Accounts');
     // Bug #57888 : REST API: Create related quote must populate billing/shipping contact and account
     if (isset($submittedData['relate_module'], $submittedData['relate_record']) && in_array($submittedData['relate_module'], $valid_relate_modules)) {
         $this->setAddressFromBean($submittedData['relate_module'], $submittedData['relate_record'], $quote);
     } else {
         // we are not on a related record, so lets check the field and fill in the data correctly
         $hasBillingAccountId = isset($quote->billing_account_id) && !empty($quote->billing_account_id);
         $hasShippingAccountId = isset($quote->shipping_account_id) && !empty($quote->shipping_account_id);
         $hasBillingContactId = isset($quote->billing_contact_id) && !empty($quote->billing_contact_id);
         $hasShippingContactId = isset($quote->shipping_contact_id) && !empty($quote->shipping_contact_id);
         if ($hasBillingAccountId) {
             $account = BeanFactory::getBean('Accounts', $quote->billing_account_id);
             $this->processBeanAddressFields($account, $quote, 'billing', 'billing', 'shipping');
         } elseif (!$hasBillingAccountId && $hasBillingContactId) {
             $contact = BeanFactory::getBean('Contacts', $quote->billing_contact_id);
             $this->processBeanAddressFields($contact, $quote, 'shipping', 'primary', 'alt');
         }
         if (!$hasShippingAccountId && !$hasShippingContactId && $hasBillingAccountId) {
             // we don't have a id set for the shipping account or contact, pull the account from the billing
             $quote->shipping_account_id = $quote->billing_account_id;
             $hasShippingAccountId = true;
         }
         if ($hasShippingAccountId && !$hasShippingContactId) {
             $account = BeanFactory::getBean('Accounts', $quote->shipping_account_id);
             $this->processBeanAddressFields($account, $quote, 'shipping', 'shipping', 'billing');
         } elseif ($hasShippingContactId) {
             $contact = BeanFactory::getBean('Contacts', $quote->shipping_contact_id);
             $this->processBeanAddressFields($contact, $quote, 'shipping', 'primary', 'alt');
         }
     }
     return true;
 }
 /**
  * {@inheritdoc}
  *
  * The bean must have values for `date_start`, `duration_hours`, and `duration_minutes` after it has been populated.
  * These values can either already exist on the bean or have been populated from the submitted data.
  *
  * Adds the calendar event specific saves for leads, contacts, and users.
  *
  * The vCal cache is not updated for the current user as it is handled in the endpoints to guarantee that it happens
  * after all recurrences of an event are saved.
  *
  * @param SugarBean $bean
  * @param array $submittedData
  * @param array $options
  * @return array
  * @throws SugarApiExceptionMissingParameter
  */
 public function populateFromApi(SugarBean $bean, array $submittedData, array $options = array())
 {
     /**
      * The duration_hours and duration_minutes fields must be positive integers; either actual integers or strings
      * that are integers.
      *
      * @param mixed $time
      * @return bool
      */
     $isPositiveInteger = function ($time) {
         return preg_match('/^\\d+$/', (string) $time) === 1;
     };
     unset($submittedData['repeat_parent_id']);
     // never allow this to be updated via the api
     $data = parent::populateFromApi($bean, $submittedData, $options);
     if (empty($bean->date_start)) {
         throw new SugarApiExceptionMissingParameter('Missing parameter: date_start');
     }
     if (!isset($bean->duration_hours) || strlen((string) $bean->duration_hours) === 0) {
         throw new SugarApiExceptionMissingParameter('Missing parameter: duration_hours');
     }
     if (!isset($bean->duration_minutes) || strlen((string) $bean->duration_minutes) === 0) {
         throw new SugarApiExceptionMissingParameter('Missing parameter: duration_minutes');
     }
     if (!$isPositiveInteger($bean->duration_hours)) {
         throw new SugarApiExceptionInvalidParameter('Invalid parameter: duration_hours');
     }
     if (!$isPositiveInteger($bean->duration_minutes)) {
         throw new SugarApiExceptionInvalidParameter('Invalid parameter: duration_minutes');
     }
     $bean->update_vcal = false;
     $bean->users_arr = $this->getUserInvitees($bean, $submittedData);
     $bean->leads_arr = $this->getInvitees($bean, 'leads', $submittedData);
     $bean->contacts_arr = $this->getInvitees($bean, 'contacts', $submittedData);
     return $data;
 }
 /**
  * This function sets the fromApi var on Reports to true so Exceptions are handled properly
  * @param SugarBean $bean
  * @param array $submittedData
  * @param array $options
  * @return array
  */
 public function populateFromApi(SugarBean $bean, array $submittedData, array $options = array())
 {
     $bean->fromApi = true;
     return parent::populateFromApi($bean, $submittedData, $options);
 }