HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
Yii2ViewPanel.php
Go to the documentation of this file.
1 <?php
2 
9 {
10  public function getName()
11  {
12  return 'Views';
13  }
14 
15  public function __construct($owner, $id)
16  {
17  parent::__construct($owner, $id);
18  $renderer = Yii::app()->getComponent('viewRenderer');
19  Yii::app()->setComponent('viewRenderer', null);
20  Yii::app()->setComponents(array(
21  'viewRenderer' => array(
22  'class' => 'Yii2DebugViewRenderer',
23  'instance' => $renderer,
24  ),
25  ), false);
26  }
27 
28  public function getSummary()
29  {
30  if ($count = count($this->data)) {
31  return $this->render(dirname(__FILE__) . '/../views/panels/view_bar.php', array(
32  'count' => $count,
33  ));
34  }
35  return '';
36  }
37 
38  public function getDetail()
39  {
40  $data = $this->getData();
41  $base = dirname(Yii::app()->getBasePath()) . DIRECTORY_SEPARATOR;
42  foreach ($data as &$item) {
43  $item['view'] = str_replace($base, '', $item['view']);
44  $item['view'] = str_replace('\\', '/', $item['view']);
45  }
46  unset($item);
47  return $this->render(dirname(__FILE__) . '/../views/panels/view.php', array(
48  'data' => $data,
49  ));
50  }
51 
52 
53  public function save()
54  {
55  $renderer = Yii::app()->getComponent('viewRenderer');
56  if ($renderer instanceof Yii2DebugViewRenderer) {
57  return Yii2Debug::prepareData($renderer->getStack());
58  }
59  return null;
60  }
61 
62  protected function prepareData($data)
63  {
64  $result = array();
65  if (is_array($data)) {
66  foreach ($data as $key => $value) {
67  $result[$key] = $this->prepareData($value);
68  }
69  } elseif (is_object($data)) {
70  $result['class'] = get_class($data);
71  if ($data instanceof CActiveRecord) {
72  foreach ($data->attributes as $field => $value) {
73  $result[$field] = $value;
74  }
75  }
76  foreach (get_object_vars($data) as $key => $value) {
77  $result[$key] = $this->prepareData($value);
78  }
79  } else {
80  $result = $data;
81  }
82  return $result;
83  }
84 
85 }