From 986bf7b25185054502b340f270b97e52ce2972fc Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Tue, 20 Sep 2011 22:22:36 +0200 Subject: [PATCH] Implement newly shared projects --- application/controllers/ajax.php | 1 + application/controllers/shares.php | 61 ++++++++++++++++++++++++++++++ application/models/share.php | 22 +++++++++++ application/views/shares/list.php | 44 +++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 application/controllers/shares.php create mode 100644 application/views/shares/list.php diff --git a/application/controllers/ajax.php b/application/controllers/ajax.php index 3c50de1..6b4f6c9 100644 --- a/application/controllers/ajax.php +++ b/application/controllers/ajax.php @@ -74,6 +74,7 @@ class Ajax extends MY_Controller { 'jobs_finished' => count($unseen), 'jobs_running' => $this->job->countRunning(), 'jobs_pending' => $this->job->countPending(), + 'shared_projects' => $this->share->countUnseen(), ); $this->output->set_output(json_encode($data)); diff --git a/application/controllers/shares.php b/application/controllers/shares.php new file mode 100644 index 0000000..3d8b18c --- /dev/null +++ b/application/controllers/shares.php @@ -0,0 +1,61 @@ + + */ +class Shares extends MY_Controller { + + /** + * Constructor. + */ + public function __construct() { + parent::__construct(); + } + + /** + * Shows a list of all projects. + */ + public function index() { + $data['projects'] = $this->share->getByUserId($this->session->userdata('user_id')); + + $this->load->view('shares/list', $data); + } + + /** + * Allows users to mark all shared projects as seen. + */ + public function mark_all_seen() { + $shares = $this->share->getByUserId($this->session->userdata('user_id')); + foreach ($shares as $share) { + if ($share['seen'] == 0) { + $this->share->markSeen($share['project_id']); + } + } + redirect('shares', 303); + } +} + +/* End of file shares.php */ +/* Location: ./application/controllers/shares.php */ diff --git a/application/models/share.php b/application/models/share.php index 59ae6cc..3b7db1e 100644 --- a/application/models/share.php +++ b/application/models/share.php @@ -72,6 +72,28 @@ class Share extends CI_Model { return $this->db->get_where('shares', array('user_id' => $userId))->result_array(); } + /** + * Counts all unseen shares. + */ + public function countUnseen() { + return $this->db->where('user_id', $this->session->userdata('user_id')) + ->where('seen', 0)->count_all_results('shares'); + } + + /** + * Marks a shared project as seen. + * + * @param string $projectId + * @return boolean Returns TRUE on success. + */ + public function markSeen($projectId) { + $this->db->where('project_id', $projectId) + ->where('user_id', $this->session->userdata('user_id')) + ->update('shares', array('seen' => 1)); + + return $this->db->affected_rows() > 0; + } + /** * Creates a share. * diff --git a/application/views/shares/list.php b/application/views/shares/list.php new file mode 100644 index 0000000..b5eb465 --- /dev/null +++ b/application/views/shares/list.php @@ -0,0 +1,44 @@ +load->view('header');?> + +
+ +
+

+
+ +
+

+ + + + + + + + +project->getById($share['project_id']); + $user = $this->user->getUserById($project['owner']); +?> + + + + + + +
+ "> + +
+

+

+ +

+
+ +
+ +load->view('footer');?>