public function testCaseNumberReadOnlyFieldNotRequired() { $parser = new GridLayoutMetaDataParser(MB_EDITVIEW, 'Cases'); $required_fields = $parser->getRequiredFields(); $vals = array_flip($required_fields); $this->assertTrue(isset($vals['"name"']), 'Assert that the AbstractMetaDataParser->getRequiredFields function returns name as required'); $this->assertFalse(isset($vals['"case_number"']), 'Assert that the AbstractMetaDataParser->getRequiredFields function does not return case_number as required'); $parser = new ListLayoutMetaDataParser(MB_LISTVIEW, 'Cases'); $required_fields = $parser->getRequiredFields(); $vals = array_flip($required_fields); $this->assertTrue(isset($vals['"name"']), 'Assert that the AbstractMetaDataParser->getRequiredFields function returns name as required'); $this->assertFalse(isset($vals['"case_number"']), 'Assert that the AbstractMetaDataParser->getRequiredFields function does not return case_number as required'); }
public function testCallsContactStudioViews() { $seed = new Call(); $def = $seed->field_defs['contact_name']; $this->assertTrue(ListLayoutMetaDataParser::isValidField($def['name'], $def)); $this->assertFalse(GridLayoutMetaDataParser::validField($def, 'editview')); $this->assertFalse(GridLayoutMetaDataParser::validField($def, 'detailview')); $this->assertFalse(GridLayoutMetaDataParser::validField($def, 'quickcreate')); }
function __construct($view, $moduleName, $packageName = '') { $this->search = $view == MB_DASHLETSEARCH ? true : false; $this->_moduleName = $moduleName; $this->_packageName = $packageName; $this->_view = $view; if ($this->search) { $this->columns = array('LBL_DEFAULT' => 'getAdditionalFields', 'LBL_HIDDEN' => 'getAvailableFields'); parent::__construct(MB_DASHLETSEARCH, $moduleName, $packageName); } else { parent::__construct(MB_DASHLET, $moduleName, $packageName); } $this->_viewdefs = $this->mergeFieldDefinitions($this->_viewdefs, $this->_fielddefs); }
function display() { $editModule = $_REQUEST['view_module']; if (!isset($_REQUEST['MB'])) { global $app_list_strings; $moduleNames = array_change_key_case($app_list_strings['moduleList']); $translatedEditModule = $moduleNames[strtolower($editModule)]; } $selected_lang = !empty($_REQUEST['selected_lang']) ? $_REQUEST['selected_lang'] : $_SESSION['authenticated_user_language']; if (empty($selected_lang)) { $selected_lang = $GLOBALS['sugar_config']['default_language']; } $smarty = new Sugar_Smarty(); global $mod_strings; $smarty->assign('mod_strings', $mod_strings); $smarty->assign('available_languages', get_languages()); global $beanList; $objectName = $beanList[$editModule]; if ($objectName == 'aCase') { $objectName = 'Case'; } VardefManager::loadVardef($editModule, $objectName); global $dictionary; $vnames = array(); //jchi 24557 . We should list all the lables in viewdefs(list,detail,edit,quickcreate) that the user can edit them. require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php'; $parser = new ListLayoutMetaDataParser(MB_LISTVIEW, $editModule); foreach ($parser->getLayout() as $key => $def) { if (isset($def['label'])) { $vnames[$def['label']] = $def['label']; } } require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php'; $variableMap = array(MB_EDITVIEW => 'EditView', MB_DETAILVIEW => 'DetailView', MB_QUICKCREATE => 'QuickCreate'); if ($editModule == 'KBDocuments') { $variableMap = array(); } foreach ($variableMap as $key => $value) { $gridLayoutMetaDataParserTemp = new GridLayoutMetaDataParser($value, $editModule); foreach ($gridLayoutMetaDataParserTemp->getLayout() as $panel) { foreach ($panel as $row) { foreach ($row as $fieldArray) { // fieldArray is an array('name'=>name,'label'=>label) if (isset($fieldArray['label'])) { $vnames[$fieldArray['label']] = $fieldArray['label']; } } } } } //end //Get Subpanel Labels: require_once 'include/SubPanel/SubPanel.php'; $subList = SubPanel::getModuleSubpanels($editModule); foreach ($subList as $subpanel => $titleLabel) { $vnames[$titleLabel] = $titleLabel; } foreach ($dictionary[$objectName]['fields'] as $name => $def) { if (isset($def['vname'])) { $vnames[$def['vname']] = $def['vname']; } } $formatted_mod_strings = array(); //we shouldn't set the $refresh=true here, or will lost template language mod_strings. //return_module_language($selected_lang, $editModule,false) : the mod_strings will be included from cache files here. foreach (return_module_language($selected_lang, $editModule, false) as $name => $label) { //#25294 if (isset($vnames[$name]) || preg_match('/lbl_city|lbl_country|lbl_billing_address|lbl_alt_address|lbl_shipping_address|lbl_postal_code|lbl_state$/si', $name)) { $formatted_mod_strings[$name] = htmlentities($label, ENT_QUOTES, 'UTF-8'); } } //Grab everything from the custom files $mod_bak = $mod_strings; $files = array("custom/modules/{$editModule}/language/{$selected_lang}.lang.php", "custom/modules/{$editModule}/Ext/Language/{$selected_lang}.lang.ext.php"); foreach ($files as $langfile) { $mod_strings = array(); if (is_file($langfile)) { include $langfile; foreach ($mod_strings as $key => $label) { $formatted_mod_strings[$key] = htmlentities($label, ENT_QUOTES, 'UTF-8'); } } } $mod_strings = $mod_bak; ksort($formatted_mod_strings); $smarty->assign('MOD', $formatted_mod_strings); $smarty->assign('view_module', $editModule); $smarty->assign('APP', $GLOBALS['app_strings']); $smarty->assign('selected_lang', $selected_lang); $smarty->assign('defaultHelp', 'labelsBtn'); $smarty->assign('assistant', array('key' => 'labels', 'group' => 'module')); $ajax = new AjaxCompose(); $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")'); $ajax->addCrumb($translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $editModule . '")'); $ajax->addCrumb($mod_strings['LBL_LABELS'], ''); $html = $smarty->fetch('modules/ModuleBuilder/tpls/labels.tpl'); $ajax->addSection('center', $GLOBALS['mod_strings']['LBL_SECTION_EDLABELS'], $html); echo $ajax->getJavascript(); }
static function _trimFieldDefs($def) { $listDef = parent::_trimFieldDefs($def); if (isset($listDef['label'])) { $listDef['vname'] = $listDef['label']; unset($listDef['label']); } return $listDef; }
public function isValidField($key, array $def) { if (isset($def['type']) && $def['type'] == "assigned_user_name") { $origDefs = $this->getOriginalViewDefs(); if (isset($def['group']) && isset($origDefs[$def['group']])) { return false; } if (!isset($def['studio']) || is_array($def['studio']) && !isset($def['studio']['searchview'])) { return true; } } if (isset($def['studio']) && is_array($def['studio']) && isset($def['studio']['searchview'])) { return $def['studio']['searchview'] !== false && ($def['studio']['searchview'] === true || $def['studio']['searchview'] != 'false'); } if (!parent::isValidField($key, $def)) { return false; } //Special case to prevent multiple copies of assigned, modified, or created by user on the search view if (empty($def['studio']) && $key == "assigned_user_name") { $origDefs = $this->getOriginalViewDefs(); if ($key == "assigned_user_name" && isset($origDefs['assigned_user_id'])) { return false; } } //Remove image fields (unless studio was set) if (!empty($def['studio']) && isset($def['type']) && $def['type'] == "image") { return false; } return true; }
function __construct($moduleName, $packageName = '') { parent::__construct(MB_LISTVIEW, $moduleName, $packageName); }
/** * Merges the fields together and stores them in $this->mergedFields * */ protected function mergeFields() { if ($this->sugarMerge instanceof SugarMerge && is_file($this->sugarMerge->getNewPath() . 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php')) { require_once $this->sugarMerge->getNewPath() . 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php'; } else { require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php'; } $objectName = BeanFactory::getBeanName($this->module); VardefManager::loadVardef($this->module, $objectName); foreach ($this->customFields as $field => $data) { $fieldName = strtolower($data['loc']['row']); if (!empty($GLOBALS['dictionary'][$objectName]['fields'][$fieldName])) { $data['data'] = array_merge(ListLayoutMetaDataParser::createViewDefsByFieldDefs($GLOBALS['dictionary'][$objectName]['fields'][$fieldName]), $data['data']); } //if we have this field in both the new fields and the original fields - it has existed since the last install/upgrade if (isset($this->newFields[$field]) && isset($this->originalFields[$field])) { //if both the custom field and the original match then we take the location of the custom field since it hasn't moved $loc = $this->customFields[$field]['loc']; $loc['source'] = 'custom'; //echo var_export($loc, true); //but we still merge the meta data of the three $this->mergedFields[$field] = array('data' => $this->mergeField($this->originalFields[$field]['data'], $this->newFields[$field]['data'], $this->customFields[$field]['data']), 'loc' => $loc); //if it's not set in the new fields then it was a custom field or an original field so we take the custom fields data and set the location source to custom } else { if (!isset($this->newFields[$field])) { $this->mergedFields[$field] = $data; $this->mergedFields[$field]['loc']['source'] = 'custom'; } else { //otherwise the field is in both new and custom but not in the orignal so we merge the new and custom data together and take the location from the custom $this->mergedFields[$field] = array('data' => $this->mergeField('', $this->newFields[$field]['data'], $this->customFields[$field]['data']), 'loc' => $this->customFields[$field]['loc']); $this->mergedFields[$field]['loc']['source'] = 'custom'; //echo var_export($this->mergedFields[$field], true); } } //then we clear out the field from unset($this->originalFields[$field]); unset($this->customFields[$field]); unset($this->newFields[$field]); } /** * These are fields that were removed by the customer */ foreach ($this->originalFields as $field => $data) { unset($this->originalFields[$field]); unset($this->newFields[$field]); } foreach ($this->newFields as $field => $data) { $data['loc']['source'] = 'new'; $this->mergedFields[$field] = array('data' => $data['data'], 'loc' => $data['loc']); unset($this->newFields[$field]); } }
function getOriginalViewDefs() { $defs = parent::getOriginalViewDefs(); return $this->convertSearchToListDefs($defs); }
/** * Clears mobile and portal metadata caches that have been created by the API * to allow immediate rendering of changes at the client */ protected function _clearCaches() { if ($this->implementation->isDeployed()) { // Installing and trying to refresh the modules cache is bad juju if (!empty($GLOBALS['installing'])) { // Use the clear NOW method so that if there is a cache it is wiped MetaDataManager::clearAPICache(true, true); } else { MetaDataManager::refreshModulesCache(array($this->_moduleName)); } parent::_clearCaches(); } }
/** * Process the ListView to set the fields correctly * * @param array $fieldMap * @param $current_fields * @param ListLayoutMetaDataParser $listParser */ private function processList(array $fieldMap, $current_fields, ListLayoutMetaDataParser $listParser) { if (!$listParser instanceof SidecarListLayoutMetaDataParser) { return false; } $handleSave = false; $saveFields = array(); // process the fields foreach ($current_fields as $panel_id => $panel) { if (is_array($panel['fields'])) { foreach ($panel['fields'] as $field) { $name = $field['name']; $addField = true; $additionalDefs = $field; if (isset($fieldMap[$name])) { if ($fieldMap[$name] === true) { // nothing to do, field is present } elseif ($fieldMap[$name] !== false) { // we have the field, so get it's defs $defs = $this->bean->getFieldDefinition($fieldMap[$name]); if ($defs) { // set the name variable to the new field name. $name = $fieldMap[$name]; // reset the additionDefs since we have a new field $additionalDefs = array(); } else { // we didn't find any defs for the new field, so error on caution and remove the old one $addField = false; } $handleSave = true; } else { // instead of a name being passed in, false was, so we should remove that field. $addField = false; $handleSave = true; } unset($fieldMap[$name]); } if ($addField) { $saveFields[] = array($name, $additionalDefs); } } } } // make sure that the field map is empty, if it's not process any remaining fields if (!empty($fieldMap)) { foreach ($fieldMap as $field => $trigger) { if ($trigger === true) { $defs = $this->bean->getFieldDefinition($field); if ($defs) { $saveFields[] = array($field, array()); $handleSave = true; } } } } if ($handleSave) { // make sure the list is reset $listParser->resetPanelFields(); foreach ($saveFields as $params) { $listParser->addField($params[0], $params[1]); } $listParser->handleSave(false); } }
/** * Returns unused fields that are available for use in either default or additional list views * @return array List of available fields as an array, where key = value = <field name> */ function getAvailableFields() { $availableFields = array(); // Select available fields from the field definitions - don't need to worry about checking if ok to include as the Implementation has done that already in its constructor foreach ($this->_fielddefs as $key => $def) { if ($this->isValidField($key, $def)) { $availableFields[$key] = self::_trimFieldDefs($this->_fielddefs[$key]); } } //$GLOBALS['log']->debug(get_class($this).'->getAvailableFields(): '.print_r($availableFields,true)); // now remove all fields that are already in the viewdef - they are not available; they are in use return ListLayoutMetaDataParser::getArrayDiff($availableFields, $this->_viewdefs); }
function mergeFieldDefinitions($viewdefs, $fielddefs) { if ($this->_view == MB_DASHLETSEARCH && isset($viewdefs['searchfields'])) { //Remove any relate fields from the possible defs as they will break the homepage foreach ($fielddefs as $id => $def) { if ($def['type'] == 'relate') { $fielddefs[$fielddefs[$id]['id_name']] = $def; unset($fielddefs[$id]); } } $viewdefs = array_change_key_case($viewdefs['searchfields']); $viewdefs = $this->_viewdefs = $this->convertSearchToListDefs($viewdefs); } else { if ($this->_view == MB_DASHLET && isset($viewdefs['columns'])) { $viewdefs = $this->_viewdefs = array_change_key_case($viewdefs['columns']); $viewdefs = $this->_viewdefs = $this->convertSearchToListDefs($viewdefs); } } return parent::mergeFieldDefinitions($viewdefs, $fielddefs); }