コード例 #1
0
 /**
  * Adds restriction (a binding between the display and item type)
  *
  * @param int $pn_type_id the type
  * @param array $pa_settings Array of options for the restriction. (No options are currently implemented).
  * @return bool True on success, false on error, null if no screen is loaded
  * 
  */
 public function addTypeRestriction($pn_type_id, $va_settings = null)
 {
     if (!($vn_display_id = $this->getPrimaryKey())) {
         return null;
     }
     // display must be loaded
     if (!is_array($va_settings)) {
         $va_settings = array();
     }
     if (!($t_instance = $this->_DATAMODEL->getInstanceByTableNum($this->get('table_num')))) {
         return false;
     }
     $va_type_list = $t_instance->getTypeList();
     if (!isset($va_type_list[$pn_type_id])) {
         return false;
     }
     $t_restriction = new ca_bundle_display_type_restrictions();
     if ($this->inTransaction()) {
         $t_restriction->setTransaction($this->getTransaction());
     }
     $t_restriction->setMode(ACCESS_WRITE);
     $t_restriction->set('table_num', $this->get('table_num'));
     $t_restriction->set('type_id', $pn_type_id);
     $t_restriction->set('display_id', $this->getPrimaryKey());
     foreach ($va_settings as $vs_setting => $vs_setting_value) {
         $t_restriction->setSetting($vs_setting, $vs_setting_value);
     }
     $t_restriction->insert();
     if ($t_restriction->numErrors()) {
         $this->errors = $t_restriction->errors();
         return false;
     }
     return true;
 }
コード例 #2
0
 public function processDisplays()
 {
     require_once __CA_MODELS_DIR__ . "/ca_bundle_displays.php";
     require_once __CA_MODELS_DIR__ . "/ca_bundle_display_placements.php";
     require_once __CA_MODELS_DIR__ . "/ca_bundle_display_type_restrictions.php";
     $o_config = Configuration::load();
     $vo_dm = Datamodel::load();
     if ($this->ops_base_name) {
         // "merge" profile and its base
         $va_displays = array();
         if ($this->opo_base->displays) {
             foreach ($this->opo_base->displays->children() as $vo_display) {
                 $va_displays[self::getAttribute($vo_display, "code")] = $vo_display;
             }
         }
         if ($this->opo_profile->displays) {
             foreach ($this->opo_profile->displays->children() as $vo_display) {
                 $va_displays[self::getAttribute($vo_display, "code")] = $vo_display;
             }
         }
     } else {
         if ($this->opo_profile->displays) {
             foreach ($this->opo_profile->displays->children() as $vo_display) {
                 $va_displays[self::getAttribute($vo_display, "code")] = $vo_display;
             }
         }
     }
     if (!is_array($va_displays) || sizeof($va_displays) == 0) {
         return true;
     }
     foreach ($va_displays as $vo_display) {
         $vs_display_code = self::getAttribute($vo_display, "code");
         $vb_system = self::getAttribute($vo_display, "system");
         $vs_table = self::getAttribute($vo_display, "type");
         if ($o_config->get($vs_table . '_disable')) {
             continue;
         }
         $t_display = $this->opb_updating ? ca_bundle_displays::find(array('code' => $vs_display_code, 'type' => $vs_table), array('returnAs' => 'firstModelInstance')) : false;
         $t_display = $t_display ? $t_display : new ca_bundle_displays();
         $t_display->setMode(ACCESS_WRITE);
         $t_display->set("display_code", $vs_display_code);
         $t_display->set("is_system", $vb_system);
         $t_display->set("table_num", $vo_dm->getTableNum($vs_table));
         $t_display->set("user_id", 1);
         // let administrative user own these
         $this->_processSettings($t_display, $vo_display->settings);
         if ($t_display->getPrimaryKey()) {
             $t_display->update();
         } else {
             $t_display->insert();
         }
         if ($t_display->numErrors()) {
             $this->addError("There was an error while inserting display {$vs_display_code}: " . join(" ", $t_display->getErrors()));
         } else {
             self::addLabelsFromXMLElement($t_display, $vo_display->labels, $this->opa_locales);
             if ($t_display->numErrors()) {
                 $this->addError("There was an error while inserting display label for {$vs_display_code}: " . join(" ", $t_display->getErrors()));
             }
             if (!$this->processDisplayPlacements($t_display, $vo_display->bundlePlacements, null)) {
                 return false;
             }
         }
         if ($vo_display->typeRestrictions) {
             foreach ($vo_display->typeRestrictions->children() as $vo_restriction) {
                 $t_list = new ca_lists();
                 $t_list_item = new ca_list_items();
                 $vs_restriction_code = trim((string) self::getAttribute($vo_restriction, "code"));
                 $vs_type = trim((string) self::getAttribute($vo_restriction, "type"));
                 $t_instance = $vo_dm->getInstanceByTableNum($vn_table_num = $vo_dm->getTableNum($vs_table));
                 $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName());
                 if ($vs_type) {
                     $t_list->load(array('list_code' => $vs_type_list_name));
                     $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'idno' => $vs_type));
                 }
                 $vn_type_id = $vs_type ? $t_list_item->getPrimaryKey() : null;
                 $t_restriction = $this->opb_updating ? ca_bundle_display_type_restrictions::find(array('table_num' => $vn_table_num, 'type_id' => $vn_type_id), array('returnAs' => 'firstModelInstance')) : false;
                 $t_restriction = $t_restriction ? $t_restriction : new ca_bundle_display_type_restrictions();
                 $t_restriction->setMode(ACCESS_WRITE);
                 $t_restriction->set('table_num', $vn_table_num);
                 $t_restriction->set('include_subtypes', (bool) $vo_restriction->includeSubtypes ? 1 : 0);
                 $t_restriction->set('type_id', $vn_type_id);
                 $t_restriction->set('display_id', $t_display->getPrimaryKey());
                 $this->_processSettings($t_restriction, $vo_restriction->settings);
                 if ($t_restriction->getPrimaryKey()) {
                     $t_restriction->update();
                 } else {
                     $t_restriction->insert();
                 }
                 if ($t_restriction->numErrors()) {
                     $this->addError("There was an error while inserting type restriction {$vs_restriction_code} in display {$vs_display_code}: " . join("; ", $t_restriction->getErrors()));
                 }
             }
         }
         if ($vo_display->userAccess) {
             $t_user = new ca_users();
             $va_display_users = array();
             foreach ($vo_display->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_display_users[$t_user->getUserID()] = $vn_access;
                 } else {
                     $this->addError("User name or access value invalid for display {$vs_display_code} (permission item with user name '{$vs_user}')");
                 }
             }
             if (sizeof($va_display_users) > 0) {
                 $t_display->addUsers($va_display_users);
             }
         }
         if ($vo_display->groupAccess) {
             $t_group = new ca_user_groups();
             $va_display_groups = array();
             foreach ($vo_display->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_display_groups[$t_group->getPrimaryKey()] = $vn_access;
                 } else {
                     $this->addError("Group code or access value invalid for display {$vs_display_code} (permission item with group code '{$vs_group}')");
                 }
             }
             if (sizeof($va_display_groups) > 0) {
                 $t_display->addUserGroups($va_display_groups);
             }
         }
     }
     return true;
 }