dolibarr 22.0.5
ExternalModules Class Reference

Class ExternalModules. More...

Public Member Functions

 __construct ($debug=false)
 Constructor.
 
 loadRemoteSources ($debug=false)
 loadRemoteSources
 
 callApi ($resource, $options=false)
 Test if we can access to remote Dolistore market place.
 
 fetchModulesFromFile ($options=array())
 Fetch modules from a cache YAML file.
 
 getCategories ($active=0)
 Generate HTML for categories and their children.
 
 getProducts ($options)
 Generate HTML for products.
 
 buildSorter (string $key)
 Sort an array by a key.
 
 versionCompare ($v1, $v2)
 version compare
 
 get_previous_link ($text='<<')
 get previous link
 
 get_next_link ($text='> >')
 get next link
 
 get_previous_url ()
 get previous url
 
 get_next_url ()
 get next url
 
 getPagination ()
 Generate pagination for navigating through pages of products.
 
 getRemoteYamlFile ($file_source_url, $cache_time)
 Get YAML file from remote source and put it into the cache file.
 
 readYaml ($yaml)
 Read a YAML string and convert it to an array.
 
 adaptData ($data, $source)
 Adapter data fetched from github remote source to the expected format.
 
 applyFilters ($list, $options)
 Apply filters to the data.
 
 checkApiStatus ()
 Check if an Dolistore API is up.
 
 libStatus ($status, $mode=3, $moretext='')
 Retrieve the status icon.
 

Protected Member Functions

 checkStatusCode ($request)
 Check the status code of the request.
 

Detailed Description

Class ExternalModules.

Definition at line 26 of file externalModules.class.php.

Constructor & Destructor Documentation

◆ __construct()

ExternalModules::__construct ( $debug = false)

Constructor.

Parameters
boolean$debugEnable debug of request on screen

Definition at line 143 of file externalModules.class.php.

References getDolGlobalString().

Member Function Documentation

◆ adaptData()

ExternalModules::adaptData ( $data,
$source )

Adapter data fetched from github remote source to the expected format.

Parameters
array<string,mixed>|list<array<string,array<string,string|null>|string|null>>$data Data fetched from github remote source
string$sourceSource of the data
Returns
list<array<string, array<string, string|null>|string|null>> Data adapted to the expected format

Definition at line 996 of file externalModules.class.php.

References $id.

Referenced by getProducts().

◆ applyFilters()

ExternalModules::applyFilters ( $list,
$options )

Apply filters to the data.

Parameters
list<array<string,mixed>>$list Data to filter
array<string,mixed>$options Options for the filter
Returns
array{total:int, data:list<array<string, mixed>>} Filtered data

Compare creation times

Parameters
array<string,mixed>$a First product for comparison.
array<string,mixed>$b Second product for comparison.
Returns
int

Filter packages that have a label or description with the search string

Parameters
array<string,mixed>$package
Returns
bool

Filter the packages that belong to the filtered category

Parameters
array<string,mixed>$package
Returns
bool

Definition at line 1121 of file externalModules.class.php.

Referenced by getProducts().

◆ buildSorter()

ExternalModules::buildSorter ( string $key)

Sort an array by a key.

Parameters
string$keyKey to sort by
Returns
Closure(array<string, mixed>, array<string, mixed>): int
Parameters
array<string,mixed>$a
array<string,mixed>$b
Returns
int

Definition at line 645 of file externalModules.class.php.

Referenced by getCategories().

◆ callApi()

ExternalModules::callApi ( $resource,
$options = false )

Test if we can access to remote Dolistore market place.

Parameters
string$resourceResource relative URL ('categories' or 'products')
array<string,mixed>|false$options Options for the request
Returns
array{status_code:int,response:null|string|array<string,mixed>}

Definition at line 202 of file externalModules.class.php.

References getDolGlobalString(), and getURLContent().

Referenced by checkApiStatus(), getCategories(), and getProducts().

◆ checkApiStatus()

ExternalModules::checkApiStatus ( )

Check if an Dolistore API is up.

Returns
int

Definition at line 1186 of file externalModules.class.php.

References callApi(), and checkStatusCode().

Referenced by loadRemoteSources().

◆ checkStatusCode()

ExternalModules::checkStatusCode ( $request)
protected

Check the status code of the request.

