public function getUIsAsDOM()
 {
     $t_list = new ca_lists();
     $t_rel_type = new ca_relationship_types();
     $vo_uis = $this->opo_dom->createElement("userInterfaces");
     $qr_uis = $this->opo_db->query("SELECT * FROM ca_editor_uis ORDER BY ui_id");
     while ($qr_uis->nextRow()) {
         $vo_ui = $this->opo_dom->createElement("userInterface");
         $t_ui = new ca_editor_uis($qr_uis->get("ui_id"));
         $vs_type = $this->opo_dm->getTableName($qr_uis->get("editor_type"));
         if (strlen($vs_code = $qr_uis->get("editor_code")) > 0) {
             $vo_ui->setAttribute("code", $this->makeIDNO($vs_code));
         } else {
             $vo_ui->setAttribute("code", "standard_{$vs_type}_ui");
         }
         $vo_ui->setAttribute("type", $vs_type);
         // labels
         $vo_labels = $this->opo_dom->createElement("labels");
         $qr_ui_labels = $this->opo_db->query("SELECT * FROM ca_editor_ui_labels WHERE ui_id=?", $qr_uis->get("ui_id"));
         if ($qr_ui_labels->numRows() > 0) {
             while ($qr_ui_labels->nextRow()) {
                 if ($vs_locale = $this->opt_locale->localeIDToCode($qr_ui_labels->get("locale_id"))) {
                     $vo_label = $this->opo_dom->createElement("label");
                     $vo_label->setAttribute("locale", $vs_locale);
                     $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_ui_labels->get("name"))));
                     $vo_labels->appendChild($vo_label);
                 }
             }
         } else {
             $vo_label = $this->opo_dom->createElement("label");
             $vo_label->setAttribute("locale", "en_US");
             $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($vs_code)));
             $vo_labels->appendChild($vo_label);
         }
         $vo_ui->appendChild($vo_labels);
         // type restrictions
         $va_ui_type_restrictions = $t_ui->getTypeRestrictions();
         if (sizeof($va_ui_type_restrictions) > 0) {
             $vo_ui_type_restrictions = $this->opo_dom->createElement("typeRestrictions");
             $vo_ui->appendChild($vo_ui_type_restrictions);
             foreach ($va_ui_type_restrictions as $va_restriction) {
                 $vo_restriction = $this->opo_dom->createElement("restriction");
                 $vo_ui_type_restrictions->appendChild($vo_restriction);
                 /** @var BaseModelWithAttributes $t_instance */
                 $t_instance = $this->opo_dm->getInstanceByTableNum($va_restriction["table_num"]);
                 if ($t_instance instanceof BaseRelationshipModel) {
                     $t_rel_type->load($va_restriction["type_id"]);
                     $vo_restriction->setAttribute("type", $t_rel_type->get('type_code'));
                 } else {
                     $vs_type_code = $t_instance->getTypeListCode();
                     $va_item = $t_list->getItemFromListByItemID($vs_type_code, $va_restriction["type_id"]);
                     $vo_restriction->setAttribute("type", $va_item["idno"]);
                 }
             }
         }
         // User and group access
         $va_users = $t_ui->getUsers();
         if (sizeof($va_users) > 0) {
             $vo_user_access = $this->opo_dom->createElement("userAccess");
             $vo_ui->appendChild($vo_user_access);
             foreach ($va_users as $va_user_info) {
                 $vo_permission = $this->opo_dom->createElement("permission");
                 $vo_user_access->appendChild($vo_permission);
                 $vo_permission->setAttribute("user", $va_user_info["user_name"]);
                 $vo_permission->setAttribute("access", $this->_convertUserGroupAccessToString(intval($va_user_info['access'])));
             }
         }
         $va_groups = $t_ui->getUserGroups();
         if (sizeof($va_groups) > 0) {
             $vo_group_access = $this->opo_dom->createElement("groupAccess");
             $vo_ui->appendChild($vo_group_access);
             foreach ($va_groups as $va_group_info) {
                 $vo_permission = $this->opo_dom->createElement("permission");
                 $vo_group_access->appendChild($vo_permission);
                 $vo_permission->setAttribute("group", $va_group_info["code"]);
                 $vo_permission->setAttribute("access", $this->_convertUserGroupAccessToString(intval($va_group_info['access'])));
             }
         }
         // screens
         $vo_screens = $this->opo_dom->createElement("screens");
         $qr_screens = $this->opo_db->query("SELECT * FROM ca_editor_ui_screens WHERE parent_id IS NOT NULL AND ui_id=? ORDER BY rank,screen_id", $qr_uis->get("ui_id"));
         while ($qr_screens->nextRow()) {
             $t_screen = new ca_editor_ui_screens($qr_screens->get("screen_id"));
             $vo_screen = $this->opo_dom->createElement("screen");
             if ($vs_idno = $qr_screens->get("idno")) {
                 $vo_screen->setAttribute("idno", $this->makeIDNO($vs_idno));
             }
             $vo_screen->setAttribute("default", $qr_screens->get("is_default"));
             $vo_labels = $this->opo_dom->createElement("labels");
             $qr_screen_labels = $this->opo_db->query("SELECT * FROM ca_editor_ui_screen_labels WHERE screen_id=?", $qr_screens->get("screen_id"));
             if ($qr_ui_labels->numRows() > 0) {
                 while ($qr_screen_labels->nextRow()) {
                     if ($vs_locale = $this->opt_locale->localeIDToCode($qr_screen_labels->get("locale_id"))) {
                         $vo_label = $this->opo_dom->createElement("label");
                         $vo_label->setAttribute("locale", $vs_locale);
                         $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_screen_labels->get("name"))));
                         if (strlen(trim($qr_screen_labels->get("description"))) > 0) {
                             $vo_label->appendChild($this->opo_dom->createElement("description", caEscapeForXML($qr_screen_labels->get("description"))));
                         }
                         $vo_labels->appendChild($vo_label);
                     }
                 }
             } else {
                 $vo_label = $this->opo_dom->createElement("label");
                 $vo_label->setAttribute("locale", "en_US");
                 $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($vs_code)));
                 $vo_labels->appendChild($vo_label);
             }
             $vo_screen->appendChild($vo_labels);
             if (is_array($t_screen->getTypeRestrictions()) && sizeof($t_screen->getTypeRestrictions()) > 0) {
                 $vo_type_restrictions = $this->opo_dom->createElement("typeRestrictions");
                 foreach ($t_screen->getTypeRestrictions() as $va_restriction) {
                     $vo_type_restriction = $this->opo_dom->createElement("restriction");
                     $t_instance = $this->opo_dm->getInstanceByTableNum($va_restriction["table_num"]);
                     if ($t_instance instanceof BaseRelationshipModel) {
                         $t_rel_type->load($va_restriction["type_id"]);
                         $vo_type_restriction->setAttribute("type", $t_rel_type->get('type_code'));
                     } else {
                         $vs_type_code = $t_instance->getTypeListCode();
                         $va_item = $t_list->getItemFromListByItemID($vs_type_code, $va_restriction["type_id"]);
                         $vo_type_restriction->setAttribute("type", $va_item["idno"]);
                     }
                     $vo_type_restrictions->appendChild($vo_type_restriction);
                 }
                 $vo_screen->appendChild($vo_type_restrictions);
             }
             $vo_placements = $this->opo_dom->createElement("bundlePlacements");
             $va_placements = $t_screen->getPlacementsInScreen();
             if (is_array($va_placements)) {
                 foreach ($va_placements as $va_placement) {
                     $vo_placement = $this->opo_dom->createElement("placement");
                     $vo_placements->appendChild($vo_placement);
                     $vo_placement->setAttribute("code", $this->makeIDNO($va_placement["placement_code"]));
                     $vo_placement->appendChild($this->opo_dom->createElement("bundle", caEscapeForXML($va_placement["bundle"])));
                     if (is_array($va_placement["settings"])) {
                         $vo_settings = $this->opo_dom->createElement("settings");
                         foreach ($va_placement["settings"] as $vs_setting => $va_values) {
                             if (is_null($va_values)) {
                                 continue;
                             }
                             if (!is_array($va_values)) {
                                 $va_values = array($va_values);
                             }
                             // account for legacy settings
                             if ($vs_setting == "restrict_to_type") {
                                 $vs_setting = "restrict_to_types";
                             }
                             foreach ($va_values as $vs_key => $vs_value) {
                                 switch ($vs_setting) {
                                     case 'restrict_to_types':
                                         $t_item = new ca_list_items($vs_value);
                                         if ($t_item->getPrimaryKey()) {
                                             $vs_value = $t_item->get('idno');
                                         }
                                         break;
                                     case 'restrict_to_lists':
                                         $t_list = new ca_lists($vs_value);
                                         if ($t_list->getPrimaryKey()) {
                                             $vs_value = $t_list->get('list_code');
                                         }
                                         break;
                                     case 'restrict_to_relationship_types':
                                         $t_rel_type = new ca_relationship_types($vs_value);
                                         if ($t_rel_type->getPrimaryKey()) {
                                             $vs_value = $t_rel_type->get('type_code');
                                         }
                                         break;
                                 }
                                 if (strlen($vs_value) > 0) {
                                     // caEscapeForXML mangles zero values for some reason -> catch them here.
                                     if ($vs_value === 0 || $vs_value === "0") {
                                         $vs_setting_val = $vs_value;
                                     } else {
                                         $vs_setting_val = caEscapeForXML($vs_value);
                                     }
                                     $vo_setting = @$this->opo_dom->createElement("setting", $vs_setting_val);
                                     $vo_setting->setAttribute("name", $vs_setting);
                                     if ($vs_setting == "label" || $vs_setting == "add_label" || $vs_setting == "description") {
                                         if (preg_match("/^[a-z]{2,3}\\_[A-Z]{2,3}\$/", $vs_key)) {
                                             $vo_setting->setAttribute("locale", $vs_key);
                                         } else {
                                             continue;
                                         }
                                     }
                                     $vo_settings->appendChild($vo_setting);
                                 }
                             }
                         }
                         $vo_placement->appendChild($vo_settings);
                     }
                 }
             }
             $vo_screen->appendChild($vo_placements);
             $vo_screens->appendChild($vo_screen);
         }
         $vo_ui->appendChild($vo_screens);
         $vo_uis->appendChild($vo_ui);
     }
     return $vo_uis;
 }
