context) { $value = $this->context[$key]; if ($purify && !empty($value)) { $value = vtlib_purify($value); } return $value; } return false; } function title() { return getTranslatedString('LBL_MODCOMMENTS_INFORMATION', 'ModComments'); } function name() { return $this->_name; } function uikey() { return "ModCommentsDetailViewBlockCommentWidget"; } function setCriteria($newCriteria) { $this->criteria = $newCriteria; } function getViewer() { global $theme, $app_strings, $current_language; $smarty = new vtigerCRM_Smarty(); $smarty->assign('APP', $app_strings); $smarty->assign('MOD', return_module_language($current_language,'ModComments')); $smarty->assign('THEME', $theme); $smarty->assign('IMAGE_PATH', "themes/$theme/images/"); $smarty->assign('UIKEY', $this->uikey()); $smarty->assign('WIDGET_TITLE', $this->title()); $smarty->assign('WIDGET_NAME', $this->name()); return $smarty; } protected function getModels($parentRecordId, $criteria) { global $adb, $current_user; $moduleName = 'ModComments'; if(vtlib_isModuleActive($moduleName)) { $entityInstance = CRMEntity::getInstance($moduleName); $queryCriteria = ''; switch($criteria) { case 'All': $queryCriteria = sprintf(" ORDER BY %s.%s DESC ", $entityInstance->table_name, $entityInstance->table_index); break; case 'Last5': $queryCriteria = sprintf(" ORDER BY %s.%s DESC LIMIT 5", $entityInstance->table_name, $entityInstance->table_index) ;break; case 'Mine': $queryCriteria = ' AND vtiger_crmentity.smownerid=' . $current_user->id.sprintf(" ORDER BY %s.%s DESC ", $entityInstance->table_name, $entityInstance->table_index); break; } $query = $entityInstance->getListQuery($moduleName, sprintf(" AND %s.related_to=?", $entityInstance->table_name)); $query .= $queryCriteria; $result = $adb->pquery($query, array($parentRecordId)); $instances = array(); if($adb->num_rows($result)) { while($resultrow = $adb->fetch_array($result)) { $instances[] = new ModComments_CommentsModel($resultrow); } } } return $instances; } function processItem($model) { $viewer = $this->getViewer(); $viewer->assign('COMMENTMODEL', $model); return $viewer->fetch(vtlib_getModuleTemplate("ModComments","widgets/DetailViewBlockCommentItem.tpl")); } function process($context = false) { $this->context = $context; $sourceRecordId = $this->getFromContext('ID', true); $usecriteria = ($this->criteria === false)? $this->defaultCriteria : $this->criteria; $viewer = $this->getViewer(); $viewer->assign('ID', $sourceRecordId); $viewer->assign('CRITERIA', $usecriteria); $viewer->assign('COMMENTS', $this->getModels($sourceRecordId, $usecriteria) ); return $viewer->fetch(vtlib_getModuleTemplate("ModComments","widgets/DetailViewBlockComment.tpl")); } }