Skip to content

Instantly share code, notes, and snippets.

@shlaikov
Last active November 22, 2017 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shlaikov/cef0fe1236ae2342cb435eac2a90ce41 to your computer and use it in GitHub Desktop.
Save shlaikov/cef0fe1236ae2342cb435eac2a90ce41 to your computer and use it in GitHub Desktop.
iCalendar
<?php
abstract class CalendarDetail extends iCalendar
{
protected function getArray($in)
{
if (is_array($in)) {
return $in;
}
$in = (int) $in;
$out = [];
for ($i = 1; $i <= $in; $i *= 2) {
if ($in & $i) {
$out[] = $i;
}
}
return $out;
}
protected function getBitwise($in)
{
if (!is_array($in)) {
return null;
}
return array_sum($in);
}
protected function runQuery($calendarId = null)
{
if ($calendarId === null) {
$calendarId = $this->getIntFromRequest('calendar_id');
}
if (empty($calendarId) || !preg_match('/^\d{1,10}$/', $calendarId)) {
throw new ProjectException(new Translatable('invalid_calendar_id'));
}
$this->sql->SQLQueryString = "SELECT
calendar_id,
calendar_uri,
category,
cs_calendar.category_id AS category_id,
changed,
date_start,
detail,
COALESCE(calendar_uri, frequent_event_uri) AS display_uri,
feature_on_page_id,
cs_calendar.frequent_event_id AS frequent_event_id,
frequent_event_uri,
is_own_event,
list_link_goes_to_id,
location_start,
note,
status,
cs_calendar.status_id,
summary,
time_end,
time_start,
title
FROM cs_calendar
LEFT JOIN cs_frequent_event USING (frequent_event_id)
LEFT JOIN cs_status
ON (cs_status.status_id = cs_calendar.status_id)
LEFT JOIN cs_category
ON (cs_category.category_id = cs_calendar.category_id)
WHERE calendar_id = $calendarId";
$this->sql->RunQuery(__FILE__, __LINE__);
if ($this->sql->SQLRecordSetRowCount == 0) {
throw new ProjectException(new Translatable('sql_no_criteria'));
}
}
public function setDataFromQuery($calendarId = null, $safeMarkup = true, $escapeHtml = true)
{
$this->run_query($calendarId);
$originalSafeMarkup = $this->sql->SQLSafeMarkup;
$originalEscapeHtml = $this->sql->SQLEscapeHTML;
$this->sql->SQLSafeMarkup = $safeMarkup ? 'Y' : 'N';
$this->sql->SQLEscapeHTML = $escapeHtml ? 'Y' : 'N';
$this->data = $this->sql->RecordAsAssocArray(__FILE__, __LINE__, ['display_uri']);
$this->data['set_from'] = 'query';
$this->sql->SQLSafeMarkup = $originalSafeMarkup;
$this->sql->SQLEscapeHTML = $originalEscapeHtml;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment