/**
  * Formats the bean so it is ready to be handed back to the API's client. Certain fields will get extra processing
  * to make them easier to work with from the client end.
  *
  * @param $bean SugarBean|ForecastManagerWorksheet The bean you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $data = parent::formatForApi($bean, $fieldList, $options);
     $sq = new SugarQuery();
     $sq->select('date_modified');
     $sq->from($bean)->where()->equals('assigned_user_id', $bean->assigned_user_id)->equals('user_id', $bean->user_id)->equals('draft', 0)->equals('timeperiod_id', $bean->timeperiod_id);
     $beans = $sq->execute();
     $data['show_history_log'] = 0;
     if (empty($beans) && !empty($bean->fetched_row['date_modified'])) {
         /* @var $tp TimePeriod */
         $tp = BeanFactory::getBean('TimePeriods', $bean->timeperiod_id);
         // When reportee has committed but manager has not
         // make sure that the reportee actually has a commit for the timeperiod,
         // this is to handle the case where the manager saves draft before the reportee can commit
         $sq = new SugarQuery();
         $sq->select('id');
         $sq->from(BeanFactory::getBean('ForecastWorksheets'))->where()->equals('assigned_user_id', $bean->user_id)->equals('draft', 0)->queryAnd()->gte('date_closed_timestamp', $tp->start_date_timestamp)->lte('date_closed_timestamp', $tp->end_date_timestamp);
         $worksheets = $sq->execute();
         if (!empty($worksheets)) {
             $data['show_history_log'] = 1;
         }
     } else {
         if (!empty($beans)) {
             $fBean = $beans[0];
             $committed_date = $bean->db->fromConvert($fBean["date_modified"], "datetime");
             if (strtotime($committed_date) < strtotime($bean->fetched_row['date_modified'])) {
                 $db = DBManagerFactory::getInstance();
                 // find the differences via the audit table
                 // we use a direct query since SugarQuery can't do the audit tables...
                 $sql = sprintf("SELECT field_name, before_value_string, after_value_string FROM %s\n                        WHERE parent_id = %s AND date_created >= " . $db->convert('%s', 'datetime'), $bean->get_audit_table_name(), $db->quoted($bean->id), $db->quoted($committed_date));
                 $results = $db->query($sql);
                 // get the setting for which fields to compare on
                 /* @var $admin Administration */
                 $admin = BeanFactory::getBean('Administration');
                 $settings = $admin->getConfigForModule('Forecasts', 'base');
                 while ($row = $db->fetchByAssoc($results)) {
                     $field = substr($row['field_name'], 0, strpos($row['field_name'], '_'));
                     if ($settings['show_worksheet_' . $field] == "1") {
                         // calculate the difference to make sure it actually changed at 2 digits vs changed at 6
                         $diff = SugarMath::init($row['after_value_string'], 6)->sub($row['before_value_string'])->result();
                         // due to decimal rounding on the front end, we only want to know about differences greater
                         // of two decimal places.
                         // todo-sfa: This hardcoded 0.01 value needs to be changed to a value determined by userprefs
                         if (abs($diff) >= 0.01) {
                             $data['show_history_log'] = 1;
                             break;
                         }
                     }
                 }
             }
         }
     }
     if (!empty($bean->user_id)) {
         $data['is_manager'] = User::isManager($bean->user_id);
     }
     return $data;
 }
