/** * 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"); }
/** * Funtion that returns fields that will be showed in the record selection popup * @return <Array of fields> */ public function getPopupViewFieldsList($sourceModule = false) { if (!empty($sourceModule)) { $parentRecordModel = Vtiger_Module_Model::getInstance($sourceModule); $relationModel = Vtiger_Relation_Model::getInstance($parentRecordModel, $this); } $popupFields = array(); if ($relationModel) { $popupFields = $relationModel->getRelationFields(true); } if (count($popupFields) == 0) { $popupFileds = $this->getSummaryViewFieldsList(); foreach ($popupFileds as $fieldName => $fieldModel) { if ($fieldName === 'folderid' || $fieldName === 'modifiedtime') { unset($popupFileds[$fieldName]); } } $reqPopUpFields = array('File Status' => 'filestatus', 'File Size' => 'filesize', 'File Location Type' => 'filelocationtype'); foreach ($reqPopUpFields as $fieldLabel => $fieldName) { $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $this); if ($fieldModel->getPermissions('readwrite')) { $popupFileds[$fieldName] = $fieldModel; } } $popupFields = array_keys($popupFileds); } return $popupFields; }
public function getRelatedModuleRecordIds(Vtiger_Request $request, $recordIds = []) { $db = PearDatabase::getInstance(); $basicModule = $request->getModule(); $relatedModules = $request->get('related_modules'); $parentModuleModel = Vtiger_Module_Model::getInstance($basicModule); $relatedIds = []; if (!empty($relatedModules)) { foreach ($relatedModules as $relModData) { $relModData = explode('::', $relModData); $relatedModule = $relModData[0]; $type = $relModData[1]; switch ($type) { case 0: $field = $relModData[2]; foreach ($recordIds as $recordId) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $basicModule); if ($recordModel->get($field) != 0 && Vtiger_Functions::getCRMRecordType($recordModel->get($field)) == $relatedModule) { $relatedIds[] = $recordModel->get($field); } } break; case 1: $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $instance = CRMEntity::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModuleModel); $fieldModel = $relationModel->getRelationField(); $tablename = $fieldModel->get('table'); $tabIndex = $instance->table_index; $relIndex = $this->getRelatedFieldName($relatedModule, $basicModule); if (!$relIndex) { break; } $sql = "SELECT vtiger_crmentity.crmid FROM vtiger_crmentity INNER JOIN {$tablename} ON {$tablename}.{$tabIndex} = vtiger_crmentity.crmid\n\t\t\t\t\t\tWHERE {$tablename}.{$relIndex} IN (" . $db->generateQuestionMarks($recordIds) . ")"; $result = $db->pquery($sql, $recordIds); while ($crmid = $db->getSingleValue($result)) { $relatedIds[] = $crmid; } break; case 2: foreach ($recordIds as $recordId) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $basicModule); $relationListView = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModule); $query = $relationListView->getRelationQuery(); $queryEx = explode('FROM', $query, 2); $query = 'SELECT DISTINCT vtiger_crmentity.crmid FROM' . $queryEx[1]; $result = $db->query($query); while ($crmid = $db->getSingleValue($result)) { $relatedIds[] = $crmid; } } break; } $relatedIds = array_unique($relatedIds); } } return $relatedIds; }
/** * Function to save record * @param <Vtiger_Request> $request - values of the record * @return <RecordModel> - record Model of saved record */ public function saveRecord($request) { $adb = PearDatabase::getInstance(); $recordModel = $this->getRecordModelFromRequest($request); $recordModel->save(); $originalRecordId = $recordModel->getId(); if ($request->get('relationOperation')) { $parentModuleName = $request->get('sourceModule'); $parentModuleModel = Vtiger_Module_Model::getInstance($parentModuleName); $parentRecordId = $request->get('sourceRecord'); $relatedModule = $recordModel->getModule(); if ($relatedModule->getName() == 'Events') { $relatedModule = Vtiger_Module_Model::getInstance('Calendar'); } $relatedRecordId = $recordModel->getId(); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModule); $relationModel->addRelation($parentRecordId, $relatedRecordId); } // Handled to save follow up event $followupMode = $request->get('followup'); //Start Date and Time values $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('followup_time_start')); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('followup_date_start') . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $subject = $request->get('subject'); if ($followupMode == 'on' && $startTime != '' && $startDate != '') { $recordModel->set('eventstatus', 'Planned'); $recordModel->set('subject', '[Followup] ' . $subject); $recordModel->set('date_start', $startDate); $recordModel->set('time_start', $startTime); $currentUser = Users_Record_Model::getCurrentUserModel(); $activityType = $recordModel->get('activitytype'); if ($activityType == 'Call') { $minutes = $currentUser->get('callduration'); } else { $minutes = $currentUser->get('othereventduration'); } $dueDateTime = date('Y-m-d H:i:s', strtotime("{$startDateTime}+{$minutes} minutes")); list($startDate, $startTime) = explode(' ', $dueDateTime); $recordModel->set('due_date', $startDate); $recordModel->set('time_end', $startTime); $recordModel->set('recurringtype', ''); $recordModel->set('mode', 'create'); $recordModel->save(); $heldevent = true; } //TODO: remove the dependency on $_REQUEST if ($_REQUEST['recurringtype'] != '' && $_REQUEST['recurringtype'] != '--None--') { vimport('~modules/Calendar/RepeatEvents.php'); $focus = new Activity(); //get all the stored data to this object $focus->column_fields = $recordModel->getData(); Calendar_RepeatEvents::repeatFromRequest($focus); } return $recordModel; }
/** * Function which will specify whether the relation is deletable * @return <Boolean> */ public function isDeletable() { $relatedModuleModel = $this->getRelationModuleModel(); $relatedModuleName = $relatedModuleModel->get('name'); $inventoryModulesList = array('Invoice', 'Quotes', 'PurchaseOrder', 'SalesOrder'); //Inventoty relationship cannot be deleted from the related list if (in_array($relatedModuleName, $inventoryModulesList)) { return false; } return parent::isDeletable(); }
/** * Function that deletes PriceBooks related records information * @param <Integer> $sourceRecordId - PriceBook Id * @param <Integer> $relatedRecordId - Related Record Id */ public function deleteRelation($sourceRecordId, $relatedRecordId) { $sourceModuleName = $this->getParentModuleModel()->get('name'); $destinationModuleName = $this->getRelationModuleModel()->get('name'); if ($sourceModuleName == 'PriceBooks' && ($destinationModuleName == 'Products' || $destinationModuleName == 'Services')) { $priceBookModel = Vtiger_Record_Model::getInstanceById($sourceRecordId, $sourceModuleName); $priceBookModel->deleteListPrice($relatedRecordId); } else { parent::deleteRelation($sourceRecordId, $relatedRecordId); } }
public function removeRelation(Vtiger_Request $request) { $relationId = $request->get('relationId'); $response = new Vtiger_Response(); try { Vtiger_Relation_Model::removeRelationById($relationId); $response->setResult(['success' => true]); } catch (Exception $e) { $response->setError($e->getCode(), $e->getMessage()); } $response->emit(); }
function addRelation($request) { $sourceModule = $request->getModule(); $sourceRecordId = $request->get('src_record'); $relatedModule = $request->get('related_module'); $relatedRecordIdList = $request->get('related_record_list'); $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); foreach ($relatedRecordIdList as $relatedRecordId) { $relationModel->addRelation($sourceRecordId, $relatedRecordId, $listPrice); } }
public function updateSelectedFields(Vtiger_Request $request) { $fields = $request->get('fields'); $relationId = $request->get('relationId'); $response = new Vtiger_Response(); try { Vtiger_Relation_Model::updateModuleRelatedFields($relationId, $fields); $response->setResult(array('success' => true)); } catch (Exception $e) { $response->setError($e->getCode(), $e->getMessage()); } $response->emit(); }
/** * Function adds Products/Services-PriceBooks Relation * @param type $request */ function addListPrice($request) { $sourceModule = $request->getModule(); $sourceRecordId = $request->get('src_record'); $relatedModule = $request->get('related_module'); $relInfos = $request->get('relinfo'); $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); foreach ($relInfos as $relInfo) { $price = CurrencyField::convertToDBFormat($relInfo['price'], null, true); $relationModel->addListPrice($sourceRecordId, $relInfo['id'], $price); } }
/** * Function to save record * @param <Vtiger_Request> $request - values of the record * @return <RecordModel> - record Model of saved record */ public function saveRecord($request) { $recordModel = $this->getRecordModelFromRequest($request); $recordModel->save(); if ($request->get('relationOperation')) { $parentModuleName = $request->get('sourceModule'); $parentModuleModel = Vtiger_Module_Model::getInstance($parentModuleName); $parentRecordId = $request->get('sourceRecord'); $relatedModule = $recordModel->getModule(); $relatedRecordId = $recordModel->getId(); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModule); $relationModel->addRelation($parentRecordId, $relatedRecordId); } return $recordModel; }
/** * Function to delete the relation for specified source record id and related record id list * @param <array> $request * keys Content * src_module source module name * src_record source record id * related_module related module name * related_record_list json encoded of list of related record ids */ function deleteRelation($request) { $sourceModule = $request->getModule(); $sourceRecordId = $request->get('src_record'); $relatedModule = $request->get('related_module'); $relatedRecordIdList = $request->get('related_record_list'); //Setting related module as current module to delete the relation vglobal('currentModule', $relatedModule); $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); foreach ($relatedRecordIdList as $relatedRecordId) { $response = $relationModel->deleteRelation($sourceRecordId, $relatedRecordId); } echo $response; }
/** * Function that deletes PriceBooks related records information * @param <Integer> $sourceRecordId - Product/Service Id * @param <Integer> $relatedRecordId - Related Record Id */ public function deleteRelation($sourceRecordId, $relatedRecordId) { $sourceModuleName = $this->getParentModuleModel()->get('name'); $relatedModuleName = $this->getRelationModuleModel()->get('name'); if (($sourceModuleName == 'Products' || $sourceModuleName == 'Services') && $relatedModuleName == 'PriceBooks') { //Description: deleteListPrice function is deleting the relation between Pricebook and Product/Service $priceBookModel = Vtiger_Record_Model::getInstanceById($relatedRecordId, $relatedModuleName); $priceBookModel->deleteListPrice($sourceRecordId); } else { if ($sourceModuleName == $relatedModuleName) { $this->deleteProductToProductRelation($sourceRecordId, $relatedRecordId); } else { parent::deleteRelation($sourceRecordId, $relatedRecordId); } } }
/** * Function to update Relation status * @param Vtiger_Request $request */ public function updateStatus(Vtiger_Request $request) { $relatedModuleName = $request->get('relatedModule'); $relatedRecordId = $request->get('relatedRecord'); $status = $request->get('status'); $response = new Vtiger_Response(); if ($relatedRecordId && $status && $status < 5) { $sourceModuleModel = Vtiger_Module_Model::getInstance($request->getModule()); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModuleName); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); $relationModel->updateStatus($request->get('sourceRecord'), array($relatedRecordId => $status)); $response->setResult(array(true)); } else { $response->setError($code); } $response->emit(); }
function addRelation($request) { $sourceModule = $request->getModule(); $sourceRecordId = $request->get('src_record'); $relatedModule = $request->get('related_module'); if (is_numeric($relatedModule)) { $relatedModule = Vtiger_Functions::getModuleName($relatedModule); } $relatedRecordIdList = $request->get('related_record_list'); $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); foreach ($relatedRecordIdList as $relatedRecordId) { $relationModel->addRelation($sourceRecordId, $relatedRecordId, $listPrice); } $response = new Vtiger_Response(); $response->setResult(true); $response->emit(); }
/** * Function to save record * @param <Vtiger_Request> $request - values of the record * @return <RecordModel> - record Model of saved record */ public function saveRecord($request) { $recordModel = $this->getRecordModelFromRequest($request); $recordModel->save(); if ($request->get('relationOperation')) { $parentModuleName = $request->get('sourceModule'); $parentModuleModel = Vtiger_Module_Model::getInstance($parentModuleName); $parentRecordId = $request->get('sourceRecord'); $relatedModule = $recordModel->getModule(); $relatedRecordId = $recordModel->getId(); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModule); $relationModel->addRelation($parentRecordId, $relatedRecordId); //To store the relationship between Products/Services and PriceBooks if ($parentRecordId && ($parentModuleName === 'Products' || $parentModuleName === 'Services')) { $parentRecordModel = Vtiger_Record_Model::getInstanceById($parentRecordId, $parentModuleName); $recordModel->updateListPrice($parentRecordId, $parentRecordModel->get('unit_price')); } } return $recordModel; }
function addRelation($request) { $sourceModule = $request->getModule(); $sourceRecordId = $request->get('src_record'); $relatedModule = $request->get('related_module'); $relatedRecordIdList = $request->get('related_record_list'); $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); foreach ($relatedRecordIdList as $relatedRecordId) { $relationModel->addRelation($sourceRecordId, $relatedRecordId, $listPrice); if ($relatedModule == 'PriceBooks') { $recordModel = Vtiger_Record_Model::getInstanceById($relatedRecordId); if ($sourceRecordId && ($sourceModule === 'Products' || $sourceModule === 'Services')) { $parentRecordModel = Vtiger_Record_Model::getInstanceById($sourceRecordId, $sourceModule); $recordModel->updateListPrice($sourceRecordId, $parentRecordModel->get('unit_price')); } } } }
/** * Function to save record * @param <Vtiger_Request> $request - values of the record * @return <RecordModel> - record Model of saved record */ public function saveRecord($request) { $recordModel = $this->getRecordModelFromRequest($request); $recordModel->save(); if ($request->get('relationOperation')) { $parentModuleName = $request->get('sourceModule'); $parentModuleModel = Vtiger_Module_Model::getInstance($parentModuleName); $parentRecordId = $request->get('sourceRecord'); $relatedModule = $recordModel->getModule(); $relatedRecordId = $recordModel->getId(); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModule); $relationModel->addRelation($parentRecordId, $relatedRecordId); } if ($request->get('imgDeleted')) { $imageIds = $request->get('imageid'); foreach ($imageIds as $imageId) { $status = $recordModel->deleteImage($imageId); } } return $recordModel; }
public function process(Vtiger_Request $request) { $relationInfo = $request->get('related_info'); $updatedRelatedList = $relationInfo['updated']; $deletedRelatedList = $relationInfo['deleted']; if (empty($updatedRelatedList)) { $updatedRelatedList = array(); } if (empty($deletedRelatedList)) { $deletedRelatedList = array(); } $sourceModule = $request->get('sourceModule'); $moduleModel = Vtiger_Module_Model::getInstance($sourceModule, false); $relationModulesList = Vtiger_Relation_Model::getAllRelations($moduleModel, false); $sequenceList = array(); foreach ($relationModulesList as $relationModuleModel) { $sequenceList[] = $relationModuleModel->get('sequence'); } //To sort sequence in ascending order sort($sequenceList); $relationUpdateDetail = array(); $index = 0; foreach ($updatedRelatedList as $relatedId) { $relationUpdateDetail[] = array('relation_id' => $relatedId, 'sequence' => $sequenceList[$index++], 'presence' => 0); } foreach ($deletedRelatedList as $relatedId) { $relationUpdateDetail[] = array('relation_id' => $relatedId, 'sequence' => $sequenceList[$index++], 'presence' => 1); } $response = new Vtiger_Response(); try { $response->setResult(array('success' => true)); Vtiger_Relation_Model::updateRelationSequenceAndPresence($relationUpdateDetail, $moduleModel->getId()); } catch (Exception $e) { $response->setError($e->getCode(), $e->getMessage()); } $response->emit(); }
public function getRelations() { if ($this->relations === null) { $this->relations = Vtiger_Relation_Model::getAllRelations($this, false); } // Contacts relation-tab is turned into custom block on DetailView. if ($this->getName() == 'Calendar') { $contactsIndex = false; foreach ($this->relations as $index => $model) { if ($model->getRelationModuleName() == 'Contacts') { $contactsIndex = $index; break; } } if ($contactsIndex !== false) { array_splice($this->relations, $contactsIndex, 1); } } return $this->relations; }
public function isDeletable() { $srcModuleModel = Vtiger_Module_Model::getInstance($this->get('srcModule')); $relationModel = Vtiger_Relation_Model::getInstance($srcModuleModel, $this->get('module')); return $relationModel->isDeletable(); }
/** * Function which will specify whether the relation is deletable * @return <Boolean> */ public function isDeletable() { $relatedModuleModel = $this->getRelationModuleModel(); $relatedModuleName = $relatedModuleModel->get('name'); $inventoryModulesList = []; //Inventoty relationship cannot be deleted from the related list if (in_array($relatedModuleName, $inventoryModulesList)) { return false; } return parent::isDeletable(); }
public static function getInstance($parentRecordModel, $relationModuleName, $label = false) { $parentModuleName = $parentRecordModel->getModule()->get('name'); $className = Vtiger_Loader::getComponentClassName('Model', 'RelationListView', $parentModuleName); $instance = new $className(); $parentModuleModel = $parentRecordModel->getModule(); $relatedModuleModel = Vtiger_Module_Model::getInstance($relationModuleName); $instance->setRelatedModuleModel($relatedModuleModel); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModuleModel, $label); $instance->setParentRecordModel($parentRecordModel); if (!$relationModel) { $relatedModuleName = $relatedModuleModel->getName(); $parentModuleModel = $instance->getParentRecordModel()->getModule(); $referenceFieldOfParentModule = $parentModuleModel->getFieldsByType('reference'); foreach ($referenceFieldOfParentModule as $fieldName => $fieldModel) { $refredModulesOfReferenceField = $fieldModel->getReferenceList(); if (in_array($relatedModuleName, $refredModulesOfReferenceField)) { $relationModelClassName = Vtiger_Loader::getComponentClassName('Model', 'Relation', $parentModuleModel->getName()); $relationModel = new $relationModelClassName(); $relationModel->setParentModuleModel($parentModuleModel)->setRelationModuleModel($relatedModuleModel); $parentModuleModel->set('directRelatedFieldName', $fieldModel->get('column')); } } } if (!$relationModel) { $relationModel = false; } $instance->setRelationModel($relationModel); return $instance; }
/** * Function to save record * @param <Vtiger_Request> $request - values of the record * @return <RecordModel> - record Model of saved record */ public function saveRecord($request) { $recordId = $request->get('record'); $recordModel = $this->getRecordModelFromRequest($request); $mode = $recordModel->get('mode'); $adb = PearDatabase::getInstance(); // check if encryption is enabled $config == false; if (file_exists('modules/OSSPasswords/config.ini.php')) { $config = parse_ini_file('modules/OSSPasswords/config.ini.php'); } //check if password was edited with hidden password $properPassword = $recordModel->get('password'); // edit mode if ($recordId != '' && $mode == 'edit') { if ($properPassword == '**********') { // hidden password sent in edit mode, get the correct one if ($config) { // when encryption is on $sql = "SELECT AES_DECRYPT(`password`, '" . $config['key'] . "') AS pass FROM `vtiger_osspasswords` WHERE `osspasswordsid` = ?;"; $result = $adb->pquery($sql, array($recordId), true); $properPassword = $adb->query_result($result, 0, 'pass'); } else { // encryption mode is off $sql = "SELECT `password` AS pass FROM `vtiger_osspasswords` WHERE `osspasswordsid` = ?;"; $result = $adb->pquery($sql, array($recordId), true); $properPassword = $adb->query_result($result, 0, 'pass'); } } $recordModel->set('password', $properPassword); $recordModel->save(); // after save we check if encryption is active if ($config) { $sql = "UPDATE `vtiger_osspasswords` SET `password` = AES_ENCRYPT(?,?) WHERE `osspasswordsid` = ?;"; $result = $adb->pquery($sql, array($properPassword, $config['key'], $recordId), true); } } else { if ($recordId == '' && $mode == '') { $recordModel->save(); // if encryption mode is on we will encrypt the password $recordId = $recordModel->get('id'); if ($config) { // when encryption is on $sql = "UPDATE `vtiger_osspasswords` SET `password` = AES_ENCRYPT(`password`, ?) WHERE `osspasswordsid` = ?;"; $result = $adb->pquery($sql, array($config['key'], $recordId), true); } } } if ($request->get('relationOperation')) { $parentModuleName = $request->get('sourceModule'); $parentModuleModel = Vtiger_Module_Model::getInstance($parentModuleName); $parentRecordId = $request->get('sourceRecord'); $relatedModule = $recordModel->getModule(); $relatedRecordId = $recordModel->getId(); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModule); $relationModel->addRelation($parentRecordId, $relatedRecordId); } return $recordModel; }
/** * Function to get popup view fields */ public function getPopupViewFieldsList($sourceModule = false) { $parentRecordModel = Vtiger_Module_Model::getInstance($sourceModule); if (!empty($sourceModule) && $parentRecordModel) { $relationModel = Vtiger_Relation_Model::getInstance($parentRecordModel, $this); } $popupFields = array(); if ($relationModel) { $popupFields = $relationModel->getRelationFields(true); } if (count($popupFields) == 0) { $popupFields = array_keys($this->getSummaryViewFieldsList()); } if (count($popupFields) == 0) { $popupFields = array_values($this->getRelatedListFields()); } return $popupFields; }
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; }
function updateFavoriteForRecord(Vtiger_Request $request) { $sourceModule = $request->getModule(); $relatedModule = $request->get('relatedModule'); $actionMode = $request->get('actionMode'); $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); if (!empty($relationModel)) { $result = $relationModel->updateFavoriteForRecord($actionMode, ['crmid' => $request->get('record'), 'relcrmid' => $request->get('relcrmid')]); } $response = new Vtiger_Response(); $response->setResult((bool) $result); $response->emit(); }
/** * Function returns all the relation models * @return <Array of Vtiger_Relation_Model> */ public function getRelations() { if (empty($this->relations)) { return Vtiger_Relation_Model::getAllRelations($this); } return $this->relations; }
public function convertToNativeLink() { $url = $this->get('linkurl'); if (empty($url)) { return $url; } //Check if the link is not javascript if (!$this->isPageLoadLink()) { //To convert single quotes and double quotes $url = Vtiger_Util_Helper::toSafeHTML($url); return $url; } $module = false; $sourceModule = false; $sourceRecord = false; $parametersParts = explode('&', $url); foreach ($parametersParts as $index => $keyValue) { $urlParts = explode('=', $keyValue); $key = $urlParts[0]; $value = $urlParts[1]; if (strcmp($key, 'module') == 0) { $module = $value; } if (strcmp($key, 'action') == 0) { if (strpos($value, 'View')) { $value = str_replace('View', '', $value); $key = 'view'; } } if (strcmp($key, 'return_module') == 0) { $key = 'sourceModule'; //Indicating that it is an relation operation $parametersParts[] = 'relationOperation=true'; } if (strcmp($key, 'return_id') == 0) { $key = 'sourceRecord'; } if (strcmp($key, 'sourceRecord') == 0) { $sourceRecord = $value; } if (strcmp($key, 'sourceModule') == 0) { $sourceModule = $value; } $newUrlParts = array(); array_push($newUrlParts, $key); array_push($newUrlParts, $value); $parametersParts[$index] = implode('=', $newUrlParts); } //to append the reference field in one to many relation if (!empty($module) && !empty($sourceModule) && !empty($sourceRecord)) { $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($module); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); if ($relationModel->isDirectRelation()) { $fieldList = $relatedModuleModel->getFields(); foreach ($fieldList as $fieldName => $fieldModel) { if ($fieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE) { $referenceList = $fieldModel->getReferenceList(); if (in_array($sourceModuleModel->get('name'), $referenceList)) { $parametersParts[] = $fieldModel->get('name') . '=' . $sourceRecord; } } } } } $url = implode('&', $parametersParts); //To convert single quotes and double quotes $url = Vtiger_Util_Helper::toSafeHTML($url); return $url; }
/** * Function to update the relation for specified source record id and related record id list * @param <array> $request * keys Content * src_module source module name * src_record source record id * related_module related module name * toRemove list of related record to remove * toAdd list of related record to add */ function updateRelation(Vtiger_Request $request) { $sourceModule = $request->getModule(); $sourceRecordId = $request->get('src_record'); $relatedModule = $request->get('related_module'); $toRemove = $request->get('toRemove'); $toAdd = $request->get('toAdd'); vglobal('currentModule', $sourceModule); $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); if (!empty($toAdd)) { foreach ($toAdd as $relatedRecordId) { if (substr($relatedRecordId, 0, 1) != 'T') { $relationModel->addRelation($sourceRecordId, $relatedRecordId); } } } if (!empty($toRemove)) { foreach ($toRemove as $relatedRecordId) { if (substr($relatedRecordId, 0, 1) != 'T') { $relationModel->deleteRelation($sourceRecordId, $relatedRecordId); } } } $response = new Vtiger_Response(); $response->setResult(true); $response->emit(); }