/** * Set related list information between other module * @param Vtiger_Module Instance of target module with which relation should be setup * @param String Label to display in related list (default is target module name) * @param Array List of action button to show ('ADD', 'SELECT') * @param String Callback function name of this module to use as handler * * @internal Creates table vtiger_crmentityrel if it does not exists */ function setRelatedList($moduleInstance, $label = '', $actions = false, $functionName = 'get_related_list') { $adb = PearDatabase::getInstance(); if (empty($moduleInstance)) { return; } if (empty($label)) { $label = $moduleInstance->name; } $result = $adb->pquery('SELECT relation_id FROM vtiger_relatedlists WHERE tabid=? AND related_tabid = ? AND name = ? AND label = ?;', [$this->id, $moduleInstance->id, $functionName, $label]); if ($result->rowCount() > 0) { self::log("Setting relation with {$moduleInstance->name} [{$useactions_text}] ... Error, the related module already exists"); return; } $sequence = $this->__getNextRelatedListSequence(); $presence = 0; // 0 - Enabled, 1 - Disabled // Allow ADD action of other module records (default) if ($actions === false) { $actions = ['ADD']; } $useactionsText = $actions; if (is_array($actions)) { $useactionsText = implode(',', $actions); } $useactionsText = strtoupper($useactionsText); $adb->insert('vtiger_relatedlists', ['relation_id' => $adb->getUniqueID('vtiger_relatedlists'), 'tabid' => $this->id, 'related_tabid' => $moduleInstance->id, 'name' => $functionName, 'sequence' => $sequence, 'label' => $label, 'presence' => $presence, 'actions' => $useactionsText]); if ($functionName == 'get_many_to_many') { $refTableName = Vtiger_Relation_Model::getReferenceTableInfo($moduleInstance->name, $this->name); if (!Vtiger_Utils::CheckTable($refTableName['table'])) { Vtiger_Utils::CreateTable($refTableName['table'], '(crmid INT(19) ,relcrmid INT(19),KEY crmid (crmid),KEY relcrmid (relcrmid))', true); } } self::log("Setting relation with {$moduleInstance->name} [{$useactions_text}] ... DONE"); }
public function getRelationQueryM2M($recordId, $relatedModule, $relationModel) { $referenceInfo = Vtiger_Relation_Model::getReferenceTableInfo($this->getName(), $relatedModule->getName()); $basetable = $relatedModule->get('basetable'); $query = 'SELECT vtiger_crmentity.*, ' . $basetable . '.*' . ' FROM ' . $basetable; $query .= ' INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = ' . $basetable . '.' . $relatedModule->get('basetableid'); $query .= ' INNER JOIN ' . $referenceInfo['table'] . ' ON ' . $referenceInfo['table'] . '.' . $referenceInfo['base'] . ' = vtiger_crmentity.crmid'; $query .= ' LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid'; $query .= ' LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid'; $query .= ' WHERE vtiger_crmentity.deleted = 0 AND ' . $referenceInfo['table'] . '.' . $referenceInfo['rel'] . ' = ' . $recordId; return $query; }