(SuiteCRM) 事件模块转换逻辑钩子?

问题描述

我不知道这个地方是否正确,但我想帮助理解。 我在论坛上找了一些东西,但没有涉及日期和时间。 在逻辑钩子中,组装起来很复杂。 在事件模块中,我想阻止用户在一段时间内使用某些数据。

示例:如果在开始日期和时间与结束日期和时间之间并确定下拉列表包含已在所选时间段中记录的相同日期和下拉数据,请避免使用警告消息进行记录.

简而言之:就像一个预订,记录期间和考虑分钟的下拉数据不能重复。

不知道有没有说清楚,就是想把活动模块改成预约模块。

拥抱。

更新:

我找到了我需要的简短解决方案。使用逻辑钩子。 我创建了此代码,以便在录制后(after_save)显示预订是否可用的信息。我不想使用 before_save 因为我希望在用户没有注意到时将其注册错误

<?PHP
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once 'include/entryPoint.PHP';

class CheckerEventsLogicHook{
     public function CheckerDates($bean,$event,$arguments){
        global $db; 

$date_start1 = $bean->date_start;
$date_start = DateTime::createFromFormat('Y-m-d H:i:s',$date_start1,new DateTimeZone('UTC'))->format('Y-m-d\H:i:s'); 
$date_end1 = $bean->date_end;
$date_end = DateTime::createFromFormat('Y-m-d H:i:s',$date_end1,new DateTimeZone('UTC'))->format('Y-m-d\H:i:s');   
$sala_c     = $bean->sala_c;

$sql = "SELECT fpc.id_c FROM fp_events fp,fp_events_cstm fpc WHERE fp.deleted = 0 and fpc.id_c = fp.id AND fp.date_start >= '$date_start' AND fp.date_end <= '$date_end' AND fpc.sala_c = '$sala_c' AND fpc.id_c <> '$bean->id' ";

$res = $db->query($sql);

if ($db->getRowCount($res) > 0) {

            $db->query(" UPDATE fp_events_cstm SET reserva_status_c='✖ ERROR!',rejeitadomotivo_c=' Change dates! ' where fp_events_cstm.id_c='$bean->id'");
     
          Sugarapplication::appendErrorMessage('<span style="color: red; display: block; width: 100%; font-size: 18px; text-align: center; margin-top: 18px;"> A error occurred!</span>');
                $params = array(
                  'module' => 'FP_events','action' => 'EditView','record' => $bean->id,);
                
      Sugarapplication::redirect('index.PHP?' . http_build_query($params));
                            }
else {

      Sugarapplication::appendErrorMessage('<span style="color: green; display: block; width: 100%; font-size: 15px; text-align: center; margin-top: 15px;">Saved Successfully!</span>');

};}}
?>

但是,它仅在日期与数据库中的日期完全相同时才有效。 我基于我所做的查询,它运行得很好,但 PHP 代码不起作用。

查询工作:

select fpc.id_c,fp.date_start,fp.date_entered
 from fp_events fp,fp_events_cstm fpc
 WHERE fp.deleted =0
 and fpc.id_c = fp.id
and fp.date_start  >= '2021-02-28\05:00:00'
and fp.date_end <= '2021-02-28\10:00:00'
 and fpc.sala_c = 'AUD_BaraTA'
and fpc.id_c <> '9afe8e46-14a4-3abf-0dd4-60300c8c8306'; // ID ignored to Save

在哪里可以找到 PHP 代码中的错误

解决方法

我很难理解要求,但如果您需要使用某些规则进行 AJAX 验证,您通常可以创建自己的 PHP 文件来响应这些请求。

有关于如何扩展 SuiteCRM https://docs.suitecrm.com/developer/extension-framework/

的指南

另一种选择是做javascript验证,更新模块vardefs.php,就像

 'validation' => 
array (
  'type' => 'callback','callback' => 'function(formname,nameIndex){if($("#" + nameIndex).val()!=999){add_error_style(formname,nameIndex,"Only 999 is allowed!"); return false;}; return true;}',),

更新: 关于日期,无论用户配置如何,SuiteCRM 都将日期存储为 UTC,因此在执行查询之前,您必须始终将日期转换为 UTC。

用户设置包含用户时区,您可以使用它来将日期转换为 UTC。为方便起见,$current_user global 包含这些设置。

,

我发现了错误。错误在我的 SELECT 中。 此 SELECT 必须连接在 date_start 和 date_end 之间,以便分析所有计划。这是选择:

select fpc.id_c,fp.date_start,fp.date_end,fp.name
from fp_events fp,fp_events_cstm fpc
WHERE fp.deleted =0
and fpc.id_c = fp.id
and fpc.sala_c = 'AUD_BARATA'
and ((fp.date_start BETWEEN '2021-02-28 13:00' AND '2021-02-28 16:00')
or (fp.date_end between '2021-02-28 13:00' and '2021-02-28 16:00')
or ('2021-02-28 13:00' between fp.date_start and fp.date_end)
or ('2021-02-28 16:00' between fp.date_start and fp.date_end))
and fpc.id_c <> '98880fc3-ef30-1046-0364-60328f45aa2c'; //ID ignored on the search

现在正在考虑分钟和秒。如果有人想验证代码或改进它,请告诉我,以便我完成此问题。