<?php
namespace App\AI\Contexts\ReportsData; class Countries extends \App\AI\Contexts\ReportsData\ReportsDataAbstract { public function getColumns($dbTable=null): array { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); $criteria = []; foreach ($CFG['countriesCriteria'] as $criterion) { $criteria[$criterion] = $_LANG['locations']['countriesCriteria']['long'][$criterion]; } $columns['rd_countries'] = [ ['name'=>'country.code', 'type'=>'string', 'description'=>'ISO 3166-1 alpha-2 country code' ], ['name'=>'country.nameStd', 'type'=>'string'], ['name'=>'country.nameLoc', 'type'=>'string'], ['name'=>'country.code3', 'type'=>'string', 'description'=>'ISO 3166-1 alpha-3 country code' ], ['name'=>'country.zone', 'type'=>'string'], ['name'=>'country.criterion', 'type'=>'string', 'enum'=>$CFG['countriesCriteria'], 'description'=>'Country criteria/location: '.json_encode($criteria) ], ['name'=>'country.continent', 'type'=>'string'], ['name'=>'country.regionCode', 'type'=>'string'], ['name'=>'country.regionName', 'type'=>'string'], ['name'=>'country.TCArea', 'type'=>'string'], ]; return $dbTable ? $columns[$dbTable] : $columns; } protected function getLinkedColumns($dbTable=null): array { $linkedColumns['rd_countries'] = [ ['country.code', 'country.nameStd', ], ]; return $dbTable ? $linkedColumns[$dbTable] : $linkedColumns; } protected function checkPermission_run_rd_countries_analytics() : bool { return true; } protected function generateFunctionObject_run_rd_countries_analytics() : \App\AI\Api\ChatGpt\Responses\ToolFunction { return parent::generateAnalyticsFunctionObject('rd_countries'); } protected function executeFunction_run_rd_countries_analytics(string $arguments) : array { $args = json_decode($arguments, 1); $listObj = new \App\ReportsData\EntityList\Countries(); $listObj->setFilter('country.deleted', '=', 0); $results = $this->executeReportsDataEntitylist('rd_countries', $listObj, $args); return $results; } protected function developerMessage_run_rd_countries_analytics(string $arguments, array $response) : string { $args = json_decode($arguments, 1); $filters = []; if ($args['filters']) { if ($args['filters']['country.criterion']['value']) { $filters['filters[criterion]'] = $args['filters']['country.criterion']['value']; } } if ($filters) { return "Allow the user to see the `Countries` section filtered by the filters `".json_encode($filters)."` by giving him a clickable link to the section: " . \Engine\Mvc\Dispatcher::getInstance()->getAppUrl('Modules/Admin/Countries', 'index', array_merge($filters, $this->listingParams)); } return "Allow the user to see the `Countries` section by giving him a clickable link to the section: " . \Engine\Mvc\Dispatcher::getInstance()->getAppUrl('Modules/Admin/Countries', 'index'); } } 