tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Source for file web_event_composite.class.php

Documentation is available at web_event_composite.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. //  $Id$
  4. //
  5.  
  6. /**
  7.  * Contains class Web_Event_Composite
  8.  *
  9.  * @package tangra_lib
  10.  * @subpackage  web_site
  11.  */
  12.  
  13. /**
  14.  *
  15.  */
  16. require_once(TANGRA_MAIN_DIR.'web_site/web_event_simple.class.php');
  17. /**
  18.  *
  19.  */
  20. require_once(TANGRA_MAIN_DIR.'web_site/web_event_simple_int.class.php');
  21. /**
  22.  *
  23.  */
  24. require_once(TANGRA_MAIN_DIR.'exceptions/te_key_already_exists.class.php');
  25.  
  26.  
  27. /**
  28.  * Web_Event_Composite is intended to contain 2 or more Web_Event_Simple
  29.  * It's contition is met if conditions of all Web_Events_Simple are met
  30.  *
  31.  *
  32.  * @package tangra_lib
  33.  * @subpackage  web_site
  34.  */
  35. class Web_Event_Composite extends Web_Event {
  36.     /**
  37.      * Array that holds Web_Event_Simple
  38.      *
  39.      * @var array 
  40.      */
  41.     private $web_events_simple = array();
  42.  
  43.  
  44.     /**
  45.      * Adds new Web_Event_Simple
  46.      *
  47.      * @param Web_Event_Simple $wes 
  48.      */
  49.     public function add_web_event_simple(Web_Event_Simple $wes{
  50.         if (!array_key_exists($wes->get_name()$this->web_events_simple)) {
  51.             $this->web_events_simple[$wes->get_name()$wes;
  52.         else {
  53.             throw new TE_Key_Already_Exists($wes->get_name());
  54.         }
  55.     }
  56.  
  57.  
  58.     /**
  59.      * Alias of add_web_event_simple
  60.      *
  61.      * @param Web_Event_Simple $wes 
  62.      */
  63.     public function add_wes(Web_Event_Simple $wes{
  64.         if (!array_key_exists($wes->get_name()$this->web_events_simple)) {
  65.             $this->web_events_simple[$wes->get_name()$wes;
  66.         else {
  67.             throw new TE_Key_Already_Exists($wes->get_name());
  68.         }
  69.     }
  70.  
  71.  
  72.     /**
  73.      * Checks if event condition is met
  74.      *
  75.      * Returns array that contain $key => $value pairs for all Web_Event_Simple.
  76.      * $key is the name of Web_Event_Simple, $value is the value of the capture
  77.      *
  78.      * @param Web_Context $context 
  79.      * @return array R
  80.      */
  81.     public function is_it_me(Web_Context $context{
  82.         $flag true;
  83.  
  84.         $ret array();
  85.         foreach($this->web_events_simple as $wes{
  86.             $tmp_ret $wes->is_it_me($context);
  87.             if ($tmp_ret !== false{
  88.                 $ret[$wes->get_name()=  $tmp_ret;
  89.             else {
  90.                 $flag false;
  91.                 break;
  92.             }
  93.         }
  94.  
  95.         if (!$flag{
  96.             $ret false;
  97.         }
  98.  
  99.         return $ret;
  100.     }
  101.  
  102.  
  103.     /**
  104.      * Returns array that contains capture labels of all Web_Event_Simple
  105.      *
  106.      * @return unknown 
  107.      */
  108.     public function get_capture({
  109.         $ret array();
  110.  
  111.         foreach($this->web_events_simple as $wes{
  112.             array_push($ret$wes->get_capture());
  113.         }
  114.  
  115.         return $ret;
  116.     }
  117. }