[Vtigercrm-developers] DETAILVIEWWIDGET

Alan Lord alanslists at gmail.com
Mon Oct 13 11:04:18 GMT 2014


Ah,

I think you might be right about vtiger_links & DETALVIEWWIDGETS...

I've started looking at creating a module which allows the user to add a 
custom widget to other modules via my extension module...

But looking at the code in the standard models in 
/modules/Vtiger/models/{Detail.php,DetailView.php} it looks like 
getDetailViewLinks() and getWidgets() will only *ever* return specific 
widgets and will override information in the vtiger_links table such as 
linkurl for example.

Is this really the case or am I missing something? Is there no way for 
me to add a new entry in the vtiger_links table such that, for example, 
I could add a new "Libertus" widget that gets displayed on the Contacts 
module Summary page or DetailView page?

> 	/**
> 	 * Function to get the detail view links (links and widgets)
> 	 * @param <array> $linkParams - parameters which will be used to calicaulate the params
> 	 * @return <array> - array of link models in the format as below
> 	 *                   array('linktype'=>list of link models);
> 	 */
> 	public function getDetailViewLinks($linkParams) {
> 		$linkTypes = array('DETAILVIEWBASIC','DETAILVIEW');
> 		$moduleModel = $this->getModule();
> 		$recordModel = $this->getRecord();
>
> 		$moduleName = $moduleModel->getName();
> 		$recordId = $recordModel->getId();
>
> 		$detailViewLink = array();
>
> 		if(Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId)) {
> 			$detailViewLinks[] = array(
> 					'linktype' => 'DETAILVIEWBASIC',
> 					'linklabel' => 'LBL_EDIT',
> 					'linkurl' => $recordModel->getEditViewUrl(),
> 					'linkicon' => ''
> 			);
>
> 			foreach ($detailViewLinks as $detailViewLink) {
> 				$linkModelList['DETAILVIEWBASIC'][] = Vtiger_Link_Model::getInstanceFromValues($detailViewLink);
> 			}
> 		}
>
> 		$linkModelListDetails = Vtiger_Link_Model::getAllByType($moduleModel->getId(),$linkTypes,$linkParams);
> 		//Mark all detail view basic links as detail view links.
> 		//Since ui will be look ugly if you need many basic links
> 		$detailViewBasiclinks = $linkModelListDetails['DETAILVIEWBASIC'];
> 		unset($linkModelListDetails['DETAILVIEWBASIC']);
>
> 		if(Users_Privileges_Model::isPermitted($moduleName, 'Delete', $recordId)) {
> 			$deletelinkModel = array(
> 					'linktype' => 'DETAILVIEW',
> 					'linklabel' => sprintf("%s %s", getTranslatedString('LBL_DELETE', $moduleName), vtranslate('SINGLE_'. $moduleName, $moduleName)),
> 					'linkurl' => 'javascript:Vtiger_Detail_Js.deleteRecord("'.$recordModel->getDeleteUrl().'")',
> 					'linkicon' => ''
> 			);
> 			$linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($deletelinkModel);
> 		}
>
> 		if(Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId)) {
> 			$duplicateLinkModel = array(
> 						'linktype' => 'DETAILVIEWBASIC',
> 						'linklabel' => 'LBL_DUPLICATE',
> 						'linkurl' => $recordModel->getDuplicateRecordUrl(),
> 						'linkicon' => ''
> 				);
> 			$linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($duplicateLinkModel);
> 		}
>
> 		if(!empty($detailViewBasiclinks)) {
> 			foreach($detailViewBasiclinks as $linkModel) {
> 				// Remove view history, needed in vtiger5 to see history but not in vtiger6
> 				if($linkModel->linklabel == 'View History') {
> 					continue;
> 				}
> 				$linkModelList['DETAILVIEW'][] = $linkModel;
> 			}
> 		}
>
> 		$relatedLinks = $this->getDetailViewRelatedLinks();
>
> 		foreach($relatedLinks as $relatedLinkEntry) {
> 			$relatedLink = Vtiger_Link_Model::getInstanceFromValues($relatedLinkEntry);
> 			$linkModelList[$relatedLink->getType()][] = $relatedLink;
> 		}
>
> 		$widgets = $this->getWidgets();
> 		foreach($widgets as $widgetLinkModel) {
> 			$linkModelList['DETAILVIEWWIDGET'][] = $widgetLinkModel;
> 		}
>
> 		$currentUserModel = Users_Record_Model::getCurrentUserModel();
> 		if($currentUserModel->isAdminUser()) {
> 			$settingsLinks = $moduleModel->getSettingLinks();
> 			foreach($settingsLinks as $settingsLink) {
> 				$linkModelList['DETAILVIEWSETTING'][] = Vtiger_Link_Model::getInstanceFromValues($settingsLink);
> 			}
> 		}
>
> 		return $linkModelList;
> 	}



> 	/**
> 	 * Function to get the detail view widgets
> 	 * @return <Array> - List of widgets , where each widget is an Vtiger_Link_Model
> 	 */
> 	public function getWidgets() {
> 		$moduleModel = $this->getModule();
> 		$widgets = array();
>
> 		$modCommentsModel = Vtiger_Module_Model::getInstance('ModComments');
> 		if($moduleModel->isCommentEnabled() && $modCommentsModel->isPermitted('DetailView')) {
> 			$widgets[] = array(
> 					'linktype' => 'DETAILVIEWWIDGET',
> 					'linklabel' => 'ModComments',
> 					'linkurl' => 'module='.$this->getModuleName().'&view=Detail&record='.$this->getRecord()->getId().
> 							'&mode=showRecentComments&page=1&limit=5'
> 			);
> 		}
>
> 		if($moduleModel->isTrackingEnabled()) {
> 			$widgets[] = array(
> 					'linktype' => 'DETAILVIEWWIDGET',
> 					'linklabel' => 'LBL_UPDATES',
> 					'linkurl' => 'module='.$this->getModuleName().'&view=Detail&record='.$this->getRecord()->getId().
> 							'&mode=showRecentActivities&page=1&limit=5',
> 			);
> 		}
>
> 		$widgetLinks = array();
> 		foreach ($widgets as $widgetDetails) {
> 			$widgetLinks[] = Vtiger_Link_Model::getInstanceFromValues($widgetDetails);
> 		}
> 		return $widgetLinks;
> 	}

Al




More information about the vtigercrm-developers mailing list