/** * return all replies on a specific ticket. * @param $ticket_id the id of the ticket of which we want the replies. * @param $view_as_admin if the browsing user is an admin/mod it should be 1, this will also show the hidden replies. * @return an array with ticket_reply objects (beware the author and content are objects on their own, not integers!) */ public static function getRepliesOfTicket($ticket_id, $view_as_admin) { $dbl = new DBLayer("lib"); $statement = $dbl->execute("SELECT * FROM ticket_reply INNER JOIN ticket_content INNER JOIN ticket_user ON ticket_reply.Content = ticket_content.TContentId and ticket_reply.Ticket=:id and ticket_user.TUserId = ticket_reply.Author ORDER BY ticket_reply.TReplyId ASC", array('id' => $ticket_id)); $row = $statement->fetchAll(); $result = array(); foreach ($row as $tReply) { //only add hidden replies if the user is a mod/admin if (!$tReply['Hidden'] || $view_as_admin) { //load author $instanceAuthor = Ticket_User::constr_TUserId($tReply['Author']); $instanceAuthor->setExternId($tReply['ExternId']); $instanceAuthor->setPermission($tReply['Permission']); //load content $instanceContent = new Ticket_Content(); $instanceContent->setTContentId($tReply['TContentId']); $instanceContent->setContent($tReply['Content']); //load reply and add the author and content object in it. $instanceReply = new self(); $instanceReply->setTReplyId($tReply['TReplyId']); $instanceReply->setTimestamp($tReply['Timestamp']); $instanceReply->setAuthor($instanceAuthor); $instanceReply->setTicket($ticket_id); $instanceReply->setContent($instanceContent); $instanceReply->setHidden($tReply['Hidden']); $result[] = $instanceReply; } } return $result; }
public static function createFromTimestamp($time) { $self = new self(); $self->setTimestamp($time); $self->setTimezone(self::_getDefaultTimeZone()); return $self; }
/** * @param $category * @param $action * @param $label * @param $day * @param $month * @param $year * @return Event */ public static function getByDate($category, $action, $label, $day, $month, $year) { $event = new self(); try { $event->getDao()->getByDate($category, $action, $label, $day, $month, $year); } catch (\Exception $e) { $event->setTimestamp(mktime(1, 0, 0, $month, $day, $year)); $event->setCategory($category); $event->setAction($action); $event->setLabel($label); } return $event; }
/** * Parse a string into a new DateTime object according to the specified format * * @param string $format Format accepted by date(). * @param string $time String representing the time. * @param \DateTimeZone $timezone A DateTimeZone object representing the desired time zone. * * @throws \Exception * * @return $this|self * * @link http://php.net/manual/en/datetime.createfromformat.php */ public static function createFromFormat($format, $time, $timezone = null) { if ($timezone) { $datetime = date_create_from_format($format, $time, $timezone); } else { $datetime = date_create_from_format($format, $time, new \DateTimeZone(date_default_timezone_get())); } if (!$datetime) { throw new \Exception(sprintf("Invalid datetime object created from '%s' with format '%s'", $format, $time)); } $return = new self(); $return->setTimestamp($datetime->getTimestamp()); $return->setTimezone(new \DateTimeZone(date_default_timezone_get())); return $return; }
/** * return all log entries related to a ticket. * @param $ticket_id the id of the ticket of which we want all related log entries returned. * @return an array of ticket_log objects, be aware that the author in the ticket_log object is a ticket_user object on its own (so not a simple integer). */ public static function getLogsOfTicket($ticket_id) { $dbl = new DBLayer("lib"); $statement = $dbl->execute("SELECT * FROM ticket_log INNER JOIN ticket_user ON ticket_log.Author = ticket_user.TUserId and ticket_log.Ticket=:id ORDER BY ticket_log.TLogId ASC", array('id' => $ticket_id)); $row = $statement->fetchAll(); $result = array(); foreach ($row as $log) { $instanceAuthor = Ticket_User::constr_TUserId($log['Author']); $instanceAuthor->setExternId($log['ExternId']); $instanceAuthor->setPermission($log['Permission']); $instanceLog = new self(); $instanceLog->setTLogId($log['TLogId']); $instanceLog->setTimestamp($log['Timestamp']); $instanceLog->setAuthor($instanceAuthor); $instanceLog->setTicket($ticket_id); $instanceLog->setQuery($log['Query']); $result[] = $instanceLog; } return $result; }
/** * return all tickets of a specific user. * an array of all tickets created by a specific user are returned by this function. * @param $author the id of the user of whom we want all tickets from. * @return an array containing all ticket objects related to a user. */ public static function getTicketsOf($author) { $dbl = new DBLayer("lib"); $statement = $dbl->execute("SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket_user.ExternId=:id", array('id' => $author)); $row = $statement->fetchAll(); $result = array(); foreach ($row as $ticket) { $instance = new self(); $instance->setTId($ticket['TId']); $instance->setTimestamp($ticket['Timestamp']); $instance->setTitle($ticket['Title']); $instance->setStatus($ticket['Status']); $instance->setQueue($ticket['Queue']); $instance->setTicket_Category($ticket['Ticket_Category']); $instance->setAuthor($ticket['Author']); $result[] = $instance; } return $result; }
/** * {@inheritdoc} */ public static function fromArray(array $values) { $message = new self(); $values = array_merge(['field1' => [], 'timestamp_since_start' => null, 'field3' => null, 'location_fix' => [], 'gps_info' => [], 'field6' => [], 'sensor_info' => [], 'device_info' => null, 'activity_status' => null, 'location_hash1' => null, 'field11' => null, 'field12' => null, 'field13' => null, 'field14' => null, 'field15' => null, 'field16' => null, 'field17' => null, 'field18' => null, 'field19' => null, 'location_hash2' => null, 'field21' => null, 'session_hash' => null, 'timestamp' => null, 'request_hash' => [], 'unknown25' => null], $values); $message->setTimestampSinceStart($values['timestamp_since_start']); $message->setField3($values['field3']); $message->setDeviceInfo($values['device_info']); $message->setActivityStatus($values['activity_status']); $message->setLocationHash1($values['location_hash1']); $message->setField11($values['field11']); $message->setField12($values['field12']); $message->setField13($values['field13']); $message->setField14($values['field14']); $message->setField15($values['field15']); $message->setField16($values['field16']); $message->setField17($values['field17']); $message->setField18($values['field18']); $message->setField19($values['field19']); $message->setLocationHash2($values['location_hash2']); $message->setField21($values['field21']); $message->setSessionHash($values['session_hash']); $message->setTimestamp($values['timestamp']); $message->setUnknown25($values['unknown25']); foreach ($values['field1'] as $item) { $message->addField1($item); } foreach ($values['location_fix'] as $item) { $message->addLocationFix($item); } foreach ($values['gps_info'] as $item) { $message->addGpsInfo($item); } foreach ($values['field6'] as $item) { $message->addField6($item); } foreach ($values['sensor_info'] as $item) { $message->addSensorInfo($item); } foreach ($values['request_hash'] as $item) { $message->addRequestHash($item); } return $message; }
/** * @param wfWAFRequest|null $request * @return wfWAFRequest */ public static function createFromGlobals($request = null) { if ($request === null) { if (version_compare(phpversion(), '5.3.0') > 0) { $class = get_called_class(); $request = new $class(); } else { $request = new self(); } } $request->setAuth(array()); $request->setCookies(array()); $request->setFileNames(array()); $request->setFiles(array()); $request->setHeaders(array()); $request->setHost(''); $request->setIP(''); $request->setMethod(''); $request->setPath(''); $request->setProtocol(''); $request->setTimestamp(''); $request->setURI(''); $request->setBody(wfWAFUtils::stripMagicQuotes($_POST)); $request->setQueryString(wfWAFUtils::stripMagicQuotes($_GET)); $request->setCookies(wfWAFUtils::stripMagicQuotes($_COOKIE)); $request->setFiles(wfWAFUtils::stripMagicQuotes($_FILES)); if (!empty($_FILES)) { $fileNames = array(); foreach ($_FILES as $input => $file) { $fileNames[$input] = wfWAFUtils::stripMagicQuotes($file['name']); } $request->setFileNames($fileNames); } if (is_array($_SERVER)) { //All of these depend on $_SERVER being non-null and an array $auth = array(); if (array_key_exists('PHP_AUTH_USER', $_SERVER)) { $auth['user'] = wfWAFUtils::stripMagicQuotes($_SERVER['PHP_AUTH_USER']); } if (array_key_exists('PHP_AUTH_PW', $_SERVER)) { $auth['password'] = wfWAFUtils::stripMagicQuotes($_SERVER['PHP_AUTH_PW']); } $request->setAuth($auth); if (array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { $timestamp = $_SERVER['REQUEST_TIME_FLOAT']; } else { if (array_key_exists('REQUEST_TIME', $_SERVER)) { $timestamp = $_SERVER['REQUEST_TIME']; } else { $timestamp = time(); } } $request->setTimestamp($timestamp); $headers = array(); foreach ($_SERVER as $key => $value) { if (wfWAFUtils::strpos($key, 'HTTP_') === 0) { $header = wfWAFUtils::substr($key, 5); $header = str_replace(array(' ', '_'), array('', ' '), $header); $header = ucwords(wfWAFUtils::strtolower($header)); $header = str_replace(' ', '-', $header); $headers[$header] = wfWAFUtils::stripMagicQuotes($value); } } if (array_key_exists('CONTENT_TYPE', $_SERVER)) { $headers['Content-Type'] = wfWAFUtils::stripMagicQuotes($_SERVER['CONTENT_TYPE']); } if (array_key_exists('CONTENT_LENGTH', $_SERVER)) { $headers['Content-Length'] = wfWAFUtils::stripMagicQuotes($_SERVER['CONTENT_LENGTH']); } $request->setHeaders($headers); $host = ''; if (array_key_exists('Host', $headers)) { $host = $headers['Host']; } else { if (array_key_exists('SERVER_NAME', $_SERVER)) { $host = wfWAFUtils::stripMagicQuotes($_SERVER['SERVER_NAME']); } } $request->setHost($host); $request->setMethod(array_key_exists('REQUEST_METHOD', $_SERVER) ? wfWAFUtils::stripMagicQuotes($_SERVER['REQUEST_METHOD']) : 'GET'); $request->setProtocol(array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http'); $request->setUri(array_key_exists('REQUEST_URI', $_SERVER) ? wfWAFUtils::stripMagicQuotes($_SERVER['REQUEST_URI']) : ''); $uri = parse_url($request->getURI()); if (is_array($uri) && array_key_exists('path', $uri)) { $path = $uri['path']; } else { $path = $request->getURI(); } $request->setPath($path); } return $request; }
public static function formatPercise($timestamp) { $ts = new self(); $ts->setTimestamp($timestamp); return $ts->format("F j, Y, g:i a"); }