예제 #1
0
 public function savePlacementsFromHTMLForm($po_request, $ps_form_prefix, $ps_placement_code)
 {
     if ($vs_bundles = $po_request->getParameter("{$ps_placement_code}{$ps_form_prefix}displayBundleList", pString)) {
         $va_bundles = explode(';', $vs_bundles);
         $t_screen = new ca_editor_ui_screens($this->getPrimaryKey());
         $va_placements = $t_screen->getPlacements(array('user_id' => $po_request->getUserID()));
         // remove deleted bundles
         foreach ($va_placements as $vn_placement_id => $va_bundle_info) {
             if (!in_array($va_bundle_info['bundle_name'] . '_' . $va_bundle_info['placement_id'], $va_bundles)) {
                 $t_screen->removePlacement($va_bundle_info['placement_id'], array('user_id' => $po_request->getUserID()));
                 if ($t_screen->numErrors()) {
                     $this->errors = $t_screen->errors;
                     return false;
                 }
             }
         }
         $va_locale_list = ca_locales::getLocaleList(array('index_by_code' => true));
         $va_available_bundles = $t_screen->getAvailableBundles();
         foreach ($va_bundles as $vn_i => $vs_bundle) {
             // get settings
             if (preg_match('!^(.*)_([\\d]+)$!', $vs_bundle, $va_matches)) {
                 $vn_placement_id = (int) $va_matches[2];
                 $vs_bundle = $va_matches[1];
             } else {
                 $vn_placement_id = null;
             }
             $vs_bundle_proc = str_replace(".", "_", $vs_bundle);
             $va_settings = array();
             foreach ($_REQUEST as $vs_key => $vs_val) {
                 if (preg_match("!^{$vs_bundle_proc}_([\\d]+)_(.*)\$!", $vs_key, $va_matches)) {
                     // is this locale-specific?
                     if (preg_match('!(.*)_([a-z]{2}_[A-Z]{2})$!', $va_matches[2], $va_locale_matches)) {
                         $vn_locale_id = isset($va_locale_list[$va_locale_matches[2]]) ? (int) $va_locale_list[$va_locale_matches[2]]['locale_id'] : 0;
                         // NOTE: we set keys for both locale_id (which how other placement-using editor like ca_search_forms and
                         // ca_bundle_displays do) *AND* the locale code (eg. "en_US"). This is because the settings created in profile and
                         // in pre v1.1 systems are keyed by code, not locale_id. There's nothing wrong with using code - it's just as unique as the locale_id
                         // and it's convenient to use both interchangeably in any event.
                         //
                         $va_settings[(int) $va_matches[1]][$va_locale_matches[1]][$vn_locale_id] = $va_settings[(int) $va_matches[1]][$va_locale_matches[1]][$va_locale_matches[2]] = $vs_val;
                     } else {
                         $va_settings[(int) $va_matches[1]][$va_matches[2]] = $vs_val;
                     }
                 }
             }
             if ($vn_placement_id === 0) {
                 $t_screen->addPlacement($vs_bundle, $vs_bundle . ($vn_i + 1), $va_settings[$vn_placement_id], $vn_i + 1, array('user_id' => $po_request->getUserID(), 'additional_settings' => $va_available_bundles[$vs_bundle]['settings']));
                 if ($t_screen->numErrors()) {
                     $this->errors = $t_screen->errors;
                     return false;
                 }
             } else {
                 $t_placement = new ca_editor_ui_bundle_placements($vn_placement_id, $va_available_bundles[$vs_bundle]['settings']);
                 $t_placement->setMode(ACCESS_WRITE);
                 $t_placement->set('rank', $vn_i + 1);
                 if (is_array($va_settings[$vn_placement_id])) {
                     foreach ($t_placement->getAvailableSettings() as $vs_setting => $va_setting_info) {
                         $vs_val = isset($va_settings[$vn_placement_id][$vs_setting]) ? $va_settings[$vn_placement_id][$vs_setting] : null;
                         $t_placement->setSetting($vs_setting, $vs_val);
                     }
                 }
                 $t_placement->update();
                 if ($t_placement->numErrors()) {
                     $this->errors = $t_placement->errors;
                     return false;
                 }
             }
         }
     }
     return true;
 }
