Ejemplo n.º 1
0
 public function getAvailableSettings($pa_element_info = null)
 {
     global $_ca_attribute_settings, $g_request;
     $va_element_settings = $_ca_attribute_settings['ListAttributeValue'];
     /*
      * For the dependent field visibility feature we need to add a select-able list of all applicable
      * UI bundle placements here ... for each item in that list!
      */
     if (Configuration::load()->get('enable_dependent_field_visibility') && is_array($pa_element_info) && isset($pa_element_info['list_id']) && (!$pa_element_info['settings']['render'] || in_array($pa_element_info['settings']['render'], array('select', 'radio_buttons', 'yes_no_checkboxes'))) && $g_request && $g_request instanceof RequestHTTP) {
         $va_options_for_settings = array();
         $t_mde = new ca_metadata_elements($pa_element_info['element_id']);
         $va_restrictions = $t_mde->getTypeRestrictions();
         $va_tables = array();
         if (is_array($va_restrictions) && sizeof($va_restrictions)) {
             foreach ($va_restrictions as $va_restriction) {
                 $va_tables[] = $va_restriction['table_num'];
             }
         }
         $t_ui = new ca_editor_uis();
         foreach (array_unique($va_tables) as $vn_table_num) {
             // get UIs
             $va_ui_list = ca_editor_uis::getAvailableUIs($vn_table_num, $g_request);
             foreach ($va_ui_list as $vn_ui_id => $vs_ui_name) {
                 $t_ui->load($vn_ui_id);
                 // get screens
                 foreach ($t_ui->getScreens() as $va_screen) {
                     // get placements
                     foreach ($t_ui->getScreenBundlePlacements($va_screen['screen_id']) as $va_placement) {
                         $va_options_for_settings[$t_ui->get('editor_code') . '/' . $va_screen['idno'] . '/' . $va_placement['placement_code']] = $t_ui->get('editor_code') . '/' . $va_screen['idno'] . '/' . $va_placement['placement_code'];
                     }
                 }
             }
         }
         $t_list = new ca_lists();
         foreach ($t_list->getItemsForList($pa_element_info['list_id']) as $va_items_by_locale) {
             foreach ($va_items_by_locale as $vn_locale_id => $va_item) {
                 $va_element_settings['hideIfSelected_' . $va_item['idno']] = array('formatType' => FT_TEXT, 'displayType' => DT_SELECT, 'options' => $va_options_for_settings, 'takesLocale' => false, 'default' => '', 'width' => "400px", 'height' => 10, 'label' => _t('Hide bundles if "%1" is selected', $va_item['name_singular']), 'description' => _t('Select bundles from the list below'));
             }
         }
     } elseif (defined('__CollectiveAccess_Installer__') && Configuration::load()->get('enable_dependent_field_visibility')) {
         // when installing, UIs, screens and placements are not yet available when we process elementSets, so
         // we just add the hideIfSelected_* as available settings (without actual settings) so that the validation doesn't fail
         $t_list = new ca_lists();
         foreach ($t_list->getItemsForList($pa_element_info['list_id']) as $va_items_by_locale) {
             foreach ($va_items_by_locale as $vn_locale_id => $va_item) {
                 $va_element_settings['hideIfSelected_' . $va_item['idno']] = true;
             }
         }
     }
     return $va_element_settings;
 }
Ejemplo n.º 2
0
 /**
  * Load standard UI (either system default or user-defined) for specified record and, optionally, record type
  *
  * @param mixed $pm_table_name_or_num Table name or number to load editor for. Values for $pm_table_name_or_num may be, for example:
  *		'ca_objects' = objects editor
  *		'ca_entities' = entities editor
  *		.. etc ..
  * @param RequestHTTP $po_request The current request
  * @param int $pn_type_id Optional type_id
  * @param array $pa_options Options are:
  *		editorPref = "cataloguing" to select UI using user's "cataloguing_<table_name>_editor_ui" preference, "quickadd" to use "quickadd_<table_name>_editor_ui" pref; default is "cataloguing"
  * @return ca_editor_uis instance loaded with default UI on success, false on failure
  */
 public static function loadDefaultUI($pm_table_name_or_num, $po_request, $pn_type_id = null, $pa_options = null)
 {
     if (ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id]) {
         return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id];
     }
     $o_dm = Datamodel::load();
     if (is_numeric($pm_table_name_or_num)) {
         $t_instance = $o_dm->getInstanceByTableNum($pm_table_name_or_num, true);
     } else {
         $t_instance = $o_dm->getInstanceByTableName($pm_table_name_or_num, true);
     }
     if (!$t_instance) {
         return false;
     }
     $vs_table_name = $t_instance->tableName();
     $vn_table_num = $t_instance->tableNum();
     if (!isset($pa_options['editorPref'])) {
         $pa_options['editorPref'] = 'cataloguing';
     }
     switch ($pa_options['editorPref']) {
         case 'quickadd':
             $va_uis_by_type = $po_request->user->getPreference("quickadd_{$vs_table_name}_editor_ui");
             break;
         default:
             $va_uis_by_type = $po_request->user->getPreference("cataloguing_{$vs_table_name}_editor_ui");
             break;
     }
     $va_available_uis_by_type = $po_request->user->_getUIListByType($vn_table_num);
     if ($pn_type_id && $va_uis_by_type) {
         if (!is_array($va_uis_by_type)) {
             if (!isset($va_available_uis_by_type[$pn_type_id][$va_uis_by_type]) && !isset($va_available_uis_by_type['__all__'][$va_uis_by_type])) {
                 $pn_type_id = null;
             }
             $va_uis_by_type = array();
         } else {
             if (!isset($va_available_uis_by_type[$pn_type_id][$va_uis_by_type[$pn_type_id]]) && !isset($va_available_uis_by_type['__all__'][$va_uis_by_type[$pn_type_id]])) {
                 $pn_type_id = null;
             }
         }
     }
     $t_ui = new ca_editor_uis();
     if (!$pn_type_id || !($vn_rc = $t_ui->load($va_uis_by_type[$pn_type_id]))) {
         $va_ui_ids = ca_editor_uis::getAvailableUIs($vn_table_num, $po_request, $pn_type_id, true);
         if (sizeof($va_ui_ids) == 0) {
             return false;
         }
         $va_tmp = array_keys($va_ui_ids);
         if ($t_ui->load($va_tmp[0])) {
             return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id] = $t_ui;
         }
         return false;
     }
     return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id] = $t_ui;
 }
