PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/application/classes/controller/data.php

https://github.com/data-quest/histat-web
PHP | 232 lines | 167 code | 28 blank | 37 comment | 11 complexity | 7356b475cfcb31c97f93988de56b2f65 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0, LGPL-2.1
  1. <?php
  2. defined('SYSPATH') or die('No direct script access.');
  3. /**
  4. * Controller <b>Data</b>
  5. */
  6. class Controller_Data extends Controller_Index {
  7. protected $dialog = "";
  8. protected $isAdmin = false;
  9. public function before() {
  10. parent::before();
  11. //Activate Data navigation point
  12. $this->main_navi->activate(__('Data'));
  13. //Add sub navigation items
  14. $this->sub_navi->add('data/themes', __('Themes'));
  15. $this->sub_navi->add('data/times', __('Times'));
  16. $this->sub_navi->add('data/names', __('Names'));
  17. $this->sub_navi->add('data/new', __('New'));
  18. $this->sub_navi->add('data/top', __('Top'));
  19. $this->isAdmin = $this->user->has_roles(array("admin"));
  20. }
  21. public function action_index() {
  22. $this->action_themes();
  23. }
  24. public function action_new() {
  25. //Activate sub navigation point "New"
  26. $this->sub_navi->activate(__('New'));
  27. //Load model/project.php
  28. $project = ORM::factory('project');
  29. //Load view/<lang>/data/index.php
  30. $view = View::factory(I18n::$lang . '/data/index');
  31. //Load view/<lang>/project/list.php prepare the subview
  32. $list = View::factory(I18n::$lang . '/project/new');
  33. //assign new projects to subview
  34. $list->projects = $project->new_projects($this->isAdmin);
  35. //assign the referrer uri
  36. $list->uri = URL::site(I18n::$lang . '/data/index');
  37. //Assign list in view
  38. $view->list = $list->render();
  39. //Setup Dialog
  40. $view->dialog = $this->dialog;
  41. //set content
  42. $this->content = $view->render();
  43. //Setup last action
  44. $this->session->set('action', array('name' => 'index'));
  45. }
  46. public function action_top() {
  47. $this->sub_navi->activate(__('Top'));
  48. //Load model/project.php
  49. $project = ORM::factory('project');
  50. //Load view/<lang>/data/index.php
  51. $view = View::factory(I18n::$lang . '/data/top');
  52. //Load view/<lang>/project/list.php prepare the subview
  53. $list = View::factory(I18n::$lang . '/project/top');
  54. //assign new projects to subview
  55. $list->projects = $project->top_projects($this->isAdmin);
  56. //assign the referrer uri
  57. $list->uri = URL::site(I18n::$lang . '/data/top');
  58. //Assign list in view
  59. $view->list = $list->render();
  60. //Setup Dialog
  61. $view->dialog = $this->dialog;
  62. //set content
  63. $this->content = $view->render();
  64. //Setup last action
  65. $this->session->set('action', array('name' => 'top'));
  66. }
  67. public function action_themes($id = NULL) {
  68. $this->sub_navi->activate(__('Themes'));
  69. if (!$id)
  70. $id = $this->request->param('id');
  71. if (!$id) {
  72. $this->scripts[] = 'jquery.tagsphere.min.js';
  73. //$this->scripts[] = 'jquery.awesomeCloud.min.js';
  74. $this->scripts[] = 'themes.js';
  75. $orm = ORM::factory('theme');
  76. $total = 0;
  77. $themes_tmp = $orm->getThemes($this->isAdmin)->order_by('summe', 'DESC')->as_object()->execute();
  78. foreach ($themes_tmp as $theme) {
  79. $total += $theme->summe;
  80. }
  81. if (!$total) $total = 1;
  82. $themes = array();
  83. $i = 0;
  84. foreach ($themes_tmp as $theme) {
  85. $themes[$theme->Thema] = array('top' => ($i < 5) ? true : false, 'count' => 15 + ceil(($theme->summe / $total) * 100), 'id' => $theme->ID_Thema);
  86. $i++;
  87. }
  88. $view = View::factory(I18n::$lang . '/data/themes/cloud');
  89. $view->themes = $themes;//$this->shuffle_assoc($themes);
  90. } else {
  91. $orm = ORM::factory('theme', $id);
  92. $view = View::factory(I18n::$lang . '/data/themes/overview');
  93. $theme_list = $orm->getThemes($this->isAdmin)->as_object()->execute();
  94. $view->theme_list = $theme_list;
  95. //Load view/<lang>/project/list.php prepare the subview
  96. $list = View::factory(I18n::$lang . '/project/list');
  97. //assign new projects to subview
  98. $list->projects = $orm->projects;
  99. //assign the referrer uri
  100. $list->uri = URL::site(I18n::$lang . '/data/themes/' . $id);
  101. //Assign list in view
  102. $view->list = $list->render();
  103. }
  104. //Setup Dialog
  105. $view->dialog = $this->dialog;
  106. $this->content = $view->render();
  107. $this->session->set('action', array('name' => 'themes', 'param' => $id));
  108. }
  109. public function action_times($id = NULL) {
  110. $this->sub_navi->activate(__('Times'));
  111. if (!$id)
  112. $id = $this->request->param('id');
  113. if (!$id) {
  114. $this->scripts[] = 'jquery.tagsphere.min.js';
  115. $this->scripts[] = 'themes.js';
  116. $orm = ORM::factory('time');
  117. $total = 0;
  118. $times_tmp = $orm->getTimes($this->isAdmin)->order_by('summe', 'DESC')->as_object()->execute();
  119. foreach ($times_tmp as $time) {
  120. $total += $time->summe;
  121. }
  122. $times = array();
  123. $i = 0;
  124. foreach ($times_tmp as $time) {
  125. $times[$time->Zeit] = array('top' => ($i < 5) ? true : false, 'count' => 15 + ceil(($time->summe / $total) * 100), 'id' => $time->ID_Zeit);
  126. $i++;
  127. }
  128. $view = View::factory(I18n::$lang . '/data/times/cloud');
  129. $view->times =$times;// $this->shuffle_assoc($times);
  130. } else {
  131. $orm = ORM::factory('time', $id);
  132. $view = View::factory(I18n::$lang . '/data/times/overview');
  133. $view->time_list = $orm->getTimes($this->isAdmin)->as_object()->execute();
  134. //Load view/<lang>/project/list.php prepare the subview
  135. $list = View::factory(I18n::$lang . '/project/list');
  136. //assign new projects to subview
  137. $list->projects = $orm->projects;
  138. //assign the referrer uri
  139. $list->uri = URL::site(I18n::$lang . '/data/times/' . $id);
  140. //Assign list in view
  141. $view->list = $list->render();
  142. }
  143. //Setup Dialog
  144. $view->dialog = $this->dialog;
  145. $this->content = $view->render();
  146. $this->session->set('action', array('name' => 'times', 'param' => $id));
  147. }
  148. public function action_names($id = NULL) {
  149. $this->sub_navi->activate(__('Names'));
  150. if (!$id)
  151. $id = (urldecode($this->request->param('id')));
  152. $orm = ORM::factory('project');
  153. $view = View::factory(I18n::$lang . '/data/names/overview');
  154. $authors = $orm->getAuthors($this->isAdmin);
  155. $author_list = array();
  156. $key_list = array();
  157. foreach ($authors as $author) {
  158. $names = explode(';', $author->Projektautor);
  159. if (count($names) > 0) {
  160. foreach ($names as $name) {
  161. $name = trim(str_replace(array('(', ')'), array(''), $name));
  162. $author_id = md5($name);
  163. $key = strtoupper($name[0]);
  164. $key_list[$key] = $key;
  165. $author_list[$key][$author_id] = $name;
  166. }
  167. } else {
  168. $name = $names;
  169. $author_id = md5($name);
  170. $key = strtoupper($name[0]);
  171. $key_list[$key] = $key;
  172. $author_list[$key][$author_id] = $name;
  173. }
  174. }
  175. $sorted = array();
  176. foreach($author_list as $key=> $author){
  177. asort($author);
  178. $sorted[$key] =$author;
  179. }
  180. ksort($sorted);
  181. ksort($key_list);
  182. $view->author_list = $sorted;
  183. $view->key_list = $key_list;
  184. $view->projects = '';
  185. if ($id) {
  186. $projects = ORM::factory('project')->where('ID_Thema', '!=', $this->config->get('example_theme_id'))->where('Projektautor', 'LIKE', '%' . $id . '%');
  187. $list = View::factory(I18n::$lang . '/project/list');
  188. $list->projects = $projects;
  189. //assign the referrer uri
  190. $list->uri = URL::site(I18n::$lang . '/data/names/' . urlencode($id)) . '#' . md5($id);
  191. $view->projects = $list->render();
  192. }
  193. $view->name = $id;
  194. //Setup Dialog
  195. $view->dialog = $this->dialog;
  196. $this->content = $view->render();
  197. $this->session->set('action', array('name' => 'names', 'param' => $id));
  198. }
  199. private function shuffle_assoc($array) {
  200. $keys = array_keys($array);
  201. shuffle($keys);
  202. return array_merge(array_flip($keys), $array);
  203. }
  204. }