-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_cards_plugin.php
More file actions
101 lines (94 loc) · 3.82 KB
/
Copy pathclient_cards_plugin.php
File metadata and controls
101 lines (94 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Client Cards plugin handler
*
* @package blesta
* @subpackage blesta.plugins.client_cards
* @copyright Copyright (c) 2020, Phillips Data, Inc.
* @license http://www.blesta.com/license/ The Blesta License Agreement
* @link http://www.blesta.com/ Blesta
*/
class ClientCardsPlugin extends Plugin
{
/**
* Initialize the plugin
*/
public function __construct()
{
Language::loadLang('client_cards_plugin', null, dirname(__FILE__) . DS . 'language' . DS);
$this->loadConfig(dirname(__FILE__) . DS . 'config.json');
}
/**
* Retrieves the total number of active and suspended services
*
* @param int $client_id The ID of the client assigned to the services
* @return int The total number of active and suspended services
*/
public function getServicesCount($client_id)
{
Loader::loadModels($this, ['Services', 'PluginManager']);
// Exclude domains, if the domain manager plugin is installed
$filters = [];
if ($this->PluginManager->isInstalled('domains', Configure::get('Blesta.company_id'))) {
$filters['type'] = 'services';
}
return $this->Services->getListCount($client_id, 'active', false, null, $filters)
+ $this->Services->getListCount($client_id, 'suspended', false, null, $filters);
}
/**
* Retrieves the total number of active invoices/proformas
*
* @param int $client_id The ID of the client assigned to the invoices/proformas
* @return int The total number of active invoices/proformas
*/
public function getInvoicesCount($client_id)
{
Loader::loadModels($this, ['Invoices']);
return $this->Invoices->getListCount($client_id);
}
/**
* Returns all cards to be configured for this plugin (invoked after install() or upgrade(),
* overwrites all existing cards)
*
* @return array A numerically indexed array containing:
*
* - level The level this card should be displayed on (client or staff) (optional, default client)
* - callback A method defined by the plugin class for calculating the value of the card or fetching a custom html
* - callback_type The callback type, 'value' to fetch the card value or
* 'html' to fetch the custom html code (optional, default value)
* - background The background color in hexadecimal or path to the background image for this card (optional)
* - background_type The background type, 'color' to set a hexadecimal background or
* 'image' to set an image background (optional, default color)
* - label A string or language key appearing under the value as a label
* - link The link to which the card will be pointed to (optional)
* - enabled Whether this card appears on client profiles by default
* (1 to enable, 0 to disable) (optional, default 1)
*/
public function getCards()
{
return [
[
'level' => 'client',
'callback' => ['this', 'getServicesCount'],
'callback_type' => 'value',
'label' => 'ClientCardsPlugin.card_client.services',
'text_color' => '#fffaeb',
'background' => '#ffc107',
'background_type' => 'color',
'link' => 'services/index/active/',
'enabled' => 1
],
[
'level' => 'client',
'callback' => ['this', 'getInvoicesCount'],
'callback_type' => 'value',
'label' => 'ClientCardsPlugin.card_client.invoices',
'text_color' => '#e4f5e7',
'background' => '#28a746',
'background_type' => 'color',
'link' => 'invoices/index/open/',
'enabled' => 1
]
];
}
}