/** * Set access setting for given source * * @param string $ps_table the table the bundle belongs to * @param string $pm_source_id_or_code the primary key or code for the type list item * @param int $pn_access access level, __CA_BUNDLE_ACCESS_NONE__, __CA_BUNDLE_ACCESS_READONLY__ or __CA_BUNDLE_ACCESS_EDIT__ * @param bool $pb_is_default Mark source as default for this table * @return boolean success or not */ public function setAccessSettingForSource($ps_table, $pm_source_id_or_code, $pn_access, $pb_is_default = false) { if (!in_array($pn_access, array(__CA_BUNDLE_ACCESS_NONE__, __CA_BUNDLE_ACCESS_READONLY__, __CA_BUNDLE_ACCESS_EDIT__))) { return false; } if (!$this->getPrimaryKey()) { return false; } //if(!$this->getAppConfig()->get('perform_source_access_checking')) { return false; } $o_dm = Datamodel::load(); $t_list = new ca_lists(); $va_vars = $this->get('vars'); if (!is_array($va_vars)) { $va_vars = array(); } if (!isset($va_vars['source_access_settings'])) { $va_vars['source_access_settings'] = array(); } $t_instance = $o_dm->getInstanceByTableName($ps_table, true); if (!$t_instance) { return false; } if (!($vs_list_code = $t_instance->getSourceListCode())) { return false; } // convert idno to id if (!is_numeric($pm_source_id_or_code)) { if (!$t_list->itemIsInList($vs_list_code, $pm_source_id_or_code)) { return false; } $pm_source_id_or_code = ca_lists::getItemID($vs_list_code, $pm_source_id_or_code); } if (!$t_list->itemIDIsInList($vs_list_code, $pm_source_id_or_code)) { return false; } $va_vars['source_access_settings'][$ps_table . "." . $pm_source_id_or_code] = $pn_access; if ($pb_is_default) { $va_vars['source_access_settings'][$ps_table . '_default_id'] = $pm_source_id_or_code; } $this->set('vars', $va_vars); $vn_old_mode = $this->getMode(); $this->setMode(ACCESS_WRITE); $this->update(); $this->setMode($vn_old_mode); if ($this->numErrors() > 0) { return false; } return true; }