context_condition_context_all.inc 941 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /**
  3. * Expose active contexts as a context condition.
  4. */
  5. class context_condition_context_all extends context_condition_path {
  6. function execute() {
  7. if ($this->condition_used()) {
  8. $active_contexts = array_keys(context_active_contexts());
  9. foreach ($this->get_contexts() as $context) {
  10. // Only test contexts that haven't been activated yet,
  11. // and have values set.
  12. if (!in_array($context->name, $active_contexts, TRUE) && $values = $this->fetch_from_context($context, 'values')) {
  13. // The condition is met if all contexts are active.
  14. if (count(array_intersect($values, $active_contexts)) == count($values)) {
  15. $this->condition_met($context);
  16. }
  17. }
  18. }
  19. // If the list of active contexts has changed, we need to recurse.
  20. if ($active_contexts != array_keys(context_active_contexts())) {
  21. $this->execute();
  22. }
  23. }
  24. }
  25. }