Ejemplo n.º 3
0
 /**
  * Load standard UI (either system default or user-defined) for specified record and, optionally, record type
  *
  * @param mixed $pm_table_name_or_num Table name or number to load editor for. Values for $pm_table_name_or_num may be, for example:
  *		'ca_objects' = objects editor
  *		'ca_entities' = entities editor
  *		.. etc ..
  * @param RequestHTTP $po_request The current request
  * @param int $pn_type_id Optional type_id
  * @param array $pa_options Options are:
  *		editorPref = "cataloguing" to select UI using user's "cataloguing_<table_name>_editor_ui" preference, "quickadd" to use "quickadd_<table_name>_editor_ui" pref; default is "cataloguing"
  * @return ca_editor_uis instance loaded with default UI on success, false on failure
  */
 public static function loadDefaultUI($pm_table_name_or_num, $po_request, $pn_type_id = null, $pa_options = null)
 {
     if (isset(ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id])) {
         return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id];
     }
     $o_dm = Datamodel::load();
     if (is_numeric($pm_table_name_or_num)) {
         $t_instance = $o_dm->getInstanceByTableNum($pm_table_name_or_num, true);
     } else {
         $t_instance = $o_dm->getInstanceByTableName($pm_table_name_or_num, true);
     }
     if (!$t_instance) {
         return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id] = false;
     }
     $vs_table_name = $t_instance->tableName();
     $vn_table_num = $t_instance->tableNum();
     if (!isset($pa_options['editorPref'])) {
         $pa_options['editorPref'] = 'cataloguing';
     }
     switch ($pa_options['editorPref']) {
         case 'quickadd':
             $va_uis_by_type = $po_request->user->getPreference("quickadd_{$vs_table_name}_editor_ui");
             break;
         default:
             $va_uis_by_type = $po_request->user->getPreference("cataloguing_{$vs_table_name}_editor_ui");
             break;
     }
     $va_available_uis_by_type = $po_request->user->_getUIListByType($vn_table_num);
     $vn_type_id = $pn_type_id;
     if ($vn_type_id && $va_uis_by_type) {
         if (!is_array($va_uis_by_type)) {
             if (!isset($va_available_uis_by_type[$vn_type_id][$va_uis_by_type]) && !isset($va_available_uis_by_type['__all__'][$va_uis_by_type])) {
                 $vn_type_id = null;
             }
             $va_uis_by_type = array();
         } else {
             if (!isset($va_available_uis_by_type[$vn_type_id][$va_uis_by_type[$vn_type_id]]) && !isset($va_available_uis_by_type['__all__'][$va_uis_by_type[$vn_type_id]])) {
                 $vn_type_id = null;
             }
         }
     }
     $t_ui = new ca_editor_uis();
     // If table supports null types take type_id=null to be  "none" rather than a signal to allow any type of editor
     if (!$vn_type_id && method_exists($t_instance, "getTypeFieldName") && (bool) $t_instance->getFieldInfo($t_instance->getTypeFieldName(), 'IS_NULL')) {
         $vn_type_id = '_NONE_';
     }
     if (!$vn_type_id || !($vn_rc = $t_ui->load($va_uis_by_type[$vn_type_id]))) {
         $va_ui_ids = ca_editor_uis::getAvailableUIs($vn_table_num, $po_request, $vn_type_id, true);
         if (sizeof($va_ui_ids) == 0) {
             return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id] = false;
         }
         $va_tmp = array_keys($va_ui_ids);
         if ($t_ui->load($va_tmp[0])) {
             return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id] = $t_ui;
         }
         return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id] = false;
     }
     return ca_editor_uis::$s_default_ui_cache[$pm_table_name_or_num . '/' . $pn_type_id] = $t_ui;
 }