Parameters
array{status_code:int,response:null|string|array{curl_error_msg:string,errors:array{code:int,message:string}[]}}$request Response elements of CURL request
Returns
string|null

Definition at line 846 of file externalModules.class.php.

Referenced by checkApiStatus().

◆ fetchModulesFromFile()

ExternalModules::fetchModulesFromFile ( $options = array())

Fetch modules from a cache YAML file.

Parameters
array<string,mixed>$options Options for filter
Returns
list<array<string, array<string, string|null>|string|null>> List of modules

Definition at line 260 of file externalModules.class.php.

References dol_syslog(), and readYaml().

Referenced by getProducts().

◆ get_next_link()

ExternalModules::get_next_link ( $text = '>>')

get next link

Parameters
string$textsymbol next
Returns
string html next link

Definition at line 721 of file externalModules.class.php.

References dol_escape_htmltag().

◆ get_next_url()

ExternalModules::get_next_url ( )

get next url

Returns
string next url

Definition at line 759 of file externalModules.class.php.

◆ get_previous_link()

ExternalModules::get_previous_link ( $text = '<<')

get previous link

Parameters
string$textsymbol previous
Returns
string html previous link

Definition at line 708 of file externalModules.class.php.

References dol_escape_htmltag().

◆ get_previous_url()

ExternalModules::get_previous_url ( )

get previous url

Returns
string previous url

Definition at line 733 of file externalModules.class.php.

◆ getCategories()

ExternalModules::getCategories ( $active = 0)

Generate HTML for categories and their children.

Parameters
int$activeThe active category id
Returns
string HTML string representing the categories and their children.

Definition at line 284 of file externalModules.class.php.

References buildSorter(), callApi(), and dol_escape_htmltag().

◆ getPagination()

ExternalModules::getPagination ( )

Generate pagination for navigating through pages of products.

Returns
string HTML string representing the pagination.

Definition at line 784 of file externalModules.class.php.

References ajax_autoselect(), and dol_escape_htmltag().

◆ getProducts()

ExternalModules::getProducts ( $options)

Generate HTML for products.

Parameters
array<string,mixed>$options Options for the request
Returns
string|null HTML string representing the products.

Definition at line 329 of file externalModules.class.php.

References $id, adaptData(), applyFilters(), callApi(), dol_escape_htmltag(), dol_now(), dol_print_date(), dol_string_nohtmltag(), dol_stringtotime(), dolPrintHTML(), fetchModulesFromFile(), getDolGlobalInt(), img_picto(), price2num(), and versionCompare().

◆ getRemoteYamlFile()

ExternalModules::getRemoteYamlFile ( $file_source_url,
$cache_time )

Get YAML file from remote source and put it into the cache file.

Parameters
string$file_source_urlURL of the remote source
int$cache_timeCache time
Returns
bool|string File content

Definition at line 888 of file externalModules.class.php.

References dol_is_dir(), dol_mkdir(), dol_now(), and getURLContent().

Referenced by loadRemoteSources().

◆ libStatus()

ExternalModules::libStatus ( $status,
$mode = 3,
$moretext = '' )

Retrieve the status icon.

Parameters
mixed$statusStatus
mixed$modeMode
string$moretextMore text to show on tooltip
Returns
string

Definition at line 1207 of file externalModules.class.php.

References dolGetStatus().

◆ loadRemoteSources()

ExternalModules::loadRemoteSources ( $debug = false)

loadRemoteSources

Parameters
boolean$debugEnable debug of request on screen
Returns
void

Definition at line 174 of file externalModules.class.php.

References checkApiStatus(), dol_is_file(), getDolGlobalInt(), getDolGlobalString(), and getRemoteYamlFile().

◆ readYaml()

ExternalModules::readYaml ( $yaml)

Read a YAML string and convert it to an array.

Parameters
string$yamlYAML string
Returns
list<array<string, array<string, string|null>|string|null>> Parsed array representation

Definition at line 924 of file externalModules.class.php.

Referenced by fetchModulesFromFile().

◆ versionCompare()

ExternalModules::versionCompare ( $v1,
$v2 )

version compare

Parameters
string$v1version 1
string$v2version 2
Returns
int result of compare

Definition at line 668 of file externalModules.class.php.

Referenced by getProducts().


The documentation for this class was generated from the following file: