1: <?php
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: Yii::import ('application.modules.mobile.components.panel.*');
38: Yii::import ('application.modules.mobile.components.*');
39:
40: class Panel extends X2Widget {
41:
42: private $_packages;
43: public function getPackages () {
44: if (!isset ($this->_packages)) {
45: $this->_packages = array_merge (parent::getPackages (), array (
46: 'PanelJS' => array(
47: 'baseUrl' => Yii::app()->controller->assetsUrl,
48: 'js' => array(
49: 'js/Panel.js',
50: ),
51: ),
52: ));
53: }
54: return $this->_packages;
55: }
56:
57: public function getModuleItems () {
58: $modules = MobileModule::supportedModules ();
59: $modules = array_filter ($modules, function ($module) {
60: if ($module->name === 'users') {
61: $action = 'ProfileMobileIndex';
62: } else {
63: $action = ucfirst ($module->name).'Index';
64: }
65: $authItem = Yii::app()->authManager->getAuthItem ($action);
66: return Yii::app()->params->isAdmin ||
67: is_null ($authItem) || Yii::app()->user->checkAccess ($action);
68: });
69: return array_map (function ($module) {
70: $item = new ModulePanelItem;
71: $item->module = $module;
72: return $item;
73: }, $modules);
74: }
75:
76: public function getRecentItems ($pageSize=1) {
77: $dataProvider = MobileRecentItems::getDataProvider ($pageSize);
78: $data = array_map (function ($record) {
79: $item = new RecentItemPanelItem;
80: $item->model = $record['model'];
81: return $item;
82: }, $dataProvider->getData ());
83: if (count ($data) < count (MobileRecentItems::getRecentItems ())) {
84: $item = new RecentItemPanelItem;
85: $item->model = 'more';
86: $data[] = $item;
87: }
88: return $data;
89: }
90:
91: public function getPages () {
92: return array (
93: 'modules' => $this->getModuleItems (),
94: 'recentItems' => $this->getRecentItems (),
95: 'auxiliary' => array (
96: Yii::createComponent (array (
97: 'class' => 'PanelItem',
98: 'title' => Yii::t('app', 'Settings'),
99: 'id' => 'settings',
100: 'isSelected' => preg_match (
101: '/mobile\/settings$/', Yii::app()->request->pathInfo),
102: 'href' => Yii::app()->createAbsoluteUrl ('/mobile/settings'),
103: )),
104: Yii::createComponent (array (
105: 'class' => 'PanelItem',
106: 'title' => Yii::t('app', 'About'),
107: 'id' => 'about',
108: 'isSelected' => preg_match ('/mobile\/about$/', Yii::app()->request->pathInfo),
109: 'href' => Yii::app()->createAbsoluteUrl ('/mobile/about'),
110: )),
111: Yii::createComponent (array (
112: 'class' => 'PanelItem',
113: 'title' => Yii::t('app', 'Log Out'),
114:
115:
116:
117: 'href' => Yii::app()->createAbsoluteUrl ('/mobile/logout'),
118: 'id' => 'logOut',
119: 'linkHtmlOptions' => array (
120: 'class' => 'logout-button'
121: )
122: )),
123: )
124: );
125: }
126:
127: public function renderSectionTitle ($section) {
128: $html = '';
129: switch ($section) {
130: case 'modules':
131: break;
132: case 'auxiliary':
133: $html .= "<li data-role='list-divider'></li>";
134: break;
135: case 'recentItems':
136: $html .=
137: "<li data-role='list-divider'
138: class='panel-recent-item ui-li-divider ui-bar-inherit'>".
139: CHtml::encode (Yii::t('app', 'RECENT')).
140: "</li>";
141: break;
142: }
143: return $html;
144: }
145:
146: public function renderItems ($filter=null) {
147: $pages = $this->getPages ();
148: if ($filter) {
149: $sections = array_filter (array_keys ($pages), $filter);
150: $pages = array_intersect_key ($pages, array_flip ($sections));
151: }
152:
153: $html = '';
154: foreach ($pages as $section => $items) {
155: $html .= $this->renderSectionTitle ($section);
156: foreach ($items as $item) {
157: $html .= $item->render ();
158: }
159: }
160: return $html;
161: }
162:
163: public function run () {
164: parent::run ();
165: $this->registerPackages ();
166: $this->render ('application.modules.mobile.views.mobile._panel');
167: }
168:
169: }
170:
171: ?>
172: