Closed lancepioch closed 8 years ago
Hey @arieltoledo, you'll want to add a unique filter to here: https://github.com/chintanbanugaria/92five/blob/3b5c12037f3517f481593c7e74811190246b0a47/app/ninetwofive/project/ProjectRepository.php#L41-L96
@lancepioch Lance I still see duplicated projects when loggin as an admin user. Any ideas ? Im using you repository as it is.
These changes were done almost 2 years ago, sorry.
Already found the solution Thanks !
@arieltoledo would be nice if you posted the solution here as well :)
@ivo1981 I just implement the @lancepioch solution with a filter. It's been a while but I look up for the code and post it later
@arieltoledo
That would be great! Thanks!
@ivo1981 so this is wha I did at the project repository. change the getProjects function, the secrete its in "$projectsList = $filter->unique(); "
public function getProjects($user) {
$userId = $user->id;
if ($user->inGroup(Sentry::findGroupByName('admin'))) {
// All projects are shown for administrators
$projectsList = ProjectUsers::lists('project_id');
$filter = $awards = new \Illuminate\Database\Eloquent\Collection($projectsList);
$projectsList = $filter->unique();
} else {
// Only retrieve for specific user
$projectsList = ProjectUsers::where('user_id', $userId)->lists('project_id');
$filter = $awards = new \Illuminate\Database\Eloquent\Collection($projectsList);
$projectsList = $filter->unique();
}
if ($projectsList->isEmpty() == true)
{
return null;
}
else
{
$data = array();
foreach ($projectsList as $key)
{
//Get the project
$projects = Project::where('id', $key)->get(array('id','project_name','start_date','end_date','status','completed_on', 'prioridad_id'));
//Get the Tasks List
$totalTaskList = Task::where('project_id','=',$key)->whereNotNull('project_id')->lists('id');
if(sizeof($totalTaskList) == 0)
{
//No Tasks. Everything is Zero
$arrayProjects = (array)json_decode($projects,1);
$arrayProjects[0]['overall_task'] = 0;
$arrayProjects[0]['overall_rem_task'] = 0;
$arrayProjects[0]['my_total_task'] = 0;
$arrayProjects[0]['my_rem_task'] = 0;
$arrayProjects[0]['percentage'] = 0;
$data[] = $arrayProjects;
}
else
{
//List our the tasks whose status is active or delayed
$totalUncomplTaskList = Task::whereNested(function($query) use ($key){
$query->where('project_id',$key);
$query->where('status','active');
})
->orWhere(function($query) use ($key){
$query->where('project_id',$key);
$query->where('status','delayed');
})->lists('id');
//Count the tasks assigned to the user
$totalMyTask = TaskUser::whereIn('task_id',$totalTaskList)->where('user_id',$userId)->count();
if(sizeof($totalUncomplTaskList) == 0)
{
$totalMyTaskRamining = 0;
}
else
{
//Count the tasks assigned to the user and which are incompleted
$totalMyTaskRamining = TaskUser::whereIn('task_id',$totalUncomplTaskList)->where('user_id',$userId)->count();
}
//Wrap Up Data
$arrayProjects = (array)json_decode($projects,1);
$arrayProjects[0]['overall_task'] = count($totalTaskList);
$arrayProjects[0]['overall_rem_task'] = count($totalUncomplTaskList);
$arrayProjects[0]['my_total_task'] = $totalMyTask;
$arrayProjects[0]['my_rem_task'] = $totalMyTaskRamining;
$arrayProjects[0]['percentage'] = ((count($totalTaskList) - count($totalUncomplTaskList))*100)/count($totalTaskList);
$data[] = $arrayProjects;
}
}
//Shuffle data
$tempData;
foreach ($data as $key)
{
$tempData[]=$key[0];
}
$projs = array();
foreach ($tempData as $key => $row)
{
$projs[$key] = $row['project_name'];
// of course, replace 0 with whatever is the date field's index
}
//Sort the data
usort($tempData, $this->sortOut('project_name'));
//Return final data
return $tempData;
}
}
Thank you!
Hi, tryed your modification but as Admin, proyects are show duplicated.