Moodle

Implement function to detect circular references

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9
  • Fix Version/s: 1.9
  • Component/s: Gradebook
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

We need a function to detect circular references whenever a calculation has been edited:

detect_circular_reference(array) => boolean

The array is a whole lot of calculation strings containing verified idnumber strings for all the calcualtions in a course, eg:

C= A + B
A = B + C
B = C + A

See Double Loop on this page for an algorithm: http://phrogz.net/nodes/traversingdirectedgraph.asp

Activity

Hide
Eloy Lafuente (stronk7) added a comment -

Added one file that contains one topological_sorter()

it provides one solution to find the correct patch for recalculating all the formulas following dependencies and, if some cyclic is found, returns false.

So, applying it when adding/modifying/deleting formulas will provide instantly the path to follow and any cyclic if found.

Hope it helps...ciao

Show
Eloy Lafuente (stronk7) added a comment - Added one file that contains one topological_sorter() it provides one solution to find the correct patch for recalculating all the formulas following dependencies and, if some cyclic is found, returns false. So, applying it when adding/modifying/deleting formulas will provide instantly the path to follow and any cyclic if found. Hope it helps...ciao
Hide
Eloy Lafuente (stronk7) added a comment -

(of course, although the file has its © message and so on, feel 100% free to extract the functions and to put them where you want. Don't need to commit the whole file at all)

Show
Eloy Lafuente (stronk7) added a comment - (of course, although the file has its © message and so on, feel 100% free to extract the functions and to put them where you want. Don't need to commit the whole file at all)
Hide
Martin Dougiamas added a comment -

For integrating into server-side validation

Show
Martin Dougiamas added a comment - For integrating into server-side validation
Hide
Petr Škoda (skodak) added a comment -

I have used a different approach both during validation and calculation itself.

thanks anyway!

Show
Petr Škoda (skodak) added a comment - I have used a different approach both during validation and calculation itself. thanks anyway!

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: