Seperate Questions into Different Category Hierarchies in Different Context Levels
---------------------------------------------------------------------------------------------------------------
Remove 'publish' field from question_categories table 'course' field will become 'contextid' and will be of INT type pointing to the 'context' table.
Calculate equivalent context
--------------------------------------
Contents of the new context table will depend on the old contents of 'publish' and 'course' if publish is 1 then we make the context the site context. If it is 0 then we make the context the context for the course indicated in the 'course' field.
Change in How Categories Are Shared
-----------------------------------------------------
Previously you could share a category anywhere in your Course's question bank category hierarchy at the site level. Now we have decided that we'll have seperate hierarchies for categories at each context level. So we need code on db upgrade to check that all parent categories referred to in the question_categories 'parent' field are in the same context. If they are not then this category becomes a new top level category.
So if a question category hierarchy in a course is as below :
- Default
o Science
+ Physics (shared)
- Momentum and Dynamics
The Physics course will get moved to the site context since it is shared and the question category hierarchies will then be as follows :
Course Level
- Default
o Science
+ Momentum and Dynamics
Site Level
- Physics
If a childs parent is gone then it get's put in the grandparent category, if no grandparent, then grand grand parent etc. We'll search up the category hierarchy till we reach a category that is still in the same context level or we reach the top level and use that as a parent.
When changing the tree, we'll preserve the existing ordering as defined by the sortorder fields.