Complete shares implementation

This commit is contained in:
Eike Foken
2011-09-09 00:27:56 +02:00
parent 4832e8eab0
commit a017aaff06
5 changed files with 60 additions and 26 deletions

View File

@@ -135,7 +135,7 @@ class Project extends CI_Model {
* Get all projects from the database.
*/
public function getAll() {
$result = $this->db->select('projects.*, users.firstname AS `firstname`, users.lastname AS `lastname`')
$result = $this->db->select('projects.*, users.username, users.firstname, users.lastname')
->join('users', 'users.id = projects.owner', 'left')
->get('projects')->result_array();

View File

@@ -53,7 +53,7 @@ class Share extends CI_Model {
* @return array
*/
public function getByProjectId($projectId) {
$this->db->select('shares.*, users.firstname, users.lastname');
$this->db->select('shares.*, users.username, 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();
@@ -79,7 +79,16 @@ class Share extends CI_Model {
* @return boolean
*/
public function create($data) {
$this->db->insert('shares', $data);
if (!isset($data['project_id']) || !isset($data['user_id'])) {
return false;
}
$this->db->query('REPLACE INTO `shares` (`project_id`, `user_id`, `can_edit`) VALUES ('
. $this->db->escape($data['project_id']) . ', '
. $this->db->escape($data['user_id']) . ', '
. $this->db->escape($data['can_edit']) . ')');
//$this->db->insert('shares', $data);
return $this->db->affected_rows() == 1;
}