/** * Sets restrictions for currently loaded screen * * @param array $pa_type_ids list of types to restrict to * @return bool True on success, false on error, null if no screen is loaded * */ public function setTypeRestrictions($pa_type_ids) { if (!($vn_screen_id = $this->getPrimaryKey())) { return null; } // screen must be loaded if (!is_array($pa_type_ids)) { if (is_numeric($pa_type_ids)) { $pa_type_ids = array($pa_type_ids); } else { $pa_type_ids = array(); } } $t_ui = new ca_editor_uis(); if (!($t_instance = $this->_DATAMODEL->getInstanceByTableNum($this->getTableNum()))) { return false; } if ($this->inTransaction()) { $t_instance->setTransaction($this->getTransaction()); $t_ui->setTransaction($this->getTransaction()); } if (!$t_ui->load($this->get('ui_id'))) { return false; } if ($t_instance instanceof BaseRelationshipModel) { // interstitial type restrictions $va_type_list = $t_instance->getRelationshipTypes(); } else { // "normal" (list-based) type restrictions $va_type_list = $t_instance->getTypeList(); } $va_current_restrictions = $this->getTypeRestrictions(); $va_current_type_ids = array(); foreach ($va_current_restrictions as $vn_i => $va_restriction) { $va_current_type_ids[$va_restriction['type_id']] = true; } foreach ($va_type_list as $vn_type_id => $va_type_info) { if (in_array($vn_type_id, $pa_type_ids)) { // need to set if (!isset($va_current_type_ids[$vn_type_id])) { $this->addTypeRestriction($vn_type_id); } } else { // need to unset if (isset($va_current_type_ids[$vn_type_id])) { $this->removeTypeRestriction($vn_type_id); } } } return true; }