diff --git a/dist/config.local.php b/dist/config.local.php index 1b7400d..7d8dd11 100644 --- a/dist/config.local.php +++ b/dist/config.local.php @@ -1,24 +1,24 @@ +$CACHE_DIRECTORY = __DIR__ . \DIRECTORY_SEPARATOR . 'cache'; diff --git a/dist/config.source-env.php b/dist/config.source-env.php index 22a995d..c01de53 100644 --- a/dist/config.source-env.php +++ b/dist/config.source-env.php @@ -1,6 +1,6 @@ +$configFile = getenv('PVV_CONFIG_FILE'); +require_once $configFile; diff --git a/dist/simplesamlphp-authsources.php b/dist/simplesamlphp-authsources.php index 6628597..1b279a6 100644 --- a/dist/simplesamlphp-authsources.php +++ b/dist/simplesamlphp-authsources.php @@ -1,9 +1,11 @@ array( - 'saml:SP', - 'idp' => 'https://idp.pvv.ntnu.no/', - ), -); +declare(strict_types=1); +$config = [ + + /* This is the name of this authentication source, and will be used to access it later. */ + 'default-sp' => [ + 'saml:SP', + 'idp' => 'https://idp.pvv.ntnu.no/', + ], +]; diff --git a/dist/simplesamlphp-config.php b/dist/simplesamlphp-config.php index f605fdf..5ff1643 100644 --- a/dist/simplesamlphp-config.php +++ b/dist/simplesamlphp-config.php @@ -1,25 +1,26 @@ 'simplesaml/', + 'baseurlpath' => 'simplesaml/', - /* + /* * The 'application' configuration array groups a set configuration options * relative to an application protected by SimpleSAMLphp. */ - 'application' => [ - /* + 'application' => [ + /* * The 'baseURL' configuration option allows you to specify a protocol, * host and optionally a port that serves as the canonical base for all * your application's URLs. This is useful when the environment @@ -54,13 +55,13 @@ $config = [ * need to compute the right URLs yourself and pass them dynamically * to SimpleSAMLphp's API. */ - //'baseURL' => 'https://example.com', - ], + // 'baseURL' => 'https://example.com', + ], - /* + /* * The following settings are *filesystem paths* which define where * SimpleSAMLphp can find or write the following things: - * - 'cachedir': Where SimpleSAMLphp can write its cache. + * - 'cachedir': Where SimpleSAMLphp can write its cache. * - 'loggingdir': Where to write logs. MUST be set to NULL when using a logging * handler other than `file`. * - 'datadir': Storage of general data. @@ -69,12 +70,12 @@ $config = [ * When specified as a relative path, this is relative to the SimpleSAMLphp * root directory. */ - 'cachedir' => $CACHE_DIRECTORY, - //'loggingdir' => '/var/log/', - //'datadir' => '/var/data/', - //'tempdir' => '/tmp/simplesamlphp', + 'cachedir' => $CACHE_DIRECTORY, + // 'loggingdir' => '/var/log/', + // 'datadir' => '/var/data/', + // 'tempdir' => '/tmp/simplesamlphp', - /* + /* * Certificate and key material can be loaded from different possible * locations. Currently two locations are supported, the local filesystem * and the database via pdo using the global database configuration. Locations @@ -82,7 +83,7 @@ $config = [ * identifier. */ - /* To load a certificate or key from the filesystem, it should be specified + /* To load a certificate or key from the filesystem, it should be specified * as 'file://' where is either a relative filename or a fully * qualified path to a file containing the certificate or key in PEM * format, such as 'cert.pem' or '/path/to/cert.pem'. If the path is @@ -92,9 +93,9 @@ $config = [ * directory. Note that locations with no prefix included will be treated * as file locations. */ - 'certdir' => 'cert/', + 'certdir' => 'cert/', - /* To load a certificate or key from the database, it should be specified + /* To load a certificate or key from the database, it should be specified * as 'pdo://' where is the identifier in the database table that * should be matched. While the certificate and key tables are expected to * be in the simplesaml database, they are not created or managed by @@ -118,33 +119,33 @@ $config = [ * Defaults are shown below, to change them, uncomment the line and update as * needed */ - //'cert.pdo.table' => 'certificates', - //'cert.pdo.keytable' => 'private_keys', - //'cert.pdo.apply_prefix' => true, - //'cert.pdo.id_column' => 'id', - //'cert.pdo.data_column' => 'data', + // 'cert.pdo.table' => 'certificates', + // 'cert.pdo.keytable' => 'private_keys', + // 'cert.pdo.apply_prefix' => true, + // 'cert.pdo.id_column' => 'id', + // 'cert.pdo.data_column' => 'data', - /* + /* * Some information about the technical persons running this installation. * The email address will be used as the recipient address for error reports, and * also as the technical contact in generated metadata. */ - 'technicalcontact_name' => $SAML_ADMIN_NAME, - 'technicalcontact_email' => $SAML_ADMIN_EMAIL, + 'technicalcontact_name' => $SAML_ADMIN_NAME, + 'technicalcontact_email' => $SAML_ADMIN_EMAIL, - /* + /* * (Optional) The method by which email is delivered. Defaults to mail which utilizes the * PHP mail() function. * * Valid options are: mail, sendmail and smtp. */ - //'mail.transport.method' => 'smtp', + // 'mail.transport.method' => 'smtp', - /* + /* * Set the transport options for the transport method specified. The valid settings are relative to the * selected transport method. */ - /* + /* 'mail.transport.options' => [ 'host' => 'mail.example.org', // required 'port' => 25, // optional @@ -161,29 +162,29 @@ $config = [ ], */ - /* + /* * The envelope from address for outgoing emails. * This should be in a domain that has your application's IP addresses in its SPF record * to prevent it from being rejected by mail filters. */ - //'sendmail_from' => 'no-reply@example.org', + // 'sendmail_from' => 'no-reply@example.org', - /* + /* * The timezone of the server. This option should be set to the timezone you want * SimpleSAMLphp to report the time in. The default is to guess the timezone based * on your system timezone. * * See this page for a list of valid timezones: http://php.net/manual/en/timezones.php */ - 'timezone' => null, + 'timezone' => null, - /********************************** + /* | SECURITY CONFIGURATION OPTIONS | - **********************************/ + */ - /* + /* * This is a secret salt used by SimpleSAMLphp when it needs to generate a secure hash * of a value. It must be changed from its default value to a secret value. The value of * 'secretsalt' can be any valid string of any length. @@ -191,28 +192,28 @@ $config = [ * A possible way to generate a random salt is by running the following command from a unix shell: * LC_ALL=C tr -c -d '0123456789abcdefghijklmnopqrstuvwxyz' /dev/null;echo */ - 'secretsalt' => $SAML_COOKIE_SALT, + 'secretsalt' => $SAML_COOKIE_SALT, - /* + /* * This password must be kept secret, and modified from the default value 123. * This password will give access to the installation page of SimpleSAMLphp with * metadata listing and diagnostics pages. * You can also put a hash here; run "bin/pwgen.php" to generate one. */ - 'auth.adminpassword' => $SAML_ADMIN_PASSWORD, + 'auth.adminpassword' => $SAML_ADMIN_PASSWORD, - /* + /* * Set this option to true if you want to require administrator password to access the metadata. */ - 'admin.protectmetadata' => false, + 'admin.protectmetadata' => false, - /* + /* * Set this option to false if you don't want SimpleSAMLphp to check for new stable releases when * visiting the configuration tab in the web interface. */ - 'admin.checkforupdates' => true, + 'admin.checkforupdates' => true, - /* + /* * Array of domains that are allowed when generating links or redirects * to URLs. SimpleSAMLphp will use this option to determine whether to * to consider a given URL valid or not, but you should always validate @@ -234,9 +235,9 @@ $config = [ * Example: * 'trusted.url.domains' => ['sp.example.com', 'app.example.com'], */ - 'trusted.url.domains' => $SAML_TRUSTED_DOMAINS, + 'trusted.url.domains' => $SAML_TRUSTED_DOMAINS, - /* + /* * Enable regular expression matching of trusted.url.domains. * * Set to true to treat the values in trusted.url.domains as regular @@ -245,9 +246,9 @@ $config = [ * If enabled, the start and end delimiters ('^' and '$') will be added to * all regular expressions in trusted.url.domains. */ - 'trusted.url.regex' => false, + 'trusted.url.regex' => false, - /* + /* * Enable secure POST from HTTPS to HTTP. * * If you have some SP's on HTTP and IdP is normally on HTTPS, this option @@ -258,9 +259,9 @@ $config = [ * https://idp.example.org/ssp/, then * http://idp.example.org/ssp/module.php/core/postredirect.php must be accessible. */ - 'enable.http_post' => false, + 'enable.http_post' => false, - /* + /* * Set the allowed clock skew between encrypting/decrypting assertions * * If you have a server that is constantly out of sync, this option @@ -269,9 +270,9 @@ $config = [ * Allowed range: 180 - 300 * Defaults to 180. */ - 'assertion.allowed_clock_skew' => 180, + 'assertion.allowed_clock_skew' => 180, - /* + /* * Set custom security headers. The defaults can be found in \SimpleSAML\Configuration::DEFAULT_SECURITY_HEADERS * * NOTE: When a header is already set on the response we will NOT overrule it and leave it untouched. @@ -287,11 +288,11 @@ $config = [ */ - /************************ + /* | ERRORS AND DEBUGGING | - ************************/ + */ - /* + /* * The 'debug' option allows you to control how SimpleSAMLphp behaves in certain * situations where further action may be taken * @@ -322,23 +323,23 @@ $config = [ * If you want to disable debugging completely, unset this option or set it to an * empty array. */ - 'debug' => [ - 'saml' => false, - 'backtraces' => true, - 'validatexml' => false, - ], + 'debug' => [ + 'saml' => false, + 'backtraces' => true, + 'validatexml' => false, + ], - /* + /* * When 'showerrors' is enabled, all error messages and stack traces will be output * to the browser. * * When 'errorreporting' is enabled, a form will be presented for the user to report * the error to 'technicalcontact_email'. */ - 'showerrors' => true, - 'errorreporting' => true, + 'showerrors' => true, + 'errorreporting' => true, - /* + /* * Custom error show function called from SimpleSAML\Error\Error::show. * See docs/simplesamlphp-errorhandling.md for function code example. * @@ -347,11 +348,11 @@ $config = [ */ - /************************** + /* | LOGGING AND STATISTICS | - **************************/ + */ - /* + /* * Define the minimum log level to log. Available levels: * - SimpleSAML\Logger::ERR No statistics, only errors * - SimpleSAML\Logger::WARNING No statistics, only warnings/errors @@ -367,10 +368,10 @@ $config = [ * must exist and be writable for SimpleSAMLphp. If set to something else, set * loggingdir above to 'null'. */ - 'logging.level' => SimpleSAML\Logger::NOTICE, - 'logging.handler' => 'syslog', + 'logging.level' => SimpleSAML\Logger::NOTICE, + 'logging.handler' => 'syslog', - /* + /* * Specify the format of the logs. Its use varies depending on the log handler used (for instance, you cannot * control here how dates are displayed when using the syslog or errorlog handlers), but in general the options * are: @@ -396,9 +397,9 @@ $config = [ * - %msg: the message to be logged. * */ - //'logging.format' => '%date{M j H:i:s} %process %level %stat[%trackid] %msg', + // 'logging.format' => '%date{M j H:i:s} %process %level %stat[%trackid] %msg', - /* + /* * Choose which facility should be used when logging with syslog. * * These can be used for filtering the syslog output from SimpleSAMLphp into its @@ -409,103 +410,103 @@ $config = [ * * The default is to use LOG_LOCAL5 if available, and fall back to LOG_USER if not. */ - 'logging.facility' => defined('LOG_LOCAL5') ? constant('LOG_LOCAL5') : LOG_USER, + 'logging.facility' => defined('LOG_LOCAL5') ? constant('LOG_LOCAL5') : \LOG_USER, - /* + /* * The process name that should be used when logging to syslog. * The value is also written out by the other logging handlers. */ - 'logging.processname' => 'simplesamlphp', + 'logging.processname' => 'simplesamlphp', - /* + /* * Logging: file - Logfilename in the loggingdir from above. */ - 'logging.logfile' => 'simplesamlphp.log', + 'logging.logfile' => 'simplesamlphp.log', - /* + /* * This is an array of outputs. Each output has at least a 'class' option, which * selects the output. */ - 'statistics.out' => [ - // Log statistics to the normal log. - /* + 'statistics.out' => [ + // Log statistics to the normal log. + /* [ 'class' => 'core:Log', 'level' => 'notice', ], */ - // Log statistics to files in a directory. One file per day. - /* + // Log statistics to files in a directory. One file per day. + /* [ 'class' => 'core:File', 'directory' => '/var/log/stats', ], */ - ], + ], - /*********************** + /* | PROXY CONFIGURATION | - ***********************/ + */ - /* + /* * Proxy to use for retrieving URLs. * * Example: * 'proxy' => 'tcp://proxy.example.com:5100' */ - 'proxy' => null, + 'proxy' => null, - /* + /* * Username/password authentication to proxy (Proxy-Authorization: Basic) * Example: * 'proxy.auth' = 'myuser:password' */ - //'proxy.auth' => 'myuser:password', + // 'proxy.auth' => 'myuser:password', - /************************** + /* | DATABASE CONFIGURATION | - **************************/ + */ - /* + /* * This database configuration is optional. If you are not using * core functionality or modules that require a database, you can * skip this configuration. */ - /* + /* * Database connection string. * Ensure that you have the required PDO database driver installed * for your connection string. */ - 'database.dsn' => 'mysql:host=localhost;dbname=saml', + 'database.dsn' => 'mysql:host=localhost;dbname=saml', - /* + /* * SQL database credentials */ - 'database.username' => 'simplesamlphp', - 'database.password' => 'secret', - 'database.options' => [], + 'database.username' => 'simplesamlphp', + 'database.password' => 'secret', + 'database.options' => [], - /* + /* * (Optional) Table prefix */ - 'database.prefix' => '', + 'database.prefix' => '', - /* + /* * (Optional) Driver options */ - 'database.driver_options' => [], + 'database.driver_options' => [], - /* + /* * True or false if you would like a persistent database connection */ - 'database.persistent' => false, + 'database.persistent' => false, - /* + /* * Database secondary configuration is optional as well. If you are only * running a single database server, leave this blank. If you have * a primary/secondary configuration, you can define as many secondary servers @@ -515,8 +516,8 @@ $config = [ * options for the primary (shown above) with the exception of the table * prefix and driver options. */ - 'database.secondaries' => [ - /* + 'database.secondaries' => [ + /* [ 'dsn' => 'mysql:host=mysecondary;dbname=saml', 'username' => 'simplesamlphp', @@ -524,29 +525,29 @@ $config = [ 'persistent' => false, ], */ - ], + ], - /************* + /* | PROTOCOLS | - *************/ + */ - /* + /* * Which functionality in SimpleSAMLphp do you want to enable. Normally you would enable only * one of the functionalities below, but in some cases you could run multiple functionalities. * In example when you are setting up a federation bridge. */ - 'enable.saml20-idp' => false, - 'enable.adfs-idp' => false, + 'enable.saml20-idp' => false, + 'enable.adfs-idp' => false, - /*********** + /* | MODULES | - ***********/ + */ - /* + /* * Configuration for enabling/disabling modules. By default the 'core', 'admin' and 'saml' modules are enabled. * * Example: @@ -558,42 +559,42 @@ $config = [ * ], */ - 'module.enable' => [ - 'exampleauth' => false, - 'core' => true, - 'admin' => true, - 'saml' => true - ], + 'module.enable' => [ + 'exampleauth' => false, + 'core' => true, + 'admin' => true, + 'saml' => true, + ], - /************************* + /* | SESSION CONFIGURATION | - *************************/ + */ - /* + /* * This value is the duration of the session in seconds. Make sure that the time duration of * cookies both at the SP and the IdP exceeds this duration. */ - 'session.duration' => 8 * (60 * 60), // 8 hours. + 'session.duration' => 8 * (60 * 60), // 8 hours. - /* + /* * Sets the duration, in seconds, data should be stored in the datastore. As the data store is used for * login and logout requests, this option will control the maximum time these operations can take. * The default is 4 hours (4*60*60) seconds, which should be more than enough for these operations. */ - 'session.datastore.timeout' => (4 * 60 * 60), // 4 hours + 'session.datastore.timeout' => (4 * 60 * 60), // 4 hours - /* + /* * Sets the duration, in seconds, auth state should be stored. */ - 'session.state.timeout' => (60 * 60), // 1 hour + 'session.state.timeout' => (60 * 60), // 1 hour - /* + /* * Option to override the default settings for the session cookie name */ - 'session.cookie.name' => 'SimpleSAMLSessionID', + 'session.cookie.name' => 'SimpleSAMLSessionID', - /* + /* * Expiration time for the session cookie, in seconds. * * Defaults to 0, which means that the cookie expires when the browser is closed. @@ -601,9 +602,9 @@ $config = [ * Example: * 'session.cookie.lifetime' => 30*60, */ - 'session.cookie.lifetime' => 0, + 'session.cookie.lifetime' => 0, - /* + /* * Limit the path of the cookies. * * Can be used to limit the path of the cookies to a specific subdirectory. @@ -611,9 +612,9 @@ $config = [ * Example: * 'session.cookie.path' => '/simplesaml/', */ - 'session.cookie.path' => '/', + 'session.cookie.path' => '/', - /* + /* * Cookie domain. * * Can be used to make the session cookie available to several domains. @@ -621,9 +622,9 @@ $config = [ * Example: * 'session.cookie.domain' => '.example.org', */ - 'session.cookie.domain' => '', + 'session.cookie.domain' => '', - /* + /* * Set the secure flag in the cookie. * * Set this to TRUE if the user only accesses your service @@ -632,9 +633,9 @@ $config = [ * * If unset, SimpleSAMLphp will try to automatically determine the right value */ - 'session.cookie.secure' => $SAML_COOKIE_SECURE, + 'session.cookie.secure' => $SAML_COOKIE_SECURE, - /* + /* * Set the SameSite attribute in the cookie. * * You can set this to the strings 'None', 'Lax', or 'Strict' to support @@ -651,21 +652,21 @@ $config = [ * Example: * 'session.cookie.samesite' => 'None', */ - 'session.cookie.samesite' => $httpUtils->canSetSameSiteNone() ? 'None' : null, + 'session.cookie.samesite' => $httpUtils->canSetSameSiteNone() ? 'None' : null, - /* + /* * Options to override the default settings for php sessions. */ - 'session.phpsession.cookiename' => 'SimpleSAML', - 'session.phpsession.savepath' => null, - 'session.phpsession.httponly' => true, + 'session.phpsession.cookiename' => 'SimpleSAML', + 'session.phpsession.savepath' => null, + 'session.phpsession.httponly' => true, - /* + /* * Option to override the default settings for the auth token cookie */ - 'session.authtoken.cookiename' => 'SimpleSAMLAuthToken', + 'session.authtoken.cookiename' => 'SimpleSAMLAuthToken', - /* + /* * Options for remember me feature for IdP sessions. Remember me feature * has to be also implemented in authentication source used. * @@ -678,11 +679,11 @@ $config = [ * It's advised to use remember me feature with session checking function * defined with 'session.check_function' option. */ - 'session.rememberme.enable' => false, - 'session.rememberme.checked' => false, - 'session.rememberme.lifetime' => (14 * 86400), + 'session.rememberme.enable' => false, + 'session.rememberme.checked' => false, + 'session.rememberme.lifetime' => (14 * 86400), - /* + /* * Custom function for session checking called on session init and loading. * See docs/simplesamlphp-advancedfeatures.md for function code example. * @@ -692,11 +693,11 @@ $config = [ - /************************** + /* | MEMCACHE CONFIGURATION | - **************************/ + */ - /* + /* * Configuration for the 'memcache' session store. This allows you to store * multiple redundant copies of sessions on different memcache servers. * @@ -779,13 +780,13 @@ $config = [ * ], * */ - 'memcache_store.servers' => [ - [ - ['hostname' => 'localhost'], - ], + 'memcache_store.servers' => [ + [ + ['hostname' => 'localhost'], ], + ], - /* + /* * This value allows you to set a prefix for memcache-keys. The default * for this value is 'simpleSAMLphp', which is fine in most cases. * @@ -793,9 +794,9 @@ $config = [ * than one instance is using memcache, you probably want to assign * a unique value per instance to this setting to avoid data collision. */ - 'memcache_store.prefix' => '', + 'memcache_store.prefix' => '', - /* + /* * This value is the duration data should be stored in memcache. Data * will be dropped from the memcache servers when this time expires. * The time will be reset every time the data is written to the @@ -810,96 +811,96 @@ $config = [ * Note: The oldest data will always be deleted if the memcache server * runs out of storage space. */ - 'memcache_store.expires' => 36 * (60 * 60), // 36 hours. + 'memcache_store.expires' => 36 * (60 * 60), // 36 hours. - /************************************* + /* | LANGUAGE AND INTERNATIONALIZATION | - *************************************/ + */ - /* + /* * Languages available, RTL languages, and what language is the default. */ - 'language.available' => [ - 'en', 'no', 'nn', 'se', 'da', 'de', 'sv', 'fi', 'es', 'ca', 'fr', 'it', 'nl', 'lb', - 'cs', 'sk', 'sl', 'lt', 'hr', 'hu', 'pl', 'pt', 'pt-br', 'tr', 'ja', 'zh', 'zh-tw', - 'ru', 'et', 'he', 'id', 'sr', 'lv', 'ro', 'eu', 'el', 'af', 'zu', 'xh', 'st', - ], - 'language.rtl' => ['ar', 'dv', 'fa', 'ur', 'he'], - 'language.default' => 'en', + 'language.available' => [ + 'en', 'no', 'nn', 'se', 'da', 'de', 'sv', 'fi', 'es', 'ca', 'fr', 'it', 'nl', 'lb', + 'cs', 'sk', 'sl', 'lt', 'hr', 'hu', 'pl', 'pt', 'pt-br', 'tr', 'ja', 'zh', 'zh-tw', + 'ru', 'et', 'he', 'id', 'sr', 'lv', 'ro', 'eu', 'el', 'af', 'zu', 'xh', 'st', + ], + 'language.rtl' => ['ar', 'dv', 'fa', 'ur', 'he'], + 'language.default' => 'en', - /* + /* * Options to override the default settings for the language parameter */ - 'language.parameter.name' => 'language', - 'language.parameter.setcookie' => true, + 'language.parameter.name' => 'language', + 'language.parameter.setcookie' => true, - /* + /* * Options to override the default settings for the language cookie */ - 'language.cookie.name' => 'language', - 'language.cookie.domain' => '', - 'language.cookie.path' => '/', - 'language.cookie.secure' => true, - 'language.cookie.httponly' => false, - 'language.cookie.lifetime' => (60 * 60 * 24 * 900), - 'language.cookie.samesite' => $httpUtils->canSetSameSiteNone() ? 'None' : null, + 'language.cookie.name' => 'language', + 'language.cookie.domain' => '', + 'language.cookie.path' => '/', + 'language.cookie.secure' => true, + 'language.cookie.httponly' => false, + 'language.cookie.lifetime' => (60 * 60 * 24 * 900), + 'language.cookie.samesite' => $httpUtils->canSetSameSiteNone() ? 'None' : null, - /** - * Custom getLanguage function called from SimpleSAML\Locale\Language::getLanguage(). - * Function should return language code of one of the available languages or NULL. - * See SimpleSAML\Locale\Language::getLanguage() source code for more info. - * - * This option can be used to implement a custom function for determining - * the default language for the user. - * - * Example: - * 'language.get_language_function' => ['\SimpleSAML\Module\example\Template', 'getLanguage'], + /* + * Custom getLanguage function called from SimpleSAML\Locale\Language::getLanguage(). + * Function should return language code of one of the available languages or NULL. + * See SimpleSAML\Locale\Language::getLanguage() source code for more info. + * + * This option can be used to implement a custom function for determining + * the default language for the user. + * + * Example: + * 'language.get_language_function' => ['\SimpleSAML\Module\example\Template', 'getLanguage'], + */ + + /* + | APPEARANCE | */ - /************** - | APPEARANCE | - **************/ - - /* + /* * Which theme directory should be used? */ - 'theme.use' => 'default', + 'theme.use' => 'default', - /* + /* * Set this option to the text you would like to appear at the header of each page. Set to false if you don't want * any text to appear in the header. */ - //'theme.header' => 'SimpleSAMLphp', + // 'theme.header' => 'SimpleSAMLphp', - /** - * A template controller, if any. - * - * Used to intercept certain parts of the template handling, while keeping away unwanted/unexpected hooks. Set - * the 'theme.controller' configuration option to a class that implements the - * \SimpleSAML\XHTML\TemplateControllerInterface interface to use it. - */ - //'theme.controller' => '', + /* + * A template controller, if any. + * + * Used to intercept certain parts of the template handling, while keeping away unwanted/unexpected hooks. Set + * the 'theme.controller' configuration option to a class that implements the + * \SimpleSAML\XHTML\TemplateControllerInterface interface to use it. + */ + // 'theme.controller' => '', - /* + /* * Templating options * * By default, twig templates are not cached. To turn on template caching: * Set 'template.cache' to an absolute path pointing to a directory that * SimpleSAMLphp has read and write permissions to. */ - //'template.cache' => '', + // 'template.cache' => '', - /* + /* * Set the 'template.auto_reload' to true if you would like SimpleSAMLphp to * recompile the templates (when using the template cache) if the templates * change. If you don't want to check the source templates for every request, * set it to false. */ - 'template.auto_reload' => false, + 'template.auto_reload' => false, - /* + /* * Set this option to true to indicate that your installation of SimpleSAMLphp * is running in a production environment. This will affect the way resources * are used, offering an optimized version when running in production, and an @@ -909,23 +910,23 @@ $config = [ * * Defaults to true. */ - 'production' => true, + 'production' => true, - /* + /* * SimpleSAMLphp modules can host static resources which are served through PHP. * The serving of the resources can be configured through these settings. */ - 'assets' => [ - /* + 'assets' => [ + /* * These settings adjust the caching headers that are sent * when serving static resources. */ - 'caching' => [ - /* + 'caching' => [ + /* * Amount of seconds before the resource should be fetched again */ - 'max_age' => 86400, - /* + 'max_age' => 86400, + /* * Calculate a checksum of every file and send it to the browser * This allows the browser to avoid downloading assets again in situations * where the Last-Modified header cannot be trusted, @@ -933,35 +934,35 @@ $config = [ * * Defaults false */ - 'etag' => false, - ], + 'etag' => false, ], + ], - /** - * Set to a full URL if you want to redirect users that land on SimpleSAMLphp's - * front page to somewhere more useful. If left unset, a basic welcome message - * is shown. - */ - //'frontpage.redirect' => 'https://example.com/', + /* + * Set to a full URL if you want to redirect users that land on SimpleSAMLphp's + * front page to somewhere more useful. If left unset, a basic welcome message + * is shown. + */ + // 'frontpage.redirect' => 'https://example.com/', - /********************* + /* | DISCOVERY SERVICE | - *********************/ + */ - /* + /* * Whether the discovery service should allow the user to save his choice of IdP. */ - 'idpdisco.enableremember' => true, - 'idpdisco.rememberchecked' => true, + 'idpdisco.enableremember' => true, + 'idpdisco.rememberchecked' => true, - /* + /* * The disco service only accepts entities it knows. */ - 'idpdisco.validate' => true, + 'idpdisco.validate' => true, - 'idpdisco.extDiscoveryStorage' => null, + 'idpdisco.extDiscoveryStorage' => null, - /* + /* * IdP Discovery service look configuration. * Whether to display a list of idp or to display a dropdown box. For many IdP' a dropdown box * gives the best use experience. @@ -971,39 +972,39 @@ $config = [ * * Options: [links,dropdown] */ - 'idpdisco.layout' => 'dropdown', + 'idpdisco.layout' => 'dropdown', - /************************************* + /* | AUTHENTICATION PROCESSING FILTERS | - *************************************/ + */ - /* + /* * Authentication processing filters that will be executed for all IdPs */ - 'authproc.idp' => [ - /* Enable the authproc filter below to add URN prefixes to all attributes + 'authproc.idp' => [ + /* Enable the authproc filter below to add URN prefixes to all attributes 10 => [ 'class' => 'core:AttributeMap', 'addurnprefix' ], */ - /* Enable the authproc filter below to automatically generated eduPersonTargetedID. + /* Enable the authproc filter below to automatically generated eduPersonTargetedID. 20 => 'core:TargetedID', */ - // Adopts language from attribute to use in UI - 30 => 'core:LanguageAdaptor', + // Adopts language from attribute to use in UI + 30 => 'core:LanguageAdaptor', - /* When called without parameters, it will fallback to filter attributes 'the old way' + /* When called without parameters, it will fallback to filter attributes 'the old way' * by checking the 'attributes' parameter in metadata on IdP hosted and SP remote. */ - 50 => 'core:AttributeLimit', + 50 => 'core:AttributeLimit', - /* + /* * Search attribute "distinguishedName" for pattern and replaces if found */ - /* + /* 60 => [ 'class' => 'core:AttributeAlter', 'pattern' => '/OU=studerende/', @@ -1013,10 +1014,10 @@ $config = [ ], */ - /* + /* * Consent module is enabled (with no permanent storage, using cookies). */ - /* + /* 90 => [ 'class' => 'consent:Consent', 'store' => 'consent:Cookie', @@ -1024,52 +1025,52 @@ $config = [ 'checked' => true ], */ - // If language is set in Consent module it will be added as an attribute. - 99 => 'core:LanguageAdaptor', - ], + // If language is set in Consent module it will be added as an attribute. + 99 => 'core:LanguageAdaptor', + ], - /* + /* * Authentication processing filters that will be executed for all SPs */ - 'authproc.sp' => [ - /* + 'authproc.sp' => [ + /* 10 => [ 'class' => 'core:AttributeMap', 'removeurnprefix' ], */ - /* + /* * Generate the 'group' attribute populated from other variables, including eduPersonAffiliation. 60 => [ 'class' => 'core:GenerateGroups', 'eduPersonAffiliation' ], */ - /* + /* * All users will be members of 'users' and 'members' */ - /* + /* 61 => [ 'class' => 'core:AttributeAdd', 'groups' => ['users', 'members'] ], */ - // Adopts language from attribute to use in UI - 90 => 'core:LanguageAdaptor', - ], + // Adopts language from attribute to use in UI + 90 => 'core:LanguageAdaptor', + ], - /************************** + /* | METADATA CONFIGURATION | - **************************/ + */ - /* + /* * This option allows you to specify a directory for your metadata outside of the standard metadata directory * included in the standard distribution of the software. */ - 'metadatadir' => 'metadata', + 'metadatadir' => 'metadata', - /* + /* * This option configures the metadata sources. The metadata sources is given as an array with * different metadata sources. When searching for metadata, SimpleSAMLphp will search through * the array from start to end. @@ -1153,19 +1154,19 @@ $config = [ * ['type' => 'flatfile'] * ], */ - 'metadata.sources' => [ - ['type' => 'flatfile'], - ], + 'metadata.sources' => [ + ['type' => 'flatfile'], + ], - /* + /* * Should signing of generated metadata be enabled by default. * * Metadata signing can also be enabled for a individual SP or IdP by setting the * same option in the metadata for the SP or IdP. */ - 'metadata.sign.enable' => false, + 'metadata.sign.enable' => false, - /* + /* * The default key & certificate which should be used to sign generated metadata. These * are files stored in the cert dir. * These values can be overridden by the options with the same names in the SP or @@ -1175,17 +1176,17 @@ $config = [ * the 'certificate' and 'privatekey' option in the metadata will be used. * if those aren't set, signing of metadata will fail. */ - 'metadata.sign.privatekey' => null, - 'metadata.sign.privatekey_pass' => null, - 'metadata.sign.certificate' => null, - 'metadata.sign.algorithm' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256', + 'metadata.sign.privatekey' => null, + 'metadata.sign.privatekey_pass' => null, + 'metadata.sign.certificate' => null, + 'metadata.sign.algorithm' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256', - /**************************** + /* | DATA STORE CONFIGURATION | - ****************************/ + */ - /* + /* * Configure the data store for SimpleSAMLphp. * * - 'phpsession': Limited datastore, which uses the PHP session. @@ -1195,39 +1196,39 @@ $config = [ * * The default datastore is 'phpsession'. */ - 'store.type' => 'phpsession', + 'store.type' => 'phpsession', - /* + /* * The DSN the sql datastore should connect to. * * See http://www.php.net/manual/en/pdo.drivers.php for the various * syntaxes. */ - 'store.sql.dsn' => 'sqlite:/path/to/sqlitedatabase.sq3', + 'store.sql.dsn' => 'sqlite:/path/to/sqlitedatabase.sq3', - /* + /* * The username and password to use when connecting to the database. */ - 'store.sql.username' => null, - 'store.sql.password' => null, + 'store.sql.username' => null, + 'store.sql.password' => null, - /* + /* * The prefix we should use on our tables. */ - 'store.sql.prefix' => 'SimpleSAMLphp', + 'store.sql.prefix' => 'SimpleSAMLphp', - /* + /* * The driver-options we should pass to the PDO-constructor. */ - 'store.sql.options' => [], + 'store.sql.options' => [], - /* + /* * The hostname and port of the Redis datastore instance. */ - 'store.redis.host' => 'localhost', - 'store.redis.port' => 6379, + 'store.redis.host' => 'localhost', + 'store.redis.port' => 6379, - /* + /* * The credentials to use when connecting to Redis. * * If your Redis server is using the legacy password protection (config @@ -1238,42 +1239,42 @@ $config = [ * Redis 6+) then you should provide both a username and a password. * See https://redis.io/docs/manual/security/acl/ */ - 'store.redis.username' => '', - 'store.redis.password' => '', + 'store.redis.username' => '', + 'store.redis.password' => '', - /* + /* * Communicate with Redis over a secure connection instead of plain TCP. * * This setting affects both single host connections as * well as Sentinel mode. */ - 'store.redis.tls' => false, + 'store.redis.tls' => false, - /* + /* * Verify the Redis server certificate. */ - 'store.redis.insecure' => false, + 'store.redis.insecure' => false, - /* + /* * Files related to secure communication with Redis. * * Files are searched in the 'certdir' when using relative paths. */ - 'store.redis.ca_certificate' => null, - 'store.redis.certificate' => null, - 'store.redis.privatekey' => null, + 'store.redis.ca_certificate' => null, + 'store.redis.certificate' => null, + 'store.redis.privatekey' => null, - /* + /* * The prefix we should use on our Redis datastore. */ - 'store.redis.prefix' => 'SimpleSAMLphp', + 'store.redis.prefix' => 'SimpleSAMLphp', - /* + /* * The master group to use for Redis Sentinel. */ - 'store.redis.mastergroup' => 'mymaster', + 'store.redis.mastergroup' => 'mymaster', - /* + /* * The Redis Sentinel hosts. * Example: * 'store.redis.sentinels' => [ @@ -1285,17 +1286,17 @@ $config = [ * Use 'tls' instead of 'tcp' in order to make use of the additional * TLS settings. */ - 'store.redis.sentinels' => [], + 'store.redis.sentinels' => [], - /********************* + /* | IdP/SP PROXY MODE | - *********************/ + */ - /* + /* * If the IdP in front of SimpleSAMLphp in IdP/SP proxy mode sends * AuthnContextClassRef, decide whether the AuthnContextClassRef will be * processed by the IdP/SP proxy or if it will be passed to the SP behind * the IdP/SP proxy. */ - 'proxymode.passAuthnContextClassRef' => false, + 'proxymode.passAuthnContextClassRef' => false, ]; diff --git a/dist/simplesamlphp-idp.php b/dist/simplesamlphp-idp.php index 5b9254d..a81399b 100644 --- a/dist/simplesamlphp-idp.php +++ b/dist/simplesamlphp-idp.php @@ -1,23 +1,21 @@ 'saml20-idp-remote', 'entityid' => 'https://idp.pvv.ntnu.no/', - 'SingleSignOnService' => - array ( - 0 => - array ( + 'SingleSignOnService' => [ + 0 => [ 'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', 'Location' => 'https://idp.pvv.ntnu.no/simplesaml/saml2/idp/SSOService.php', - ), - ), - 'SingleLogoutService' => - array ( - 0 => - array ( + ], + ], + 'SingleLogoutService' => [ + 0 => [ 'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', 'Location' => 'https://idp.pvv.ntnu.no/simplesaml/saml2/idp/SingleLogoutService.php', - ), - ), + ], + ], 'certData' => 'MIIDpTCCAo2gAwIBAgIJAJIgibrB7NvsMA0GCSqGSIb3DQEBCwUAMGkxCzAJBgNVBAYTAk5PMR4wHAYDVQQKDBVQcm9ncmFtdmFyZXZlcmtzdGVkZXQxGDAWBgNVBAMMD2lkcC5wdnYubnRudS5ubzEgMB4GCSqGSIb3DQEJARYRZHJpZnRAcHZ2Lm50bnUubm8wHhcNMTcxMTEzMjI0NTQyWhcNMjcxMTEzMjI0NTQyWjBpMQswCQYDVQQGEwJOTzEeMBwGA1UECgwVUHJvZ3JhbXZhcmV2ZXJrc3RlZGV0MRgwFgYDVQQDDA9pZHAucHZ2Lm50bnUubm8xIDAeBgkqhkiG9w0BCQEWEWRyaWZ0QHB2di5udG51Lm5vMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAveLujCsgVCRA360y5yezy8FcSPhaqodggDqY12UTkYOMQLBFaph6uUL4oCUlXZqxScrAYVRt9yw+7BYpcm0p51VZzVCsfMxRVkn+O1eUvsaXq3f13f87QHKYP2f0uqkGf5PvnKIdSaI/ix8WJhD8XT+h0OkHEcaBvUtSG7zbEhvG21WPHwgw2rvZSneArQ8tOitZC0u8VXSfdhtf6ynRseo0xC95634UwQAZivhQ2v4A6Tp57QG5DCXIJ9/z3PkINx3KB/hOeh0EP6Dpbp+7V0/t9778E3whpm4llrH144kzROhA7EgUgkZOjAVjxGCYlcj3xQPnnItihVOZ5B5qLwIDAQABo1AwTjAdBgNVHQ4EFgQUPLhrB+Qb/Kzz7Car9GJkKmEkz6swHwYDVR0jBBgwFoAUPLhrB+Qb/Kzz7Car9GJkKmEkz6swDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAd+4E6t0j8/p8rbZE8y/gZ9GsiRhxkR4l6JbMRUfEpqHKi415qstChRcP2Lo3Yd5qdmj9tLDWoPsqet1QgyTTmQTgUmPhhMOQDqSh90LuqEJseKWafXGS/SfWLH6MWVmzDV5YofJEw2ThPiU58GiS06OLS2poq1eAesa2LQ22J8yYisXM4sxImIFte+LYQ1+1evfBWcvU1vrGsQ0VLJHdef9WoXp1swUFhq4Zk0c7gjHiB1CFVlExAAlk9L6W3CVXmKIYlf4eUnEBGkC061Ir42+uhAMWO9Y/L1NEuboTyd2KAI/6JdKdzpmfk7zPVxWlNxNCZ7OPNuvOKp6VlpB2EA==', 'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient', -); +]; diff --git a/inc/agenda.php b/inc/agenda.php index cc1f917..7fa67b9 100644 --- a/inc/agenda.php +++ b/inc/agenda.php @@ -1,11 +1,13 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -$agenda = new \pvv\side\Agenda([ - new \pvv\side\social\NerdepitsaActivity, - new \pvv\side\social\AnimekveldActivity, - new \pvv\side\DBActivity($pdo), - ]); +$agenda = new pvv\side\Agenda([ + new pvv\side\social\NerdepitsaActivity(), + new pvv\side\social\AnimekveldActivity(), + new pvv\side\DBActivity($pdo), +]); diff --git a/inc/include.php b/inc/include.php index 516de07..0905a9c 100644 --- a/inc/include.php +++ b/inc/include.php @@ -1,33 +1,36 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -$userManager = new \pvv\admin\UserManager($pdo); +$userManager = new pvv\admin\UserManager($pdo); $sp = 'default-sp'; -$as = new \SimpleSAML\Auth\Simple($sp); +$as = new SimpleSAML\Auth\Simple($sp); -use \pvv\side\Agenda; -$agenda = new \pvv\side\Agenda([ +use pvv\side\Agenda; + +$agenda = new Agenda([ // new \pvv\side\social\NerdepitsaActivity, // new \pvv\side\social\AnimekveldActivity, - new \pvv\side\social\HackekveldActivity, - new \pvv\side\social\BrettspillActivity, - new \pvv\side\social\DriftkveldActivity, - new \pvv\side\DBActivity($pdo), + new pvv\side\social\HackekveldActivity(), + new pvv\side\social\BrettspillActivity(), + new pvv\side\social\DriftkveldActivity(), + new pvv\side\DBActivity($pdo), ]); $months_translations = ['januar', 'februar', 'mars', 'april', 'mai', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'desember']; diff --git a/inc/navbar.php b/inc/navbar.php index d9c9f49..3d8d20e 100644 --- a/inc/navbar.php +++ b/inc/navbar.php @@ -1,70 +1,74 @@ \n"; - $menuItems = [ - 'Hjem' => '', - 'Hendelser' => 'hendelser', - //'Kalender' => 'kalender', - //'Aktiviteter' => 'aktiviteter', - 'Prosjekter' => 'prosjekt', - 'Kontakt' => 'kontakt', - 'Webmail' => 'https://webmail.pvv.ntnu.no/roundcube/', - 'Galleri' => 'galleri', - 'Wiki' => 'https://wiki.pvv.ntnu.no/', - 'Git' => 'https://git.pvv.ntnu.no/', - 'Tjenester' => 'tjenester', - ]; - foreach($menuItems as $caption => $link) { - $isActive = $active === $link; - if (substr( $link, 0, 4 ) != "http") { - $link = rtrim(str_repeat('../', $depth) . $link, '/') . '/'; - } - - //if ($isActive) $link = '#'; - - $result .= "\t\t' - . '' - . $caption - . "\n" - ; - } - return $result . "\t\n"; + +declare(strict_types=1); +function navbar($depth, $active = null) { + $result = "\n\t
    \n"; + $menuItems = [ + 'Hjem' => '', + 'Hendelser' => 'hendelser', + // 'Kalender' => 'kalender', + // 'Aktiviteter' => 'aktiviteter', + 'Prosjekter' => 'prosjekt', + 'Kontakt' => 'kontakt', + 'Webmail' => 'https://webmail.pvv.ntnu.no/roundcube/', + 'Galleri' => 'galleri', + 'Wiki' => 'https://wiki.pvv.ntnu.no/', + 'Git' => 'https://git.pvv.ntnu.no/', + 'Tjenester' => 'tjenester', + ]; + foreach ($menuItems as $caption => $link) { + $isActive = $active === $link; + if (substr($link, 0, 4) != 'http') { + $link = rtrim(str_repeat('../', $depth) . $link, '/') . '/'; + } + + // if ($isActive) $link = '#'; + + $result .= "\t\t' + . '' + . $caption + . "\n"; + } + + return $result . "\t
\n"; } function loginBar($sp = null, $pdo = null) { - if (is_null($sp)) $sp = 'default-sp'; - $result = "\n"; - require_once(__DIR__ . '/../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php'); - $as = new \SimpleSAML\Auth\Simple($sp); + if (null === $sp) { + $sp = 'default-sp'; + } + $result = "\n"; + require_once __DIR__ . '/../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php'; + $as = new SimpleSAML\Auth\Simple($sp); - $svg = ' + $svg = ' '; - $attr = $as->getAttributes(); - if($attr) { - $uname = $attr['uid'][0]; - $isAdmin = false; - if (isset($pdo)) { - $userManager = new \pvv\admin\UserManager($pdo); - $isAdmin = $userManager->isAdmin($uname); - } - $result .= "\t{$svg}" . htmlspecialchars($uname) . "\n"; + $attr = $as->getAttributes(); + if ($attr) { + $uname = $attr['uid'][0]; + $isAdmin = false; + if (isset($pdo)) { + $userManager = new pvv\admin\UserManager($pdo); + $isAdmin = $userManager->isAdmin($uname); + } + $result .= "\t{$svg}" . htmlspecialchars($uname) . "\n"; - $result .= "\n\t\n"; - } else { - $result .= "\tgetLoginURL()) . "\">{$svg}Logg inn\n"; - } + $result .= "\n\t\n"; + } else { + $result .= "\tgetLoginURL()) . "\">{$svg}Logg inn\n"; + } - $result .= "\n\t☰ MENU\n"; + $result .= "\n\t☰ MENU\n"; - return $result; + return $result; } diff --git a/src/_autoload.php b/src/_autoload.php index c8a7111..cbc15da 100644 --- a/src/_autoload.php +++ b/src/_autoload.php @@ -1,4 +1,6 @@ * @@ -14,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/** +/* * Register SPL autoloading for classes and interfaces. Put this file in your * namespace root and make sure it gets included from your PHP entry-point. * @@ -34,6 +36,6 @@ * @link http://php.net/manual/en/function.spl-autoload.php * @license http://choosealicense.com/licenses/isc/ ISC license */ -spl_autoload_extensions( '.php' ); -spl_autoload_register( 'spl_autoload' ); -set_include_path( realpath( __DIR__ ) . PATH_SEPARATOR . get_include_path() ); +spl_autoload_extensions('.php'); +spl_autoload_register('spl_autoload'); +set_include_path(realpath(__DIR__) . \PATH_SEPARATOR . get_include_path()); diff --git a/src/pvv/admin/usermanager.php b/src/pvv/admin/usermanager.php index 3f45a9b..84e63ef 100644 --- a/src/pvv/admin/usermanager.php +++ b/src/pvv/admin/usermanager.php @@ -1,134 +1,138 @@ 1, + 'prosjekt' => 2, + 'aktiviteter' => 4, + ]; - public $usergroups = [ - 'admin' => 1, - 'prosjekt' => 2, - 'aktiviteter' => 4 - ]; + public function __construct($pdo) { + $this->pdo = $pdo; + } - public function __construct($pdo){ - $this->pdo = $pdo; - } + public function setupUser($uname, $groups = 0): void { + $query = 'INSERT INTO users (uname, groups) VALUES (:uname, :groups)'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':uname', $uname, \PDO::PARAM_STR); + $statement->bindParam(':groups', $groups, \PDO::PARAM_INT); + $statement->execute(); + } - public function setupUser($uname, $groups=0){ - $query = 'INSERT INTO users (uname, groups) VALUES (:uname, :groups)'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':uname', $uname, PDO::PARAM_STR); - $statement->bindParam(':groups', $groups, PDO::PARAM_INT); - $statement->execute(); - } + public function updateFlags($uname, $flags): void { + $query = 'UPDATE users set groups=:groups WHERE uname=:uname'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':groups', $flags, \PDO::PARAM_INT); + $statement->bindParam(':uname', $uname, \PDO::PARAM_STR); + } - public function updateFlags($uname, $flags){ - $query = 'UPDATE users set groups=:groups WHERE uname=:uname'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':groups', $flags, PDO::PARAM_INT); - $statement->bindParam(':uname', $uname, PDO::PARAM_STR); - } + public function addGroup($uname, $group): void { + $userFlags = $this->getUsergroups($uname); - public function addGroup($uname, $group){ - $userFlags = $this->getUsergroups($uname); + if ($userFlags) { + $newFlags = ($group | $userFlags); + $this->updateFlags($uname, $newFlags); + } + } - if($userFlags){ - $newFlags = ($group | $userFlags); - $this->updateFlags($uname, $newFlags); - } - } + public function removeGroup($uname, $group): void { + $userFlags = $this->getUsergroups($uname); - public function removeGroup($uname, $group){ - $userFlags = $this->getUsergroups($uname); + if ($userFlags) { + $newFlags = ($userFlags & (~ $group)); + $this->updateFlags($uname, $newFlags); + } + } - if($userFlags){ - $newFlags = ($userFlags & (~ $group)); - $this->updateFlags($uname, $newFlags); - } - } + public function setGroups($uname, $groups): void { + $query = 'SELECT * FROM users WHERE uname=:uname LIMIT 1'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':uname', $uname, \PDO::PARAM_STR); + $statement->execute(); + $row = $statement->fetch(); - public function setGroups($uname, $groups){ - $query = 'SELECT * FROM users WHERE uname=:uname LIMIT 1'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':uname', $uname, PDO::PARAM_STR); - $statement->execute(); - $row = $statement->fetch(); + if ($row) { + $query = 'UPDATE users set groups=:groups WHERE uname=:uname'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':groups', $groups, \PDO::PARAM_INT); + $statement->bindParam(':uname', $uname, \PDO::PARAM_STR); + $statement->execute(); + } else { + $this->setupUser($uname, $groups); + } + } - if($row){ - $query = 'UPDATE users set groups=:groups WHERE uname=:uname'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':groups', $groups, PDO::PARAM_INT); - $statement->bindParam(':uname', $uname, PDO::PARAM_STR); - $statement->execute(); - }else{ - $this->setupUser($uname, $groups); - } - } + public function hasGroup($uname, $groupName) { + $userFlags = $this->getUsergroups($uname); - public function hasGroup($uname, $groupName){ - $userFlags = $this->getUsergroups($uname); + return $userFlags & $this->usergroups[$groupName]; + } - return ($userFlags & $this->usergroups[$groupName]); - } + // for convenience + public function isAdmin($uname) { + return $this->hasGroup($uname, 'admin'); + } - // for convenience - public function isAdmin($uname){ - return $this->hasGroup($uname, 'admin'); - } + public function getFlagfromNames($names) { + $resultFlag = 0; - public function getFlagfromNames($names){ - $resultFlag = 0; + foreach ($this->usergroups as $name => $flag) { + if (\in_array($name, $names, true)) { + $resultFlag = ($resultFlag | $flag); + } + } - foreach($this->usergroups as $name => $flag){ - if(in_array($name, $names)){ - $resultFlag = ($resultFlag | $flag); - } - } + return $resultFlag; + } - return $resultFlag; - } + public function getUsergroups($uname) { + $query = 'SELECT groups FROM users WHERE uname=:uname LIMIT 1'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':uname', $uname, \PDO::PARAM_STR); + $statement->execute(); - public function getUsergroups($uname){ - $query = 'SELECT groups FROM users WHERE uname=:uname LIMIT 1'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':uname', $uname, PDO::PARAM_STR); - $statement->execute(); + $row = $statement->fetch(); + if ($row == false) { + return 0; + } - $row = $statement->fetch(); - if ($row == false) return 0; - return $row[0]; - } + return $row[0]; + } - public function getUsergroupNames($uname){ - $usersGroups = []; + public function getUsergroupNames($uname) { + $usersGroups = []; - $userFlags = $this->getUsergroups($uname); + $userFlags = $this->getUsergroups($uname); - foreach($this->usergroups as $name => $flag){ - if($userFlags & $flag){ - $usersGroups[] = $name; - } - } + foreach ($this->usergroups as $name => $flag) { + if ($userFlags & $flag) { + $usersGroups[] = $name; + } + } - return $usersGroups; - } + return $usersGroups; + } - public function getAllUserData(){ - $query = 'SELECT uname FROM users ORDER BY uname ASC'; - $statement = $this->pdo->prepare($query); - $statement->execute(); + public function getAllUserData() { + $query = 'SELECT uname FROM users ORDER BY uname ASC'; + $statement = $this->pdo->prepare($query); + $statement->execute(); - $users = []; - foreach($statement->fetchAll() as $userData){ - $uname = $userData['uname']; - $users[] = [ - 'name' => $uname, - 'groups' => $this->getUsergroupNames($uname) - ]; - } + $users = []; + foreach ($statement->fetchAll() as $userData) { + $uname = $userData['uname']; + $users[] = [ + 'name' => $uname, + 'groups' => $this->getUsergroupNames($uname), + ]; + } - return $users; - } + return $users; + } } diff --git a/src/pvv/side/activity.php b/src/pvv/side/activity.php index 9fd6a46..4a1319a 100644 --- a/src/pvv/side/activity.php +++ b/src/pvv/side/activity.php @@ -1,12 +1,11 @@ -activities = $activities; - } + public function __construct($activities) { + $this->activities = $activities; + } - public static function getFormattedDate($date) { - return $date->format("l j. M H.i"); + public static function getFormattedDate($date) { + return $date->format('l j. M H.i'); + } + + public function getEventsBetween(\DateTimeImmutable $from, \DateTimeImmutable $to) { + $results = []; + for ($i = 0; $i < \count($this->activities); ++$i) { + $result = []; + do { + $run = false; + if (\count($result)) { + $date = end($result)->getStop(); + } else { + $date = $from; + } + $next = $this->activities[$i]->getNextEventFrom($date); + if (isset($next) && $next->getStart() < $to) { + $result[] = $this->activities[$i]->getNextEventFrom($date); + $run = true; + } + } while ($run); + $results[] = $result; + } + $result = []; + foreach ($results as $a) { + foreach ($a as $b) { + $result[] = $b; + } + } + usort($result, static fn($a, $b) => ($a->getStart() < $b->getStart()) ? -1 : 1); + + return $result; + } + + public function getNextDays() { + $result = [[], [], [], [], [], []]; + $events = $this->getEventsBetween( + (new \DateTimeImmutable())->setTime(0, 0), + (new \DateTimeImmutable())->setTime(23, 59)->add(new \DateInterval('P1M')) + ); + foreach ($events as $event) { + $index = self::NEXT_MONTH; + if (self::isToday($event->getStart())) { + $index = self::TODAY; + } elseif (self::isTomorrow($event->getStart())) { + $index = self::TOMORROW; + } elseif (self::isThisWeek($event->getStart())) { + $index = self::THIS_WEEK; + } elseif (self::isNextWeek($event->getStart())) { + $index = self::NEXT_WEEK; + } elseif (self::isThisMonth($event->getStart())) { + $index = self::THIS_MONTH; + } + $result[$index][] = $event; } - public function getEventsBetween(DateTimeImmutable $from, DateTimeImmutable $to) { - $results = []; - for($i = 0; $i < sizeof($this->activities); $i++) { - $result = []; - do { - $run = false; - if (sizeof($result)) { - $date = end($result)->getStop(); - } else { - $date = $from; - } - $next = $this->activities[$i]->getNextEventFrom($date); - if (isset($next) && $next->getStart() < $to) { - $result[] = $this->activities[$i]->getNextEventFrom($date); - $run = true; - } - } while ($run); - $results[] = $result; - } - $result = []; - foreach($results as $a) foreach($a as $b) $result[] = $b; - usort($result, function($a, $b) { - return ($a->getStart() < $b->getStart()) ? -1 : 1; - }); - return $result; - } + return $result; + } - public function getNextDays() { - $result = [[], [], [], [], [], []]; - $events = $this->getEventsBetween( - (new DateTimeImmutable)->setTime(0, 0), - (new DateTimeImmutable)->setTime(23, 59)->add(new DateInterval('P1M')) - ); - foreach ($events as $event) { - $index = self::NEXT_MONTH; - if (self::isToday($event->getStart())) $index = self::TODAY; - elseif (self::isTomorrow($event->getStart())) $index = self::TOMORROW; - elseif (self::isThisWeek($event->getStart())) $index = self::THIS_WEEK; - elseif (self::isNextWeek($event->getStart())) $index = self::NEXT_WEEK; - elseif (self::isThisMonth($event->getStart())) $index = self::THIS_MONTH; - $result[$index][] = $event; - } - return $result; - } + public function getNextOfEach(\DateTimeImmutable $startDate) { + $result = array_filter(array_map( + static fn($a) => $a->getNextEventFrom($startDate), + $this->activities + ), static fn($a) => isset($a)); + usort( + $result, + static fn($a, $b) => ($a->getStart()->getTimeStamp() < $b->getStart()->getTimeStamp()) + ? -1 + : 1 + ); - public function getNextOfEach(DateTimeImmutable $startDate) { - $result = array_filter(array_map( - function($a) use ($startDate){ - return $a->getNextEventFrom($startDate); - }, $this->activities - ), function($a){ - return isset($a); - }); - usort($result, function($a, $b) { - return ($a->getStart()->getTimeStamp() < $b->getStart()->getTimeStamp()) - ? -1 - : 1 - ; - }); - return $result; - } + return $result; + } - public static function isToday(DateTimeImmutable $date) { - return $date->format('dmY') == date('dmY'); - } + public static function isToday(\DateTimeImmutable $date) { + return $date->format('dmY') == date('dmY'); + } - public static function isTomorrow(DateTimeImmutable $date) { - return $date->sub(new DateInterval('P1D'))->format('dmY') == date('dmY'); - } + public static function isTomorrow(\DateTimeImmutable $date) { + return $date->sub(new \DateInterval('P1D'))->format('dmY') == date('dmY'); + } - public static function isThisWeek(DateTimeImmutable $date) { - return $date->format('WY') == date('WY'); - } + public static function isThisWeek(\DateTimeImmutable $date) { + return $date->format('WY') == date('WY'); + } - public static function isNextWeek(DateTimeImmutable $date) { - return $date->sub(new DateInterval('P7D'))->format('WY') == date('WY'); - } - - public static function isThisMonth(DateTimeImmutable $date) { - return $date->format('mY') == date('mY'); - } + public static function isNextWeek(\DateTimeImmutable $date) { + return $date->sub(new \DateInterval('P7D'))->format('WY') == date('WY'); + } + public static function isThisMonth(\DateTimeImmutable $date) { + return $date->format('mY') == date('mY'); + } } diff --git a/src/pvv/side/dbactivity.php b/src/pvv/side/dbactivity.php index 142cff6..43aa088 100644 --- a/src/pvv/side/dbactivity.php +++ b/src/pvv/side/dbactivity.php @@ -1,85 +1,83 @@ pdo = $pdo; - } + public function __construct(\PDO $pdo) { + $this->pdo = $pdo; + } - public function getAllEvents() { - $query = 'SELECT * FROM events ORDER BY id DESC'; - $statement = $this->pdo->prepare($query); - $statement->execute(); + public function getAllEvents() { + $query = 'SELECT * FROM events ORDER BY id DESC'; + $statement = $this->pdo->prepare($query); + $statement->execute(); - $events = []; - foreach($statement->fetchAll() as $dbEvent){ - $event = new SimpleEvent( - $dbEvent['id'], - $dbEvent['name'], - DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['start']), - DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['stop']), - $dbEvent['organiser'], - $dbEvent['location'], - $dbEvent['description'] - ); - $events[] = $event; - } + $events = []; + foreach ($statement->fetchAll() as $dbEvent) { + $event = new SimpleEvent( + $dbEvent['id'], + $dbEvent['name'], + \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['start']), + \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['stop']), + $dbEvent['organiser'], + $dbEvent['location'], + $dbEvent['description'] + ); + $events[] = $event; + } - return $events; - } + return $events; + } - public function getEventByID($id) { - $query = 'SELECT * FROM events WHERE id=:id LIMIT 1'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':id', $id, PDO::PARAM_INT); - $statement->execute(); + public function getEventByID($id) { + $query = 'SELECT * FROM events WHERE id=:id LIMIT 1'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':id', $id, \PDO::PARAM_INT); + $statement->execute(); - $dbEvent = $statement->fetch(); - $event = new SimpleEvent( - $dbEvent['id'], - $dbEvent['name'], - DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['start']), - DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['stop']), - $dbEvent['organiser'], - $dbEvent['location'], - $dbEvent['description'] - ); + $dbEvent = $statement->fetch(); - return $event; - } + return new SimpleEvent( + $dbEvent['id'], + $dbEvent['name'], + \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['start']), + \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['stop']), + $dbEvent['organiser'], + $dbEvent['location'], + $dbEvent['description'] + ); + } + public function getNextEventFrom(\DateTimeImmutable $date) { + $query = 'SELECT id,name,start,stop,organiser,location,description FROM events WHERE start > :date ORDER BY start ASC LIMIT 1'; - public function getNextEventFrom(DateTimeImmutable $date) { - $query = 'SELECT id,name,start,stop,organiser,location,description FROM events WHERE start > :date ORDER BY start ASC LIMIT 1'; - return $this->retrieve($date, $query); - } + return $this->retrieve($date, $query); + } - public function getPreviousEventFrom(DateTimeImmutable $date) { - $query = 'SELECT id,name,start,stop,organiser,location,description FROM events WHERE start < :date ORDER BY start DESC LIMIT 1'; - return $this->retrieve($date, $query); - } + public function getPreviousEventFrom(\DateTimeImmutable $date) { + $query = 'SELECT id,name,start,stop,organiser,location,description FROM events WHERE start < :date ORDER BY start DESC LIMIT 1'; - private function retrieve($date, $query) { - $stmt = $this->pdo->prepare($query); - $stmt->execute(['date' => $date->format('Y-m-d H:i:s')]); - if ($result = $stmt->fetch(PDO::FETCH_ASSOC)){ - $ev = new SimpleEvent( - $result['id'], - $result['name'], - DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $result['start']), - DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $result['stop']), - $result['organiser'], - $result['location'], - $result['description'] - ); - return $ev; - } - return null; - } + return $this->retrieve($date, $query); + } + private function retrieve($date, $query) { + $stmt = $this->pdo->prepare($query); + $stmt->execute(['date' => $date->format('Y-m-d H:i:s')]); + if ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new SimpleEvent( + $result['id'], + $result['name'], + \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $result['start']), + \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $result['stop']), + $result['organiser'], + $result['location'], + $result['description'] + ); + } + + } } diff --git a/src/pvv/side/door.php b/src/pvv/side/door.php index 2a868ee..c07d70f 100644 --- a/src/pvv/side/door.php +++ b/src/pvv/side/door.php @@ -1,74 +1,76 @@ pdo = $pdo; + } - public function __construct(PDO $pdo){ - $this->pdo = $pdo; - } + public function getAll() { + $query = 'SELECT time, open FROM door ORDER BY time DESC'; + $statement = $this->pdo->prepare($query); + $statement->execute(); - public function getAll() { - $query = 'SELECT time, open FROM door ORDER BY time DESC'; - $statement = $this->pdo->prepare($query); - $statement->execute(); + $doorEvents = []; + foreach ($statement->fetchAll() as $row) { + $doorEvents[] = [ + 'time' => (int) $row['time'], + 'open' => (bool) $row['open'], + ]; + } - $doorEvents = []; - foreach($statement->fetchAll() as $row){ - $doorEvents[] = [ - 'time' => (int)$row['time'], - 'open' => (bool)$row['open'] - ]; - } + return $doorEvents; + } - return $doorEvents; - } + public function getEntriesAfter($startTime) { + $query = 'SELECT time, open FROM door WHERE time > :startTime ORDER BY time DESC'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':startTime', $startTime, \PDO::PARAM_STR); + $statement->execute(); - public function getEntriesAfter($startTime) { - $query = 'SELECT time, open FROM door WHERE time > :startTime ORDER BY time DESC'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':startTime', $startTime, PDO::PARAM_STR); - $statement->execute(); + $doorEvents = []; + foreach ($statement->fetchAll() as $row) { + $doorEvents[] = [ + 'time' => (int) $row['time'], + 'open' => (bool) $row['open'], + ]; + } - $doorEvents = []; - foreach($statement->fetchAll() as $row){ - $doorEvents[] = [ - 'time' => (int)$row['time'], - 'open' => (bool)$row['open'] - ]; - } + return $doorEvents; + } - return $doorEvents; - } + public function getCurrent() { + $query = 'SELECT time, open FROM door ORDER BY time DESC LIMIT 1'; + $statement = $this->pdo->prepare($query); + $statement->execute(); + $row = $statement->fetch(); - public function getCurrent() { - $query = 'SELECT time, open FROM door ORDER BY time DESC LIMIT 1'; - $statement = $this->pdo->prepare($query); - $statement->execute(); - $row = $statement->fetch(); - return [ - 'time' => (int)$row['time'], - 'open' => (bool)$row['open'] - ]; - } + return [ + 'time' => (int) $row['time'], + 'open' => (bool) $row['open'], + ]; + } - private function removeOld() { - $firstValidTime = time() - 60*60*24*7; //One week before now - $query = 'DELETE FROM door WHERE time < :firstValid'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':firstValid', $firstValidTime, PDO::PARAM_STR); - $statement->execute(); - } + private function removeOld(): void { + $firstValidTime = time() - 60 * 60 * 24 * 7; // One week before now + $query = 'DELETE FROM door WHERE time < :firstValid'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':firstValid', $firstValidTime, \PDO::PARAM_STR); + $statement->execute(); + } - public function createEvent($time, $open) { - $query = 'INSERT INTO door(time, open) VALUES (:time, :open)'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':time', $time, PDO::PARAM_STR); - $statement->bindParam(':open', $open, PDO::PARAM_STR); - $statement->execute(); + public function createEvent($time, $open): void { + $query = 'INSERT INTO door(time, open) VALUES (:time, :open)'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':time', $time, \PDO::PARAM_STR); + $statement->bindParam(':open', $open, \PDO::PARAM_STR); + $statement->execute(); - $this->removeOld(); - } + $this->removeOld(); + } } diff --git a/src/pvv/side/event.php b/src/pvv/side/event.php index fbf9b37..f563fda 100644 --- a/src/pvv/side/event.php +++ b/src/pvv/side/event.php @@ -1,53 +1,55 @@ -start = $start; + } - public function __construct(DateTimeImmutable $start) { - $this->start = $start; - } + public function getStart() { + return $this->start; + } - public function getStart() { - return $this->start; - } + public function getRelativeDate() { + if (Agenda::isToday($this->getStart())) { + return 'i dag'; + } + if (Agenda::isTomorrow($this->getStart())) { + return 'i morgen'; + } + if (Agenda::isThisWeek($this->getStart()) || $this->getStart()->sub(new \DateInterval('P4D'))->getTimestamp() < time()) { + return $this->getStart()->format('l'); + } + if (Agenda::isNextWeek($this->getStart())) { + return 'neste uke'; + } + if (Agenda::isThisMonth($this->getStart())) { + return 'denne måneden'; + } - public function getRelativeDate() { - if (Agenda::isToday($this->getStart())) { - return 'i dag'; - } - if (Agenda::isTomorrow($this->getStart())) { - return 'i morgen'; - } - if (Agenda::isThisWeek($this->getStart()) || $this->getStart()->sub(new DateInterval('P4D'))->getTimestamp() < time()) { - return $this->getStart()->format("l"); - } - if (Agenda::isNextWeek($this->getStart())) { - return 'neste uke'; - } - if (Agenda::isThisMonth($this->getStart())) { - return 'denne måneden'; - } - return $this->getStart()->format("j. F"); - } + return $this->getStart()->format('j. F'); + } - public abstract function getStop(); /* : DateTimeImmutable */ + abstract public function getStop(); /* : DateTimeImmutable */ - public abstract function getName(); + abstract public function getName(); - public abstract function getLocation(); + abstract public function getLocation(); - public abstract function getOrganiser(); + abstract public function getOrganiser(); - public abstract function getURL(); /* : string */ + abstract public function getURL(); /* : string */ - public abstract function getImageURL(); /* : string */ + abstract public function getImageURL(); /* : string */ - public abstract function getDescription(); /* : string */ + abstract public function getDescription(); /* : string */ - public abstract function getColor(); /* : string */ + abstract public function getColor(); /* : string */ } diff --git a/src/pvv/side/motd.php b/src/pvv/side/motd.php index 4a71a6c..db18aa6 100644 --- a/src/pvv/side/motd.php +++ b/src/pvv/side/motd.php @@ -1,49 +1,47 @@ pdo = $pdo; + } - public function __construct($pdo){ - $this->pdo = $pdo; - } + public function setMOTD($title, $content): void { + if (\is_array($content)) { + $content = implode('_', $content); + } + $query = 'INSERT INTO motd(title, content) VALUES (:title, :content);'; + $statement = $this->pdo->prepare($query); - public function setMOTD($title, $content) { - if (is_array($content)) { - $content = implode("_", $content); - } - $query = 'INSERT INTO motd(title, content) VALUES (:title, :content);'; - $statement = $this->pdo->prepare($query); + $statement->bindParam(':title', $title, \PDO::PARAM_STR); + $statement->bindParam(':content', $content, \PDO::PARAM_STR); - $statement->bindParam(':title', $title, PDO::PARAM_STR); - $statement->bindParam(':content', $content, PDO::PARAM_STR); + $statement->execute(); + } - $statement->execute(); - } - - public function getMOTD() { - $query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1'; - $statement = $this->pdo->prepare($query); - $statement->execute(); + public function getMOTD() { + $query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1'; + $statement = $this->pdo->prepare($query); + $statement->execute(); - $data = $statement->fetch(); - $motd = array("title" => $data[0], "content" => explode("\n", $data[1])); + $data = $statement->fetch(); - return $motd; - } - - public function getMOTD_history($limit = 5) { - $query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':limit', $limit, PDO::PARAM_STR); - $statement->execute(); + return ['title' => $data[0], 'content' => explode("\n", $data[1])]; + } - $data = $statement->fetch(); - $motd = array("title" => $data[0], "content" => explode("\n", $data[1])); + public function getMOTD_history($limit = 5) { + $query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':limit', $limit, \PDO::PARAM_STR); + $statement->execute(); - return $motd; - } - + $data = $statement->fetch(); + + return ['title' => $data[0], 'content' => explode("\n", $data[1])]; + } } diff --git a/src/pvv/side/project.php b/src/pvv/side/project.php index 5985c1c..8f94375 100644 --- a/src/pvv/side/project.php +++ b/src/pvv/side/project.php @@ -1,29 +1,35 @@ id = $id; - $this->name = $name; - $this->descr = explode("\n", $descr); - $this->active = $active; - } + public function __construct($id, $name, $descr, $active) { + $this->id = $id; + $this->name = $name; + $this->descr = explode("\n", $descr); + $this->active = $active; + } - public function getID(){ - return $this->id; - } + public function getID() { + return $this->id; + } - public function getName(){ - return $this->name; - } + public function getName() { + return $this->name; + } - public function getDescription(){ - return $this->descr; - } + public function getDescription() { + return $this->descr; + } - public function getActive(){ - return $this->active; - } -} \ No newline at end of file + public function getActive() { + return $this->active; + } +} diff --git a/src/pvv/side/projectmanager.php b/src/pvv/side/projectmanager.php index 87a75a6..c4ae7d6 100644 --- a/src/pvv/side/projectmanager.php +++ b/src/pvv/side/projectmanager.php @@ -1,121 +1,120 @@ pdo = $pdo; + } - public function __construct(PDO $pdo){ - $this->pdo = $pdo; - } + public function getAll() { + $query = 'SELECT * FROM projects ORDER BY id ASC'; + $statement = $this->pdo->prepare($query); + $statement->execute(); - public function getAll() { - $query = 'SELECT * FROM projects ORDER BY id ASC'; - $statement = $this->pdo->prepare($query); - $statement->execute(); + $projects = []; + foreach ($statement->fetchAll() as $dbProj) { + $project = new Project( + $dbProj['id'], + $dbProj['name'], + $dbProj['description'], + $dbProj['active'] + ); + $projects[] = $project; + } - $projects = []; - foreach($statement->fetchAll() as $dbProj){ - $project = new Project( - $dbProj['id'], - $dbProj['name'], - $dbProj['description'], - $dbProj['active'] - ); - $projects[] = $project; - } + return $projects; + } - return $projects; - } + public function getByID($id) { + $query = 'SELECT * FROM projects WHERE id=:id LIMIT 1'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':id', $id, \PDO::PARAM_INT); + $statement->execute(); - public function getByID($id){ - $query = 'SELECT * FROM projects WHERE id=:id LIMIT 1'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':id', $id, PDO::PARAM_INT); - $statement->execute(); + $dbProj = $statement->fetch(); + if (!$dbProj) { + return false; + } - $dbProj = $statement->fetch(); - if (!$dbProj) { - return false; - } - $project = new Project( - $dbProj['id'], - $dbProj['name'], - $dbProj['description'], - $dbProj['active'] - ); + return new Project( + $dbProj['id'], + $dbProj['name'], + $dbProj['description'], + $dbProj['active'] + ); + } - return $project; - } + public function getByOwner($uname) { + $query = 'SELECT projectid FROM projectmembers WHERE uname=:uname'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':uname', $uname, \PDO::PARAM_STR); + $statement->execute(); - public function getByOwner($uname){ - $query = 'SELECT projectid FROM projectmembers WHERE uname=:uname'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':uname', $uname, PDO::PARAM_STR); - $statement->execute(); + $projectIDs = $statement->fetchAll(); + $projects = []; + foreach ($projectIDs as $id) { + $id = $id['projectid']; - $projectIDs = $statement->fetchAll(); - $projects = []; - foreach($projectIDs as $id){ - $id = $id['projectid']; - - $query = 'SELECT * FROM projects WHERE id=:id'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':id', $id, PDO::PARAM_INT); - $statement->execute(); - - foreach($statement->fetchAll() as $dbProj){ - $project = new Project( - $dbProj['id'], - $dbProj['name'], - $dbProj['description'], - $dbProj['active'] - ); - $projects[] = $project; - } - } + $query = 'SELECT * FROM projects WHERE id=:id'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':id', $id, \PDO::PARAM_INT); + $statement->execute(); - return $projects; - } + foreach ($statement->fetchAll() as $dbProj) { + $project = new Project( + $dbProj['id'], + $dbProj['name'], + $dbProj['description'], + $dbProj['active'] + ); + $projects[] = $project; + } + } - public function getProjectMembers($id){ - $query = 'SELECT * FROM projectmembers WHERE projectid=:id'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':id', $id, PDO::PARAM_STR); - $statement->execute(); + return $projects; + } - $members = []; - foreach($statement->fetchAll() as $dbUsr){ - $members[] = [ - 'name' => $dbUsr['name'], - 'uname' => $dbUsr['uname'], - 'mail' => $dbUsr['mail'], - 'role' => $dbUsr['role'], - 'lead' => $dbUsr['lead'], - 'owner' => $dbUsr['owner'] - ]; - } + public function getProjectMembers($id) { + $query = 'SELECT * FROM projectmembers WHERE projectid=:id'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':id', $id, \PDO::PARAM_STR); + $statement->execute(); - return $members; - } + $members = []; + foreach ($statement->fetchAll() as $dbUsr) { + $members[] = [ + 'name' => $dbUsr['name'], + 'uname' => $dbUsr['uname'], + 'mail' => $dbUsr['mail'], + 'role' => $dbUsr['role'], + 'lead' => $dbUsr['lead'], + 'owner' => $dbUsr['owner'], + ]; + } - public function getProjectOwner($id){ - $query = 'SELECT * FROM projectmembers WHERE (projectid=:id AND owner=1)'; - $statement = $this->pdo->prepare($query); - $statement->bindParam(':id', $id, PDO::PARAM_STR); - $statement->execute(); + return $members; + } - $dbOwner = $statement->fetch(); - $owner = [ - 'name' => $dbOwner['name'], - 'uname' => $dbOwner['uname'], - 'mail' => $dbOwner['mail'], - 'role' => $dbOwner['role'], - 'lead' => $dbOwner['lead'], - 'owner' => $dbOwner['owner'] - ]; + public function getProjectOwner($id) { + $query = 'SELECT * FROM projectmembers WHERE (projectid=:id AND owner=1)'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':id', $id, \PDO::PARAM_STR); + $statement->execute(); - return $owner; - } + $dbOwner = $statement->fetch(); + + return [ + 'name' => $dbOwner['name'], + 'uname' => $dbOwner['uname'], + 'mail' => $dbOwner['mail'], + 'role' => $dbOwner['role'], + 'lead' => $dbOwner['lead'], + 'owner' => $dbOwner['owner'], + ]; + } } diff --git a/src/pvv/side/simpleevent.php b/src/pvv/side/simpleevent.php index ff0641f..1d10bc9 100644 --- a/src/pvv/side/simpleevent.php +++ b/src/pvv/side/simpleevent.php @@ -1,58 +1,63 @@ id = $id; + $this->name = $name; + $this->start = $start; + $this->end = $end; + $this->org = $org; + $this->loc = $loc; + $this->descr = explode("\n", $descr); + } - public function __construct($id, $name,\DateTimeImmutable $start,\DateTimeImmutable $end,$org, $loc, $descr, $_isDBEvent = false){ - $this->id = $id; - $this->name = $name; - $this->start = $start; - $this->end = $end; - $this->org = $org; - $this->loc = $loc; - $this->descr = explode("\n", $descr); - } + public function getID() { + return $this->id; + } - public function getID(){ - return $this->id; - } + public function getStart() { + return $this->start; + } - public function getStart(){ - return $this->start; - } + public function getStop() { + return $this->end; + } - public function getStop(){ - return $this->end; - } + public function getOrganiser() { + return $this->org; + } - public function getOrganiser(){ - return $this->org; - } + public function getLocation() { + return $this->loc; + } - public function getLocation(){ - return $this->loc; - } + public function getName() { + return $this->name; + } - public function getName(){ - return $this->name; - } + public function getURL() { + return '/hendelser/info.php?id=' . $this->id; + } - public function getURL() { - return ('/hendelser/info.php?id=' . $this->id); - } + public function getImageURL(): void {} - public function getImageURL() { - return null; - } - - public function getDescription() { - return $this->descr; - } - - public function getColor() { - return "#3b7"; - } + public function getDescription() { + return $this->descr; + } + public function getColor() { + return '#3b7'; + } } diff --git a/src/pvv/side/social/animekveldactivity.php b/src/pvv/side/social/animekveldactivity.php index 11a0e37..0714ba1 100644 --- a/src/pvv/side/social/animekveldactivity.php +++ b/src/pvv/side/social/animekveldactivity.php @@ -1,36 +1,41 @@ -format('H') > 20 || $date->format('H') == 19 && $date->format('i') > 30) { + return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(19, 30, 0)); + } + $date = $date->setTime(19, 30, 0); + if ($date->format('N') != 5) { + return $this->nextDate($date->add(new \DateInterval('P1D'))); + } - public function nextDate(DateTimeImmutable $date) { - if ($date->format('H') > 20 || $date->format('H') == 19 && $date->format('i') > 30) - return $this->nextDate($date->add(new DateInterval('P1D'))->setTime(19, 30, 0)); - $date = $date->setTime(19, 30, 0); - if ($date->format('N') != 5) - return $this->nextDate($date->add(new DateInterval('P1D'))); - return $date; - } + return $date; + } - public function prevDate(DateTimeImmutable $date) { - if ($date->format('H') < 19 || $date->format('H') == 20 && $date->format('i') < 30) - return $this->prevDate($date->sub(new DateInterval('P1D'))->setTime(19, 30, 0)); - $date = $date->setTime(19, 30, 0); - if ($date->format('N') != 5) - return $this->prevDate($date->sub(new DateInterval('P1D'))); - return $date; - } + public function prevDate(\DateTimeImmutable $date) { + if ($date->format('H') < 19 || $date->format('H') == 20 && $date->format('i') < 30) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(19, 30, 0)); + } + $date = $date->setTime(19, 30, 0); + if ($date->format('N') != 5) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))); + } - public function getNextEventFrom(DateTimeImmutable $date) /* : Event */ { - return new AnimekveldEvent($this->nextDate($date)); - } + return $date; + } - public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */ { - return new AnimekveldEvent($this->prevDate($date)); - } + public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new AnimekveldEvent($this->nextDate($date)); + } + public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new AnimekveldEvent($this->prevDate($date)); + } } diff --git a/src/pvv/side/social/animekveldevent.php b/src/pvv/side/social/animekveldevent.php index d62a0eb..0fad249 100644 --- a/src/pvv/side/social/animekveldevent.php +++ b/src/pvv/side/social/animekveldevent.php @@ -1,48 +1,47 @@ -getStart()->add(new \DateInterval('PT4H1800S')); + } - public function getStop() { - return $this->getStart()->add(new DateInterval('PT4H1800S')); - } + public function getName() { /* : string */ + return 'Animekveld'; + } - public function getName() /* : string */ { - return "Animekveld"; - } + public function getLocation() { /* : Location */ + return 'Koserommet'; + } - public function getLocation() /* : Location */ { - return "Koserommet"; - } + public function getOrganiser() { /* : User */ + return 'Christoffer Viken'; + } - public function getOrganiser() /* : User */ { - return "Christoffer Viken"; - } + public function getURL() { /* : string */ + return '/anime/'; + } - public function getURL() /* : string */ { - return '/anime/'; - } + public function getImageURL() { + return '/sosiale/animekveld.jpg'; + } - public function getImageURL() { - return '/sosiale/animekveld.jpg'; - } - - public function getDescription() { - return [ - 'Er du glad i japanske tegneserier eller bare nysgjerrig på hva anime er?', - 'Bli med oss hver fredag, der vi finner frem de nyeste episodene for sesongen!', - '', - 'Alle kan være med på å anbefale eller veto serier.', - '', - ]; - } - - public function getColor() { - return "#35a"; - } + public function getDescription() { + return [ + 'Er du glad i japanske tegneserier eller bare nysgjerrig på hva anime er?', + 'Bli med oss hver fredag, der vi finner frem de nyeste episodene for sesongen!', + '', + 'Alle kan være med på å anbefale eller veto serier.', + '', + ]; + } + public function getColor() { + return '#35a'; + } } diff --git a/src/pvv/side/social/brettspillactivity.php b/src/pvv/side/social/brettspillactivity.php index 7dd2c1b..2d8a982 100644 --- a/src/pvv/side/social/brettspillactivity.php +++ b/src/pvv/side/social/brettspillactivity.php @@ -1,41 +1,47 @@ -format('H') > 17 || $date->format('H') == 16 && $date->format('i') > 15) { + return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(16, 15, 0)); + } + $date = $date->setTime(16, 15, 0); + if ($date->format('N') != 7) { + return $this->nextDate($date->add(new \DateInterval('P1D'))); + } + if ($date->format('W') % 2 - 1) { + return $this->nextDate($date->add(new \DateInterval('P7D'))); + } - public function nextDate(DateTimeImmutable $date) { - if ($date->format('H') > 17 || $date->format('H') == 16 && $date->format('i') > 15) - return $this->nextDate($date->add(new DateInterval('P1D'))->setTime(16, 15, 0)); - $date = $date->setTime(16, 15, 0); - if ($date->format('N') != 7) - return $this->nextDate($date->add(new DateInterval('P1D'))); - if ($date->format('W') % 2 - 1) - return $this->nextDate($date->add(new DateInterval('P7D'))); - return $date; - } + return $date; + } - public function prevDate(DateTimeImmutable $date) { - if ($date->format('H') < 16 || $date->format('H') == 17 && $date->format('i') < 15) - return $this->prevDate($date->sub(new DateInterval('P1D'))->setTime(16, 15, 0)); - $date = $date->setTime(16, 15, 0); - if ($date->format('N') != 7) - return $this->prevDate($date->sub(new DateInterval('P1D'))); - if ($date->format('W') % 2 - 1) - return $this->prevDate($date->sub(new DateInterval('P7D'))); + public function prevDate(\DateTimeImmutable $date) { + if ($date->format('H') < 16 || $date->format('H') == 17 && $date->format('i') < 15) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(16, 15, 0)); + } + $date = $date->setTime(16, 15, 0); + if ($date->format('N') != 7) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))); + } + if ($date->format('W') % 2 - 1) { + return $this->prevDate($date->sub(new \DateInterval('P7D'))); + } - return $date; - } + return $date; + } - public function getNextEventFrom(DateTimeImmutable $date) /* : Event */ { - return new BrettspillEvent($this->nextDate($date)); - } - - public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */ { - return new BrettspillEvent($this->prevDate($date)); - } + public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new BrettspillEvent($this->nextDate($date)); + } + public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new BrettspillEvent($this->prevDate($date)); + } } diff --git a/src/pvv/side/social/brettspillevent.php b/src/pvv/side/social/brettspillevent.php index 79d6b1c..2c8daff 100644 --- a/src/pvv/side/social/brettspillevent.php +++ b/src/pvv/side/social/brettspillevent.php @@ -1,65 +1,64 @@ -getStart()->add(new \DateInterval('PT4H1800S')); + } - public function getStop() { - return $this->getStart()->add(new DateInterval('PT4H1800S')); - } + public function getName() { /* : string */ + return 'Brettspillkveld'; + } - public function getName() /* : string */ { - return "Brettspillkveld"; - } + public function getLocation() { /* : Location */ + return 'Programvareverkstedet'; + } - public function getLocation() /* : Location */ { - return "Programvareverkstedet"; - } + public function getOrganiser() { /* : User */ + return 'Programvareverkstedet'; + } - public function getOrganiser() /* : User */ { - return "Programvareverkstedet"; - } + public function getURL() { /* : string */ + return '/brettspill/'; + } - public function getURL() /* : string */ { - return '/brettspill/'; - } + public function getImageURL() { + return '/sosiale/brettspill.jpg'; + } - public function getImageURL() { - return '/sosiale/brettspill.jpg'; - } - - public function getDescription() { - return [ - 'Er du en hardcore brettspillentusiast eller en nybegynner som har så vidt spilt ludo? '. - 'Da er vår brettspillkveld noe for deg! ' . - 'Vi tar ut et par spill fra vårt samling of spiller så mye vi orker. Kom innom!', - '', - '## Vår samling', - '', - '* Dominion\*', - '* Three cheers for master', - '* Avalon', - '* Hanabi', - '* Cards aginst humanity\*', - '* Citadels', - '* Munchkin\*\*', - '* Exploding kittens\*\*', - '* Aye dark overlord', - '* Settlers of catan\*', - '* Risk\*\*', - '* og mange flere...', - '', - '\* Vi har flere ekspansjoner til spillet', - '', - '\*\* Vi har flere varianter av spillet', - ]; - } - - public function getColor() { - return "#000"; - } + public function getDescription() { + return [ + 'Er du en hardcore brettspillentusiast eller en nybegynner som har så vidt spilt ludo? ' . + 'Da er vår brettspillkveld noe for deg! ' . + 'Vi tar ut et par spill fra vårt samling of spiller så mye vi orker. Kom innom!', + '', + '## Vår samling', + '', + '* Dominion\*', + '* Three cheers for master', + '* Avalon', + '* Hanabi', + '* Cards aginst humanity\*', + '* Citadels', + '* Munchkin\*\*', + '* Exploding kittens\*\*', + '* Aye dark overlord', + '* Settlers of catan\*', + '* Risk\*\*', + '* og mange flere...', + '', + '\* Vi har flere ekspansjoner til spillet', + '', + '\*\* Vi har flere varianter av spillet', + ]; + } + public function getColor() { + return '#000'; + } } diff --git a/src/pvv/side/social/driftkveldactivity.php b/src/pvv/side/social/driftkveldactivity.php index dd1a367..ec50c40 100644 --- a/src/pvv/side/social/driftkveldactivity.php +++ b/src/pvv/side/social/driftkveldactivity.php @@ -1,40 +1,47 @@ -format('H') > 18 || $date->format('H') == 17 && $date->format('i') > 30) { + return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(18, 15, 0)); + } + $date = $date->setTime(18, 15, 0); + if ($date->format('N') != 6) { + return $this->nextDate($date->add(new \DateInterval('P1D'))); + } + if ($date->format('W') % 2 - 1) { + return $this->nextDate($date->add(new \DateInterval('P7D'))); + } - public function nextDate(DateTimeImmutable $date) { - if ($date->format('H') > 18 || $date->format('H') == 17 && $date->format('i') > 30) - return $this->nextDate($date->add(new DateInterval('P1D'))->setTime(18, 15, 0)); - $date = $date->setTime(18, 15, 0); - if ($date->format('N') != 6) - return $this->nextDate($date->add(new DateInterval('P1D'))); - if ($date->format('W') % 2 - 1) - return $this->nextDate($date->add(new DateInterval('P7D'))); - return $date; - } + return $date; + } - public function prevDate(DateTimeImmutable $date) { - if ($date->format('H') < 17 || $date->format('H') == 18 && $date->format('i') < 30) - return $this->prevDate($date->sub(new DateInterval('P1D'))->setTime(18, 15, 0)); - $date = $date->setTime(18, 15, 0); - if ($date->format('N') != 6) - return $this->prevDate($date->sub(new DateInterval('P1D'))); - if ($date->format('W') % 2 - 1) - return $this->prevDate($date->sub(new DateInterval('P7D'))); - return $date; - } + public function prevDate(\DateTimeImmutable $date) { + if ($date->format('H') < 17 || $date->format('H') == 18 && $date->format('i') < 30) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(18, 15, 0)); + } + $date = $date->setTime(18, 15, 0); + if ($date->format('N') != 6) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))); + } + if ($date->format('W') % 2 - 1) { + return $this->prevDate($date->sub(new \DateInterval('P7D'))); + } - public function getNextEventFrom(DateTimeImmutable $date) /* : Event */ { - return new DriftkveldEvent($this->nextDate($date)); - } + return $date; + } - public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */ { - return new DriftkveldEvent($this->prevDate($date)); - } + public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new DriftkveldEvent($this->nextDate($date)); + } + public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new DriftkveldEvent($this->prevDate($date)); + } } diff --git a/src/pvv/side/social/driftkveldevent.php b/src/pvv/side/social/driftkveldevent.php index 56eb132..9ec402b 100644 --- a/src/pvv/side/social/driftkveldevent.php +++ b/src/pvv/side/social/driftkveldevent.php @@ -1,49 +1,48 @@ -getStart()->add(new \DateInterval('PT4H1800S')); + } - public function getStop() { - return $this->getStart()->add(new DateInterval('PT4H1800S')); - } + public function getName() { /* : string */ + return 'Driftkveld'; + } - public function getName() /* : string */ { - return "Driftkveld"; - } + public function getLocation() { /* : Location */ + return 'Terminalrommet / Discord / IRC'; + } - public function getLocation() /* : Location */ { - return "Terminalrommet / Discord / IRC"; - } + public function getOrganiser() { /* : User */ + return 'Torstein Nordgård-Hansen'; + } - public function getOrganiser() /* : User */ { - return "Torstein Nordgård-Hansen"; - } + public function getURL() { /* : string */ + return '/driftkveld/'; + } - public function getURL() /* : string */ { - return '/driftkveld/'; - } + public function getImageURL() { + return '/sosiale/drift.jpg'; + } - public function getImageURL() { - return '/sosiale/drift.jpg'; - } - - public function getDescription() { - return [ - 'Vil du drifte?', - 'Vil du være kul kis TM?', - 'Kom på driftkveld!', - '', - 'Vi møtes annenhver uke for å ta unna driftarbeid og drikke kaffe.', - 'Alle PVVere er velkommene, enten de er erfarne driftere eller helt utenforstående!' - ]; - } - - public function getColor() { - return "#35a"; - } + public function getDescription() { + return [ + 'Vil du drifte?', + 'Vil du være kul kis TM?', + 'Kom på driftkveld!', + '', + 'Vi møtes annenhver uke for å ta unna driftarbeid og drikke kaffe.', + 'Alle PVVere er velkommene, enten de er erfarne driftere eller helt utenforstående!', + ]; + } + public function getColor() { + return '#35a'; + } } diff --git a/src/pvv/side/social/hackekveldactivity.php b/src/pvv/side/social/hackekveldactivity.php index 7b27319..3e94384 100644 --- a/src/pvv/side/social/hackekveldactivity.php +++ b/src/pvv/side/social/hackekveldactivity.php @@ -1,40 +1,47 @@ -format('H') > 18 || $date->format('H') == 17 && $date->format('i') > 30) { + return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(18, 15, 0)); + } + $date = $date->setTime(16, 15, 0); + if ($date->format('N') != 6) { + return $this->nextDate($date->add(new \DateInterval('P1D'))); + } + if ($date->format('W') % 2) { + return $this->nextDate($date->add(new \DateInterval('P7D'))); + } - public function nextDate(DateTimeImmutable $date) { - if ($date->format('H') > 18 || $date->format('H') == 17 && $date->format('i') > 30) - return $this->nextDate($date->add(new DateInterval('P1D'))->setTime(18, 15, 0)); - $date = $date->setTime(16, 15, 0); - if ($date->format('N') != 6) - return $this->nextDate($date->add(new DateInterval('P1D'))); - if ($date->format('W') % 2) - return $this->nextDate($date->add(new DateInterval('P7D'))); - return $date; - } + return $date; + } - public function prevDate(DateTimeImmutable $date) { - if ($date->format('H') < 17 || $date->format('H') == 18 && $date->format('i') < 30) - return $this->prevDate($date->sub(new DateInterval('P1D'))->setTime(18, 15, 0)); - $date = $date->setTime(18, 15, 0); - if ($date->format('N') != 6) - return $this->prevDate($date->sub(new DateInterval('P1D'))); - if ($date->format('W') % 2) - return $this->prevDate($date->sub(new DateInterval('P7D'))); - return $date; - } + public function prevDate(\DateTimeImmutable $date) { + if ($date->format('H') < 17 || $date->format('H') == 18 && $date->format('i') < 30) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(18, 15, 0)); + } + $date = $date->setTime(18, 15, 0); + if ($date->format('N') != 6) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))); + } + if ($date->format('W') % 2) { + return $this->prevDate($date->sub(new \DateInterval('P7D'))); + } - public function getNextEventFrom(DateTimeImmutable $date) /* : Event */ { - return new HackekveldEvent($this->nextDate($date)); - } + return $date; + } - public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */ { - return new HackekveldEvent($this->prevDate($date)); - } + public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new HackekveldEvent($this->nextDate($date)); + } + public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new HackekveldEvent($this->prevDate($date)); + } } diff --git a/src/pvv/side/social/hackekveldevent.php b/src/pvv/side/social/hackekveldevent.php index 74bea7f..d5cc578 100644 --- a/src/pvv/side/social/hackekveldevent.php +++ b/src/pvv/side/social/hackekveldevent.php @@ -1,45 +1,44 @@ -getStart()->add(new \DateInterval('PT4H1800S')); + } - public function getStop() { - return $this->getStart()->add(new DateInterval('PT4H1800S')); - } + public function getName() { /* : string */ + return 'Hackekveld'; + } - public function getName() /* : string */ { - return "Hackekveld"; - } + public function getLocation() { /* : Location */ + return 'Terminalrommet / Discord / IRC'; + } - public function getLocation() /* : Location */ { - return "Terminalrommet / Discord / IRC"; - } + public function getOrganiser() { /* : User */ + return 'PVV'; + } - public function getOrganiser() /* : User */ { - return "PVV"; - } + public function getURL() { /* : string */ + return '#'; + } - public function getURL() /* : string */ { - return '#'; - } + public function getImageURL() { + return '/pvv-logo.png'; + } - public function getImageURL() { - return '/pvv-logo.png'; - } - - public function getDescription() { - return [ - 'Mange PVV-medlemmer liker å programmere.', - 'Hvis du også liker å programmere, så bli med! Her kan du jobbe med dine egne prosjekter eller starte noe med andre nerder her på huset. Vi møtes for en hyggelig prat, mye god programmering og delsponset pizza.' - ]; - } - - public function getColor() { - return "#35a"; - } + public function getDescription() { + return [ + 'Mange PVV-medlemmer liker å programmere.', + 'Hvis du også liker å programmere, så bli med! Her kan du jobbe med dine egne prosjekter eller starte noe med andre nerder her på huset. Vi møtes for en hyggelig prat, mye god programmering og delsponset pizza.', + ]; + } + public function getColor() { + return '#35a'; + } } diff --git a/src/pvv/side/social/nerdepitsaactivity.php b/src/pvv/side/social/nerdepitsaactivity.php index d320a51..5032e00 100644 --- a/src/pvv/side/social/nerdepitsaactivity.php +++ b/src/pvv/side/social/nerdepitsaactivity.php @@ -1,40 +1,47 @@ -format('H') > 19) { + return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(19, 0, 0)); + } + $date = $date->setTime(19, 0, 0); + if ($date->format('N') != 5) { + return $this->nextDate($date->add(new \DateInterval('P1D'))); + } + if ($date->format('W') % 2) { + return $this->nextDate($date->add(new \DateInterval('P7D'))); + } - public function nextDate(DateTimeImmutable $date) { - if ($date->format('H') > 19) - return $this->nextDate($date->add(new DateInterval('P1D'))->setTime(19, 0, 0)); - $date = $date->setTime(19, 0, 0); - if ($date->format('N') != 5) - return $this->nextDate($date->add(new DateInterval('P1D'))); - if ($date->format('W') % 2) - return $this->nextDate($date->add(new DateInterval('P7D'))); - return $date; - } + return $date; + } - public function prevDate(DateTimeImmutable $date) { - if ($date->format('H') < 19) - return $this->prevDate($date->sub(new DateInterval('P1D'))->setTime(19, 0, 0)); - $date = $date->setTime(19, 0, 0); - if ($date->format('N') != 5) - return $this->prevDate($date->sub(new DateInterval('P1D'))); - if ($date->format('W') % 2) - return $this->prevDate($date->sub(new DateInterval('P7D'))); - return $date; - } + public function prevDate(\DateTimeImmutable $date) { + if ($date->format('H') < 19) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(19, 0, 0)); + } + $date = $date->setTime(19, 0, 0); + if ($date->format('N') != 5) { + return $this->prevDate($date->sub(new \DateInterval('P1D'))); + } + if ($date->format('W') % 2) { + return $this->prevDate($date->sub(new \DateInterval('P7D'))); + } - public function getNextEventFrom(DateTimeImmutable $date) /* : Event */ { - return new NerdepitsaEvent($this->nextDate($date)); - } + return $date; + } - public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */ { - return new NerdepitsaEvent($this->prevDate($date)); - } + public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new NerdepitsaEvent($this->nextDate($date)); + } + public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */ + return new NerdepitsaEvent($this->prevDate($date)); + } } diff --git a/src/pvv/side/social/nerdepitsaevent.php b/src/pvv/side/social/nerdepitsaevent.php index 14cf00c..779dc06 100644 --- a/src/pvv/side/social/nerdepitsaevent.php +++ b/src/pvv/side/social/nerdepitsaevent.php @@ -1,50 +1,49 @@ -getStart()->add(new \DateInterval('PT2H1800S')); + } - public function getStop() { - return $this->getStart()->add(new DateInterval('PT2H1800S')); - } + public function getName() { + return 'Nerdepitsa'; + } - public function getName() { - return "Nerdepitsa"; - } + public function getLocation() { /* : Location */ + return 'Peppes Kjøpmansgata'; + } - public function getLocation() /* : Location */ { - return "Peppes Kjøpmansgata"; - } + public function getOrganiser() { /* : User */ + return 'Anders Christensen'; + } - public function getOrganiser() /* : User */ { - return "Anders Christensen"; - } + public function getURL() { /* : string */ + return '/nerdepitsa/'; + } - public function getURL() /* : string */ { - return '/nerdepitsa/'; - } + public function getImageURL() { + return '/sosiale/nerdepitsa.jpg'; + } - public function getImageURL() { - return '/sosiale/nerdepitsa.jpg'; - } - - public function getDescription() { - return [ - 'Hei, har du lyst til å bli med på pizzaspising annenhver fredag? Vi møtes på Peppes i Kjøpmannsgata fredag klokken 19.00 hver partallsuke!', - '', - 'Vi er en trivelig gjeng hvis der fellestrekk er en viss interesse for data, samt har eller har hatt en tilknytning til studentmiljøet ved NTNU. For å treffe andre som også faller inn under disse kriteriene treffes vi over pizza på Peppes annenhver fredag. (Definisjon: En fredag er annenhver dersom den ligger i en partallsuke). Vi har reservasjon under navnet Christensen med storkunderabatt.', - '', - 'Det er ikke noe krav at du er nerd... noen av oss virker faktisk nesten normale! Det er heller ikke noe krav at du kjenner noen fra før. Det er ikke engang et krav at du må like pizza! (selv om det hjelper) Dersom du har lyst til å treffe personer fra datamiljøet ved NTNU så bare still opp! Vi biter ikke, vel, bortsett fra pizzaen da.', - '', - 'Vi bestiller så mye pizza som vi i fellesskap klarer å stappe i oss, og splitter dermed pizza-regningen broderlig, mens hver enkelt betaler for sin egen drikke, dessert mm. Vell møtt!' - ]; - } - - public function getColor() { - return "#c35"; - } + public function getDescription() { + return [ + 'Hei, har du lyst til å bli med på pizzaspising annenhver fredag? Vi møtes på Peppes i Kjøpmannsgata fredag klokken 19.00 hver partallsuke!', + '', + 'Vi er en trivelig gjeng hvis der fellestrekk er en viss interesse for data, samt har eller har hatt en tilknytning til studentmiljøet ved NTNU. For å treffe andre som også faller inn under disse kriteriene treffes vi over pizza på Peppes annenhver fredag. (Definisjon: En fredag er annenhver dersom den ligger i en partallsuke). Vi har reservasjon under navnet Christensen med storkunderabatt.', + '', + 'Det er ikke noe krav at du er nerd... noen av oss virker faktisk nesten normale! Det er heller ikke noe krav at du kjenner noen fra før. Det er ikke engang et krav at du må like pizza! (selv om det hjelper) Dersom du har lyst til å treffe personer fra datamiljøet ved NTNU så bare still opp! Vi biter ikke, vel, bortsett fra pizzaen da.', + '', + 'Vi bestiller så mye pizza som vi i fellesskap klarer å stappe i oss, og splitter dermed pizza-regningen broderlig, mens hver enkelt betaler for sin egen drikke, dessert mm. Vell møtt!', + ]; + } + public function getColor() { + return '#c35'; + } } diff --git a/src/pvv/side/social/testanimekveld.php b/src/pvv/side/social/testanimekveld.php index 86fed78..deca11a 100644 --- a/src/pvv/side/social/testanimekveld.php +++ b/src/pvv/side/social/testanimekveld.php @@ -1,9 +1,12 @@ -nextDate(new \DateTimeImmutable)->format(DATE_RFC2822)); +$c = new AnimekveldActivity(); +exit($c->nextDate(new \DateTimeImmutable())->format(\DATE_RFC2822)); diff --git a/src/pvv/side/social/testnerdepitsa.php b/src/pvv/side/social/testnerdepitsa.php index 22f385c..ce49a1e 100644 --- a/src/pvv/side/social/testnerdepitsa.php +++ b/src/pvv/side/social/testnerdepitsa.php @@ -1,9 +1,12 @@ -prevDate(new \DateTimeImmutable)->format(DATE_RFC2822)); +$c = new NerdepitsaActivity(); +exit($c->prevDate(new \DateTimeImmutable())->format(\DATE_RFC2822));