コード例 #1
0
 /**
  * Utility method to check if we have a Currency Field or not.
  *
  * @param SugarBean $bean
  * @param string $field
  * @return bool
  */
 protected function isCurrencyField($bean, $field)
 {
     $is_currency = false;
     $def = $bean->getFieldDefinition($field);
     if (is_array($def)) {
         // start by just using the type in the def
         $type = $def['type'];
         // but if custom_type is set, use it, when it's not set and dbType is, use dbType
         if (isset($def['custom_type']) && !empty($def['custom_type'])) {
             $type = $def['custom_type'];
         } elseif (isset($def['dbType']) && !empty($def['dbType'])) {
             $type = $def['dbType'];
         }
         // always lower case the type just to make sure.
         $is_currency = strtolower($type) === 'currency';
     }
     return $is_currency;
 }
コード例 #2
0
 public function getDuplicateCheckIndexedFiles()
 {
     require_once 'include/export_utils.php';
     $import_fields = $this->_focus->get_importable_fields();
     $importable_keys = array_keys($import_fields);
     //
     $index_array = array();
     $fields_used = array();
     $mstr_exclude_array = array('all' => array('team_set_id', 'id', 'deleted'), 'contacts' => array('email2'), array('leads' => 'reports_to_id'), array('prospects' => 'tracker_key'));
     //create exclude array from subset of applicable mstr_exclude_array elements
     $exclude_array = isset($mstr_exclude_array[strtolower($this->_focus->module_dir)]) ? array_merge($mstr_exclude_array[strtolower($this->_focus->module_dir)], $mstr_exclude_array['all']) : $mstr_exclude_array['all'];
     //process all fields belonging to indexes
     foreach ($this->_getIndexVardefs() as $index) {
         if ($index['type'] == "index") {
             foreach ($index['fields'] as $field) {
                 $fieldName = '';
                 //skip this field if it is the deleted field, not in the importable keys array, or a field in the exclude array
                 if (!in_array($field, $importable_keys) || in_array($field, $exclude_array)) {
                     continue;
                 }
                 $fieldDef = $this->_focus->getFieldDefinition($field);
                 //skip if this field is already defined (from another index)
                 if (in_array($fieldDef['name'], $fields_used)) {
                     continue;
                 }
                 //get the proper export label
                 $fieldName = translateForExport($fieldDef['name'], $this->_focus);
                 $index_array[$index['name'] . '::' . $fieldDef['name']] = $fieldName;
                 $fields_used[] = $fieldDef['name'];
             }
         }
     }
     //special handling for beans with first_name and last_name
     if (in_array('first_name', $fields_used) && in_array('last_name', $fields_used)) {
         //since both full name and last name fields have been mapped, add full name index
         $index_array['full_name::full_name'] = translateForExport('full_name', $this->_focus);
         $fields_used[] = 'full_name';
     }
     asort($index_array);
     return $index_array;
 }
コード例 #3
0
 /**
  * Verify that the currency_base_rate is set and updated as it should when the bean is saving
  *
  * @see SugarBean::save()
  * @param SugarBean $bean
  * @param bool @isUpdate This is bean in an update save()?
  */
 public static function verifyCurrencyBaseRateSet(SugarBean $bean, $isUpdate = true)
 {
     if ($bean->getFieldDefinition('currency_id') && $bean->getFieldDefinition('base_rate') && !empty($bean->currency_id)) {
         $currency = static::getCurrency($bean);
         // check if the bean has the updateCurrencyBaseRate method as an additional check
         $beanCurrencyCheck = true;
         if (method_exists($bean, 'updateCurrencyBaseRate')) {
             $beanCurrencyCheck = call_user_func(array($bean, 'updateCurrencyBaseRate'));
         }
         // we should only check if the currencyId has changed if we the be is doing an update, not an insert
         if ($beanCurrencyCheck || !isset($bean->base_rate) || static::hasCurrencyIdChanged($bean) && $isUpdate) {
             $bean->base_rate = $currency->conversion_rate;
         }
     }
 }
コード例 #4
0
ファイル: DBManager.php プロジェクト: jglaine/sugar761-ent
 /**
  * Make array of types for prepared statement from list of columns
  * @param SugarBean $bean
  * @param array $columns
  * @return array
  */
 protected function prepareTypeData(SugarBean $bean, $columns)
 {
     $types = array();
     foreach ($columns as $name) {
         $def = $bean->getFieldDefinition($name);
         $types[$name] = "?" . $def['type'];
     }
     return $types;
 }
