imagina/requestable-module

安装: 230

依赖项: 1

建议者: 0

安全: 0

星标: 0

关注者: 5

分支: 7

开放问题: 0

类型:asgard-module

v8.x-dev 2024-04-10 16:54 UTC

This package is auto-updated.

Last update: 2024-09-11 22:23:05 UTC


README

Requestable 是一个为全球企业家量身定制的 Imagina CMS 开源模块。

### Seeder 配置 此模块包含一个种子,用于遍历所有启用的模块配置,查找名为 'requestable' 的配置,并创建必要的类别和状态数据库,此类配置必须为数组数组,并需要以下结构


   /*
|--------------------------------------------------------------------------
| Requestable config
|--------------------------------------------------------------------------
*/
  "requestable" => [
    
    1 => [
      //Required: this is the identificator of the request, must be unique with respect to other requestable types 
      "type" => "nameOfTheRequest",
     
      // Title can be trantaled or not, the language take the config app.locale 
      "title" => "module::tranlation.requestable1.title",
           
      // Time elapsed to cancel in days
      "timeElapsedToCancel" => 30,
      
      /* 
       Optional: Path of the Entity related to the requestable 
       The requestable Id can be saved in the requestable
       if the requestableType is  Modules\\User\\Entities\\Sentinel\\User the id can be taked automatically of the Auth User if the id it's not specified
       */
      "requestableType" => "Modules\\ModuleName\\Entities\\EntityName",
      
      // Optional: this form is used to get the fields data of the requestable, need to be a setting name previously charged with the formId
      "formId" => "module::settingNameForm",
        
      // Optional: This columns has true by default
      "internal" => false,
        
      //requestable events to dispatch  
      "events" => [
          "create" => "Modules\\ModuleName\\Events\\EventDispatchedWhenRequestWasCreated",
          "update" => "Modules\\ModuleName\\Events\\EventDispatchedWhenRequestWasUpdated",
          "delete" => "Modules\\ModuleName\\Events\\EventDispatchedWhenRequestWasDeleted",
          "etaUpdated" => "Modules\\ModuleName\\Events\\EventDispatchedWhenRequestEtaWasUpdated",
      ],
      
      /*
      The module has four statuses by default with the following structure:
          const PENDING = 1; (default)
          const INPROGRESS = 2;
          const COMPLETED = 3; (final)
          const CANCELLED = 4; (final)
      */
      "useDefaultStatuses" => true,
      
      //Optional: if the useDefaultStatuses is true, statuses is ignored 
      "statuses" => [
        1 => [
            "id" => 1,
            "title" => "module::translation.status1.title", // Title can be trantaled or not, the language take the config app.locale 
            "final" => false, //optional (default false)
            "default" => true,
            "delete_request" => false, //optional (default false)
            "cancelled_elapsed_time" => false,
            "events" => "Modules\\ModuleName\\Events\\RequestInStatus1" //optional (default null)
        ],
        2 => [
            "id" => 2,
            "title" => "module::translation.status2.title",
            "final" => true,
            "default" => false,
            "delete_request" => true,
            "cancelled_elapsed_time" => true,
            "events" => [ //optional can be multiple too
                "Modules\\ModuleName\\Events\\RequestInStatus2",
                "Modules\\ModuleName\\Events\\RequestInStatus2SecondEvent"
            ]
        ],
        .
        .
        .
        "N" => [
            "id" => "N",
            "title" => "module::translation.statusN.title"
            "final" => true/false,
            "default" => true/false,
            "delete_request" => true/false,
            "cancelled_elapsed_time" => true/false,
             "events" => [
                "Modules\\ModuleName\\Events\\RequestInStatusN",
                "Modules\\ModuleName\\Events\\RequestInStatusNSecondEvent"
            ]
        ],
      ],
      
      //if you don't use the statuses configuration but you need to configure the delete request by status you can use this extra config: 
      'deleteRequestWhenStatus' => [
        1 => false,
        2 => true,
        3 => false,
        4 => true
      ],
      
      //if you don't use the statuses configuration but you need to configure the events by status you can use this extra config:
      "eventsWhenStatus" => [
        2 => "Modules\\ModuleName\\Events\\RequestInStatus2",
        3 =>  [
                "Modules\\ModuleName\\Events\\RequestInStatus3",
                "Modules\\ModuleName\\Events\\RequestInStatus3SecondEvent"
            ],
      ], 
      
      /*
      Optional: If you don't use this config and the useDefaultStatuses is true the default status used is 1
      if you use the statuses and defined some one by default that's would be the status applied.
      */
      'defaultStatus' => 1,
      
      //Optional: if you don't use the statuses configuration but you need to configure the cancelled when elapsed time status you can use this extra config:
      "statusToSetWhenElapsedTime" => 4,
           
    ]
  ]


  • 注意:从配置中获取的所有信息都存储在数据库中的类别和状态模型中,如果需要,可以通过 API 进行自定义。

### API 该模块在其所有实体中实现了标准 json:api,以便可以通过端点前缀 api/requestable/v1 进行消费

### 服务 存在服务用于创建和更新请求,以便在需要时由后端本身消费。

Modules\Requestable\Services\RequestableService

服务创建的数据示例

    $requestableService = app("Modules\Requestable\Services\RequestableService");
    
    $requestableService->create([
        "type":"withdrawalFunds",
        "fields": [
            {
            "name": "amount",
            "value": 43000
            }
        ]
    ]);

服务更新数据示例

    $requestableService = app("Modules\Requestable\Services\RequestableService");
    
    $requestableService->update(11, [
        //if you know the status_id in the database you can send status_id, but if only know the status value defined in the config just send status
        "status": 2,
        "eta": "2021-06-21"
    ]);

其余的请求配置都是从与相同类型从配置中获得的信息中获取的

### 事件

当需要执行事件时,该模块非常可定制,每个启用的事件类型都发送不同的参数

作业到自动化规则

迁移命令

php artisan queue:table
php artisan queue:failed-table

额外命令

php artisan queue:restart

文件 .env

QUEUE_CONNECTION=database

迁移作业表

php artisan migrate

报告

创建多个报告

  1. 在 reportType 中添加一个新的 "选项" ("config.exportable.requestables.exportFields.reportType") 示例
 ['label' => 'requestable::exports.exportFields.type.mynew', 'value' => "mynew"],
  1. 转到 Requestable/Exports/Reports/" 并从其他报告(例如:detailedReport.php)复制文件,将文件名设置为文件(mynewReport.php)和新的类(class mynewReport)与上面创建的选项相同的值 示例
mynewReport.php
  1. 要设置标题,请在新文件中使用 "getHeading" 方法。
public function getHeading()
{
    //your nice code here
}
  1. 要设置每一行,请在新文件中使用 "getMap" 方法。
public function getMap($item)
{
    //your nice code here
}
  1. 如果您需要从 RequestableExport 中使用方法,可以使用
$this->requestableExport