mysql - Smyfony2 Comparing Data with existing data from other table -
i output list of task based on current user.
my task table looks this:
id | task title | user |
i have second table called "taskdone"
there store when task marked "done" specific user. example this:
id | task id | user id | 1 | 13 | 3 |
when output list of task user id 3 , list of task assigned user id 3. want check if there task in list, has entry in table "taskdone" user id = current user , task id = id of task output list.
my controller looks this:
/** @route( * path = "/taskmanager/user/{id}", * name = "taskmanager" * ) * @template() */ public function taskmanageraction($id) { $priorities = array( 0 => array('name' => 'hoch', 'class' => 'high' ), 1 => array('name' => 'normal', 'class' => 'normal' ), 2 => array('name' => 'niedrig', 'class' => 'low' ) ); $all_tasks = $this->getdoctrine() ->getrepository('seotoolmainbundle:task') ->findall(); $user = $this->getdoctrine() ->getrepository('seotoolmainbundle:user') ->findall(); return array( 'list_user' => $user, 'list_open_tasks' => $all_tasks, 'current_user' => $id, 'priorities' => $priorities, ); }
my output of task list looks this:
{% task in list_open_tasks if (task.user.id == current_user or task.user.id == "global") , task.taskpriority == priority.name %} {{ task.tasktitle }} # here want check if there entry in taskdone table task , user {% endfor %}
does have idea ?
you need within controller!
this code give out entries array taskdone
entity user_id
same given $id
.
$tasks_done = $this->getdoctrine() ->getrepository('seotoolmainbundle:taskdone') ->findby(array('user' => $id);
save results in array $tasksdone
, return twigtemplate.
return array( 'list_user' => $user, 'list_open_tasks' => $all_tasks, 'current_user' => $id, 'priorities' => $priorities, 'tasks_done' => $tasksdone );
then give them out other twig variable
Comments
Post a Comment