/**
  * Utility method to to make it easier to determine if we should save or not.
  *
  * @param AbstractMetaDataParser $parser
  * @param array $fields
  * @return bool
  */
 protected function removeFields($parser, $fields)
 {
     $shouldSave = false;
     foreach ($fields as $field) {
         if ($parser->removeField($field)) {
             $shouldSave = true;
         }
     }
     return $shouldSave;
 }
 public function testValidField()
 {
     $validDef = array('name' => 'status', 'vname' => 'LBL_STATUS', 'type' => 'enum', 'len' => '25', 'options' => 'meeting_status_dom', 'comment' => 'Meeting status (ex: Planned, Held, Not held)');
     $invalidDef = array('name' => 'direction', 'vname' => 'LBL_DIRECTION', 'type' => 'enum', 'len' => '25', 'options' => 'call_direction_dom', 'comment' => 'Indicates whether call is inbound or outbound', 'source' => 'non-db', 'importable' => 'false', 'massupdate' => false, 'reportable' => false);
     $this->assertTrue(AbstractMetaDataParser::validField($validDef));
     $this->assertFalse(AbstractMetaDataParser::validField($invalidDef));
     //Test the studio override property
     $invalidDef['studio'] = 'visible';
     $validDef['studio'] = false;
     $this->assertFalse(AbstractMetaDataParser::validField($validDef));
     $this->assertTrue(AbstractMetaDataParser::validField($invalidDef));
     $invalidDef['studio'] = array('editview' => 'visible');
     $this->assertTrue(AbstractMetaDataParser::validField($invalidDef, 'editview'));
     $this->assertFalse(AbstractMetaDataParser::validField($invalidDef, 'detailview'));
 }
 public function isValidField($key, array $def)
 {
     if (isset($def['studio'])) {
         if (is_array($def['studio'])) {
             // Bug 54507 - Need to set the view properly for portal
             // Portal editor requests vary in that the requested view is ListView
             // but what we really need is portallistview, which is in $this->view
             // All other instances of ListLayoutMetaDataParser set $this->view
             // to $_REQUEST['view']
             $view = $this->view;
             // Handle client specific studio setting for a field
             $clientRules = AbstractMetaDataParser::getClientStudioValidation($def['studio'], $view, $this->client);
             if ($clientRules !== null) {
                 return $clientRules;
             }
             // fix for removing email1 field from studio popup searchview - bug 42902
             if ($view == 'popupsearch' && $key == 'email1') {
                 return false;
             }
             //end bug 42902
             // Bug 54507 Return explicit setting of a fields view setting if there is one
             if (!empty($view) && isset($def['studio'][$view])) {
                 return $def['studio'][$view] !== false && (string) $def['studio'][$view] != 'false' && (string) $def['studio'][$view] != 'hidden';
             }
             if (isset($def['studio']['listview'])) {
                 return $def['studio']['listview'] !== false && (string) $def['studio']['listview'] != 'false' && (string) $def['studio']['listview'] != 'hidden';
             }
             // End Bug 54507
             if (isset($def['studio']['visible'])) {
                 return $def['studio']['visible'];
             }
         } else {
             if (is_string($def['studio'])) {
                 return $def['studio'] != 'false' && $def['studio'] != 'hidden';
             } else {
                 if (is_bool($def['studio'])) {
                     return $def['studio'];
                 }
             }
         }
     }
     //Bug 32520. We need to dissalow currency_id fields on list views.
     //This should be removed once array based studio definitions are in.
     if (isset($def['type']) && $def['type'] == "id" && $def['name'] == 'currency_id') {
         return false;
     }
     //Check fields types
     if (isset($def['dbType']) && $def['dbType'] == "id") {
         return false;
     }
     if (isset($def['type'])) {
         if ($def['type'] == 'html' || $def['type'] == 'parent' && !$this->allowParent || $def['type'] == "id" || $def['type'] == "link" || $def['type'] == 'image') {
             return false;
         }
     }
     //hide currency_id, deleted, and _name fields by key-name
     if (strcmp($key, 'deleted') == 0) {
         return false;
     }
     //if all the tests failed, the field is probably ok
     return true;
 }
 function __construct($subpanelName, $moduleName)
 {
     $GLOBALS['log']->debug(get_class($this) . "->__construct({$subpanelName} , {$moduleName})");
     $this->_subpanelName = $subpanelName;
     $this->_moduleName = $moduleName;
     $module = BeanFactory::getBean($moduleName);
     // BEGIN ASSERTIONS
     if (empty($module)) {
         sugar_die(get_class($this) . ": Modulename {$moduleName} is not a Deployed Module");
     }
     // END ASSERTIONS
     $this->historyPathname = 'custom/history/modules/' . $moduleName . '/subpanels/' . $subpanelName . '/' . self::HISTORYFILENAME;
     $this->_history = new History($this->historyPathname);
     require_once 'include/SubPanel/SubPanelDefinitions.php';
     // retrieve the definitions for all the available subpanels for this module from the subpanel
     $spd = new SubPanelDefinitions($module);
     // Get the lists of fields already in the subpanel and those that can be added in
     // Get the fields lists from an aSubPanel object describing this subpanel from the SubPanelDefinitions object
     $this->_viewdefs = array();
     $this->_fielddefs = array();
     $this->_language = '';
     if (!empty($spd->layout_defs)) {
         if (array_key_exists(strtolower($subpanelName), $spd->layout_defs['subpanel_setup'])) {
             //First load the original defs from the module folder
             $originalSubpanel = $spd->load_subpanel($subpanelName, false, true);
             $this->_fullFielddefs = $originalSubpanel ? $originalSubpanel->get_list_fields() : array();
             $this->_mergeFielddefs($this->_fielddefs, $this->_fullFielddefs);
             $this->_aSubPanelObject = $spd->load_subpanel($subpanelName);
             // now check if there is a restored subpanel in the history area - if there is, then go ahead and use it
             if (file_exists($this->historyPathname)) {
                 // load in the subpanelDefOverride from the history file
                 $GLOBALS['log']->debug(get_class($this) . ": loading from history");
                 require $this->historyPathname;
                 $this->_viewdefs = $layout_defs;
             } else {
                 $this->_viewdefs = $this->_aSubPanelObject->get_list_fields();
             }
             // don't attempt to access the template_instance property if our subpanel represents a collection, as it won't be there - the sub-sub-panels get this value instead
             if (!$this->_aSubPanelObject->isCollection()) {
                 $this->_language = $this->_aSubPanelObject->template_instance->module_dir;
             }
             // Retrieve a copy of the bean for the parent module of this subpanel - so we can find additional fields for the layout
             $subPanelParentModuleName = $this->_aSubPanelObject->get_module_name();
             $beanListLower = array_change_key_case($GLOBALS['beanList']);
             if (!empty($subPanelParentModuleName) && isset($beanListLower[strtolower($subPanelParentModuleName)])) {
                 $subPanelParentModule = get_module_info($subPanelParentModuleName);
                 // Run through the preliminary list, keeping only those fields that are valid to include in a layout
                 foreach ($subPanelParentModule->field_defs as $key => $def) {
                     $key = strtolower($key);
                     if (AbstractMetaDataParser::validField($def)) {
                         if (!isset($def['label'])) {
                             $def['label'] = $def['name'];
                         }
                         $this->_fielddefs[$key] = $def;
                     }
                 }
             }
             $this->_mergeFielddefs($this->_fielddefs, $this->_viewdefs);
         }
     }
 }
Exemple #5
0
 /**
  * Relate to email1 should be true
  * @group 39729
  */
 public function testEmail1FieldOnTrue()
 {
     $this->assertTrue(AbstractMetaDataParser::validField($this->def, $this->_view));
 }
 protected function resetToDefault()
 {
     $implementation = $this->parser->getImplementation();
     $fileName = $implementation->getDefaultFileName($this->layout, $this->module);
     $this->history->savePreview($fileName);
 }
Exemple #7
0
 public function testHideMeetingDisplayedURL()
 {
     $validDef = $this->meeting->field_defs['displayed_url'];
     $this->assertFalse(AbstractMetaDataParser::validField($validDef, 'wirelesseditview'));
     $this->assertFalse(AbstractMetaDataParser::validField($validDef, 'wirelessdetailview'));
 }
 function getAvailableFields()
 {
     // Obtain the full list of valid fields in this module
     $availableFields = array();
     foreach ($this->_fielddefs as $key => $def) {
         if (AbstractMetaDataParser::validField($def) || isset($this->_originalViewDef[$key])) {
             $availableFields[$key] = array('name' => $key, 'label' => $def['label']);
             // layouts use 'label' not 'vname' for the label entry
         }
     }
     // Available fields are those that are in the Model and the original layout definition, but not already shown in the View
     // So, because the formats of the two are different we brute force loop through View and unset the fields we find in a copy of Model
     if (!empty($this->_viewdefs)) {
         foreach ($this->_viewdefs['panels'] as $panel) {
             foreach ($panel as $row) {
                 foreach ($row as $field) {
                     unset($availableFields[$field]);
                 }
             }
         }
     }
     return $availableFields;
 }
 /**
  * The actual legacy defs converter. For list it is simply taking the old
  * def array, looping over it, lowercasing the field names, adding that to
  * each iteration and saving that into a 'fields' array inside of the panels
  * array.
  */
 public function convertLegacyViewDefsToSidecar()
 {
     $this->logUpgradeStatus('Converting ' . $this->client . ' list view defs for ' . $this->module);
     if (empty($this->legacyViewdefs)) {
         $this->logUpgradeStatus('Empty metadata, doing nothing');
         return false;
     }
     // Get the default defs so that data can be merged as needed
     $defaults = $this->loadDefaultMetadata();
     $defaults = $this->setDefaultsByKey($defaults);
     // Now get to the converting
     $newdefs = array();
     foreach ($this->legacyViewdefs as $field => $def) {
         if (!$this->isValidField($field)) {
             continue;
         }
         $defs = array();
         $defs['name'] = strtolower($field);
         unset($def['name']);
         // Prevents old defs from overriding the new
         // Bug 57414 - Available fields of mobile listview shown under
         //             default fields list after upgrade
         // For portal upgrades:
         //  - Default should be true by virtue of the field being in the viewdefs
         // For mobile upgrades:
         //  - Default is true if default was set truthy before
         // For both platforms:
         //  - enabled is true if it was not set before, or if it was set to true
         if ($this->client == 'portal') {
             $defs['default'] = true;
         } else {
             if (isset($def['default'])) {
                 // If it was set in the mobile metadata, use that (bool) value
                 $defs['default'] = AbstractMetaDataParser::isTruthy($def['default']);
                 unset($def['default']);
                 // remove to prevent overriding in merge
             } else {
                 // Was not set, so it is not default. This allows a field to
                 // be available without being default
                 $defs['default'] = false;
             }
         }
         // Enabled is almost always true by virtue of this field being in the defs
         if (!isset($def['enabled'])) {
             $defs['enabled'] = true;
         } else {
             // This will more than likely never run, but you never know
             // If somehow the field was marked enabled in a non truthy way...
             $defs['enabled'] = AbstractMetaDataParser::isTruthy($def['enabled']);
             unset($def['enabled']);
             // unsetting to prevent clash in merge
         }
         // Merge the rest of the defs
         $defs = array_merge($defs, $def);
         // Merge the new defs into the defaults
         if (isset($defaults[$defs['name']])) {
             $defs = array_merge($defaults[$defs['name']], $defs);
         }
         // Remove module from the defs since the app doesn't like that
         unset($defs['module']);
         // Some MergeTemplate merges leave type for fields like team_name as relate
         // ignoring custom_type. We can't fix it there so we fix it here.
         // Since list takes def from vardef anyway, we can delete type if it matches vardef
         // See BR-1402
         if (!empty($defs['type']) && !empty($this->field_defs) && !empty($this->field_defs[$field]['type']) && $defs['type'] == $this->field_defs[$field]['type']) {
             unset($defs['type']);
         }
         $newdefs[] = $defs;
     }
     $this->logUpgradeStatus("view defs converted, getting normalized module name");
     // This is the structure of the sidecar list meta
     $module = $this->getNormalizedModuleName();
     $this->logUpgradeStatus("module name normalized to: {$module}");
     // Clean up client to mobile for wireless clients
     $client = $this->client == 'wireless' ? 'mobile' : $this->client;
     $this->logUpgradeStatus("Setting new {$client} {$this->type} view defs internally for {$module}");
     $this->sidecarViewdefs[$module][$client]['view']['list'] = array('panels' => array(array('label' => 'LBL_PANEL_DEFAULT', 'fields' => $newdefs)));
 }
 /**
  * Determines if a field exists on the bean
  * @param $field
  * @return bool
  */
 public function isValidField($field)
 {
     $field = strtolower($field);
     $defs = $this->getFieldDefs();
     if (empty($defs)) {
         // no idea where it came from, let it pass.no reason to remove fields that may be necessary
         return true;
     }
     if (empty($defs[$field])) {
         return false;
     }
     $viewname = $this->views[$this->client . $this->viewtype] == MB_SIDECARLISTVIEW ? MB_LISTVIEW : $this->views[$this->client . $this->viewtype];
     $parser = ParserFactory::getParser($viewname, $this->module);
     if ($parser && method_exists($parser, 'isValidField')) {
         return $parser->isValidField($field, $defs[$field]);
     } else {
         return AbstractMetaDataParser::validField($defs[$field], $this->viewtype, $this->client);
     }
 }