我正在为sugarCRM编写一些代码,我想通过电子邮件通知员工。我正在使用活动记录模型来获取员工,但他们的电子邮件无处可寻。
$employees = BeanFactory::getBean('Employees')->get_full_list();
如何通过此界面获取有效的员工电子邮件?我需要将它们从记录中删除并将它们添加到我发送的电子邮件中。
答案 0 :(得分:2)
我也遇到过这种情况,但我提出了以下解决方案。希望对你有效。干杯!!
<?php
$userId=array('2132131312323232','323232323232323'); //array of users id's
foreach($userId as $key => $val) {
$email_query = "select E.email_address from email_addr_bean_rel EB inner join email_addresses E on EB.email_address_id = E.id WHERE EB.bean_id='".$val."' and E.deleted = 0";
// Your implementation
}
?>
答案 1 :(得分:1)
引用sAcH和the schema documentation,我最终编写了下面的查询。它可能会被清理很多,但它起作用,这就是我现在所关心的。
它会返回所有活动的,未删除的员工的主电子邮件,从而有效地为您的活跃用户制作电子邮件列表:
select e.email_address
from email_addr_bean_rel eb
inner join email_addresses e
on eb.email_address_id = e.id
where eb.bean_id in
(select id
from users
where deleted = 0 and employee_status = 'Active')
and e.deleted = 0 and eb.primary_address = 1
and eb.deleted = 0 and eb.bean_module = 'Users'
需要注意的重要一点是,用户可以在两个字段中处于活动状态:status和employee_status。这会检查后者;请注意,有两个状态&#39;领域,而不是一个!
答案 2 :(得分:1)
要保存用户的电子邮件地址,请使用以下命令:
$sea = new SugarEmailAddress;
$sea->addAddress($bean->email1, true);
$sea->save($newUser->id, "Users");
要检索主电子邮件地址,请使用以下命令:
$primary_email=$user->emailAddress->getPrimaryAddress($user);
希望这会对你有所帮助...... :)
结帐以获取更多信息: SugarCRM Developer