public function processUserInterfaces() { require_once __CA_MODELS_DIR__ . "/ca_editor_uis.php"; require_once __CA_MODELS_DIR__ . "/ca_editor_ui_screens.php"; require_once __CA_MODELS_DIR__ . "/ca_lists.php"; require_once __CA_MODELS_DIR__ . "/ca_list_items.php"; require_once __CA_MODELS_DIR__ . "/ca_relationship_types.php"; $vo_dm = Datamodel::load(); $t_list = new ca_lists(); $t_rel_types = new ca_relationship_types(); $va_uis = array(); if ($this->ops_base_name) { // "merge" profile and its base foreach ($this->opo_base->userInterfaces->children() as $vo_ui) { $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui; } foreach ($this->opo_profile->userInterfaces->children() as $vo_ui) { $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui; } } else { foreach ($this->opo_profile->userInterfaces->children() as $vo_ui) { $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui; } } foreach ($va_uis as $vs_ui_code => $vo_ui) { $vs_type = self::getAttribute($vo_ui, "type"); if (!($vn_type = $vo_dm->getTableNum($vs_type))) { $this->addError("Invalid type {$vs_type} for UI code {$vs_ui_code}"); return false; } // model instance of UI type $t_instance = $vo_dm->getInstanceByTableNum($vn_type); // create ui row $t_ui = ca_editor_uis::find(array('editor_code' => $vs_ui_code, 'editor_type' => $vn_type), array('returnAs' => 'firstModelInstance')); $t_ui = $t_ui ? $t_ui : new ca_editor_uis(); $t_ui->setMode(ACCESS_WRITE); $t_ui->set('user_id', null); $t_ui->set('is_system_ui', 1); $t_ui->set('editor_code', $vs_ui_code); $t_ui->set('editor_type', $vn_type); if ($t_ui->getPrimaryKey()) { $t_ui->update(); } else { $t_ui->insert(); } if ($t_ui->numErrors()) { $this->addError("Errors inserting UI {$vs_ui_code}: " . join("; ", $t_ui->getErrors())); return false; } $vn_ui_id = $t_ui->getPrimaryKey(); self::addLabelsFromXMLElement($t_ui, $vo_ui->labels, $this->opa_locales); // create ui type restrictions if ($vo_ui->typeRestrictions) { foreach ($vo_ui->typeRestrictions->children() as $vo_restriction) { $vs_restriction_type = self::getAttribute($vo_restriction, "type"); if (strlen($vs_restriction_type) > 0) { // interstitial with type restriction -> code is relationship type code if ($t_instance instanceof BaseRelationshipModel) { $vn_type_id = $t_rel_types->getRelationshipTypeID($t_instance->tableName(), $vs_restriction_type); } else { // "normal" type restriction -> code is from actual type list $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName()); $vn_type_id = $t_list->getItemIDFromList($vs_type_list_name, $vs_restriction_type); } if ($vn_type_id) { $t_ui->addTypeRestriction($vn_type_id); } } } } // create ui screens foreach ($vo_ui->screens->children() as $vo_screen) { $vs_screen_idno = self::getAttribute($vo_screen, "idno"); $vn_is_default = self::getAttribute($vo_screen, "default"); $t_ui_screens = ca_editor_ui_screens::find(array('idno' => $vs_screen_idno, 'ui_id' => $vn_ui_id), array('returnAs' => 'firstModelInstance')); $t_ui_screens = $t_ui_screens ? $t_ui_screens : new ca_editor_ui_screens(); $t_ui_screens->setMode(ACCESS_WRITE); $t_ui_screens->set('idno', $vs_screen_idno); $t_ui_screens->set('ui_id', $vn_ui_id); $t_ui_screens->set('is_default', $vn_is_default); if ($t_ui_screens->getPrimaryKey()) { $t_ui_screens->update(); } else { $t_ui_screens->set('parent_id', null); $t_ui_screens->insert(); } if ($t_ui_screens->numErrors()) { $this->addError("Errors inserting UI screen {$vs_screen_idno} for UI {$vs_ui_code}: " . join("; ", $t_ui_screens->getErrors())); return false; } self::addLabelsFromXMLElement($t_ui_screens, $vo_screen->labels, $this->opa_locales); $va_available_bundles = $t_ui_screens->getAvailableBundles(null, array('dontCache' => true)); // create ui bundle placements foreach ($vo_screen->bundlePlacements->children() as $vo_placement) { $vs_placement_code = self::getAttribute($vo_placement, "code"); $vs_bundle = trim((string) $vo_placement->bundle); $va_settings = $this->_processSettings(null, $vo_placement->settings); $t_ui_screens->addPlacement($vs_bundle, $vs_placement_code, $va_settings, null, array('additional_settings' => $va_available_bundles[$vs_bundle]['settings'])); } // create ui screen type restrictions if ($vo_screen->typeRestrictions) { foreach ($vo_screen->typeRestrictions->children() as $vo_restriction) { $vs_restriction_type = self::getAttribute($vo_restriction, "type"); if (strlen($vs_restriction_type) > 0) { // interstitial with type restriction -> code is relationship type code if ($t_instance instanceof BaseRelationshipModel) { $vn_type_id = $t_rel_types->getRelationshipTypeID($t_instance->tableName(), $vs_restriction_type); } else { // "normal" type restriction -> code is from actual type list $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName()); $vn_type_id = $t_list->getItemIDFromList($vs_type_list_name, $vs_restriction_type); } if ($vn_type_id) { $t_ui_screens->addTypeRestriction($vn_type_id); } } } } } // set user and group access if ($vo_ui->userAccess) { $t_user = new ca_users(); $va_ui_users = array(); foreach ($vo_ui->userAccess->children() as $vo_permission) { $vs_user = trim((string) self::getAttribute($vo_permission, "user")); $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access')); if ($vn_access && $t_user->load(array('user_name' => $vs_user))) { $va_ui_users[$t_user->getUserID()] = $vn_access; } else { $this->addError("User name or access value invalid for UI {$vs_ui_code} (permission item with user name '{$vs_user}')"); } } if (sizeof($va_ui_users) > 0) { $t_ui->addUsers($va_ui_users); } } if ($vo_ui->groupAccess) { $t_group = new ca_user_groups(); $va_ui_groups = array(); foreach ($vo_ui->groupAccess->children() as $vo_permission) { $vs_group = trim((string) self::getAttribute($vo_permission, "group")); $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access')); if ($vn_access && $t_group->load(array('code' => $vs_group))) { $va_ui_groups[$t_group->getPrimaryKey()] = $vn_access; } else { $this->addError("Group code or access value invalid for UI {$vs_ui_code} (permission item with group code '{$vs_group}')"); } } if (sizeof($va_ui_groups) > 0) { $t_ui->addUserGroups($va_ui_groups); } } } return true; }