1<?php 2 3namespace Kanboard\Controller; 4 5/** 6 * Class ProjectViewController 7 * 8 * @package Kanboard\Controller 9 * @author Frederic Guillot 10 */ 11class ProjectViewController extends BaseController 12{ 13 /** 14 * Show the project information page 15 * 16 * @access public 17 */ 18 public function show() 19 { 20 $project = $this->getProject(); 21 $columns = $this->columnModel->getAllWithTaskCount($project['id']); 22 23 $this->response->html($this->helper->layout->project('project_view/show', array( 24 'project' => $project, 25 'columns' => $columns, 26 'title' => $project['name'], 27 ))); 28 } 29 30 /** 31 * Public access management 32 * 33 * @access public 34 */ 35 public function share() 36 { 37 $project = $this->getProject(); 38 39 $this->response->html($this->helper->layout->project('project_view/share', array( 40 'project' => $project, 41 'title' => t('Public access'), 42 ))); 43 } 44 45 /** 46 * Change project sharing 47 * 48 * @throws \Kanboard\Core\Controller\AccessForbiddenException 49 * @throws \Kanboard\Core\Controller\PageNotFoundException 50 */ 51 public function updateSharing() 52 { 53 $project = $this->getProject(); 54 $this->checkCSRFParam(); 55 $switch = $this->request->getStringParam('switch'); 56 57 if ($this->projectModel->{$switch.'PublicAccess'}($project['id'])) { 58 $this->flash->success(t('Project updated successfully.')); 59 } else { 60 $this->flash->failure(t('Unable to update this project.')); 61 } 62 63 $this->response->redirect($this->helper->url->to('ProjectViewController', 'share', array('project_id' => $project['id']))); 64 } 65 66 /** 67 * Integrations page 68 * 69 * @access public 70 */ 71 public function integrations() 72 { 73 $project = $this->getProject(); 74 75 $this->response->html($this->helper->layout->project('project_view/integrations', array( 76 'project' => $project, 77 'title' => t('Integrations'), 78 'webhook_token' => $this->configModel->get('webhook_token'), 79 'values' => $this->projectMetadataModel->getAll($project['id']), 80 'errors' => array(), 81 ))); 82 } 83 84 /** 85 * Update integrations 86 * 87 * @throws \Kanboard\Core\Controller\PageNotFoundException 88 */ 89 public function updateIntegrations() 90 { 91 $project = $this->getProject(); 92 93 $this->projectMetadataModel->save($project['id'], $this->request->getValues()); 94 $this->flash->success(t('Project updated successfully.')); 95 $this->response->redirect($this->helper->url->to('ProjectViewController', 'integrations', array('project_id' => $project['id']))); 96 } 97 98 /** 99 * Display project notifications 100 * 101 * @access public 102 */ 103 public function notifications() 104 { 105 $project = $this->getProject(); 106 107 $this->response->html($this->helper->layout->project('project_view/notifications', array( 108 'notifications' => $this->projectNotificationModel->readSettings($project['id']), 109 'types' => $this->projectNotificationTypeModel->getTypes(), 110 'project' => $project, 111 'title' => t('Notifications'), 112 ))); 113 } 114 115 /** 116 * Update notifications 117 * 118 * @throws \Kanboard\Core\Controller\PageNotFoundException 119 */ 120 public function updateNotifications() 121 { 122 $project = $this->getProject(); 123 $values = $this->request->getValues(); 124 125 $this->projectNotificationModel->saveSettings($project['id'], $values); 126 $this->flash->success(t('Project updated successfully.')); 127 $this->response->redirect($this->helper->url->to('ProjectViewController', 'notifications', array('project_id' => $project['id']))); 128 } 129 130 /** 131 * Duplicate a project 132 * 133 * @author Antonio Rabelo 134 * @author Michael Lüpkes 135 * @access public 136 */ 137 public function duplicate() 138 { 139 $project = $this->getProject(); 140 141 $this->response->html($this->helper->layout->project('project_view/duplicate', array( 142 'project' => $project, 143 'title' => t('Clone this project') 144 ))); 145 } 146 147 /** 148 * Do project duplication 149 */ 150 public function doDuplication() 151 { 152 $this->checkCSRFForm(); 153 154 $project = $this->getProject(); 155 $values = $this->request->getRawFormValues(); 156 157 $project_id = $this->projectDuplicationModel->duplicate($project['id'], array_keys($values), $this->userSession->getId()); 158 159 if ($project_id !== false) { 160 $this->flash->success(t('Project cloned successfully.')); 161 } else { 162 $this->flash->failure(t('Unable to clone this project.')); 163 } 164 165 $this->response->redirect($this->helper->url->to('ProjectViewController', 'show', array('project_id' => $project_id))); 166 } 167} 168