PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/admin/projects.php

https://bitbucket.org/prat_h/rakbuku
PHP | 413 lines | 266 code | 74 blank | 73 comment | 17 complexity | 71e8fe71e5484f3af19a323f1b3f7db7 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. require_once(APPPATH.'controllers/admin/dashboard.php');
  3. class Projects extends Dashboard {
  4. public $data;
  5. public $fw_default_num = 4;
  6. function __construct() {
  7. parent::__construct();
  8. $this->load->model('projects_model', 'projects');
  9. $this->load->model('types_model', 'types');
  10. $this->load->model('topics_model', 'topics');
  11. $this->load->model('page_template_model', 'ptm');
  12. if(! $this->is_login())
  13. {
  14. redirect('admin/dashboard');
  15. }
  16. }
  17. public function index($offset=0)
  18. {
  19. /*
  20. * tentukan menu-menu sidebar ke dalam array $this->data['menu']
  21. */
  22. $this->data['title'] = 'Projects';
  23. $this->data['menu'] = $this->get_sidebar_menu();
  24. $this->load->view('admin/projects/projects', $this->data);
  25. }
  26. /*------------------------------------------------------------------------
  27. | Method : getmenu
  28. |-------------------------------------------------------------------------
  29. | Paramater : void
  30. | Return : array
  31. | Description : fungsi controller untuk menset menusidebar
  32. | Author : Pratama Hasriyan
  33. ------------------------------------------------------------------------*/
  34. private function get_sidebar_menu()
  35. {
  36. $menu = array(
  37. 'title' => 'Projects',
  38. 'menus' => array(
  39. 'need_reviews' => 'Need-Review Projects',
  40. //'published' => 'Published Projects',
  41. //'drafts' => 'Draft Projects',
  42. //'unpublished' => 'Unpublished Projects',
  43. 'project_types' => 'Project Types',
  44. //'topics' => 'Topics',
  45. //'project_data_template' => 'Project Data Template',
  46. 'project_frameworks' => 'Project Frameworks'
  47. ),
  48. );
  49. return $menu;
  50. }
  51. /**
  52. * PROJECT TYPES
  53. */
  54. public function project_types($offset=0)
  55. {
  56. /*
  57. * tentukan menu-menu sidebar ke dalam array $this->data['menu']
  58. */
  59. $this->data['title'] = 'Project Types';
  60. $this->data['menu'] = $this->get_sidebar_menu();
  61. $order = array(
  62. 'type_id'=>'ASC'
  63. );//end menu
  64. /*
  65. * pagination
  66. */
  67. $perpage = 2;
  68. $totalrow = count($this->types->get_types('', $order));
  69. $this->paginating($totalrow, "admin/projects/project_types/", 4, $perpage);//end pagination
  70. $this->data['types'] = $this->types->get_types('', $order, $perpage, $offset);
  71. $this->load->view('admin/projects/types', $this->data);
  72. }
  73. public function add_type()
  74. {
  75. $this->form_validation->set_rules('type_name', 'Project Type', 'required');
  76. if($this->form_validation->run() == FALSE)
  77. {
  78. $return['validation_error'] = 'validation error';
  79. $return['errors'] = validation_errors('<div class="error">', '</div>');
  80. echo json_encode($return);
  81. die();
  82. }
  83. $tp = $this->input->post('type_name');
  84. $slug = strtolower(str_replace(" ", "-", $tp));
  85. $par = array(
  86. 'type_name'=>$this->input->post('type_name'),
  87. 'type_slug'=>$slug
  88. );
  89. $return['datainput'] = $this->types->add_type($par);
  90. if($return['datainput'] === 'gagal add')
  91. {
  92. $return['data_ada'] = "Tipe Project yang Anda masukkan telah ada, coba yang lain";
  93. }
  94. else
  95. {
  96. $return['sukses_add'] = 'sukses';
  97. }
  98. echo json_encode($return);
  99. }
  100. public function edit_type()
  101. {
  102. $this->form_validation->set_rules('type_name', 'Nama Tipe', 'required');
  103. if($this->form_validation->run() == FALSE)
  104. {
  105. $return['validation_error'] = 'validation error';
  106. $return['errors'] = validation_errors('<div class="error">', '</div>');
  107. echo json_encode($return);
  108. die();
  109. }
  110. $par = array(
  111. 'type_name'=>$this->input->post('type_name')
  112. );
  113. $clause = array(
  114. 'type_id'=>$this->input->post('ID')
  115. );
  116. $return['dataupdate'] = $this->types->edit_type($par, $clause);
  117. $return[0] = $return['dataupdate'][0]['type_name'];
  118. $return['input'] = array($return['dataupdate'][0]['type_id'], $return[0]);
  119. echo json_encode($return);
  120. }
  121. public function del_type()
  122. {
  123. $type_id = $this->input->post('ID');
  124. $clause = array(
  125. 'type_id'=>$type_id
  126. );
  127. $return['sukses_del'] = $this->types->del_type($clause);
  128. echo json_encode($return);
  129. }
  130. /**
  131. * end PROJECT TYPES
  132. */
  133. /**
  134. * PROJECT TOPICS
  135. */
  136. public function topics($offset=0)
  137. {
  138. /*
  139. * tentukan menu-menu sidebar ke dalam array $this->data['menu']
  140. */
  141. $this->data['title'] = 'Project Topics';
  142. $this->data['menu'] = $this->get_sidebar_menu();
  143. $order = array(
  144. 'topic_id'=>'ASC'
  145. );//end menu
  146. /*
  147. * pagination
  148. */
  149. $perpage = 2;
  150. $totalrow = count($this->topics->get_topics('', $order));
  151. $this->paginating($totalrow, "admin/projects/topics/", 4, $perpage);//end pagination
  152. $this->data['topics'] = $this->topics->get_topics('', $order, $perpage, $offset);
  153. $this->load->view('admin/projects/topics', $this->data);
  154. }
  155. public function add_topic()
  156. {
  157. $this->form_validation->set_rules('topic_name', 'Project Topics', 'required');
  158. if($this->form_validation->run() == FALSE)
  159. {
  160. $return['validation_error'] = 'validation error';
  161. $return['errors'] = validation_errors('<div class="error">', '</div>');
  162. echo json_encode($return);
  163. die();
  164. }
  165. $par = array(
  166. 'topic_name'=>$this->input->post('topic_name')
  167. );
  168. $return['datainput'] = $this->topics->add_topic($par);
  169. if($return['datainput'] === 'gagal add')
  170. {
  171. $return['data_ada'] = "Tipe Project yang Anda masukkan telah ada, coba yang lain";
  172. }
  173. else
  174. {
  175. $return['sukses_add'] = 'sukses';
  176. }
  177. echo json_encode($return);
  178. }
  179. public function edit_topic()
  180. {
  181. $this->form_validation->set_rules('topic_name', 'Nama Topic', 'required');
  182. if($this->form_validation->run() == FALSE)
  183. {
  184. $return['validation_error'] = 'validation error';
  185. $return['errors'] = validation_errors('<div class="error">', '</div>');
  186. echo json_encode($return);
  187. die();
  188. }
  189. $par = array(
  190. 'topic_name'=>$this->input->post('topic_name')
  191. );
  192. $clause = array(
  193. 'topic_id'=>$this->input->post('ID')
  194. );
  195. $return['dataupdate'] = $this->topics->edit_topic($par, $clause);
  196. $return[0] = $return['dataupdate'][0]['topic_name'];
  197. $return['input'] = array($return['dataupdate'][0]['topic_id'], $return[0]);
  198. echo json_encode($return);
  199. }
  200. public function del_topic()
  201. {
  202. $topic_id = $this->input->post('ID');
  203. $clause = array(
  204. 'topic_id'=>$topic_id
  205. );
  206. $return['sukses_del'] = $this->topics->del_topic($clause);
  207. echo json_encode($return);
  208. }
  209. /**
  210. * end PROJECT TOPICS
  211. */
  212. /**
  213. * NEED REVIEWS
  214. */
  215. public function need_reviews($offset=0)
  216. {
  217. /*
  218. * tentukan menu-menu sidebar ke dalam array $this->data['menu']
  219. */
  220. $this->data['title'] = 'Project Types';
  221. $this->data['menu'] = $this->get_sidebar_menu();
  222. //end menu
  223. /*
  224. * pagination
  225. */
  226. $par = array(
  227. "rb_projects_state" => array(
  228. "project_state" => "admin review"
  229. )
  230. );
  231. $perpage = 2;
  232. $totalrow = count($this->projects_model->get_projects_state($par));
  233. //$this->paginating("projects_model", "home/index/", 3, $perpage);//end pagination
  234. $this->paginating_project($totalrow, "admin/projects/need_reviews/", 4, $perpage);//end pagination
  235. $this->data['need_reviews'] = $this->projects_model->get_projects_need_review("admin review", "ASC", $perpage, $offset);
  236. $this->data['types'] = array();
  237. if( !empty($this->data['need_reviews']) ) {
  238. foreach( $this->data['need_reviews'] as $k => $v ) {
  239. $par = array(
  240. "type_id" => $v["type_id"]
  241. );
  242. $types = $this->types->get_types($par);
  243. array_push($this->data['types'], $types[0]["type_name"]);
  244. }
  245. }
  246. /*
  247. echo "<pre>";
  248. print_r($this->data["types"]);
  249. echo "</pre>";
  250. */
  251. $this->load->view('admin/projects/need_reviews', $this->data);
  252. }
  253. /**
  254. * END NEED REVIEWS
  255. */
  256. /**
  257. * PROJECT FRAMEWORKS
  258. */
  259. public function project_frameworks()
  260. {
  261. /*
  262. * tentukan menu-menu sidebar ke dalam array $this->data['menu']
  263. */
  264. $this->data['title'] = 'Project Frameworks';
  265. $this->data['menu'] = $this->get_sidebar_menu();
  266. $order = array(
  267. 'type_id'=>'ASC'
  268. );//end menu
  269. $this->data['types'] = $this->types->get_types('', $order);
  270. $this->load->view('admin/projects/frameworks', $this->data);
  271. }
  272. public function load_frameworks($arg) {
  273. $this->data["par"] = $arg;
  274. $par = array(
  275. "rb_projects_fw" => array(
  276. "type_id" => $arg
  277. )
  278. );
  279. $partype = array(
  280. "type_id" => $arg
  281. );
  282. $this->data['types'] = $this->types->get_types($partype);
  283. $this->data["fw_data"] = $this->projects->get_projects_fw($par);
  284. $this->data["fw"] = unserialize($this->data["fw_data"][0]["fw"]);
  285. $countfw = count($this->data["fw"]);
  286. $diff = $countfw - $this->fw_default_num;
  287. if( $countfw == $this->fw_default_num ) {
  288. $this->data["slice"] = NULL;
  289. } else {
  290. if( $diff > 0 ) {
  291. $this->data["slice"] = array_slice($this->data["fw"], 2, $diff);
  292. }
  293. }
  294. $this->load->view( "admin/projects/ajax_fw", $this->data );
  295. }
  296. public function save_frameworks($arg) {
  297. $inputs = $this->input->post();
  298. $seri = serialize($inputs);
  299. $return["result"] = $seri;
  300. $par = array(
  301. "type_id" => $arg,
  302. "fw" => $seri
  303. );
  304. $return["result"] = $this->projects->add_projects_fw($par);
  305. echo json_encode($return);
  306. }
  307. /**
  308. * end PROJECT FRAMEWORKS
  309. */
  310. /**
  311. * MODAL CONTROLLERS
  312. */
  313. public function get_modal_add_type()
  314. {
  315. $this->load->view('admin/modals/add_type');
  316. }
  317. public function get_modal_edit_type()
  318. {
  319. $this->load->view('admin/modals/edit_type');
  320. }
  321. public function get_modal_del_type()
  322. {
  323. $this->load->view('admin/modals/del_type');
  324. }
  325. public function get_modal_add_topic()
  326. {
  327. $this->load->view('admin/modals/add_topic');
  328. }
  329. public function get_modal_edit_topic()
  330. {
  331. $this->load->view('admin/modals/edit_topic');
  332. }
  333. public function get_modal_del_topic()
  334. {
  335. $this->load->view('admin/modals/del_topic');
  336. }
  337. }
  338. /* End of file welcome.php */
  339. /* Location: ./application/controllers/welcome.php */