예제 #2
0
 /** 
  *
  */
 public function addScreen($ps_name, $pn_locale_id, $ps_idno, $ps_color = '000000', $is_default = false)
 {
     if (!$this->getPrimaryKey()) {
         return false;
     }
     $t_screen = new ca_editor_ui_screens();
     $t_screen->setMode(ACCESS_WRITE);
     $t_screen->set('idno', $ps_idno);
     $t_screen->set('ui_id', $this->getPrimaryKey());
     $t_screen->set('color', $ps_color);
     $t_screen->set('is_default', (bool) $is_default ? 1 : 0);
     $t_screen->insert();
     if ($t_screen->numErrors()) {
         $this->errors = $t_screen->errors;
         return false;
     }
     $t_screen->addLabel(array('name' => $ps_name), $pn_locale_id, null, true);
     if ($t_screen->numErrors()) {
         $this->errors = $t_screen->errors;
         $t_screen->delete(true);
         return false;
     }
     return $t_screen;
 }
예제 #3
0
 /**
  * Checks for presence of configuration for ca_editor_uis and ca_editor_ui_screens editors, and if not
  * present, loads a default configuration. Since these editors are used to configure themselves, lack of 
  * configuration (the case with all pre-version 1.1 installations), will effectively make it impossible to 
  * change the setup for any editor in the installation.
  *
  * @return bool Returns true on success (either UI already exists or was created successfully), false on error (UI does not exist and could not be created)
  *
  */
 public function checkConfiguration()
 {
     global $g_ui_locale_id;
     $t_ui = new ca_editor_uis();
     if (!$t_ui->load(array('editor_type' => 101))) {
         $t_ui->setMode(ACCESS_WRITE);
         $t_ui->set('user_id', null);
         $t_ui->set('is_system_ui', 1);
         $t_ui->set('editor_type', 101);
         $t_ui->set('editor_code', 'ui_editor');
         $t_ui->set('color', '000000');
         $t_ui->insert();
         if ($t_ui->numErrors()) {
             return false;
         }
         $t_ui->addLabel(array('name' => 'UI Editor'), $g_ui_locale_id, null, true);
         if ($t_ui->numErrors()) {
             return false;
         }
         $vn_ui_id = $t_ui->getPrimaryKey();
         $t_screen = new ca_editor_ui_screens();
         $t_screen->setMode(ACCESS_WRITE);
         $t_screen->set('ui_id', $vn_ui_id);
         $t_screen->set('idno', 'basic_' . $vn_ui_id);
         $t_screen->set('rank', 1);
         $t_screen->set('default', 1);
         $t_screen->insert();
         if ($t_screen->numErrors()) {
             return false;
         }
         $t_screen->addLabel(array('name' => 'Basic'), $g_ui_locale_id, null, true);
         if ($t_screen->numErrors()) {
             return false;
         }
         $vn_i = 1;
         foreach (array('preferred_labels', 'editor_code', 'color', 'editor_type', 'ca_editor_ui_type_restrictions', 'ca_editor_ui_screens', 'is_system_ui', 'ca_users', 'ca_user_groups', 'ca_user_roles') as $vs_bundle_name) {
             $t_screen->addPlacement($vs_bundle_name, $vs_bundle_name, array(), $vn_i);
             $vn_i++;
         }
     }
     if (!$t_ui->load(array('editor_type' => 100))) {
         $t_ui->setMode(ACCESS_WRITE);
         $t_ui->set('user_id', null);
         $t_ui->set('is_system_ui', 1);
         $t_ui->set('editor_type', 100);
         $t_ui->set('color', 'CC0000');
         $t_ui->set('editor_code', 'ui_screen_editor');
         $t_ui->insert();
         if ($t_ui->numErrors()) {
             return false;
         }
         $t_ui->addLabel(array('name' => 'UI Screen Editor'), $g_ui_locale_id, null, true);
         if ($t_ui->numErrors()) {
             return false;
         }
         $vn_ui_id = $t_ui->getPrimaryKey();
         $t_screen = new ca_editor_ui_screens();
         $t_screen->setMode(ACCESS_WRITE);
         $t_screen->set('ui_id', $vn_ui_id);
         $t_screen->set('idno', 'basic_' . $vn_ui_id);
         $t_screen->set('rank', 1);
         $t_screen->set('default', 1);
         $t_screen->insert();
         if ($t_screen->numErrors()) {
             return false;
         }
         $t_screen->addLabel(array('name' => 'Basic'), $g_ui_locale_id, null, true);
         if ($t_screen->numErrors()) {
             return false;
         }
         $vn_i = 1;
         foreach (array('preferred_labels', 'idno', 'color', 'is_default', 'ca_editor_ui_screen_type_restrictions', 'ca_editor_ui_bundle_placements', 'ca_users', 'ca_user_groups', 'ca_user_roles') as $vs_bundle_name) {
             $t_screen->addPlacement($vs_bundle_name, $vs_bundle_name, array(), $vn_i);
             $vn_i++;
         }
     }
     return true;
 }