@@ -22,6 +22,11 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | protected $exclude; |
| 24 | 24 | |
| 25 | + /** |
|
| 26 | + * @param boolean $enabled |
|
| 27 | + * @param string|null $include |
|
| 28 | + * @param string|null $exclude |
|
| 29 | + */ |
|
| 25 | 30 | public function __construct($enabled, $include, $exclude) |
| 26 | 31 | { |
| 27 | 32 | $this->setEnabled($enabled); |
@@ -4,84 +4,84 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Filter |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Whether or not this filter is enabled |
|
| 9 | - * @var boolean |
|
| 10 | - */ |
|
| 11 | - protected $enabled = false; |
|
| 7 | + /** |
|
| 8 | + * Whether or not this filter is enabled |
|
| 9 | + * @var boolean |
|
| 10 | + */ |
|
| 11 | + protected $enabled = false; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Regex to include (applied first) |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $include; |
|
| 13 | + /** |
|
| 14 | + * Regex to include (applied first) |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $include; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Regex to exclude (applied second) |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $exclude; |
|
| 19 | + /** |
|
| 20 | + * Regex to exclude (applied second) |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $exclude; |
|
| 24 | 24 | |
| 25 | - public function __construct($enabled, $include, $exclude) |
|
| 26 | - { |
|
| 27 | - $this->setEnabled($enabled); |
|
| 28 | - $this->setIncludeExpression($include); |
|
| 29 | - $this->setExcludeExpression($exclude); |
|
| 30 | - } |
|
| 25 | + public function __construct($enabled, $include, $exclude) |
|
| 26 | + { |
|
| 27 | + $this->setEnabled($enabled); |
|
| 28 | + $this->setIncludeExpression($include); |
|
| 29 | + $this->setExcludeExpression($exclude); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function setEnabled($enabled) |
|
| 33 | - { |
|
| 34 | - $this->enabled = (boolean) $enabled; |
|
| 35 | - } |
|
| 32 | + public function setEnabled($enabled) |
|
| 33 | + { |
|
| 34 | + $this->enabled = (boolean) $enabled; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function isEnabled() |
|
| 38 | - { |
|
| 39 | - return $enabled; |
|
| 40 | - } |
|
| 37 | + public function isEnabled() |
|
| 38 | + { |
|
| 39 | + return $enabled; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function setIncludeExpression($regex) |
|
| 43 | - { |
|
| 44 | - $this->include = (string) $regex; |
|
| 45 | - } |
|
| 42 | + public function setIncludeExpression($regex) |
|
| 43 | + { |
|
| 44 | + $this->include = (string) $regex; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function getIncludeExpression() |
|
| 48 | - { |
|
| 49 | - if (empty($this->include)) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 52 | - return $this->include; |
|
| 53 | - } |
|
| 47 | + public function getIncludeExpression() |
|
| 48 | + { |
|
| 49 | + if (empty($this->include)) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | + return $this->include; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function setExcludeExpression($regex) |
|
| 56 | - { |
|
| 57 | - $this->exclude = (string) $regex; |
|
| 58 | - } |
|
| 55 | + public function setExcludeExpression($regex) |
|
| 56 | + { |
|
| 57 | + $this->exclude = (string) $regex; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function getExcludeExpression() |
|
| 61 | - { |
|
| 62 | - if (empty($this->exclude)) { |
|
| 63 | - return false; |
|
| 64 | - } |
|
| 65 | - return $this->exclude; |
|
| 66 | - } |
|
| 60 | + public function getExcludeExpression() |
|
| 61 | + { |
|
| 62 | + if (empty($this->exclude)) { |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | + return $this->exclude; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function filter(Event $event) |
|
| 69 | - { |
|
| 70 | - return ( |
|
| 71 | - // include this event if filtering is off... |
|
| 72 | - $this->isEnabled() == false || |
|
| 73 | - ( |
|
| 74 | - ( |
|
| 75 | - ( // if filtering is on, and there's an include pattern test that pattern... |
|
| 76 | - $this->getIncludeExpression() && |
|
| 77 | - preg_match('%' . $this->getIncludeExpression() . '%', $event->getProperty('SUMMARY')) |
|
| 78 | - ) |
|
| 79 | - ) && |
|
| 80 | - !( // if there is an exclude pattern, make sure that this event is NOT excluded |
|
| 81 | - $this->getExcludeExpression() && |
|
| 82 | - preg_match('%' . $this->getExcludeExpression() . '%', $event->getProperty('SUMMARY')) |
|
| 83 | - ) |
|
| 84 | - ) |
|
| 85 | - ); |
|
| 86 | - } |
|
| 68 | + public function filter(Event $event) |
|
| 69 | + { |
|
| 70 | + return ( |
|
| 71 | + // include this event if filtering is off... |
|
| 72 | + $this->isEnabled() == false || |
|
| 73 | + ( |
|
| 74 | + ( |
|
| 75 | + ( // if filtering is on, and there's an include pattern test that pattern... |
|
| 76 | + $this->getIncludeExpression() && |
|
| 77 | + preg_match('%' . $this->getIncludeExpression() . '%', $event->getProperty('SUMMARY')) |
|
| 78 | + ) |
|
| 79 | + ) && |
|
| 80 | + !( // if there is an exclude pattern, make sure that this event is NOT excluded |
|
| 81 | + $this->getExcludeExpression() && |
|
| 82 | + preg_match('%' . $this->getExcludeExpression() . '%', $event->getProperty('SUMMARY')) |
|
| 83 | + ) |
|
| 84 | + ) |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function setEnabled($enabled) |
| 33 | 33 | { |
| 34 | - $this->enabled = (boolean) $enabled; |
|
| 34 | + $this->enabled = (boolean)$enabled; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function isEnabled() |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | public function setIncludeExpression($regex) |
| 43 | 43 | { |
| 44 | - $this->include = (string) $regex; |
|
| 44 | + $this->include = (string)$regex; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function getIncludeExpression() |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | public function setExcludeExpression($regex) |
| 56 | 56 | { |
| 57 | - $this->exclude = (string) $regex; |
|
| 57 | + $this->exclude = (string)$regex; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public function getExcludeExpression() |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | ( |
| 75 | 75 | ( // if filtering is on, and there's an include pattern test that pattern... |
| 76 | 76 | $this->getIncludeExpression() && |
| 77 | - preg_match('%' . $this->getIncludeExpression() . '%', $event->getProperty('SUMMARY')) |
|
| 77 | + preg_match('%'.$this->getIncludeExpression().'%', $event->getProperty('SUMMARY')) |
|
| 78 | 78 | ) |
| 79 | 79 | ) && |
| 80 | 80 | !( // if there is an exclude pattern, make sure that this event is NOT excluded |
| 81 | 81 | $this->getExcludeExpression() && |
| 82 | - preg_match('%' . $this->getExcludeExpression() . '%', $event->getProperty('SUMMARY')) |
|
| 82 | + preg_match('%'.$this->getExcludeExpression().'%', $event->getProperty('SUMMARY')) |
|
| 83 | 83 | ) |
| 84 | 84 | ) |
| 85 | 85 | ); |
@@ -7,24 +7,24 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Write messages to the log file if a script is being run |
|
| 12 | - * non-interactively from the command line |
|
| 13 | - * |
|
| 14 | - * @param string $subject |
|
| 15 | - * @param string $body |
|
| 16 | - * @param string $flag (Optional, default `NotificationMessage::INFO`) |
|
| 17 | - * @param Log $log (Optional, defaults to app log) |
|
| 18 | - */ |
|
| 19 | - public function smarty_addMessage($subject, $body, $flag = NotificationMessage::INFO, Log $log = null) |
|
| 20 | - { |
|
| 21 | - if (empty($log)) { |
|
| 22 | - $log = $this->getLog(); |
|
| 23 | - } |
|
| 24 | - if (php_sapi_name() == 'cli') { |
|
| 25 | - $log->log("[$flag] $subject: $body"); |
|
| 26 | - } else { |
|
| 27 | - parent::smarty_addMessage($subject, $body, $flag); |
|
| 28 | - } |
|
| 29 | - } |
|
| 10 | + /** |
|
| 11 | + * Write messages to the log file if a script is being run |
|
| 12 | + * non-interactively from the command line |
|
| 13 | + * |
|
| 14 | + * @param string $subject |
|
| 15 | + * @param string $body |
|
| 16 | + * @param string $flag (Optional, default `NotificationMessage::INFO`) |
|
| 17 | + * @param Log $log (Optional, defaults to app log) |
|
| 18 | + */ |
|
| 19 | + public function smarty_addMessage($subject, $body, $flag = NotificationMessage::INFO, Log $log = null) |
|
| 20 | + { |
|
| 21 | + if (empty($log)) { |
|
| 22 | + $log = $this->getLog(); |
|
| 23 | + } |
|
| 24 | + if (php_sapi_name() == 'cli') { |
|
| 25 | + $log->log("[$flag] $subject: $body"); |
|
| 26 | + } else { |
|
| 27 | + parent::smarty_addMessage($subject, $body, $flag); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -4,40 +4,40 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Event |
| 6 | 6 | { |
| 7 | - const FIELD_MAP = [ |
|
| 8 | - 'calendar_event[title]' => 'SUMMARY', |
|
| 9 | - 'calendar_event[description]' => 'DESCRIPTION', |
|
| 10 | - 'calendar_event[start_at]' => [ |
|
| 11 | - 0 => 'X-CURRENT-DTSTART', |
|
| 12 | - 1 => 'DTSTART' |
|
| 13 | - ], |
|
| 14 | - 'calendar_event[end_at]' => [ |
|
| 15 | - 0 => 'X-CURRENT-DTEND', |
|
| 16 | - 1 => 'DTEND' |
|
| 17 | - ], |
|
| 18 | - 'calendar_event[location_name]' => 'LOCATION' |
|
| 19 | - ]; |
|
| 7 | + const FIELD_MAP = [ |
|
| 8 | + 'calendar_event[title]' => 'SUMMARY', |
|
| 9 | + 'calendar_event[description]' => 'DESCRIPTION', |
|
| 10 | + 'calendar_event[start_at]' => [ |
|
| 11 | + 0 => 'X-CURRENT-DTSTART', |
|
| 12 | + 1 => 'DTSTART' |
|
| 13 | + ], |
|
| 14 | + 'calendar_event[end_at]' => [ |
|
| 15 | + 0 => 'X-CURRENT-DTEND', |
|
| 16 | + 1 => 'DTEND' |
|
| 17 | + ], |
|
| 18 | + 'calendar_event[location_name]' => 'LOCATION' |
|
| 19 | + ]; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Generate a hash of this version of an event to cache in the database |
|
| 23 | - **/ |
|
| 24 | - public function getEventHash($event) |
|
| 25 | - { |
|
| 26 | - $blob = ''; |
|
| 27 | - foreach (static::$FIELD_MAP as $field) { |
|
| 28 | - if (is_array($field)) { |
|
| 29 | - foreach ($field as $option) { |
|
| 30 | - if (!empty($property = $event->getProperty($option))) { |
|
| 31 | - $blob .= serialize($property); |
|
| 32 | - break; |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - } else { |
|
| 36 | - if (!empty($property = $event->getProperty($field))) { |
|
| 37 | - $blob .= serialize($property); |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - return md5($blob); |
|
| 42 | - } |
|
| 21 | + /** |
|
| 22 | + * Generate a hash of this version of an event to cache in the database |
|
| 23 | + **/ |
|
| 24 | + public function getEventHash($event) |
|
| 25 | + { |
|
| 26 | + $blob = ''; |
|
| 27 | + foreach (static::$FIELD_MAP as $field) { |
|
| 28 | + if (is_array($field)) { |
|
| 29 | + foreach ($field as $option) { |
|
| 30 | + if (!empty($property = $event->getProperty($option))) { |
|
| 31 | + $blob .= serialize($property); |
|
| 32 | + break; |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + } else { |
|
| 36 | + if (!empty($property = $event->getProperty($field))) { |
|
| 37 | + $blob .= serialize($property); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + return md5($blob); |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -4,23 +4,23 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Schedule |
| 6 | 6 | { |
| 7 | - protected $syncTimestamp; |
|
| 7 | + protected $syncTimestamp; |
|
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Generate a unique identifier for this synchronization pass |
|
| 11 | - **/ |
|
| 12 | - public function getSyncTimestamp() |
|
| 13 | - { |
|
| 14 | - if (empty($this->syncTimestamp)) { |
|
| 15 | - $timestamp = new DateTime(); |
|
| 16 | - $this->syncTimestamp = |
|
| 17 | - $timestamp->format(Constants::SYNC_TIMESTAMP_FORMAT) . |
|
| 18 | - Constants::SEPARATOR . md5( |
|
| 19 | - (php_sapi_name() == 'cli' ? |
|
| 20 | - 'cli' : $_SERVER['REMOTE_ADDR'] |
|
| 21 | - ) . time() |
|
| 22 | - ); |
|
| 23 | - } |
|
| 24 | - return $this->syncTimestamp; |
|
| 25 | - } |
|
| 9 | + /** |
|
| 10 | + * Generate a unique identifier for this synchronization pass |
|
| 11 | + **/ |
|
| 12 | + public function getSyncTimestamp() |
|
| 13 | + { |
|
| 14 | + if (empty($this->syncTimestamp)) { |
|
| 15 | + $timestamp = new DateTime(); |
|
| 16 | + $this->syncTimestamp = |
|
| 17 | + $timestamp->format(Constants::SYNC_TIMESTAMP_FORMAT) . |
|
| 18 | + Constants::SEPARATOR . md5( |
|
| 19 | + (php_sapi_name() == 'cli' ? |
|
| 20 | + 'cli' : $_SERVER['REMOTE_ADDR'] |
|
| 21 | + ) . time() |
|
| 22 | + ); |
|
| 23 | + } |
|
| 24 | + return $this->syncTimestamp; |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -14,11 +14,11 @@ |
||
| 14 | 14 | if (empty($this->syncTimestamp)) { |
| 15 | 15 | $timestamp = new DateTime(); |
| 16 | 16 | $this->syncTimestamp = |
| 17 | - $timestamp->format(Constants::SYNC_TIMESTAMP_FORMAT) . |
|
| 18 | - Constants::SEPARATOR . md5( |
|
| 17 | + $timestamp->format(Constants::SYNC_TIMESTAMP_FORMAT). |
|
| 18 | + Constants::SEPARATOR.md5( |
|
| 19 | 19 | (php_sapi_name() == 'cli' ? |
| 20 | 20 | 'cli' : $_SERVER['REMOTE_ADDR'] |
| 21 | - ) . time() |
|
| 21 | + ).time() |
|
| 22 | 22 | ); |
| 23 | 23 | } |
| 24 | 24 | return $this->syncTimestamp; |
@@ -12,86 +12,86 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | abstract class Syncable |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * MySQL connection |
|
| 17 | - * |
|
| 18 | - * @var mysqli|null |
|
| 19 | - */ |
|
| 20 | - protected static $mysql; |
|
| 15 | + /** |
|
| 16 | + * MySQL connection |
|
| 17 | + * |
|
| 18 | + * @var mysqli|null |
|
| 19 | + */ |
|
| 20 | + protected static $mysql; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Canvas API connection |
|
| 24 | - * |
|
| 25 | - * @var CanvasPest|null |
|
| 26 | - */ |
|
| 27 | - protected static $api; |
|
| 22 | + /** |
|
| 23 | + * Canvas API connection |
|
| 24 | + * |
|
| 25 | + * @var CanvasPest|null |
|
| 26 | + */ |
|
| 27 | + protected static $api; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Update the MySQL connection |
|
| 31 | - * |
|
| 32 | - * @param mysqli $mysql |
|
| 33 | - * @throws Exception If `$mysql` is null |
|
| 34 | - */ |
|
| 35 | - public static function setMySql(mysqli $mysql) |
|
| 36 | - { |
|
| 37 | - if (empty($mysql)) { |
|
| 38 | - throw new Exception( |
|
| 39 | - 'A non-null MySQL connection is required' |
|
| 40 | - ); |
|
| 41 | - } else { |
|
| 42 | - static::$mysql = $mysql; |
|
| 43 | - } |
|
| 44 | - } |
|
| 29 | + /** |
|
| 30 | + * Update the MySQL connection |
|
| 31 | + * |
|
| 32 | + * @param mysqli $mysql |
|
| 33 | + * @throws Exception If `$mysql` is null |
|
| 34 | + */ |
|
| 35 | + public static function setMySql(mysqli $mysql) |
|
| 36 | + { |
|
| 37 | + if (empty($mysql)) { |
|
| 38 | + throw new Exception( |
|
| 39 | + 'A non-null MySQL connection is required' |
|
| 40 | + ); |
|
| 41 | + } else { |
|
| 42 | + static::$mysql = $mysql; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get the MySQL connection |
|
| 48 | - * |
|
| 49 | - * @return mysqli |
|
| 50 | - */ |
|
| 51 | - public static function getMySql() |
|
| 52 | - { |
|
| 53 | - return static::$mysql; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * Get the MySQL connection |
|
| 48 | + * |
|
| 49 | + * @return mysqli |
|
| 50 | + */ |
|
| 51 | + public static function getMySql() |
|
| 52 | + { |
|
| 53 | + return static::$mysql; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Update the API connection |
|
| 58 | - * |
|
| 59 | - * @param CanvasPest $api |
|
| 60 | - * @throws Exception if `$api` is null |
|
| 61 | - */ |
|
| 62 | - public static function setApi(CanvasPest $api) |
|
| 63 | - { |
|
| 64 | - if (empty($api)) { |
|
| 65 | - throw new Exception( |
|
| 66 | - 'A non-null API connection is required' |
|
| 67 | - ); |
|
| 68 | - } else { |
|
| 69 | - static::$api = $api; |
|
| 70 | - } |
|
| 71 | - } |
|
| 56 | + /** |
|
| 57 | + * Update the API connection |
|
| 58 | + * |
|
| 59 | + * @param CanvasPest $api |
|
| 60 | + * @throws Exception if `$api` is null |
|
| 61 | + */ |
|
| 62 | + public static function setApi(CanvasPest $api) |
|
| 63 | + { |
|
| 64 | + if (empty($api)) { |
|
| 65 | + throw new Exception( |
|
| 66 | + 'A non-null API connection is required' |
|
| 67 | + ); |
|
| 68 | + } else { |
|
| 69 | + static::$api = $api; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Get the API connection |
|
| 75 | - * |
|
| 76 | - * @return CanvasPest|null |
|
| 77 | - */ |
|
| 78 | - public static function getApi() |
|
| 79 | - { |
|
| 80 | - return static::$api; |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * Get the API connection |
|
| 75 | + * |
|
| 76 | + * @return CanvasPest|null |
|
| 77 | + */ |
|
| 78 | + public static function getApi() |
|
| 79 | + { |
|
| 80 | + return static::$api; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Save the syncable object to the MySQL database |
|
| 85 | - * |
|
| 86 | - * @return [type] [description] |
|
| 87 | - */ |
|
| 88 | - abstract public function save(); |
|
| 83 | + /** |
|
| 84 | + * Save the syncable object to the MySQL database |
|
| 85 | + * |
|
| 86 | + * @return [type] [description] |
|
| 87 | + */ |
|
| 88 | + abstract public function save(); |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Load a syncable object from the MySQL database |
|
| 92 | - * |
|
| 93 | - * @param int $id |
|
| 94 | - * @return Syncable |
|
| 95 | - */ |
|
| 96 | - abstract public static function load($id); |
|
| 90 | + /** |
|
| 91 | + * Load a syncable object from the MySQL database |
|
| 92 | + * |
|
| 93 | + * @param int $id |
|
| 94 | + * @return Syncable |
|
| 95 | + */ |
|
| 96 | + abstract public static function load($id); |
|
| 97 | 97 | } |
@@ -4,107 +4,107 @@ |
||
| 4 | 4 | |
| 5 | 5 | class CalendarContext |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * The canonical URL for this context in Canvas |
|
| 9 | - * @var string |
|
| 10 | - */ |
|
| 11 | - protected $canonicalUrl; |
|
| 7 | + /** |
|
| 8 | + * The canonical URL for this context in Canvas |
|
| 9 | + * @var string |
|
| 10 | + */ |
|
| 11 | + protected $canonicalUrl; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * The context for this calendar in Canvas (user, group, course) |
|
| 15 | - * @var CanvasContext |
|
| 16 | - */ |
|
| 17 | - protected $context; |
|
| 13 | + /** |
|
| 14 | + * The context for this calendar in Canvas (user, group, course) |
|
| 15 | + * @var CanvasContext |
|
| 16 | + */ |
|
| 17 | + protected $context; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Unique ID for this Canvas context |
|
| 21 | - * @var int |
|
| 22 | - */ |
|
| 23 | - protected $id; |
|
| 19 | + /** |
|
| 20 | + * Unique ID for this Canvas context |
|
| 21 | + * @var int |
|
| 22 | + */ |
|
| 23 | + protected $id; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * URL to verify this context against API |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $verificationUrl; |
|
| 25 | + /** |
|
| 26 | + * URL to verify this context against API |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $verificationUrl; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Compute the calendar context for the canvas object based on its URL |
|
| 33 | - * |
|
| 34 | - * @param string $canvasUrl URL to the context for a calendar on this |
|
| 35 | - * Canvas instance |
|
| 36 | - * @throws Exception If `$canvasInstance` is not a URL on this Canvas |
|
| 37 | - * instance |
|
| 38 | - * @throws Exception if `$canvasInstance` is not a URL to a recognizable |
|
| 39 | - * calendar context |
|
| 40 | - */ |
|
| 41 | - public function __construct($canvasUrl) |
|
| 42 | - { |
|
| 43 | - /* |
|
| 31 | + /** |
|
| 32 | + * Compute the calendar context for the canvas object based on its URL |
|
| 33 | + * |
|
| 34 | + * @param string $canvasUrl URL to the context for a calendar on this |
|
| 35 | + * Canvas instance |
|
| 36 | + * @throws Exception If `$canvasInstance` is not a URL on this Canvas |
|
| 37 | + * instance |
|
| 38 | + * @throws Exception if `$canvasInstance` is not a URL to a recognizable |
|
| 39 | + * calendar context |
|
| 40 | + */ |
|
| 41 | + public function __construct($canvasUrl) |
|
| 42 | + { |
|
| 43 | + /* |
|
| 44 | 44 | * TODO: accept calendar2?contexts links too (they would be an intuitively obvious link to use, after all) |
| 45 | 45 | */ |
| 46 | - /* |
|
| 46 | + /* |
|
| 47 | 47 | * FIXME: users aren't working |
| 48 | 48 | */ |
| 49 | - /* |
|
| 49 | + /* |
|
| 50 | 50 | * TODO: it would probably be better to look up users by email address than URL |
| 51 | 51 | */ |
| 52 | - /* get the context (user, course or group) for the canvas URL */ |
|
| 53 | - if (preg_match('%(https?://)?(' . parse_url($_SESSION[Constants::CANVAS_INSTANCE_URL], PHP_URL_HOST) . '/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $canvasUrl, $match)) { |
|
| 54 | - $this->canonicalUrl = "https://{$match[2]}"; // https://stmarksschool.instructure.com/courses/953 |
|
| 52 | + /* get the context (user, course or group) for the canvas URL */ |
|
| 53 | + if (preg_match('%(https?://)?(' . parse_url($_SESSION[Constants::CANVAS_INSTANCE_URL], PHP_URL_HOST) . '/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $canvasUrl, $match)) { |
|
| 54 | + $this->canonicalUrl = "https://{$match[2]}"; // https://stmarksschool.instructure.com/courses/953 |
|
| 55 | 55 | |
| 56 | - // course or account groups |
|
| 57 | - if (isset($match[9]) || isset($match[11])) { |
|
| 58 | - $this->context = CanvasContext::GROUP(); // used for context_code in events |
|
| 59 | - $this->id = ($match[9] > $match[11] ? $match[9] : $match[11]); |
|
| 60 | - $this->verificationUrl = "groups/{$this->id}"; // used once to look up the object to be sure it really exists |
|
| 56 | + // course or account groups |
|
| 57 | + if (isset($match[9]) || isset($match[11])) { |
|
| 58 | + $this->context = CanvasContext::GROUP(); // used for context_code in events |
|
| 59 | + $this->id = ($match[9] > $match[11] ? $match[9] : $match[11]); |
|
| 60 | + $this->verificationUrl = "groups/{$this->id}"; // used once to look up the object to be sure it really exists |
|
| 61 | 61 | |
| 62 | - // courses |
|
| 63 | - } elseif (isset($match[7])) { |
|
| 64 | - $this->context = CanvasContext::COURSE(); |
|
| 65 | - $this->id = $match[7]; |
|
| 66 | - $this->verificationUrl = "courses/{$this->id}"; |
|
| 62 | + // courses |
|
| 63 | + } elseif (isset($match[7])) { |
|
| 64 | + $this->context = CanvasContext::COURSE(); |
|
| 65 | + $this->id = $match[7]; |
|
| 66 | + $this->verificationUrl = "courses/{$this->id}"; |
|
| 67 | 67 | |
| 68 | - // users |
|
| 69 | - } elseif (isset($match[5])) { |
|
| 70 | - $this->context = CanvasContext::USER(); |
|
| 71 | - $this->id = $match[5]; |
|
| 72 | - $this->verificationUrl = "users/{$this->id}/profile"; |
|
| 68 | + // users |
|
| 69 | + } elseif (isset($match[5])) { |
|
| 70 | + $this->context = CanvasContext::USER(); |
|
| 71 | + $this->id = $match[5]; |
|
| 72 | + $this->verificationUrl = "users/{$this->id}/profile"; |
|
| 73 | 73 | |
| 74 | - // we're somewhere where we don't know where we are |
|
| 75 | - } else { |
|
| 76 | - throw new Exception( |
|
| 77 | - "'$canvasUrl' is not a recognizable calendar context" |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - throw new Exception( |
|
| 82 | - "'$canvasUrl' is not recognized as a URL to a calendar context on this Canvas instance" |
|
| 83 | - ); |
|
| 84 | - } |
|
| 74 | + // we're somewhere where we don't know where we are |
|
| 75 | + } else { |
|
| 76 | + throw new Exception( |
|
| 77 | + "'$canvasUrl' is not a recognizable calendar context" |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + throw new Exception( |
|
| 82 | + "'$canvasUrl' is not recognized as a URL to a calendar context on this Canvas instance" |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function getCanonicalUrl() |
|
| 87 | - { |
|
| 88 | - return $this->canonicalUrl; |
|
| 89 | - } |
|
| 86 | + public function getCanonicalUrl() |
|
| 87 | + { |
|
| 88 | + return $this->canonicalUrl; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - public function getContext() |
|
| 92 | - { |
|
| 93 | - return $this->context; |
|
| 94 | - } |
|
| 91 | + public function getContext() |
|
| 92 | + { |
|
| 93 | + return $this->context; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function getId() |
|
| 97 | - { |
|
| 98 | - return $this->id; |
|
| 99 | - } |
|
| 96 | + public function getId() |
|
| 97 | + { |
|
| 98 | + return $this->id; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - public function getVerificationUrl() |
|
| 102 | - { |
|
| 103 | - return $this->verificationUrl; |
|
| 104 | - } |
|
| 101 | + public function getVerificationUrl() |
|
| 102 | + { |
|
| 103 | + return $this->verificationUrl; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function __toString() |
|
| 107 | - { |
|
| 108 | - return $this->getCanonicalUrl(); |
|
| 109 | - } |
|
| 106 | + public function __toString() |
|
| 107 | + { |
|
| 108 | + return $this->getCanonicalUrl(); |
|
| 109 | + } |
|
| 110 | 110 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | * TODO: it would probably be better to look up users by email address than URL |
| 51 | 51 | */ |
| 52 | 52 | /* get the context (user, course or group) for the canvas URL */ |
| 53 | - if (preg_match('%(https?://)?(' . parse_url($_SESSION[Constants::CANVAS_INSTANCE_URL], PHP_URL_HOST) . '/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $canvasUrl, $match)) { |
|
| 53 | + if (preg_match('%(https?://)?('.parse_url($_SESSION[Constants::CANVAS_INSTANCE_URL], PHP_URL_HOST).'/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $canvasUrl, $match)) { |
|
| 54 | 54 | $this->canonicalUrl = "https://{$match[2]}"; // https://stmarksschool.instructure.com/courses/953 |
| 55 | 55 | |
| 56 | 56 | // course or account groups |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CanvasContext extends Enum |
| 8 | 8 | { |
| 9 | - const COURSE = 'course'; |
|
| 10 | - const USER = 'user'; |
|
| 11 | - const GROUP = 'group'; |
|
| 9 | + const COURSE = 'course'; |
|
| 10 | + const USER = 'user'; |
|
| 11 | + const GROUP = 'group'; |
|
| 12 | 12 | } |
@@ -4,220 +4,220 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Calendar |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Canvas calendar context |
|
| 9 | - * @var CalendarContext |
|
| 10 | - */ |
|
| 11 | - protected $context; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * ICS or webcal feed URL |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $feedUrl; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Name of this calendar (extracted from feed) |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $name; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Filter for events in this calendar |
|
| 27 | - * @var Filter |
|
| 28 | - */ |
|
| 29 | - protected $filter; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Construct a Calendar object |
|
| 33 | - * |
|
| 34 | - * @param string $canvasUrl URL of a Canvas calendar context |
|
| 35 | - * @param string $feedUrl URL of a webcal or ICS calendar feed |
|
| 36 | - * @param boolean $enableFilter (Optional, default `false`) |
|
| 37 | - * @param string $include (Optional) Regular expression to select events |
|
| 38 | - * for inclusion in the calendar sync |
|
| 39 | - * @param string $exclude (Optional) Regular expression to select events |
|
| 40 | - * for exclusion from the calendar sync |
|
| 41 | - */ |
|
| 42 | - public function __construct($canvasUrl, $feedUrl, $enableFilter = false, $include = null, $exclude = null) |
|
| 43 | - { |
|
| 44 | - $this->setContext(new CalendarContext($canvasUrl)); |
|
| 45 | - $this->setFeed($feedUrl); |
|
| 46 | - $this->setFilter(new Filter( |
|
| 47 | - $enableFilter, |
|
| 48 | - $include, |
|
| 49 | - $exclude |
|
| 50 | - )); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Set the Canvas calendar context |
|
| 55 | - * |
|
| 56 | - * @param CalendarContext $context |
|
| 57 | - * @throws Exception If `$context` is null |
|
| 58 | - */ |
|
| 59 | - public function setContext(CalendarContext $context) |
|
| 60 | - { |
|
| 61 | - if (!empty($context)) { |
|
| 62 | - $this->context = $context; |
|
| 63 | - } else { |
|
| 64 | - throw new Exception( |
|
| 65 | - 'Context cannot be null' |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Get the Canvas calendar context |
|
| 72 | - * |
|
| 73 | - * @return CalendarContext |
|
| 74 | - */ |
|
| 75 | - public function getContext() |
|
| 76 | - { |
|
| 77 | - return $this->context; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Set the webcal or ICS feed URl for this calendar |
|
| 82 | - * |
|
| 83 | - * @param string $feedUrl |
|
| 84 | - * @throws Exception If `$feedUrl` is not a valid URL |
|
| 85 | - */ |
|
| 86 | - public function setFeedUrl($feedUrl) |
|
| 87 | - { |
|
| 88 | - if (!empty($feedUrl)) { |
|
| 89 | - /* crude test to see if the feed is a valid URL */ |
|
| 90 | - $handle = fopen($feedUrl, 'r'); |
|
| 91 | - if ($handle !== false) { |
|
| 92 | - $this->feedUrl = $feedUrl; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - throw new Exception( |
|
| 96 | - 'Feed must be a valid URL' |
|
| 97 | - ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Get the feed URL for this calendar |
|
| 102 | - * |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function getFeedUrl() |
|
| 106 | - { |
|
| 107 | - return $this->feedUrl; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Set the name of the calendar |
|
| 112 | - * |
|
| 113 | - * @param string $name |
|
| 114 | - */ |
|
| 115 | - public function setName($name) |
|
| 116 | - { |
|
| 117 | - $this->name = (string) $name; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Get the name of the calendar |
|
| 122 | - * |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public function getName() |
|
| 126 | - { |
|
| 127 | - return $this->name; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Set the regular expression filter for this calendar |
|
| 132 | - * |
|
| 133 | - * @param Filter $filter |
|
| 134 | - */ |
|
| 135 | - public function setFilter(Filter $filter) |
|
| 136 | - { |
|
| 137 | - $this->filter = $filter; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Get the regular expression filter for this calendar |
|
| 142 | - * |
|
| 143 | - * @return Filter |
|
| 144 | - */ |
|
| 145 | - public function getFilter() |
|
| 146 | - { |
|
| 147 | - return $this->filter; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Generate a unique ID to identify this particular pairing of ICS feed and |
|
| 152 | - * Canvas calendar |
|
| 153 | - **/ |
|
| 154 | - protected function getPairingHash() |
|
| 155 | - { |
|
| 156 | - global $metadata; |
|
| 157 | - return md5($this->getContext() . $this->getFeedUrl()); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - public function save() |
|
| 161 | - { |
|
| 162 | - $sql = static::getMySql(); |
|
| 163 | - |
|
| 164 | - $params = [ |
|
| 165 | - 'id' => $sql->escape_string($this->getPairingHash()), |
|
| 166 | - 'name' => $sql->escape_string($this->getName()), |
|
| 167 | - 'canvas_url' => $sql->escape_string($this->getContext()->getCanonicalUrl()), |
|
| 168 | - 'ics_url' => $sql->escape_string($this->getFeedUrl()), |
|
| 169 | - 'enable_regex_filter' => $this->getFilter()->isEnabled(), |
|
| 170 | - 'include_regexp' => $sql->escape_string($this->getFilter()->getIncludeExpression()), |
|
| 171 | - 'exclude_regexp' => $sql->escape_string($this->getFilter()->getExcludeExpression()) |
|
| 172 | - ]; |
|
| 173 | - foreach ($params as $field => $value) { |
|
| 174 | - if (empty($value)) { |
|
| 175 | - $params[$field] = 'NULL'; |
|
| 176 | - } else { |
|
| 177 | - $params[$field] = "'$value'"; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - $response = static::getMySql()->query(" |
|
| 7 | + /** |
|
| 8 | + * Canvas calendar context |
|
| 9 | + * @var CalendarContext |
|
| 10 | + */ |
|
| 11 | + protected $context; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * ICS or webcal feed URL |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $feedUrl; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Name of this calendar (extracted from feed) |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $name; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Filter for events in this calendar |
|
| 27 | + * @var Filter |
|
| 28 | + */ |
|
| 29 | + protected $filter; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Construct a Calendar object |
|
| 33 | + * |
|
| 34 | + * @param string $canvasUrl URL of a Canvas calendar context |
|
| 35 | + * @param string $feedUrl URL of a webcal or ICS calendar feed |
|
| 36 | + * @param boolean $enableFilter (Optional, default `false`) |
|
| 37 | + * @param string $include (Optional) Regular expression to select events |
|
| 38 | + * for inclusion in the calendar sync |
|
| 39 | + * @param string $exclude (Optional) Regular expression to select events |
|
| 40 | + * for exclusion from the calendar sync |
|
| 41 | + */ |
|
| 42 | + public function __construct($canvasUrl, $feedUrl, $enableFilter = false, $include = null, $exclude = null) |
|
| 43 | + { |
|
| 44 | + $this->setContext(new CalendarContext($canvasUrl)); |
|
| 45 | + $this->setFeed($feedUrl); |
|
| 46 | + $this->setFilter(new Filter( |
|
| 47 | + $enableFilter, |
|
| 48 | + $include, |
|
| 49 | + $exclude |
|
| 50 | + )); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Set the Canvas calendar context |
|
| 55 | + * |
|
| 56 | + * @param CalendarContext $context |
|
| 57 | + * @throws Exception If `$context` is null |
|
| 58 | + */ |
|
| 59 | + public function setContext(CalendarContext $context) |
|
| 60 | + { |
|
| 61 | + if (!empty($context)) { |
|
| 62 | + $this->context = $context; |
|
| 63 | + } else { |
|
| 64 | + throw new Exception( |
|
| 65 | + 'Context cannot be null' |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Get the Canvas calendar context |
|
| 72 | + * |
|
| 73 | + * @return CalendarContext |
|
| 74 | + */ |
|
| 75 | + public function getContext() |
|
| 76 | + { |
|
| 77 | + return $this->context; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Set the webcal or ICS feed URl for this calendar |
|
| 82 | + * |
|
| 83 | + * @param string $feedUrl |
|
| 84 | + * @throws Exception If `$feedUrl` is not a valid URL |
|
| 85 | + */ |
|
| 86 | + public function setFeedUrl($feedUrl) |
|
| 87 | + { |
|
| 88 | + if (!empty($feedUrl)) { |
|
| 89 | + /* crude test to see if the feed is a valid URL */ |
|
| 90 | + $handle = fopen($feedUrl, 'r'); |
|
| 91 | + if ($handle !== false) { |
|
| 92 | + $this->feedUrl = $feedUrl; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + throw new Exception( |
|
| 96 | + 'Feed must be a valid URL' |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Get the feed URL for this calendar |
|
| 102 | + * |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function getFeedUrl() |
|
| 106 | + { |
|
| 107 | + return $this->feedUrl; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Set the name of the calendar |
|
| 112 | + * |
|
| 113 | + * @param string $name |
|
| 114 | + */ |
|
| 115 | + public function setName($name) |
|
| 116 | + { |
|
| 117 | + $this->name = (string) $name; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Get the name of the calendar |
|
| 122 | + * |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public function getName() |
|
| 126 | + { |
|
| 127 | + return $this->name; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Set the regular expression filter for this calendar |
|
| 132 | + * |
|
| 133 | + * @param Filter $filter |
|
| 134 | + */ |
|
| 135 | + public function setFilter(Filter $filter) |
|
| 136 | + { |
|
| 137 | + $this->filter = $filter; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Get the regular expression filter for this calendar |
|
| 142 | + * |
|
| 143 | + * @return Filter |
|
| 144 | + */ |
|
| 145 | + public function getFilter() |
|
| 146 | + { |
|
| 147 | + return $this->filter; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Generate a unique ID to identify this particular pairing of ICS feed and |
|
| 152 | + * Canvas calendar |
|
| 153 | + **/ |
|
| 154 | + protected function getPairingHash() |
|
| 155 | + { |
|
| 156 | + global $metadata; |
|
| 157 | + return md5($this->getContext() . $this->getFeedUrl()); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + public function save() |
|
| 161 | + { |
|
| 162 | + $sql = static::getMySql(); |
|
| 163 | + |
|
| 164 | + $params = [ |
|
| 165 | + 'id' => $sql->escape_string($this->getPairingHash()), |
|
| 166 | + 'name' => $sql->escape_string($this->getName()), |
|
| 167 | + 'canvas_url' => $sql->escape_string($this->getContext()->getCanonicalUrl()), |
|
| 168 | + 'ics_url' => $sql->escape_string($this->getFeedUrl()), |
|
| 169 | + 'enable_regex_filter' => $this->getFilter()->isEnabled(), |
|
| 170 | + 'include_regexp' => $sql->escape_string($this->getFilter()->getIncludeExpression()), |
|
| 171 | + 'exclude_regexp' => $sql->escape_string($this->getFilter()->getExcludeExpression()) |
|
| 172 | + ]; |
|
| 173 | + foreach ($params as $field => $value) { |
|
| 174 | + if (empty($value)) { |
|
| 175 | + $params[$field] = 'NULL'; |
|
| 176 | + } else { |
|
| 177 | + $params[$field] = "'$value'"; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + $response = static::getMySql()->query(" |
|
| 181 | 181 | SELECT * FROM `calendars` WHERE `id` = '$_id' |
| 182 | 182 | "); |
| 183 | - $previous = $response->fetch_assoc(); |
|
| 184 | - if ($previous) { |
|
| 185 | - $query = "UPDATE `calendars` SET\n"; |
|
| 186 | - foreach ($params as $field => $value) { |
|
| 187 | - if ($key != 'id') { |
|
| 188 | - $query .= "`$field` = $value\n"; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - $query .= "WHERE `id` = '{$params['id']}'"; |
|
| 192 | - } else { |
|
| 193 | - $query = "INSERT INTO `calendars` (\n`"; |
|
| 194 | - $query .= implode('`, `', array_keys($params)); |
|
| 195 | - $query .= "`) VALUES ("; |
|
| 196 | - $query .= implode(', ', $params); |
|
| 197 | - $query .= ')'; |
|
| 198 | - } |
|
| 199 | - if (static::getMySql($query)->query() === false) { |
|
| 200 | - throw new Exception( |
|
| 201 | - "Failed to store calendar ID {$this->id} to database" |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Load a Calendar from the MySQL database |
|
| 208 | - * |
|
| 209 | - * @param int $id |
|
| 210 | - * @return Calendar |
|
| 211 | - */ |
|
| 212 | - public static function load($id) |
|
| 213 | - { |
|
| 214 | - $sql = static::getMySql(); |
|
| 215 | - $query = "SELECT * FROM `calendars` WHERE `id` = '" . $sql->escape_string($id) . "'"; |
|
| 216 | - $response = $sql->query($query); |
|
| 217 | - if ($response) { |
|
| 218 | - $calendar = $response->fetch_assoc(); |
|
| 219 | - return new Calendar($calendar['canvas_url'], $calendar['ics_url'], $calendar['enable_regex_filter'], $calendar['include_regexp'], $calendar['exclude_regexp']); |
|
| 220 | - } |
|
| 221 | - return null; |
|
| 222 | - } |
|
| 183 | + $previous = $response->fetch_assoc(); |
|
| 184 | + if ($previous) { |
|
| 185 | + $query = "UPDATE `calendars` SET\n"; |
|
| 186 | + foreach ($params as $field => $value) { |
|
| 187 | + if ($key != 'id') { |
|
| 188 | + $query .= "`$field` = $value\n"; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + $query .= "WHERE `id` = '{$params['id']}'"; |
|
| 192 | + } else { |
|
| 193 | + $query = "INSERT INTO `calendars` (\n`"; |
|
| 194 | + $query .= implode('`, `', array_keys($params)); |
|
| 195 | + $query .= "`) VALUES ("; |
|
| 196 | + $query .= implode(', ', $params); |
|
| 197 | + $query .= ')'; |
|
| 198 | + } |
|
| 199 | + if (static::getMySql($query)->query() === false) { |
|
| 200 | + throw new Exception( |
|
| 201 | + "Failed to store calendar ID {$this->id} to database" |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Load a Calendar from the MySQL database |
|
| 208 | + * |
|
| 209 | + * @param int $id |
|
| 210 | + * @return Calendar |
|
| 211 | + */ |
|
| 212 | + public static function load($id) |
|
| 213 | + { |
|
| 214 | + $sql = static::getMySql(); |
|
| 215 | + $query = "SELECT * FROM `calendars` WHERE `id` = '" . $sql->escape_string($id) . "'"; |
|
| 216 | + $response = $sql->query($query); |
|
| 217 | + if ($response) { |
|
| 218 | + $calendar = $response->fetch_assoc(); |
|
| 219 | + return new Calendar($calendar['canvas_url'], $calendar['ics_url'], $calendar['enable_regex_filter'], $calendar['include_regexp'], $calendar['exclude_regexp']); |
|
| 220 | + } |
|
| 221 | + return null; |
|
| 222 | + } |
|
| 223 | 223 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function setName($name) |
| 116 | 116 | { |
| 117 | - $this->name = (string) $name; |
|
| 117 | + $this->name = (string)$name; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | protected function getPairingHash() |
| 155 | 155 | { |
| 156 | 156 | global $metadata; |
| 157 | - return md5($this->getContext() . $this->getFeedUrl()); |
|
| 157 | + return md5($this->getContext().$this->getFeedUrl()); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | public function save() |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | public static function load($id) |
| 213 | 213 | { |
| 214 | 214 | $sql = static::getMySql(); |
| 215 | - $query = "SELECT * FROM `calendars` WHERE `id` = '" . $sql->escape_string($id) . "'"; |
|
| 215 | + $query = "SELECT * FROM `calendars` WHERE `id` = '".$sql->escape_string($id)."'"; |
|
| 216 | 216 | $response = $sql->query($query); |
| 217 | 217 | if ($response) { |
| 218 | 218 | $calendar = $response->fetch_assoc(); |