Implement project shares
This commit is contained in:
@@ -35,6 +35,8 @@ class Projects extends CI_Controller {
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
$this->load->model('experiment');
|
$this->load->model('experiment');
|
||||||
|
$this->load->model('job');
|
||||||
|
$this->load->model('share');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,19 +129,41 @@ class Projects extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->load->helper('typography');
|
$this->load->helper('typography');
|
||||||
$this->load->model('job');
|
|
||||||
|
|
||||||
$data['project'] = $project;
|
$data['project'] = $project;
|
||||||
$data['experiments'] = $this->experiment->getByProjectId($id);
|
$data['experiments'] = $this->experiment->getByProjectId($id);
|
||||||
$data['jobs'] = $this->job->getRecent($id);
|
$data['jobs'] = $this->job->getRecent($id);
|
||||||
|
$data['shares'] = $this->share->getByProjectId($id);
|
||||||
|
|
||||||
$this->load->view('projects/detail', $data);
|
$this->load->view('projects/detail', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows users to share their projects.
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
*/
|
||||||
|
public function share($id) {
|
||||||
|
$project = $this->project->getById($id);
|
||||||
|
if (!$project) {
|
||||||
|
show_404();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->_checkAccess($id)) {
|
||||||
|
// check if the user has access
|
||||||
|
show_error(_("Sorry, you don't have access to this project."), 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['project'] = $project;
|
||||||
|
$data['shares'] = $this->share->getByProjectId($id);
|
||||||
|
|
||||||
|
$this->load->view('projects/shares', $data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows users to delete a project.
|
* Allows users to delete a project.
|
||||||
*
|
*
|
||||||
* @param integer $projectId
|
* @param string $id
|
||||||
*/
|
*/
|
||||||
public function delete($id) {
|
public function delete($id) {
|
||||||
if (!$this->_checkAccess($id)) { // check if the user has access
|
if (!$this->_checkAccess($id)) { // check if the user has access
|
||||||
|
|||||||
@@ -95,9 +95,19 @@ class Project extends CI_Model {
|
|||||||
* @return array All accessible projects
|
* @return array All accessible projects
|
||||||
*/
|
*/
|
||||||
public function getAccessible($userId) {
|
public function getAccessible($userId) {
|
||||||
|
$shares = array();
|
||||||
|
$query = $this->db->get_where('shares', array('user_id' => $userId));
|
||||||
|
foreach ($query->result_array() as $share) {
|
||||||
|
$shares[] = $share['project_id'];
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->where('public', 1);
|
$this->db->where('public', 1);
|
||||||
$this->db->or_where('owner', $userId);
|
$this->db->or_where('owner', $userId);
|
||||||
|
|
||||||
|
if (count($shares) > 0) {
|
||||||
|
$this->db->or_where_in('projects.id', $shares);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->getAll();
|
return $this->getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +157,6 @@ class Project extends CI_Model {
|
|||||||
* @param type $needle The needle to look for in the haystack.
|
* @param type $needle The needle to look for in the haystack.
|
||||||
*/
|
*/
|
||||||
public function search($needle) {
|
public function search($needle) {
|
||||||
|
|
||||||
// get matching projects that are public
|
// get matching projects that are public
|
||||||
$query = $this->db->query("SELECT * FROM `projects` WHERE `public`='1' AND `name` LIKE ".$this->db->escape('%'.$needle.'%'));
|
$query = $this->db->query("SELECT * FROM `projects` WHERE `public`='1' AND `name` LIKE ".$this->db->escape('%'.$needle.'%'));
|
||||||
$public_results = $query->result_array();
|
$public_results = $query->result_array();
|
||||||
|
|||||||
94
application/models/share.php
Normal file
94
application/models/share.php
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011 Eike Foken <kontakt@eikefoken.de>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model for shares.
|
||||||
|
*
|
||||||
|
* @author Eike Foken <kontakt@eikefoken.de>
|
||||||
|
*/
|
||||||
|
class Share extends CI_Model {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the parent constructor.
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all share for a specific project.
|
||||||
|
*
|
||||||
|
* @param string $projectId
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getByProjectId($projectId) {
|
||||||
|
$this->db->select('shares.*, users.firstname, users.lastname');
|
||||||
|
$this->db->join('users', 'users.id = shares.user_id', 'left');
|
||||||
|
|
||||||
|
return $this->db->get_where('shares', array('project_id' => $projectId))->result_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a share.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function create($data) {
|
||||||
|
$this->db->insert('shares', $data);
|
||||||
|
return $this->db->affected_rows() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a share.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function update($data) {
|
||||||
|
if (!isset($data['project_id']) || !isset($data['user_id'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->update('shares', $data, array('project_id' => $data['project_id'], 'user_id' => $data['user_id']));
|
||||||
|
return $this->db->affected_rows() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a share.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function delete($data) {
|
||||||
|
if (!isset($data['project_id']) || !isset($data['user_id'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->delete('shares', array('project_id' => $data['project_id'], 'user_id' => $data['user_id']));
|
||||||
|
return $this->db->affected_rows() > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of file share.php */
|
||||||
|
/* Location: ./application/controllers/share.php */
|
||||||
@@ -3,7 +3,11 @@
|
|||||||
<div id="content">
|
<div id="content">
|
||||||
|
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<h2><?=_('Project details');?></h2>
|
<h2>
|
||||||
|
<?=_('Project');?> »<?=$project['name'];?>«
|
||||||
|
|
||||||
|
<a class="share" href="<?=site_url('projects/share/' . $project['id']);?>"><?=_(sprintf('Shared with %s people', count($shares)));?></a>
|
||||||
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
@@ -34,6 +38,7 @@
|
|||||||
<?php
|
<?php
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<h3><?=_('Experiments');?></h3>
|
<h3><?=_('Experiments');?></h3>
|
||||||
<table class="tableList">
|
<table class="tableList">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -71,7 +76,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p><a class="button add" href="<?=site_url('experiments/create/' . $project['id']);?>"><?=_('Create experiment');?></a>
|
<p><a class="button add" href="<?=site_url('experiments/create/' . $project['id']);?>"><?=_('Create experiment');?></a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="title">
|
<div class="title">
|
||||||
|
|||||||
58
application/views/projects/shares.php
Normal file
58
application/views/projects/shares.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php $this->load->view('header');?>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<div class="title">
|
||||||
|
<h2><?=_('Project');?> »<?=$project['name'];?>«</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<table class="tableList">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col"><?=_('User');?></th>
|
||||||
|
<th scope="col"><?=_('Rights');?></th>
|
||||||
|
<th scope="col"><?=_('Actions');?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
foreach ($shares as $share):
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><a href="<?=site_url('users/profile/' . $share['user_id']);?>"><?=$share['firstname'];?> <?=$share['lastname'];?></a></td>
|
||||||
|
<td><?=form_dropdown('rights', array('Can edit', 'Can view'), $share['can_edit'], 'class="drop"')?></td>
|
||||||
|
<td><a href="?action=delete&user_id=<?=$share['user_id'];?>"><?=_('Delete');?></a></td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<form method="post" name="addShare" action="<?=site_url('projects/share/' . $project['id']);?>">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<div>
|
||||||
|
<?=form_label(_('Add person:'), 'user_id');?>
|
||||||
|
<select name="user_id" id="user_id" class="drop">
|
||||||
|
<?php
|
||||||
|
foreach ($this->user->getAll() as $user):
|
||||||
|
?>
|
||||||
|
<option value="<?=$user['id'];?>"><?=$user['firstname'];?> <?=$user['lastname'];?></option>
|
||||||
|
<?php
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<?=form_submit('', _('Share'), 'class="submit"');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p><a class="button save" href="javascript:history.back();"><?=_('Save and back');?></a></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $this->load->view('footer');?>
|
||||||
@@ -45,6 +45,11 @@ input.button {
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input.submit {
|
||||||
|
padding: 0 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
select.drop {
|
select.drop {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
margin: 5px 5px 0 0;
|
margin: 5px 5px 0 0;
|
||||||
@@ -75,11 +80,14 @@ p.success {
|
|||||||
color: #008000;
|
color: #008000;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.error, span.req {
|
p.error,
|
||||||
|
span.req {
|
||||||
color: #d8122d;
|
color: #d8122d;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.success strong, p.error strong, p.req strong {
|
p.success strong,
|
||||||
|
p.error strong,
|
||||||
|
p.req strong {
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -447,6 +447,11 @@ a.delete {
|
|||||||
padding-left: 30px;
|
padding-left: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.edit {
|
||||||
|
background: url(../images/icons/pencil.png) 10px center no-repeat #f3f3f3;
|
||||||
|
padding-left: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
a.flag {
|
a.flag {
|
||||||
background: url(../images/icons/flag.png) 10px center no-repeat #f3f3f3;
|
background: url(../images/icons/flag.png) 10px center no-repeat #f3f3f3;
|
||||||
padding-left: 30px;
|
padding-left: 30px;
|
||||||
@@ -505,6 +510,13 @@ a.down-big {
|
|||||||
padding: 10px 15px;
|
padding: 10px 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.share {
|
||||||
|
background: url(../images/icons/hand-share.png) 6px center no-repeat;
|
||||||
|
padding-left: 28px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
/* Tabs */
|
/* Tabs */
|
||||||
|
|
||||||
ul.tabs {
|
ul.tabs {
|
||||||
|
|||||||
Reference in New Issue
Block a user