コード例 #5
0
 /**
  * Generic method for un-deleting records of all types
  *
  * @param SugarBean $parentBean Parent bean module to get field definitions from
  * @param array $where_data Array of fields to filter on in the where clause
  * @param bool $updateDateModified Boolean to indicate if the date_modified should be updated in the query or not
  * @param string $tableName Table name to run the query from. If excluded will use the parentBean->table_name passed
  * @return Array $results Results of query
  *
  */
 private function unmarkDeletedRecord($parentBean, $where_data, $updateDateModified = false, $tableName = "")
 {
     if ($tableName == "") {
         $tableName = $parentBean->getTableName();
     }
     $usePreparedStatements = false;
     $dataFields['deleted'] = $parentBean->getFieldDefinition('deleted');
     $dataValues['deleted'] = '0';
     if ($updateDateModified) {
         $dataFields['date_modified'] = $parentBean->getFieldDefinition('date_modified');
         $dataValues['date_modified'] = $this->db->timedate->nowDb();
     }
     $sql = $this->db->updateParams($tableName, $dataFields, $dataValues, $where_data, null, false, $usePreparedStatements);
     $sqlResults = $this->db->query($sql);
     //All supported dbs have affected_rows, but lets check just to be sure
     if (isset($this->db->capabilities["affected_rows"]) && $this->db->capabilities["affected_rows"] == true) {
         $unDeletedResults = $this->db->getAffectedRowCount($sqlResults);
     } else {
         $unDeletedResults = 1;
     }
     return $unDeletedResults;
 }
コード例 #6
0
 /**
  * Return file list with definition of relationship and/or field.
  * @param SugarBean $seed
  * @param string $rel_name
  * @param string $field_name
  * @return array
  */
 protected function getFiles($seed, $rel_name = '', $field_name = '')
 {
     if (empty($rel_name) && !empty($field_name)) {
         $tmpRelName = $seed->getFieldDefinition($field_name);
         $tmpRelName = isset($tmpRelName['relationship']) ? $tmpRelName['relationship'] : '';
     } else {
         $tmpRelName = $rel_name;
     }
     $availableFiles = $this->getAvailableFiles($seed, $tmpRelName);
     $result = $availableFiles['main'];
     $files = $availableFiles['addon'];
     if (!empty($rel_name)) {
         $definition = "\$dictionary['{$seed->object_name}']['relationships']['{$rel_name}']";
         foreach ($files as $file) {
             if ($this->fileHasDefinition($file, $definition)) {
                 array_push($result, $file);
             }
         }
         $definition = "\$dictionary['{$rel_name}']";
         foreach ($files as $file) {
             if ($this->fileHasDefinition($file, $definition)) {
                 array_push($result, $file);
             }
         }
     }
     if (!empty($field_name)) {
         $definition = "\$dictionary['{$seed->object_name}']['fields']['{$field_name}']";
         foreach ($files as $file) {
             if (!in_array($file, $result) && $this->fileHasDefinition($file, $definition)) {
                 array_push($result, $file);
             }
         }
     }
     return $result;
 }
コード例 #7
0
 /**
  * @param SugarBean $bean SugarBean instance that represents module metadata
  * @param string $collectionName Collection name
  *
  * @return array Link definition
  * @throws SugarApiExceptionError
  * @throws SugarApiExceptionNotFound
  */
 protected function getCollectionDefinition(SugarBean $bean, $collectionName)
 {
     $definition = $bean->getFieldDefinition($collectionName);
     if (!is_array($definition) || !isset($definition['type']) || $definition['type'] !== 'collection') {
         throw new SugarApiExceptionNotFound('Collection not found');
     }
     if (!isset($definition['links'])) {
         throw new SugarApiExceptionError(sprintf('Links are not defined for collection %s in module %s', $collectionName, $bean->module_name));
     }
     $definition['links'] = $this->normalizeLinks($definition['links'], $collectionName, $bean->module_name);
     return $definition;
 }
コード例 #8
0
 /**
  * Returns name of the file containing legacy subpanel metadata
  *
  * @param SugarBean $bean Parent bean
  * @param string $linkName Subpanel link name
  * @return string|null
  */
 public function getLegacySubpanelFileName(SugarBean $bean, $linkName)
 {
     $field = $bean->getFieldDefinition($linkName);
     if ($field && $field['type'] == 'link') {
         if (!empty($bean->field_defs[$linkName]['relationship'])) {
             $relName = $bean->field_defs[$linkName]['relationship'];
         } else {
             $relName = $linkName;
         }
         // since we have a valid link, we need to test the relationship to see if it's custom relationship
         $relationships = new DeployedRelationships($bean->module_name);
         $relationship = $relationships->get($relName);
         if ($relationship) {
             $relDef = $relationship->getDefinition();
             if (!empty($relDef['is_custom']) && !empty($relDef['from_studio'])) {
                 return 'For' . $relDef['relationship_name'];
             }
         }
     }
     return 'For' . $bean->module_name;
 }