我想过滤记录,以便分配的用户只能从弹出列表视图中看到分配给他的记录。
我之所以没有在角色管理中执行此操作,是因为如果我将一个用户分配给客户记录,那么其他具有相同角色的用户将看不到它,因此我设置了角色->列表标签设置为“全部”,并在列表视图中添加了自定义代码,只有登录用户才能看到他们自己的记录。
这就是我所做的。
<?php
require_once('include/MVC/View/views/view.popup.php');
class AccountsViewPopup extends ViewPopup
{
public function display()
{
parent::display(); // TODO: Change the autogenerated stub
require_once 'modules/ACLRoles/ACLRole.php';
$ACLRole = new ACLRole();
$roles = $ACLRole->getUserRoles($GLOBALS['current_user']->id);
if (in_array('User1', $roles)) {
global $db, $current_user;
$this->where .= " AND accounts.assigned_user_id = '$current_user->id' AND deleted=0 ";
}
}
}
但是我得到这个错误:
未定义的属性:AccountsViewPopup :: $ where
答案 0 :(得分:2)
仅适用于列表视图:custom/modules/MODULE_NAME/views/view.list.php
以下是帮助代码:
require_once('include/MVC/View/views/view.list.php');
class MODULE_NAMEViewList extends ViewList {
function listViewProcess() {
global $current_user;
$this->params['custom_where'] = ' AND module_name.name = "test" ';
parent::listViewProcess();
}
}
对于列表视图和弹出视图(两者):
您需要更改实际上准备查询的create_new_list_query
函数内部的逻辑。某些模块已将其替换为Bean级(例如,参见modules/Leads/Lead.php
)。
如果要以安全升级的方式覆盖它,则在自定义目录中创建一个文件,例如:custom/modules/Leads/Lead.php
,然后从核心bean类扩展它,如下所示:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('modules/Leads/Lead.php');
class CustomLead extends Lead {
function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean=null, $singleSelect = false, $ifListForExport = false)
{
// Code from create_new_list_query in and then modify it accordingly.
}
}
在以下位置注册新的bean类:custom/Extension/application/Ext/Include/custom_leads_class.php
,注册代码如下所示:
<?php
$objectList['Leads'] = 'Lead';
$beanList['Leads'] = 'CustomLead';
$beanFiles['CustomLead'] = 'custom/modules/Leads/Lead.php';
?>
答案 1 :(得分:0)
我知道已经回答了,但还是决定发布我的解决方案。我前一段时间(7.10.7)遇到了几乎相同的问题。
PopupView具有方法getCustomWhereClause()
,您可以在自定义视图中实现该方法。
它必须返回包含条件的字符串。
示例:
custom/modules/Meetings/views/view.popup.php
/*class declaration and other stuff*/
protected function getCustomWhereClause()
{
global $current_user;
return " ( {$this->bean->table_name}.assigned_user_id='{$current_user->id}') ";
}
请记住在开头和结尾留至少一个空格,因为SuiteCRM实际上会忘记添加空格,这可能会导致查询中断(但是在日志中很容易找到)。