Implement project shares
This commit is contained in:
@@ -95,9 +95,19 @@ class Project extends CI_Model {
|
||||
* @return array All accessible projects
|
||||
*/
|
||||
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->or_where('owner', $userId);
|
||||
|
||||
if (count($shares) > 0) {
|
||||
$this->db->or_where_in('projects.id', $shares);
|
||||
}
|
||||
|
||||
return $this->getAll();
|
||||
}
|
||||
|
||||
@@ -147,7 +157,6 @@ class Project extends CI_Model {
|
||||
* @param type $needle The needle to look for in the haystack.
|
||||
*/
|
||||
public function search($needle) {
|
||||
|
||||
// get matching projects that are public
|
||||
$query = $this->db->query("SELECT * FROM `projects` WHERE `public`='1' AND `name` LIKE ".$this->db->escape('%'.$needle.'%'));
|
||||
$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 */
|
||||
Reference in New Issue
Block a user