public function save() { $db = PearDatabase::getInstance(); $ruleId = $this->getId(); if (!$ruleId) { $ruleId = $db->getUniqueId('vtiger_datashare_module_rel'); $this->set('shareid', $ruleId); $db->pquery("INSERT INTO vtiger_datashare_module_rel(shareid, tabid) VALUES(?,?)", array($ruleId, $this->getModule()->getId())); } else { $relationTypeComponents = explode('::', $this->get('relationtype')); $sourceType = $relationTypeComponents[0]; $targetType = $relationTypeComponents[1]; $tableColumnInfo = self::$dataShareTableColArr[$sourceType][$targetType]; $tableName = $tableColumnInfo['table']; $sourceColumnName = $tableColumnInfo['source_id']; $targetColumnName = $tableColumnInfo['target_id']; $db->pquery("DELETE FROM {$tableName} WHERE shareid=?", array($ruleId)); } $sourceId = $this->get('source_id'); $sourceIdComponents = Settings_SharingAccess_RuleMember_Model::getIdComponentsFromQualifiedId($sourceId); $sourceType = array_search($sourceIdComponents[0], self::$ruleMemberToRelationMapping); $targetId = $this->get('target_id'); $targetIdComponents = Settings_SharingAccess_RuleMember_Model::getIdComponentsFromQualifiedId($targetId); $targetType = array_search($targetIdComponents[0], self::$ruleMemberToRelationMapping); $tableColumnName = self::$dataShareTableColArr[$sourceType][$targetType]; $tableName = $tableColumnName['table']; $sourceColumnName = $tableColumnName['source_id']; $targetColumnName = $tableColumnName['target_id']; $this->set('relationtype', implode('::', array($sourceType, $targetType))); $permission = $this->get('permission'); $sql = "INSERT INTO {$tableName} (shareid, {$sourceColumnName}, {$targetColumnName}, permission) VALUES (?,?,?,?)"; $params = array($ruleId, $sourceIdComponents[1], $targetIdComponents[1], $permission); $db->pquery($sql, $params); $sql = 'UPDATE vtiger_datashare_module_rel SET relationtype=? WHERE shareid=?'; $params = array($this->get('relationtype'), $ruleId); $db->pquery($sql, $params); Settings_SharingAccess_Module_Model::recalculateSharingRules(); }
public function save() { $db = PearDatabase::getInstance(); $ruleId = $this->getId(); if (!$ruleId) { $ruleId = $db->getUniqueId('vtiger_datashare_module_rel'); $this->set('shareid', $ruleId); $db->insert('vtiger_datashare_module_rel', ['shareid' => $ruleId, 'tabid' => $this->getModule()->getId()]); } else { $relationTypeComponents = explode('::', $this->get('relationtype')); $sourceType = $relationTypeComponents[0]; $targetType = $relationTypeComponents[1]; $tableColumnInfo = self::$dataShareTableColArr[$sourceType][$targetType]; $tableName = $tableColumnInfo['table']; $sourceColumnName = $tableColumnInfo['source_id']; $targetColumnName = $tableColumnInfo['target_id']; $db->delete($tableName, 'shareid = ?', [$ruleId]); } $sourceId = $this->get('source_id'); $sourceIdComponents = Settings_SharingAccess_RuleMember_Model::getIdComponentsFromQualifiedId($sourceId); $sourceType = array_search($sourceIdComponents[0], self::$ruleMemberToRelationMapping); $targetId = $this->get('target_id'); $targetIdComponents = Settings_SharingAccess_RuleMember_Model::getIdComponentsFromQualifiedId($targetId); $targetType = array_search($targetIdComponents[0], self::$ruleMemberToRelationMapping); $tableColumnName = self::$dataShareTableColArr[$sourceType][$targetType]; $tableName = $tableColumnName['table']; $sourceColumnName = $tableColumnName['source_id']; $targetColumnName = $tableColumnName['target_id']; $this->set('relationtype', implode('::', array($sourceType, $targetType))); $db->insert($tableName, ['shareid' => $ruleId, $sourceColumnName => $sourceIdComponents[1], $targetColumnName => $targetIdComponents[1], 'permission' => $this->get('permission')]); $db->update('vtiger_datashare_module_rel', ['relationtype' => $this->get('relationtype')], 'shareid = ?', [$ruleId]); Settings_SharingAccess_Module_Model::recalculateSharingRules(); }