php - How to update the status of a task that have sub task in the same table

375
+----+---------+--------+

I have the above table structure. From the records it can be seen that{-code-2},{-code-3} and{-code-4} are the child of{-code-5} and{-code-4} again have a child{-code-7}.

The needed operations are:

  1. Marking a task as DONE will also check the status of all sub task. When all sub task are COMPLETE, mark the task as COMPLETE (instead of DONE).

  2. Marking a task as IN PROGRESS (by changing the status to 0) should update its parent task (if it has one) so that the parent’s status changes from COMPLETE to DONE. A parent task must not revert to IN PROGRESS from DONE or COMPLETE.

The status values for each state

  1. IN PROGRESS
  2. DONE
  3. COMPLETE
598

Answer

-+ | id | title | status | parent_id | +----+---------+--------+
547

Answer

-+ | 1 | Task 1 | 2 | 0 | | 2 | Task 2 | 2 | 3 | | 3 | Task 3 | 0 | 0 | | 4 | Task 4 | 2 | 3 | | 5 | Task 5 | 0 | 3 | | 6 | Task 6 | 2 | 5 | | 7 | Task 10 | 2 | 0 | | 8 | Task 8 | 0 | 0 | +----+---------+--------+
9

Answer

-+ 8 rows in set (0.03 sec)|||TASK 2|||TASK 4|||TASK 5|||TASK 3|||TASK 5|||TASK 6

People are also looking for solutions to the problem: php - Events not firing on before filters in a standalone Illuminate 4.1 stack

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.