예제 #2
0
 public function getUIsAsDOM()
 {
     $t_list = new ca_lists();
     $vo_uis = $this->opo_dom->createElement("userInterfaces");
     $qr_uis = $this->opo_db->query("SELECT * FROM ca_editor_uis ORDER BY ui_id");
     while ($qr_uis->nextRow()) {
         $vo_ui = $this->opo_dom->createElement("userInterface");
         $vs_type = $this->opo_dm->getTableName($qr_uis->get("editor_type"));
         if (strlen($vs_code = $qr_uis->get("editor_code")) > 0) {
             $vo_ui->setAttribute("code", $this->makeIDNO($vs_code));
         } else {
             $vo_ui->setAttribute("code", "standard_{$vs_type}_ui");
         }
         $vo_ui->setAttribute("type", $vs_type);
         $vo_labels = $this->opo_dom->createElement("labels");
         $qr_ui_labels = $this->opo_db->query("SELECT * FROM ca_editor_ui_labels WHERE ui_id=?", $qr_uis->get("ui_id"));
         if ($qr_ui_labels->numRows() > 0) {
             while ($qr_ui_labels->nextRow()) {
                 if ($vs_locale = $this->opt_locale->localeIDToCode($qr_ui_labels->get("locale_id"))) {
                     $vo_label = $this->opo_dom->createElement("label");
                     $vo_label->setAttribute("locale", $vs_locale);
                     $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_ui_labels->get("name"))));
                     $vo_labels->appendChild($vo_label);
                 }
             }
         } else {
             $vo_label = $this->opo_dom->createElement("label");
             $vo_label->setAttribute("locale", "en_US");
             $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($vs_code)));
             $vo_labels->appendChild($vo_label);
         }
         $vo_ui->appendChild($vo_labels);
         $vo_screens = $this->opo_dom->createElement("screens");
         $qr_screens = $this->opo_db->query("SELECT * FROM ca_editor_ui_screens WHERE parent_id IS NOT NULL AND ui_id=? ORDER BY screen_id", $qr_uis->get("ui_id"));
         while ($qr_screens->nextRow()) {
             $t_screen = new ca_editor_ui_screens($qr_screens->get("screen_id"));
             $vo_screen = $this->opo_dom->createElement("screen");
             if ($vs_idno = $qr_screens->get("idno")) {
                 $vo_screen->setAttribute("idno", $this->makeIDNO($vs_idno));
             }
             $vo_screen->setAttribute("default", $qr_screens->get("is_default"));
             $vo_labels = $this->opo_dom->createElement("labels");
             $qr_screen_labels = $this->opo_db->query("SELECT * FROM ca_editor_ui_screen_labels WHERE screen_id=?", $qr_screens->get("screen_id"));
             if ($qr_ui_labels->numRows() > 0) {
                 while ($qr_screen_labels->nextRow()) {
                     if ($vs_locale = $this->opt_locale->localeIDToCode($qr_screen_labels->get("locale_id"))) {
                         $vo_label = $this->opo_dom->createElement("label");
                         $vo_label->setAttribute("locale", $vs_locale);
                         $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_screen_labels->get("name"))));
                         if (strlen(trim($qr_screen_labels->get("description"))) > 0) {
                             $vo_label->appendChild($this->opo_dom->createElement("description", caEscapeForXML($qr_screen_labels->get("description"))));
                         }
                         $vo_labels->appendChild($vo_label);
                     }
                 }
             } else {
                 $vo_label = $this->opo_dom->createElement("label");
                 $vo_label->setAttribute("locale", "en_US");
                 $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($vs_code)));
                 $vo_labels->appendChild($vo_label);
             }
             $vo_screen->appendChild($vo_labels);
             if (is_array($t_screen->getTypeRestrictions()) && sizeof($t_screen->getTypeRestrictions()) > 0) {
                 $vo_type_restrictions = $this->opo_dom->createElement("typeRestrictions");
                 foreach ($t_screen->getTypeRestrictions() as $va_restriction) {
                     $vo_type_restriction = $this->opo_dom->createElement("restriction");
                     $t_instance = $this->opo_dm->getInstanceByTableNum($va_restriction["table_num"]);
                     $vs_type_code = $t_instance->getTypeListCode();
                     $va_item = $t_list->getItemFromListByItemID($vs_type_code, $va_restriction["type_id"]);
                     $vo_type_restriction->setAttribute("type", $va_item["idno"]);
                     $vo_type_restrictions->appendChild($vo_type_restriction);
                 }
                 $vo_screen->appendChild($vo_type_restrictions);
             }
             $vo_placements = $this->opo_dom->createElement("bundlePlacements");
             $va_placements = $t_screen->getPlacementsInScreen();
             if (is_array($va_placements)) {
                 foreach ($va_placements as $va_placement) {
                     $vo_placement = $this->opo_dom->createElement("placement");
                     $vo_placements->appendChild($vo_placement);
                     $vo_placement->setAttribute("code", $this->makeIDNO($va_placement["placement_code"]));
                     $vo_placement->appendChild($this->opo_dom->createElement("bundle", caEscapeForXML($va_placement["bundle"])));
                     if (is_array($va_placement["settings"])) {
                         $vo_settings = $this->opo_dom->createElement("settings");
                         foreach ($va_placement["settings"] as $vs_setting => $va_values) {
                             if (is_null($va_values)) {
                                 continue;
                             }
                             if (!is_array($va_values)) {
                                 $va_values = array($va_values);
                             }
                             // account for legacy settings
                             if ($vs_setting == "restrict_to_type") {
                                 $vs_setting = "restrict_to_types";
                             }
                             foreach ($va_values as $vs_key => $vs_value) {
                                 if (strlen($vs_value) > 0) {
                                     if ($vs_value == 0 || $vs_value == "0") {
                                         // caExcapeForXML mangles zero values for some reason -> catch them here.
                                         $vs_setting_val = $vs_value;
                                     } else {
                                         $vs_setting_val = caEscapeForXML($vs_value);
                                     }
                                     $vo_setting = @$this->opo_dom->createElement("setting", $vs_setting_val);
                                     $vo_setting->setAttribute("name", $vs_setting);
                                     if ($vs_setting == "label" || $vs_setting == "add_label" || $vs_setting == "description") {
                                         if (preg_match("/^[a-z]{2,3}\\_[A-Z]{2,3}\$/", $vs_key)) {
                                             $vo_setting->setAttribute("locale", $vs_key);
                                         } else {
                                             continue;
                                         }
                                     }
                                     $vo_settings->appendChild($vo_setting);
                                 }
                             }
                         }
                         $vo_placement->appendChild($vo_settings);
                     }
                 }
             }
             $vo_screen->appendChild($vo_placements);
             $vo_screens->appendChild($vo_screen);
         }
         $vo_ui->appendChild($vo_screens);
         $vo_uis->appendChild($vo_ui);
     }
     return $vo_uis;
 }