Implement newly shared projects

This commit is contained in:
Eike Foken
2011-09-20 22:22:36 +02:00
parent 11b3e4f109
commit 986bf7b251
4 changed files with 128 additions and 0 deletions

View File

@@ -74,6 +74,7 @@ class Ajax extends MY_Controller {
'jobs_finished' => count($unseen), 'jobs_finished' => count($unseen),
'jobs_running' => $this->job->countRunning(), 'jobs_running' => $this->job->countRunning(),
'jobs_pending' => $this->job->countPending(), 'jobs_pending' => $this->job->countPending(),
'shared_projects' => $this->share->countUnseen(),
); );
$this->output->set_output(json_encode($data)); $this->output->set_output(json_encode($data));

View File

@@ -0,0 +1,61 @@
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Karsten Heiken, Eike Foken
*
* 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.
*/
/**
*
* @author Eike Foken <kontakt@eikefoken.de>
*/
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 */

View File

@@ -72,6 +72,28 @@ class Share extends CI_Model {
return $this->db->get_where('shares', array('user_id' => $userId))->result_array(); 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. * Creates a share.
* *

View File

@@ -0,0 +1,44 @@
<?php $this->load->view('header');?>
<div id="content">
<div class="title">
<h2><?=_('Projects shared with me');?></h2>
</div>
<div class="box">
<h3><?=_('List of projects');?></h3>
<table class="tableList paginated">
<thead>
<tr>
<th scope="col"><?=_('Project');?></th>
<th scope="col"><?=_('Owner');?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($projects as $share):
$project = $this->project->getById($share['project_id']);
$user = $this->user->getUserById($project['owner']);
?>
<tr>
<td>
<a href="<?=site_url('projects/detail/' . $project['id'] . '?active_project=' . $project['id']);?>"><abbr title="<?=$project['name'] . "\n\n" . $project['description'];?>"><?=$project['mediumname'];?></abbr></a>
<?=($share['seen'] == 0) ? image_asset('icons/new-text.png', 'class="icon"') : '';?>
</td>
<td><a href="<?=site_url('users/profile/' . urlencode($user['username']));?>" title="<?=_('Show profile');?>"><?=$user['firstname'] . ' ' . $user['lastname'];?></a></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
<h3><?=_('Actions');?></h3>
<p>
<a href="<?=site_url('shares/mark_all_seen');?>" class="button"><?=_('Mark all as seen');?></a>
</p>
</div>
</div>
<?php $this->load->view('footer');?>