]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/Portlets/BaculaConfigResources.php
baculum: Add module to check resource dependencies
[bacula/bacula] / gui / baculum / protected / Web / Portlets / BaculaConfigResources.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 Kern Sibbald
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The original author of Bacula is Kern Sibbald, with contributions
10  * from many others, a complete list can be found in the file AUTHORS.
11  *
12  * You may use this file and others of this release according to the
13  * license defined in the LICENSE file, which includes the Affero General
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and
15  * terms pursuant to its AGPLv3 Section 7.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
24 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
25 Prado::using('Application.Web.Portlets.ResourceListTemplate');
26
27 class BaculaConfigResources extends ResourceListTemplate {
28
29         const CHILD_CONTROL = 'BaculaConfigDirectives';
30
31         public $resource_names = array();
32
33         private function getConfigData($host, $component_type) {
34                 $params = array('config', $component_type);
35                 $result = $this->Application->getModule('api')->get($params, $host, false);
36                 $config = array();
37                 if (is_object($result) && $result->error === 0 && is_array($result->output)) {
38                         $config = $result->output;
39                 }
40                 return $config;
41         }
42
43         public function loadConfig() {
44                 $host = $this->getHost();
45                 $component_type = $this->getComponentType();
46                 $component_name = $this->getComponentName();
47                 $resources = array();
48                 $config = $this->getConfigData($host, $component_type);
49                 for ($i = 0; $i < count($config); $i++) {
50                         $resource_type = $this->getConfigResourceType($config[$i]);
51                         $resource_name = property_exists($config[$i]->{$resource_type}, 'Name') ? $config[$i]->{$resource_type}->Name : '';
52                         $resource = array(
53                                 'host' => $host,
54                                 'component_type' => $component_type,
55                                 'component_name' => $component_name,
56                                 'resource_type' => $resource_type,
57                                 'resource_name' => $resource_name
58                         );
59                         array_push($resources, $resource);
60                         if (!array_key_exists($resource_type, $this->resource_names)) {
61                                 $this->resource_names[$resource_type] = array();
62                         }
63                         array_push($this->resource_names[$resource_type], $resource_name);
64                 }
65
66                 $this->RepeaterResources->DataSource = $resources;
67                 $this->RepeaterResources->dataBind();
68         }
69
70         public function createResourceListElement($sender, $param) {
71                 $control = $this->getChildControl($param->Item, self::CHILD_CONTROL);
72                 if (is_object($control)) {
73                         $control->setHost($param->Item->DataItem['host']);
74                         $control->setComponentType($param->Item->DataItem['component_type']);
75                         $control->setComponentName($param->Item->DataItem['component_name']);
76                         $control->setResourceType($param->Item->DataItem['resource_type']);
77                         $control->setResourceName($param->Item->DataItem['resource_name']);
78                         $control->setResourceNames($this->resource_names);
79                 }
80         }
81
82         public function getDirectives($sender, $param) {
83                 $control = $this->getChildControl($sender->getParent(), self::CHILD_CONTROL);
84                 if (is_object($control)) {
85                         $control->raiseEvent('OnDirectiveListLoad', $this, null);
86                 }
87         }
88 }
89 ?>