本文整理汇总了PHP中SugarFieldHandler类的典型用法代码示例。如果您正苦于以下问题:PHP SugarFieldHandler类的具体用法?PHP SugarFieldHandler怎么用?PHP SugarFieldHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SugarFieldHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFile
/**
* Gets a file and returns an HTTP response with the contents of the request file for download
*
* @param SugarBean $bean The SugarBean to get the file for
* @param string $field The field name to get the file for
* @param boolean $forceDownload force to download the file if true.
*/
public function getFile(SugarBean $bean, $field, $forceDownload = false)
{
if ($this->validateBeanAndField($bean, $field, 'file') || $this->validateBeanAndField($bean, $field, 'image')) {
$def = $bean->field_defs[$field];
if ($def['type'] == 'image') {
$info = $this->getImageInfo($bean, $field);
} elseif ($def['type'] == 'file') {
$info = $this->getFileInfo($bean, $field);
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfh = new SugarFieldHandler();
/* @var $sf SugarFieldFile */
$sf = $sfh->getSugarField($def['type']);
//If the requested file is not a supported image type, we should force a download.
if (!$forceDownload && !in_array($info['content-type'], $sf::$imageFileMimeTypes)) {
$forceDownload = true;
}
}
if ($info) {
$this->outputFile($forceDownload, $info);
} else {
// @TODO Localize this exception message
throw new Exception('File information could not be retrieved for this record');
}
}
}
示例2: process_reports
private function process_reports()
{
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfh = new SugarFieldHandler();
$sf = $sfh->getSugarField('Teamset', true);
$teams = $sf->getTeamsFromRequest($this->name);
$full_form_values = array();
if (!empty($teams)) {
if (isset($_REQUEST["primary_{$this->name}_collection"])) {
$this->ss->assign('hasPrimaryTeam', true);
$primary = $_REQUEST["primary_{$this->name}_collection"];
$key = "id_{$this->name}_collection_{$primary}";
//Get the $_REQUEST index key
$primary = $_REQUEST[$key];
$primaryTeam = array('id' => $primary, 'name' => $teams[$primary]);
$full_form_values['primary'] = $primaryTeam;
unset($teams[$primary]);
//Unset the primary team
} else {
//Here we technically don't have a primary team chosen, but we need to allocate
//a primary team to display as the first team in the widget
foreach ($teams as $team_id => $team_name) {
$full_form_values['primary'] = array('id' => $team_id, 'name' => $team_name);
$this->showPrimaryChecked = false;
unset($teams[$team_id]);
break;
}
}
foreach ($teams as $team_id => $team_name) {
$full_form_values['secondaries'][] = array('id' => $team_id, 'name' => $team_name);
}
$this->bean->{$this->value_name} = array_merge($this->bean->{$this->value_name}, $full_form_values);
}
}
示例3: __call
/**
* Checks the SugarField defintion for an available santization method.
*
* @param $value string
* @param $vardef array
* @param $focus object bean of the module we're importing into
* @return string sanitized and validated value on success, bool false on failure
*/
public function __call($name, $params)
{
static $sfh;
if (!isset($sfh)) {
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfh = new SugarFieldHandler();
}
$value = $params[0];
$vardef = $params[1];
if (isset($params[2])) {
$focus = $params[2];
} else {
$focus = null;
}
if ($name == 'relate' && !empty($params[3])) {
$this->addRelatedBean = true;
} else {
$this->addRelatedBean = false;
}
$field = $sfh->getSugarField(ucfirst($name));
if ($field instanceof SugarFieldBase) {
$value = $field->importSanitize($value, $vardef, $focus, $this);
}
return $value;
}
示例4: smarty_function_sugarvar_teamset
function smarty_function_sugarvar_teamset($params, &$smarty)
{
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfh = new SugarFieldHandler();
$sugarField = $sfh->getSugarField('Teamset');
return $sugarField->render($params, $smarty);
}
示例5: populateFromPost
function populateFromPost($prefix, &$focus, $skipRetrieve = false)
{
global $current_user;
if (!empty($_REQUEST[$prefix . 'record']) && !$skipRetrieve) {
$focus->retrieve($_REQUEST[$prefix . 'record']);
}
if (!empty($_POST['assigned_user_id']) && $focus->assigned_user_id != $_POST['assigned_user_id'] && $_POST['assigned_user_id'] != $current_user->id) {
$GLOBALS['check_notify'] = true;
}
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfh = new SugarFieldHandler();
foreach ($focus->field_defs as $field => $def) {
$type = !empty($def['custom_type']) ? $def['custom_type'] : $def['type'];
$sf = $sfh->getSugarField(ucfirst($type), true);
if ($sf != null) {
$sf->save($focus, $_POST, $field, $def);
}
if (isset($_POST[$prefix . $field])) {
if (is_array($_POST[$prefix . $field]) && !empty($focus->field_defs[$field]['isMultiSelect'])) {
if (empty($_POST[$prefix . $field][0])) {
unset($_POST[$prefix . $field][0]);
}
if (!empty($_POST[$prefix . $field][0])) {
$_POST[$prefix . $field] = implode('^,^', $_POST[$prefix . $field]);
} else {
continue;
}
}
$focus->{$field} = $_POST[$prefix . $field];
/*
* overrides the passed value for booleans.
* this will be fully deprecated when the change to binary booleans is complete.
*/
if (isset($focus->field_defs[$prefix . $field]) && $focus->field_defs[$prefix . $field]['type'] == 'bool' && isset($focus->field_defs[$prefix . $field]['options'])) {
$opts = explode("|", $focus->field_defs[$prefix . $field]['options']);
$bool = $_POST[$prefix . $field];
if (is_int($bool) || ($bool === "0" || $bool === "1" || $bool === "2")) {
// 1=on, 2=off
$selection = $_POST[$prefix . $field] == "0" ? 1 : 0;
} elseif (is_bool($_POST[$prefix . $field])) {
// true=on, false=off
$selection = $_POST[$prefix . $field] ? 0 : 1;
}
$focus->{$field} = $opts[$selection];
}
} else {
if (!empty($focus->field_defs[$field]['isMultiSelect']) && !isset($_POST[$prefix . $field]) && isset($_POST[$prefix . $field . '_multiselect'])) {
$focus->{$field} = '';
}
}
}
foreach ($focus->additional_column_fields as $field) {
if (isset($_POST[$prefix . $field])) {
$value = $_POST[$prefix . $field];
$focus->{$field} = $value;
}
}
return $focus;
}
示例6: smarty_function_sugar_teamset_list
function smarty_function_sugar_teamset_list($params, &$smarty)
{
if (!isset($params['row']) && !isset($params['col'])) {
$smarty->trigger_error("sugar_phone: missing parameters, cannot continue");
return '';
}
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfh = new SugarFieldHandler();
return $sfh->displaySmarty($params['row'], $params['vardef'], 'ListView', array('col' => $params['col']));
}
示例7: normalizeFieldDefs
/**
* Cleans field def default values before returning them as a member of the
* metadata response payload
*
* Bug 56505
* Cleans default value of fields to strip out metacharacters used by the app.
* Used initially for cleaning default multienum values.
*
* @param array $fielddefs
* @return array
*/
public function normalizeFieldDefs(array $defs)
{
$this->getSugarFieldHandler();
foreach ($defs['fields'] as $name => $def) {
if (isset($def['type'])) {
$type = !empty($def['custom_type']) ? $def['custom_type'] : $def['type'];
$field = $this->sfh->getSugarField($type);
$defs['fields'][$name] = $field->getNormalizedDefs($def, $defs);
}
}
return $defs['fields'];
}
示例8: toJson
/**
* Method that returns a JSON representation of the bean.
* @return string
*/
public function toJson()
{
$this->retrieve();
$sfh = new SugarFieldHandler();
$data = array();
require_once 'include/api/RestService.php';
$service = new RestService();
foreach ($this->field_defs as $fieldName => $properties) {
$type = !empty($properties['custom_type']) ? $properties['custom_type'] : $properties['type'];
$field = $sfh->getSugarField($type);
if ($field != null && isset($this->{$fieldName})) {
$field->apiFormatField($data, $this, array(), $fieldName, $properties, array(), $service);
}
}
return json_encode($data);
}
示例9: testEmailTemplateFormat
/**
* @dataProvider _providerEmailTemplateFormat
*/
public function testEmailTemplateFormat($unformattedValue, $expectedValue)
{
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfr = SugarFieldHandler::getSugarField('encrypt');
$formattedValue = $sfr->getEmailTemplateValue($unformattedValue, array(), array('notify_user' => $GLOBALS['current_user']));
$this->assertEquals($expectedValue, $formattedValue);
}
示例10: apiSave
/**
* Override of parent apiSave to force the custom save to be run from API
* @param SugarBean $bean
* @param array $params
* @param string $field
* @param array $properties
*/
public function apiSave(SugarBean $bean, array $params, $field, $properties)
{
// Mapped fields needs to have something to map from.
if (empty($properties['mapFunction']) || empty($properties['parentField'])) {
return;
}
// First make sure the parent field exists on this bean
if (isset($bean->field_defs[$properties['parentField']])) {
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfh = new SugarFieldHandler();
$sf = $sfh->getSugarField($bean->field_defs[$properties['parentField']]['type']);
if (method_exists($sf, $properties['mapFunction'])) {
$bean->{$field} = $sf->{$properties['mapFunction']}($bean->{$properties['parentField']});
}
}
}
示例11: smarty_function_sugar_field
function smarty_function_sugar_field($params, &$smarty)
{
if (!isset($params['vardef']) || !isset($params['displayType']) || !isset($params['parentFieldArray'])) {
if (!isset($params['vardef'])) {
$smarty->trigger_error("sugar_field: missing 'vardef' parameter");
}
if (!isset($params['displayType'])) {
$smarty->trigger_error("sugar_field: missing 'displayType' parameter");
}
if (!isset($params['parentFieldArray'])) {
$smarty->trigger_error("sugar_field: missing 'parentFieldArray' parameter");
}
return;
}
static $sfh;
if (!isset($sfh)) {
$sfh = new SugarFieldHandler();
}
if (!isset($params['displayParams'])) {
$displayParams = array();
} else {
$displayParams = $params['displayParams'];
}
if (isset($params['labelSpan'])) {
$displayParams['labelSpan'] = $params['labelSpan'];
} else {
$displayParams['labelSpan'] = null;
}
if (isset($params['fieldSpan'])) {
$displayParams['fieldSpan'] = $params['fieldSpan'];
} else {
$displayParams['fieldSpan'] = null;
}
if (isset($params['typeOverride'])) {
// override the type in the vardef?
$params['vardef']['type'] = $params['typeOverride'];
}
if (isset($params['formName'])) {
$displayParams['formName'] = $params['formName'];
}
if (isset($params['field'])) {
$params['vardef']['name'] = $params['field'];
}
if (isset($params['call_back_function'])) {
$displayParams['call_back_function'] = $params['call_back_function'];
}
if (isset($params['skipClearButton'])) {
$displayParams['skipClearButton'] = $params['skipClearButton'];
}
if (isset($params['idName'])) {
$displayParams['idName'] = $params['idName'];
}
if (isset($params['accesskey'])) {
$displayParams['accesskey'] = $params['accesskey'];
}
$_contents = $sfh->displaySmarty($params['parentFieldArray'], $params['vardef'], $params['displayType'], $displayParams, $params['tabindex']);
return $_contents;
}
示例12: testEmailTemplateFormat
/**
* @dataProvider _providerEmailTemplateFormat
*/
public function testEmailTemplateFormat($unformattedValue, $expectedValue, $dateFormat, $timeFormat)
{
$GLOBALS['sugar_config']['default_date_format'] = $dateFormat;
$GLOBALS['sugar_config']['default_time_format'] = $timeFormat;
$this->user->setPreference('datef', $dateFormat);
$this->user->setPreference('timef', $timeFormat);
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfr = SugarFieldHandler::getSugarField('datetimecombo');
$formattedValue = $sfr->getEmailTemplateValue($unformattedValue, array(), array('notify_user' => $this->user));
$this->assertEquals($expectedValue, $formattedValue);
}
示例13: setUp
public function setUp()
{
$enumField = SugarFieldHandler::getSugarField('enum');
$parentFieldArray = array('ACCEPT_STATUS_NAME' => 'Accepted');
$vardef = array('name' => 'accept_status_name', 'type' => 'enum', 'source' => 'non-db', 'vname' => 'LBL_LIST_ACCEPT_STATUS', 'options' => 'dom_meeting_accept_status', 'massupdate' => false, 'studio' => array('listview' => false, 'searchview' => false));
$displayParams = array('vname' => 'LBL_LIST_ACCEPT_STATUS', 'width' => '11%', 'sortable' => false, 'linked_field' => 'users', 'linked_field_set' => 'users', 'name' => 'accept_status_name', 'module' => 'Users');
$col = 1;
$this->_listViewSmartyOutput1 = trim($enumField->getListViewSmarty($parentFieldArray, $vardef, $displayParams, $col));
$vardef['name'] = 'just_another_name';
$parentFieldArray['JUST_ANOTHER_NAME'] = 'None';
$this->_listViewSmartyOutput2 = trim($enumField->getListViewSmarty($parentFieldArray, $vardef, $displayParams, $col));
}
示例14: testFormatEnumField
/**
* @ticket 36744
*/
public function testFormatEnumField()
{
$langpack = new SugarTestLangPackCreator();
$langpack->setAppListString('case_priority_dom', array('P1' => 'High', 'P2' => 'Medium', 'P3' => 'Low'));
$langpack->save();
$GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
$fieldDef = array('name' => 'priority', 'vname' => 'LBL_PRIORITY', 'type' => 'enum', 'options' => 'case_priority_dom', 'len' => 25, 'audited' => true, 'comment' => 'The priority of the case');
$field_value = "P2";
require_once 'include/SugarFields/SugarFieldHandler.php';
$sfr = SugarFieldHandler::getSugarField('enum');
$this->assertEquals(trim($sfr->formatField($field_value, $fieldDef)), 'Medium');
}
示例15: save
/**
* Save the Individual Worksheet
*
* @return ForecastWorksheet
* @throws SugarApiException
*/
public function save()
{
require_once 'include/SugarFields/SugarFieldHandler.php';
/* @var $seed ForecastWorksheet */
$seed = BeanFactory::getBean("ForecastWorksheets");
$seed->loadFromRow($this->args);
$sfh = new SugarFieldHandler();
foreach ($seed->field_defs as $properties) {
$fieldName = $properties['name'];
if (!isset($this->args[$fieldName])) {
continue;
}
if (!$seed->ACLFieldAccess($fieldName, 'save')) {
// No write access to this field, but they tried to edit it
global $app_strings;
throw new SugarApiException(string_format($app_strings['SUGAR_API_EXCEPTION_NOT_AUTHORIZED'], array($fieldName, $this->args['module'])));
}
$type = !empty($properties['custom_type']) ? $properties['custom_type'] : $properties['type'];
$field = $sfh->getSugarField($type);
if (!is_null($field)) {
$field->save($seed, $this->args, $fieldName, $properties);
}
}
// Check if this is the first commit, then save has_commits true to the config table
$admin = BeanFactory::getBean('Administration');
$settings = $admin->getConfigForModule('Forecasts');
if (!isset($settings['has_commits']) || !$settings['has_commits']) {
$admin->saveSetting('Forecasts', 'has_commits', true, 'base');
MetaDataManager::refreshModulesCache(array('Forecasts'));
}
$seed->setWorksheetArgs($this->args);
// we need to set the parent_type and parent_id so it finds it when we try and retrieve the old records
$seed->parent_type = $this->getArg('parent_type');
$seed->parent_id = $this->getArg('parent_id');
$seed->saveWorksheet();
// we have the id, just retrieve the record again
$seed = BeanFactory::getBean("ForecastWorksheets", $this->getArg('record'));
return $seed;
}