示例#2
0
 /**
  * Formats the bean so it is ready to be handed back to the API's client. Certian fields will get extra processing
  * to make them easier to work with from the client end.
  *
  * @param $bean SugarBean The bean you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     if (isset($bean->fetched_row) && !empty($bean->fetched_row['report_type']) && $bean->report_type == 'summary' && $bean->fetched_row['report_type'] == 'Matrix') {
         $bean->report_type = $bean->fetched_row['report_type'];
     }
     return parent::formatForApi($bean, $fieldList, $options);
 }
 /**
  * 'view' is deprecated because it's reserved db word.
  * Some old API (before 7.2.0) can use 'view'.
  * Because of that API will return 'view' with the same value as 'view_name'.
  *
  * @param SugarBean $bean
  * @param array     $fieldList
  * @param array     $options
  *
  * @return array
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $data = parent::formatForApi($bean, $fieldList, $options);
     if (isset($data['view_name'])) {
         $data['view'] = $data['view_name'];
     }
     return $data;
 }
示例#4
0
 /**
  * Formats the bean so it is ready to be handed back to the API's client.
  * Checks if user has access to a given record (if record module/id is specified in the api args)
  *
  * @param $bean SugarBean The bean you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $data = parent::formatForApi($bean, $fieldList, $options);
     $args = $options['args'];
     if (!empty($args['has_access_module']) && !empty($args['has_access_record'])) {
         $data['has_access'] = $this->checkUserAccess($bean, $args['has_access_module'], $args['has_access_record']);
     }
     return $data;
 }
示例#5
0
 /**
  * Formats the bean so it is ready to be handed back to the API's client. Certian fields will get extra processing
  * to make them easier to work with from the client end.
  *
  * @param $bean SugarBean The bean you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $data = parent::formatForApi($bean, $fieldList, $options);
     if (in_array("name", $fieldList) && !empty($bean->name_2)) {
         $data['name'] = trim($bean->name . ' ' . $bean->name_2);
         if (!empty($data['name_2'])) {
             $data['name_2'] = '';
         }
     }
     return $data;
 }
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $db = DBManagerFactory::getInstance();
     $query = "SELECT\n            jt0.id assigned_user_id,\n            jt0.user_name assigned_user_name,\n            jt0.first_name assgn_fn,\n            jt0.last_name assgn_ln,\n            jt1.id kbdoc_approver_id,\n            jt1.user_name kbdoc_approver_name,\n            jt1.first_name appr_fn,\n            jt1.last_name appr_ln,\n            kvr.views_number views_number\n        FROM\n            kbdocuments LEFT JOIN kbdocuments_views_ratings kvr ON kbdocuments.id = kvr.kbdocument_id\n            LEFT JOIN  users jt0 ON jt0.id = kbdocuments.assigned_user_id AND jt0.deleted = 0\n            LEFT JOIN  users jt1 ON jt1.id = kbdocuments.kbdoc_approver_id AND jt1.deleted = 0\n        WHERE\n            kbdocuments.id = {$db->quoted($bean->id)}";
     $res = $db->query($query);
     $addon = $db->fetchRow($res);
     if (in_array('views_number', $fieldList) && !empty($addon['views_number'])) {
         $bean->views_number = $addon['views_number'];
     }
     // bug 56834 - the api doesn't return kbdoc_approver_name
     $isKbApprover = in_array('kbdoc_approver_name', $fieldList);
     if ($isKbApprover && !empty($addon['kbdoc_approver_id'])) {
         $bean->kbdoc_approver_id = $addon['kbdoc_approver_id'];
     }
     //add kbdoc_approver_id if not in fieldList
     if ($isKbApprover && !in_array('kbdoc_approver_id', $fieldList)) {
         $fieldList[] = 'kbdoc_approver_id';
     }
     $data = parent::formatForApi($bean, $fieldList, $options);
     // bug 56834 - manually fill kbdoc_approver_name if in fieldList
     if ((empty($fieldList) || $isKbApprover) && isset($data['kbdoc_approver_id'])) {
         $user = BeanFactory::getBean('Users');
         $user->populateFromRow(array('id' => $addon['kbdoc_approver_id'], 'first_name' => $addon['appr_fn'], 'last_name' => $addon['appr_ln']));
         $data['kbdoc_approver_name'] = Localization::getObject()->formatName($user);
     }
     if (in_array('assigned_user_name', $fieldList) && !empty($addon['assigned_user_id'])) {
         $user = BeanFactory::getBean('Users');
         $user->populateFromRow(array('id' => $addon['assigned_user_id'], 'first_name' => $addon['assgn_fn'], 'last_name' => $addon['assgn_ln']));
         $data['assigned_user_name'] = Localization::getObject()->formatName($user);
     }
     if (empty($fieldList) || in_array('attachment_list', $fieldList)) {
         $query = "SELECT rev.id rev_id, rev.filename filename, kbrev.id docrev_id FROM kbdocument_revisions kbrev LEFT JOIN document_revisions rev ON (kbrev.document_revision_id = rev.id) WHERE kbrev.kbdocument_id = '" . $bean->id . "' AND kbrev.deleted = 0 AND rev.deleted = 0 AND kbrev.kbcontent_id is NULL";
         $ret = $db->query($query, true);
         $files = array();
         while ($row = $db->fetchByAssoc($ret)) {
             $thisFile = array();
             $thisFile['document_revision_id'] = $row['rev_id'];
             // add some extra meta so we can build the urls on the client
             $thisFile['id'] = $row['rev_id'];
             $thisFile['module'] = 'DocumentRevisions';
             $thisFile['field_name'] = 'filename';
             $thisFile['name'] = $row['filename'];
             $thisFile['kbdocument_revision_id'] = $row['docrev_id'];
             $thisFile['uri'] = $this->api->getResourceURI(array('DocumentRevisions', $row['rev_id'], 'file', 'filename'));
             $files[] = $thisFile;
         }
         $data['attachment_list'] = $files;
     }
     return $data;
 }
示例#7
0
 /**
  * Formats the bean so it is ready to be handed back to the API's client.
  *
  * @param $bean SugarBean The Task you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $data = parent::formatForApi($bean, $fieldList, $options);
     if (isset($bean->contact_id)) {
         $contact = BeanFactory::getBean('Contacts', $bean->contact_id);
         if (!empty($contact) && $contact->id != "") {
             if (isset($data['contact_name'])) {
                 $data['contact_name'] = empty($contact->full_name) ? '' : $contact->full_name;
             }
             if (isset($data['contact_phone'])) {
                 $data['contact_phone'] = empty($contact->phone_work) ? '' : $contact->phone_work;
             }
         }
     }
     return $data;
 }
 /**
  * Formats the bean so it is ready to be handed back to the API's client. Certian fields will get extra processing
  * to make them easier to work with from the client end.
  *
  * @param $bean SugarBean|ForecastWorksheet The bean you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $data = parent::formatForApi($bean, $fieldList, $options);
     $data['parent_deleted'] = 0;
     if ($bean->draft == 0) {
         $sq = new SugarQuery();
         $sq->select('id');
         $sq->from(BeanFactory::getBean($bean->parent_type))->where()->equals('id', $bean->parent_id);
         $beans = $sq->execute();
         if (empty($beans)) {
             $data['parent_name'] = $data['name'];
             $data['parent_deleted'] = 1;
         }
     }
     return $data;
 }
 /**
  * This function adds support for the related_name field (of type 'function' which is no longer supported)
  * @param $bean SugarBean The bean you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $data = parent::formatForApi($bean, $fieldList, $options);
     if (in_array('related_name', $fieldList) && !empty($bean->related_id) && !empty($bean->related_type)) {
         $relatedBean = BeanFactory::getBean($bean->related_type, $bean->related_id);
         if (!empty($relatedBean)) {
             if ($bean->related_type == 'CampaignTrackers') {
                 $relatedNameField = 'tracker_url';
             } elseif ($bean->related_type == 'Contacts' || $bean->related_type == 'Leads' || $bean->related_type == 'Prospects') {
                 $relatedNameField = 'full_name';
             } else {
                 $relatedNameField = 'name';
             }
             $data['parent_id'] = $bean->related_id;
             $data['parent_type'] = $bean->related_type;
             $data['related_name'] = $relatedBean->{$relatedNameField};
         }
     }
     return $data;
 }
示例#10
0
 /**
  * Formats the bean so it is ready to be handed back to the API's client. Certian fields will get extra processing
  * to make them easier to work with from the client end.
  *
  * @param $bean SugarBean The bean you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     // If there was a field list requested and document_revision_id was not
     // a requested field we will have problems. Set the revision id so that
     // additional fields like filename get picked up.
     if (!empty($fieldList) && !in_array('document_revision_id', $fieldList)) {
         $db = DBManagerFactory::getInstance();
         // Get the revision ID so that it can be set into the bean
         $sql = "SELECT document_revision_id \n                    FROM {$bean->table_name} \n                    WHERE id = '{$bean->id}'";
         $rs = $db->query($sql);
         $row = $db->fetchByAssoc($rs);
         if (isset($row['document_revision_id'])) {
             // Set the revision and setup everything else for a document that
             // depends on a revision id, like filename, revision, etc
             $bean->document_revision_id = $row['document_revision_id'];
             $bean->fill_in_additional_detail_fields();
         }
     }
     return parent::formatForApi($bean, $fieldList, $options);
 }
示例#11
0
 /**
  * Formats the bean so it is ready to be handed back to the API's client. Certain fields will get extra processing
  * to make them easier to work with from the client end.
  *
  * @param $quote SugarBean|Quote The bean you want formatted
  * @param $fieldList array Which fields do you want formatted and returned (leave blank for all fields)
  * @param $options array Currently no options are supported
  * @return array The bean in array format, ready for passing out the API to clients.
  */
 public function formatForApi(SugarBean $quote, array $fieldList = array(), array $options = array())
 {
     // call the legacy method here to load all the data that we need
     $quote->fill_in_additional_detail_fields();
     return parent::formatForApi($quote, $fieldList, $options);
 }
 /**
  * {@inheritdoc}
  *
  * Adds the contact's name if one is related.
  *
  * `send_invites` and `auto_invite_parent` are internal processing flags and should never be
  * returned as fields.
  *
  * @param SugarBean $bean
  * @param array $fieldList
  * @param array $options
  * @return array
  */
 public function formatForApi(SugarBean $bean, array $fieldList = array(), array $options = array())
 {
     $data = parent::formatForApi($bean, $fieldList, $options);
     if (!empty($bean->contact_id)) {
         $contact = BeanFactory::getBean('Contacts', $bean->contact_id);
         if ($contact instanceof Contact) {
             $data['contact_name'] = $contact->full_name;
         }
     }
     unset($data['send_invites']);
     unset($data['auto_invite_parent']);
     // Handle enforcement of numerics, an issue introduced in MACAROON-684.
     foreach ($this->numericFields as $field) {
         if (array_key_exists($field, $data)) {
             $data[$field] = $this->getNumericValue($data[$field]);
         }
     }
     return $data;
 }