Beispiel #1
0
 /**
  * Posts multiple events to the container.
  *
  * <p>Valid keys for each event are:</p>
  * - event		- the event name (case-sensitive);
  * - className	- the class that is the source of the event;
  * - sender		- the sender object of the event;
  * - data		- the data associated with the event;
  * - filter		- the event filter data (case-insensitive);
  *				  using this key you can post events with
  *				  the same name but with different filter data;
  *				  the client will respond to them individually;
  * - time		- the event start time (seconds since the Unix
  *				  Epoch (January 1 1970 00:00:00 GMT);
  * - lifetime	- the event lifetime (in seconds);
  *
  * @access	public
  *
  * @param	array	$eventsData		Array containing associative arrays
  *									with information for each event.
  *
  * @return	bool	true on success, false otherwise.
  *
  */
 public function postMultipleEvents($eventsData)
 {
     $handle = @fopen($this->getFileName(), 'a');
     if (!$handle) {
         return false;
     }
     @ignore_user_abort(true);
     flock($handle, LOCK_EX);
     foreach ($eventsData as $event) {
         if (!parent::postMultipleEvents($event)) {
             continue;
         }
         $row = $event['event'];
         $row .= $this->separator;
         $row .= $event['className'];
         $row .= $this->separator;
         $row .= $event['time'];
         $row .= $this->separator;
         $row .= $event['time'] + $event['lifetime'];
         $row .= $this->separator;
         $row .= isset($event['filter']) ? serialize($event['filter']) : 'N;';
         $row .= $this->separator;
         $rowData = array();
         if (isset($event['sender'])) {
             $rowData['sender'] = $event['sender'];
         }
         if (isset($event['data'])) {
             $rowData['data'] = $event['data'];
         }
         $row .= serialize($rowData);
         $row .= "\n";
         fwrite($handle, $row);
     }
     flock($handle, LOCK_UN);
     fclose($handle);
     @ignore_user_abort(false);
     return true;
 }
Beispiel #2
0
    /**
     * Posts multiple events to the database.
     *
     * <p>Valid keys for each event are:</p>
     * - event		- the event name (case-sensitive);
     * - className	- the class that is the source of the event;
     * - sender		- the sender object of the event;
     * - data		- the data associated with the event;
     * - filter		- the event filter data (case-insensitive);
     *				  using this key you can post events with
     *				  the same name but with different filter data;
     *				  the client will respond to them individually;
     * - time		- the event start time (seconds since the Unix
     *				  Epoch (January 1 1970 00:00:00 GMT);
     * - lifetime	- the event lifetime (in seconds);
     *
     * @access	public
     *
     * @param	array	$eventsData		Array containing associative arrays
     *									with information for each event.
     *
     * @return	bool	true on success, false otherwise.
     *
     */
    public function postMultipleEvents($eventsData)
    {
        $connection =& $this->getConnection();
        foreach ($eventsData as $event) {
            if (!parent::postMultipleEvents($event)) {
                continue;
            }
            $sqlQuery = '
				INSERT INTO
					`' . XOAD_EVENTS_TABLE_NAME . '`
				(
					`event`,
					`className`,
					`filter`,
					`sender`,
					`data`,
					`time`,
					`endTime`
				)
				VALUES
				(
					\'' . $this->escapeString($event['event'], $connection) . '\',
					\'' . $this->escapeString($event['className'], $connection) . '\',
			';
            if (isset($event['filter'])) {
                $sqlQuery .= '\'' . $this->escapeString($event['filter'], $connection) . '\',';
            } else {
                $sqlQuery .= 'NULL,';
            }
            if (isset($event['sender'])) {
                $sqlQuery .= '\'' . $this->escapeString(serialize($event['sender']), $connection) . '\',';
            } else {
                $sqlQuery .= 'NULL,';
            }
            if (isset($event['data'])) {
                $sqlQuery .= '\'' . $this->escapeString(serialize($event['data']), $connection) . '\',';
            } else {
                $sqlQuery .= 'NULL,';
            }
            $sqlQuery .= '
					' . $this->escapeString($event['time'], $connection) . ',
					' . $this->escapeString($event['time'] + $event['lifetime'], $connection) . '
				)';
            $connection->query($sqlQuery);
        }
        $this->closeConnection($connection);
        return true;
    }