Beispiel #1
0
 /**
  * Filters the events in the container using multiple criterias.
  *
  * <p>Valid keys for each event are:</p>
  * - event		- the event name (case-sensitive);
  * - className	- the class that is the source of the event;
  * - filter		- the event filter data (case-insensitive);
  * 				  using this argument you can filter events with
  *				  the same name but with different filter data;
  * - time		- the event start time (seconds since the Unix
  *				  Epoch (January 1 1970 00:00:00 GMT).
  *
  * @access	public
  *
  * @param	array	$eventsData		Array containing associative arrays
  *									with information for each event.
  *
  * @return	array	Sequental array that contains all events that match the
  *					supplied criterias, ordered by time (ascending).
  *
  */
 public function filterMultipleEvents($eventsData)
 {
     $events = array();
     $containerData = @file($this->getFileName());
     if (empty($containerData)) {
         return $events;
     }
     foreach ($eventsData as $event) {
         if (!parent::filterMultipleEvents($event)) {
             continue;
         }
         foreach ($containerData as $row) {
             list($eventName, $className, $time, $endTime, $filter, $rowData) = explode($this->separator, $row, 6);
             $filter = unserialize($filter);
             $match = strcmp($eventName, $event['event']) == 0;
             $match &= strcasecmp($className, $event['className']) == 0;
             $match &= $time > $event['time'];
             if (isset($event['filter'])) {
                 $match &= $filter == $event['filter'];
             }
             if ($match) {
                 $rowData = unserialize($rowData);
                 $events[] = array('event' => $eventName, 'className' => $className, 'filter' => $filter, 'time' => (double) $time, 'endTime' => (double) $endTime, 'eventData' => array('sender' => isset($rowData['sender']) ? $rowData['sender'] : null, 'data' => isset($rowData['data']) ? $rowData['data'] : null));
             }
         }
     }
     if (!empty($events)) {
         usort($events, array('XOAD_Events_Storage_File', 'sortEvents'));
     }
     return $events;
 }
Beispiel #2
0
    /**
     * Filters the events in the database using multiple criterias.
     *
     * <p>Valid keys for each event are:</p>
     * - event		- the event name (case-sensitive);
     * - className	- the class that is the source of the event;
     * - filter		- the event filter data (case-insensitive);
     * 				  using this argument you can filter events with
     *				  the same name but with different filter data;
     * - time		- the event start time (seconds since the Unix
     *				  Epoch (January 1 1970 00:00:00 GMT).
     *
     * @access	public
     *
     * @param	array	$eventsData		Array containing associative arrays
     *									with information for each event.
     *
     * @return	array	Sequental array that contains all events that match the
     *					supplied criterias, ordered by time (ascending).
     *
     */
    public function filterMultipleEvents($eventsData)
    {
        $connection =& $this->getConnection();
        $sqlQuery = '
			SELECT
				`event`,
				`className`,
				`filter`,
				`sender`,
				`data`,
				`time`,
				`endTime`
			FROM
				`' . XOAD_EVENTS_TABLE_NAME . '`
			WHERE
		';
        $index = 0;
        $length = sizeof($eventsData);
        foreach ($eventsData as $event) {
            if (!parent::filterMultipleEvents($event)) {
                continue;
            }
            $sqlQuery .= '(
				`time` > ' . $this->escapeString($event['time'], $connection) . '
				AND
				`event` = \'' . $this->escapeString($event['event'], $connection) . '\'
				AND
				`className` = \'' . $this->escapeString($event['className'], $connection) . '\'
			';
            if (isset($event['filter'])) {
                $sqlQuery .= 'AND `filter` = \'' . $this->escapeString($event['filter'], $connection) . '\'';
            }
            if ($index < $length - 1) {
                $sqlQuery .= ') OR ';
            } else {
                $sqlQuery .= ')';
            }
            $index++;
        }
        $sqlQuery .= '
			ORDER BY
				`time` ASC
		';
        $events = array();
        $sqlResult =& $connection->query($sqlQuery);
        while (($row =& $sqlResult->fetchRow()) != false) {
            $events[] = array('event' => $row['event'], 'className' => $row['className'], 'filter' => $row['filter'], 'time' => (double) $row['time'], 'endTime' => (double) $row['endTime'], 'eventData' => array('sender' => $row['sender'] === null ? null : unserialize($row['sender']), 'data' => $row['data'] === null ? null : unserialize($row['data'])));
        }
        $sqlResult->free();
        $this->closeConnection($connection);
        return $events;
    }