Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SS4 Upgrade **** WORK IN PROGRESS **** #48

Open
wants to merge 152 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
3971085
UPGRADE: Upgrader tool for SS4
gordonbanderson Apr 19, 2018
b75b247
WIP: dev/build works, and the admin interface does not fall over
gordonbanderson Apr 19, 2018
eaee607
Expose!
gordonbanderson Apr 20, 2018
398defe
FIX: Removed extension as the inverse relationship defined here needs…
gordonbanderson Apr 20, 2018
9f9554e
WIP: Path fixes for assets, namespace fixes for code
gordonbanderson Apr 20, 2018
0032ae8
WIP: Fixing path issues
gordonbanderson Apr 20, 2018
11ffa9f
FIX: Use silverware datetimepicker
gordonbanderson Apr 20, 2018
a7dc343
WIP: Tidying up admin interface
gordonbanderson Apr 22, 2018
117402e
FIX: Make this a vendor module
gordonbanderson Apr 22, 2018
57e267b
WIP: Debugging
gordonbanderson Apr 22, 2018
ebf8077
MINOR: Debug removal
gordonbanderson Apr 22, 2018
3f6f255
FIX: Namespace
gordonbanderson Apr 23, 2018
214fc41
FIX: Lots of code inferred relationship to Calendar, put it back to f…
gordonbanderson Apr 23, 2018
cf59e4c
FIX: Namespace
gordonbanderson Apr 23, 2018
27f1bef
WIP: Basic event registration now works
gordonbanderson Apr 23, 2018
46f85d0
FIX: Added extension points
gordonbanderson Apr 23, 2018
e51436a
FIX: icons are in the images folder
gordonbanderson Apr 24, 2018
8ff99bb
WIP: Trying to hook in event payment via PayPal
gordonbanderson Apr 24, 2018
a7aab90
WIP: Event payment hooks
gordonbanderson Apr 24, 2018
5af8d1e
FIX: Email field was incorrect
gordonbanderson Apr 24, 2018
add2423
WIP: Can now get a successful or not registration message to the fron…
gordonbanderson Apr 24, 2018
96cb92d
FIX: Upgrade to SS4 compatiable Travis file
gordonbanderson Apr 24, 2018
1d65e27
ENHANCEMENT: CircleCI for faster testing
gordonbanderson Apr 24, 2018
911e731
FIX: Namespace
gordonbanderson Apr 24, 2018
4d64559
Badger!
gordonbanderson Apr 24, 2018
a52f6a7
WIP: Shells of tests created by Ruby script
gordonbanderson Apr 24, 2018
a8659aa
FIX: PSR2 sweep
gordonbanderson Apr 24, 2018
adfaa2a
MINOR: Adding dev tools
gordonbanderson Apr 24, 2018
2511e12
ENHANCEMENT: phpstan
gordonbanderson Apr 24, 2018
e91e0a0
WIP: Trying phpstan in Circle CI
gordonbanderson Apr 24, 2018
36370bf
FIX: Whitelist this branch
gordonbanderson Apr 24, 2018
0379a0f
FIX: Stability
gordonbanderson Apr 24, 2018
c0f34a6
MINOR: A single text
gordonbanderson Apr 24, 2018
9ba8c22
Scrutinizer Auto-Fixes
scrutinizer-auto-fixer Apr 24, 2018
82678ec
Merge pull request #1 from gordonbanderson/scrutinizer-patch-1
gordonbanderson Apr 24, 2018
6336a04
MINOR: Skip phpstan for now
gordonbanderson Apr 24, 2018
0a7602f
FIX: Add missing PHPUnit to composer.json file
gordonbanderson Apr 24, 2018
3b179c0
FIX: Versions of PHP and silverstripe
gordonbanderson Apr 24, 2018
ef1fe22
FIX: Remove sphinx install
gordonbanderson Apr 24, 2018
0565891
FIX: Added missing phpunit.xml.dist file for bootstrapping tests
gordonbanderson Apr 24, 2018
5511492
Debug
gordonbanderson Apr 24, 2018
80b742c
Debug
gordonbanderson Apr 24, 2018
541c5ca
Debug
gordonbanderson Apr 24, 2018
d095196
Debug
gordonbanderson Apr 24, 2018
d367786
WIP: Deleted test
gordonbanderson Apr 24, 2018
67cae23
FIX: Avoid name clash of temporary and actual test directories
gordonbanderson Apr 24, 2018
217af59
FIX: Whitelist was src, not code dir
gordonbanderson Apr 24, 2018
28989e9
MINOR: Remove debug
gordonbanderson Apr 24, 2018
cd6855f
WIP: Remove auto generated tests
gordonbanderson Apr 24, 2018
6f0f876
WIP: Want one test working before I sleeep
gordonbanderson Apr 24, 2018
04a1fd9
FIX: dev/build error
gordonbanderson Apr 25, 2018
4855d4a
FIX: Moved code to Event.php
gordonbanderson Apr 25, 2018
4a8ff6b
FIX: Remove PublicEvent form codebase
gordonbanderson Apr 26, 2018
b61aa87
FIX: Remove public calendar
gordonbanderson Apr 26, 2018
93084e2
ENHANCEMENT: Now require calendars ids to render events
gordonbanderson Apr 26, 2018
043d8f5
ENHANCEMENT: Backend tweaks to force calendars to be mandatory and ge…
gordonbanderson Apr 26, 2018
40d5945
ENHANCEMENT: Can filter listing
gordonbanderson Apr 26, 2018
c045321
ENHANCEMENT: Can filter listing
gordonbanderson Apr 26, 2018
a46121f
FIX: Use filter, issue was bad data, not a bad query
gordonbanderson Apr 26, 2018
e9e392e
FIX: Event registration name reference
gordonbanderson Apr 28, 2018
f4ddc78
ENHANCEMENT: Event image extension
gordonbanderson Apr 29, 2018
31eb694
WIP: Add notes re date formatting todos, made them consistent
gordonbanderson Apr 29, 2018
773b27b
FIX: Separate files a per PSR whatever
gordonbanderson Apr 30, 2018
159d569
WIP: Resurrecting and half fixing bulk uploader
gordonbanderson May 3, 2018
a6021cf
ENHANCEMENT: Added formatted start date
gordonbanderson May 3, 2018
7d1970a
FIX: Paginate events
gordonbanderson May 3, 2018
eab4f5f
ENHANCEMENT: Add carbon as this module is date centric hell
gordonbanderson May 3, 2018
532178c
ENHANCEMENT: month/date links widget
gordonbanderson May 3, 2018
4f47ae7
WIP: Added tags
gordonbanderson May 3, 2018
f3ff796
ENHANCEMENT: Can now view a listing of tags, refactor of grid
gordonbanderson May 3, 2018
accbb6d
FIX: private static instead of public static
gordonbanderson May 4, 2018
bd9dbe1
WIP: Calendars and groups many many
gordonbanderson May 4, 2018
f9ffa30
FIX: Use correct path/class
gordonbanderson May 4, 2018
8747fb8
WIP: Groups editing
gordonbanderson May 4, 2018
b5f9727
FIX: Groups now selectable for a calendar
gordonbanderson May 4, 2018
14ae33a
FIX: CalendarPage now has many Calendar
gordonbanderson May 4, 2018
e4944f4
FIX: events for month method now requires an array
gordonbanderson May 4, 2018
8bd8356
ENHANCEMENT: Listing now filtered to calendars for event page
gordonbanderson May 4, 2018
12ff3af
ENHANCEMENT: Listing restricted appropriately if logged in / logged out
gordonbanderson May 4, 2018
3859568
MINOR: Remove debug
gordonbanderson May 4, 2018
73cf9d3
FIX: Calendar now respects group restriction
gordonbanderson May 4, 2018
8649d3a
WIP: Centralised valid calendars method, fixed tags widget
gordonbanderson May 4, 2018
2d24a57
FIX: Restrict tag to pages calendars
gordonbanderson May 4, 2018
9ea4640
FIX: Widgets now filter appropriately
gordonbanderson May 4, 2018
f932885
ENHANCEMENT: Member cost
gordonbanderson May 4, 2018
39fb352
FIX: Remove title from calendar listing
gordonbanderson May 5, 2018
3b29d7e
FIX: Added relative event link, to avoid jumping to the first calenda…
gordonbanderson May 6, 2018
e4bd3b4
FIX: Filter by url segment of tag, not title
gordonbanderson May 6, 2018
44499aa
FIX: Rogue char
gordonbanderson May 6, 2018
c4e6cad
ENHANCEMENT: Location for an event
gordonbanderson May 8, 2018
a1961d6
FIX: Color of icon
gordonbanderson May 9, 2018
a82fbee
WIP
gordonbanderson May 11, 2018
830a977
WIP: Trying to get forms working
gordonbanderson May 12, 2018
aae2d88
WIP: Number of tickets
gordonbanderson May 12, 2018
6ff6186
WIP: Saving with tickets
gordonbanderson May 12, 2018
6803d1a
WIP: Ticketing
gordonbanderson May 12, 2018
c9f7421
FIX: Take account of status when counting
gordonbanderson May 12, 2018
f716c80
ENHANCEMENT: Show image in summary
gordonbanderson May 13, 2018
6fc7ff2
WIP: Event tidy up
gordonbanderson May 13, 2018
d5b3ce4
WIP: Attendees
gordonbanderson May 16, 2018
7d37aef
WIP: Adding tests for embargo
gordonbanderson May 16, 2018
da4e104
MINOR: Add unittests to branches checked
gordonbanderson May 16, 2018
1743a53
FI: Fat finger typo
gordonbanderson May 16, 2018
eb1b686
FIX: Name of write/save method
gordonbanderson May 16, 2018
1e3844d
WIP: Checking carbon formatting
gordonbanderson May 16, 2018
2f31c0f
FIX: Added parent setup call
gordonbanderson May 16, 2018
224763a
ENHANCEMENT: Added get embargo date method
gordonbanderson May 16, 2018
ff8bdb2
WIP: Embargo date testing
gordonbanderson May 16, 2018
a41f449
FIX: Syntax error
gordonbanderson May 16, 2018
b83fc1a
FIX: Start date field name
gordonbanderson May 16, 2018
3514db2
WIP: Embargo test
gordonbanderson May 16, 2018
171f8b0
WIP
gordonbanderson May 16, 2018
64e0743
WIP: Export of registrations
gordonbanderson May 16, 2018
be48bc3
MINOR: Notes doc from Slack
gordonbanderson May 16, 2018
1aa697a
WIP: Embargo now working
gordonbanderson May 16, 2018
cb468b1
WIP: Testing
gordonbanderson May 16, 2018
88a5f8a
FIX: Spam widget now honoured
gordonbanderson May 19, 2018
8a42a44
FIX: Provide DateTimeField to template
gordonbanderson May 19, 2018
b22284e
WIP: Attendee editing working in the backend
gordonbanderson May 21, 2018
80608e2
WIP
gordonbanderson May 21, 2018
e07922d
MINOR: Whitespace
gordonbanderson May 21, 2018
61929e2
WIP: Attendee names showing
gordonbanderson May 21, 2018
39c2f29
FIX: Enable month title, set height to auto
gordonbanderson May 23, 2018
1bb3b14
FIX: Show registration info if available
gordonbanderson May 23, 2018
0850b6b
MINOR: Added constant for session key representing registration id
gordonbanderson May 23, 2018
6692d1c
FIX: Event ID order
gordonbanderson May 23, 2018
62e45a6
FIX: Gridfield
gordonbanderson May 23, 2018
10eeab0
ENHANCEMENT: Added recent and upcoming events, need to filter to corr…
gordonbanderson May 24, 2018
3f7c35d
FIX: Refactored to add date range method
gordonbanderson May 24, 2018
00b9d4a
FIX: Upcoming working as expected if explicit "upcoming" added to URL
gordonbanderson May 24, 2018
814d26a
FIX: Recent now working
gordonbanderson May 24, 2018
71ede0c
FIX: Upcoming dates and links
gordonbanderson May 24, 2018
5ddfd91
WIP: Multiple attendees
gordonbanderson Jun 1, 2018
7ef6e80
FIX: Position of scroll to
gordonbanderson Jun 1, 2018
8354ed0
WIP: Delete working
gordonbanderson Jun 2, 2018
5c35364
MINOR: Remove debug, fix JSON for empty case
gordonbanderson Jun 5, 2018
2dee47c
FIX: Local storage for attendees json
gordonbanderson Jun 5, 2018
84a8810
FIX: Removed test field
gordonbanderson Jun 5, 2018
40c6720
ENHANCEMENT: Form validation
gordonbanderson Jun 5, 2018
73b1632
WIP: Need to fix the summary columns after the changes
gordonbanderson Jun 5, 2018
7a85353
ENHANCEMENT: Populate with logged in member
gordonbanderson Jun 5, 2018
58328a7
FIX: Data loading
gordonbanderson Jun 5, 2018
18d701e
FIX: Do not load old data. Leave in place for now though
gordonbanderson Jun 5, 2018
4e82034
FIX: Only allow form submission if attendees
gordonbanderson Jun 5, 2018
96d1af1
WIP: Export report
gordonbanderson Jun 5, 2018
8f63198
FIX: Disable registration button if no signature
gordonbanderson Jun 7, 2018
d875c3d
MINOR: Whitespace and note
gordonbanderson Jun 7, 2018
976c971
FIX: Duplication of fields, export
gordonbanderson Jun 8, 2018
8638687
MINOR: Comment out alerts
gordonbanderson Jun 8, 2018
7e35ef8
FIX: Grid
gordonbanderson Jun 8, 2018
f59ffdb
MINOR: whitespace
gordonbanderson Jun 8, 2018
7750220
FIX: Added missing dependency (it was in the project composer.json, n…
gordonbanderson Oct 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
build:
docker:
- image: brettt89/silverstripe-web:7.1-platform
environment:
- SS_DATABASE_CLASS=MySQLPDODatabase
- SS_DATABASE_SERVER=127.0.0.1
- SS_DATABASE_USERNAME=root
- SS_DATABASE_PASSWORD=ubuntu
- SS_DATABASE_NAME=circle_test
- SS_ENVIRONMENT_TYPE=dev
- image: circleci/mysql:5.7
environment:
- MYSQL_USER=root
- MYSQL_ROOT_PASSWORD=ubuntu
- MYSQL_DATABASE=circle_test
- MYSQL_HOST=127.0.0.1

working_directory: ~/var/www

branches:
only:
- master
- develop
- upgradess4
- unittests

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "composer.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: composer validate
- run: composer require --prefer-source --no-update silverstripe/recipe-cms:1.1.x-dev
- run: composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile



- save_cache:
paths:
- ./vendor
key: v1-dependencies-{{ checksum "composer.json" }}

# run test,upload coverage
#- run: vendor/bin/phpstan analyze code
- run: phpdbg -qrr vendor/bin/phpunit -d memory_limit=512M --coverage-clover=coverage.xml tests/
- run: bash <(curl -s https://codecov.io/bash) -f coverage.xml

54 changes: 31 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details

sudo: false

language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
dist: trusty

cache:
directories:
- $HOME/.composer/cache/files

env:
- DB=MYSQL CORE_RELEASE=3.2
global:
- COMPOSER_ROOT_VERSION=4.0.x-dev

matrix:
include:
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3.1
- php: 5.6
env: DB=PGSQL CORE_RELEASE=3.2
allow_failures:
env: DB=MYSQL INSTALLER_VERSION=4.0.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0
env: DB=PGSQL INSTALLER_VERSION=4.1.x-dev PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL INSTALLER_VERSION=4.2.x-dev PHPUNIT_COVERAGE_TEST=1
- php: 7.2
env: DB=MYSQL INSTALLER_VERSION=4.x-dev PHPUNIT_TEST=1

before_script:
- composer self-update || true
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- composer install
# Init PHP
- phpenv rehash
- phpenv config-rm xdebug.ini

# Install composer dependencies
- composer validate
- echo $INSTALLER_VERSION
- composer require --prefer-source --no-update silverstripe/recipe-cms:1.1.x-dev
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi
- composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
- vendor/bin/sake flush=all

- php vendor/silverstripe/framework/tests/dump_constants.php

script:
- vendor/bin/phpunit silverstripe-calendar/tests
- if [[ $PHPUNIT_TEST ]]; then find . | grep Sapphire && vendor/bin/phpunit tests/; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml tests/; fi

after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# SilverStripe Calendar
[![Build Status](https://travis-ci.org/gordonbanderson/silverstripe-calendar.svg?branch=upgradess4)](https://travis-ci.org/gordonbanderson/silverstripe-calendar)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/gordonbanderson/silverstripe-calendar/badges/quality-score.png?b=upgradess4)](https://scrutinizer-ci.com/g/gordonbanderson/silverstripe-calendar/?branch=upgradess4)
[![Code Coverage](https://scrutinizer-ci.com/g/gordonbanderson/silverstripe-calendar/badges/coverage.png?b=upgradess4)](https://scrutinizer-ci.com/g/gordonbanderson/silverstripe-calendar/?branch=upgradess4)
[![Build Status](https://scrutinizer-ci.com/g/gordonbanderson/silverstripe-calendar/badges/build.png?b=upgradess4)](https://scrutinizer-ci.com/g/gordonbanderson/silverstripe-calendar/build-status/upgradess4)
[![codecov.io](https://codecov.io/github/gordonbanderson/silverstripe-calendar/coverage.svg?branch=upgradess4)](https://codecov.io/github/gordonbanderson/silverstripe-calendar?branch=upgradess4)

[![Latest Stable Version](https://poser.pugx.org/titledk/silverstripe-calendar/version)](https://packagist.org/packages/titledk/silverstripe-calendar)
[![Latest Unstable Version](https://poser.pugx.org/titledk/silverstripe-calendar/v/unstable)](//packagist.org/packages/titledk/silverstripe-calendar)
[![Total Downloads](https://poser.pugx.org/titledk/silverstripe-calendar/downloads)](https://packagist.org/packages/titledk/silverstripe-calendar)
[![License](https://poser.pugx.org/titledk/silverstripe-calendar/license)](https://packagist.org/packages/titledk/silverstripe-calendar)
[![Monthly Downloads](https://poser.pugx.org/titledk/silverstripe-calendar/d/monthly)](https://packagist.org/packages/titledk/silverstripe-calendar)
[![Daily Downloads](https://poser.pugx.org/titledk/silverstripe-calendar/d/daily)](https://packagist.org/packages/titledk/silverstripe-calendar)

[![Dependency Status](https://www.versioneye.com/php/titledk:silverstripe-calendar/badge.svg)](https://www.versioneye.com/php/titledk:silverstripe-calendar)
[![Reference Status](https://www.versioneye.com/php/titledk:silverstripe-calendar/reference_badge.svg?style=flat)](https://www.versioneye.com/php/titledk:silverstripe-calendar/references)

![codecov.io](https://codecov.io/github/gordonbanderson/silverstripe-calendar/branch.svg?branch=upgradess4)

_by Title Web Solutions_

Expand Down Expand Up @@ -93,6 +110,7 @@ time picker and dropdown, and duration dropdown, still allowing manual inputs

* [Anselm Christophersen](https://github.com/anselmdk)
* [Colin Burns](https://github.com/colinburns)
* [Gordon Anderson](https://github.com/gordonbanderson) (SS4 upgrade)


## License
Expand Down
2 changes: 2 additions & 0 deletions _config/pickers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SilverStripe\Forms\FormField:
calendar_datepicker_class: 'hasDatepicker'
7 changes: 7 additions & 0 deletions _config/registration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
Name: silverstripe-calendar-registration
---
TitleDK\Calendar\Events\Event:
# Embargo registration relative to end date or calculated end date. Negative values are before the end datetime, so
# a value of -1440 is a day ago. Use a positive value to allow for registration during a multiday event
embargo_registration_relative_to_end_datetime_mins: 0
3 changes: 3 additions & 0 deletions _config/relationships.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SilverStripe\Security\Group:
many_many:
Calendars: TitleDK\Calendar\Calendars\Calendar
10 changes: 5 additions & 5 deletions _config/routes.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
Name: calendaroutes
---
Director:
SilverStripe\Control\Director:
rules:
'fullcalendar//$Action/$ID/$OtherID': 'FullcalendarController'
'calregistrations//$Action/$ID/$OtherID': 'EventRegistrationController'
'ics//$Action/$ID/$OtherID': 'ICSExport_Controller'
'EventRegistrationController//$Action/$ID/$OtherID': 'EventRegistrationController'
fullcalendar//$Action/$ID/$OtherID: TitleDK\Calendar\FullCalendar\FullcalendarController
calregistrations//$Action/$ID/$OtherID: TitleDK\Calendar\Registrations\EventRegistrationController
ics//$Action/$ID/$OtherID: TitleDK\Calendar\Libs\ColorPool\ICSExport_Controller
EventRegistrationController//$Action/$ID/$OtherID: TitleDK\Calendar\Registrations\EventRegistrationController
199 changes: 199 additions & 0 deletions code/Admin/CalendarAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php
namespace TitleDK\Calendar\Admin;

use SilverShop\Admin\ProductBulkLoader;
use SilverShop\Model\Variation\AttributeType;
use SilverShop\Page\Product;
use SilverShop\Page\ProductCategory;
use SilverStripe\Dev\CsvBulkLoader;
use SilverStripe\Forms\GridField\GridFieldImportButton;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\GridField\GridFieldExportButton;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
use SilverStripe\Forms\GridField\GridFieldPrintButton;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\FieldList;
use SilverStripe\Control\Controller;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Security\PermissionProvider;
use TitleDK\Calendar\Core\CalendarConfig;
use TitleDK\Calendar\Events\Event;
use TitleDK\Calendar\Events\EventCsvBulkLoader;

/**
* Calendar Admin
*
* @package calendar
* @subpackage admin
*/
class CalendarAdmin extends ModelAdmin implements PermissionProvider
{

private static $menu_title = "Calendar";
private static $url_segment = "calendar";

private static $allowed_actions = array(
'CalendarsForm',
'CategoriesForm',
'EventsForm'
);




private static $managed_models = array(
'TitleDK\Calendar\Events\Event',
'TitleDK\Calendar\Categories\PublicEventCategory',
'TitleDK\Calendar\Calendars\Calendar'
);

private static $model_importers = array(
'TitleDK\Calendar\Events\Event' => 'TitleDK\Calendar\Events\EventCsvBulkLoader',
'TitleDK\Calendar\Categories\PublicEventCategory' => 'SilverStripe\Dev\CsvBulkLoader',
'TitleDK\Calendar\Calendars\Calendar' => 'SilverStripe\Dev\CsvBulkLoader'
);


private static $menu_icon = "titledk/silverstripe-calendar:images/icons/calendar.png";

public function init()
{
parent::init();


//CSS/JS Dependencies - currently not much there
Requirements::css("titledk/silverstripe-calendar:css/admin/CalendarAdmin.css");
Requirements::javascript("titledk/silverstripe-calendar:javascript/admin/CalendarAdmin.js");
}

public function getModelClass()
{
return $this->sanitiseClassName($this->modelClass);
}

public function getManagedModels()
{
// Unset managed models according to config
/** @todo change to use config API */
$models = parent::getManagedModels();
if (!$this->calendarsEnabled()
&& isset($models['Calendar'])) {
unset($models['Calendar']);
}
if (!$this->categoriesEnabled()
&& isset($models['Calendar'])) {
unset($models['PublicEventCategory']);
}
return $models;
}

protected function determineFormClass()
{
switch ($this->modelClass) {
case 'Calendar':
$class = 'TitleDK\Calendar\Admin\Forms\CalendarsForm';
break;
case 'EventCategory':
$class = 'TitleDK\Calendar\Admin\Forms\CategoriesForm';
break;
case 'Event':
$class = 'TitleDK\Calendar\Admin\Forms\EventsForm';
break;
default:
$class = 'SilverStripe\Forms\Form'; // @todo was CMSForm
break;
}

return $class;
}

public function getEditForm($id = null, $fields = null)
{
$list = $this->getList();
$exportButton = new GridFieldExportButton('buttons-before-left');
$exportButton->setExportColumns($this->getExportFields());
$listField = GridField::create(
$this->sanitiseClassName($this->modelClass),
false,
$list,
$fieldConfig = GridFieldConfig_RecordEditor::create($this->stat('page_length'))
->addComponent($exportButton)
->removeComponentsByType(GridFieldFilterHeader::class)
->addComponents(new GridFieldPrintButton('buttons-before-left'))
);

// Validation
if (singleton($this->modelClass)->hasMethod('getCMSValidator')) {
$detailValidator = singleton($this->modelClass)->getCMSValidator();
$listField->getConfig()->getComponentByType(GridFieldDetailForm::class)->setValidator($detailValidator);
}

if ($this->showImportForm) {
$fieldConfig->addComponent(
GridFieldImportButton::create('buttons-before-left')
->setImportForm($this->ImportForm())
->setModalTitle(_t('SilverStripe\\Admin\\ModelAdmin.IMPORT', 'Import from CSV'))
);
}

$formClass = $this->determineFormClass();

$form = $formClass::create(
$this,
'EditForm',
new FieldList($listField),
new FieldList()
)->setHTMLID('Form_EditForm');

// @todo This method does not exist $form->setResponseNegotiator($this->getResponseNegotiator());
$form->addExtraClass('cms-edit-form cms-panel-padded center');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
$editFormAction = Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'EditForm');
$form->setFormAction($editFormAction);
$form->setAttribute('data-pjax-fragment', 'CurrentForm');

$this->extend('updateEditForm', $form);

return $form;
}

protected function calendarsEnabled()
{
return CalendarConfig::subpackage_enabled('calendars');
}

protected function categoriesEnabled()
{
return CalendarConfig::subpackage_enabled('categories');
}

public function providePermissions()
{
$title = LeftAndMain::menu_title_for_class($this->class);
return array(
"CMS_ACCESS_CalendarAdmin" => array(
'name' => _t('CMSMain.ACCESS', "Access to '{title}' section", array('title' => $title)),
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access'),
'help' => 'Allow access to calendar management module.'
),
"CALENDAR_MANAGE" => array(
'name' => _t('CalendarAdmin.CALENDAR_MANAGE', 'Manage calendars'),
'category' => _t('CalendarAdmin.CALENDAR_PERMISSION_CATEGORY', 'Calender'),
'help' => 'Allow creating, editing, and deleting calendars.'
),
"EVENTCATEGORY_MANAGE" => array(
'name' => _t('CalendarAdmin.EVENTCATEGORY_MANAGE', 'Manage event categories'),
'category' => _t('CalendarAdmin.CALENDAR_PERMISSION_CATEGORY', 'Calender'),
'help' => 'Allow creating, editing, and deleting event categories.'
),
"EVENT_MANAGE" => array(
'name' => _t('CalendarAdmin.EVENT_MANAGE', 'Manage events'),
'category' => _t('CalendarAdmin.CALENDAR_PERMISSION_CATEGORY', 'Calender'),
'help' => 'Allow creating, editing, and deleting events.'
)
);
}
}
Loading