Blame view

protected/components/NodeSiteController.php 1.32 KB
a1684257   Administrator   first commit
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
  <?php
  abstract class NodeSiteController extends Controller
  {
      public $node_id;
      /** @var Node|null */
      private $_node;
  
      public function init()
      {
          parent::init();
          if (isset($_GET['node_id'])) $this->node_id = $_GET['node_id'];
          else throw new CHttpException(500, 'node_id is not set');
      }
  
      public function createUrl($route, $params = array(), $ampersand = '&')
      {
          if ($route === '') {
              $route = $this->getId() . '/' . $this->getAction()->getId();
              if (!isset($params['node_id']))
                  $params['node_id'] = $this->node_id;
          } else if (strpos($route, '/') === false) {
              $route = $this->getId() . '/' . $route;
              if (!isset($params['node_id']))
                  $params['node_id'] = $this->node_id;
          } else {
              if (substr($route, 0, strlen($this->getId())) == $this->getId()) {
                  if (!isset($params['node_id']))
                      $params['node_id'] = $this->node_id;
              }
          }
          return Yii::app()->createUrl(trim($route, '/'), $params, $ampersand);
      }
  
      /**
       * @return Node
       */
      public function getNode()
      {
          if (!isset($this->_node))
              $this->_node = Node::model()->with('i18n')->findByPk($this->node_id);
          return $this->_node;
      }
  }