-
-
Notifications
You must be signed in to change notification settings - Fork 37
feat: First checkin for the ical direct features #189
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
Open
dploeger
wants to merge
5
commits into
ColdTrick:master
Choose a base branch
from
wabuehamm:feature/dpr/icaldirect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0bbb1e
added: Integrated iCal import and export features
dploeger 9a2baf8
fixed: Updated composer.lock
dploeger 01bf912
fixed: Updated composer.lock and composer.json
dploeger d8f7138
fixed: First fixes of PR
dploeger 2ada5f8
fixed: Sanity Check import
dploeger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| <?php | ||
|
|
||
| $calendar_type = get_input('calendar_type', 'all'); | ||
| $date_format = elgg_get_config('date_format', elgg_echo('input:date_format')); | ||
|
|
||
| $start_date = (string) get_input('start_date'); | ||
| if (empty($start_date)) { | ||
| $start_date = time(); | ||
| } else { | ||
| $start_date = DateTime::createFromFormat($date_format, $start_date)->getTimestamp(); | ||
| } | ||
|
|
||
| $end_date = (string) get_input('end_date'); | ||
| if (empty($end_date)) { | ||
| $end_date = DateTime::createFromFormat('U', time()) | ||
| ->add(DateInterval::createFromDateString('1 month')) | ||
| ->getTimestamp(); | ||
| } else { | ||
| $end_date = DateTime::createFromFormat($date_format, $end_date)->getTimestamp(); | ||
| } | ||
|
|
||
| $region = (string) get_input('region'); | ||
| $event_type = (string) get_input('event_type'); | ||
|
|
||
| $owner = (string) get_input('owner'); | ||
| $group = (string) get_input('group'); | ||
|
|
||
| $options = [ | ||
| 'types' => ['object'], | ||
| 'subTypes' => [Event::SUBTYPE], | ||
| 'metadata_name_value_pairs' => [ | ||
| [ | ||
| 'name' => 'event_start', | ||
| 'operand' => '>=', | ||
| 'value' => $start_date, | ||
| ], | ||
| [ | ||
| 'name' => 'event_end', | ||
| 'operand' => '<=', | ||
| 'value' => $end_date, | ||
| ], | ||
| ] | ||
| ]; | ||
|
|
||
| if (!empty($region)) { | ||
| $options['metadata_name_value_pairs'][] = [ | ||
| 'name' => 'region', | ||
| 'operand' => 'IN', | ||
| 'value' => $region, | ||
| ]; | ||
| } | ||
|
|
||
| if (!empty($event_type)) { | ||
| $options['metadata_name_value_pairs'][] = [ | ||
| 'name' => 'event_type', | ||
| 'operand' => 'IN', | ||
| 'value' => $event_type, | ||
| ]; | ||
| } | ||
|
|
||
| switch ($calendar_type) { | ||
| case 'group': | ||
| if (empty($group)) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:export:errors:groupempty')); | ||
| } | ||
|
|
||
| $options['container_guids'] = [$group]; | ||
| break; | ||
| case 'owner': | ||
| if (empty($owner)) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:export:errors:ownerempty')); | ||
| } | ||
|
|
||
| if (elgg_is_admin_logged_in() || $owner === elgg_get_logged_in_user_guid()) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:export:errors:ownermismatch')); | ||
| } | ||
|
|
||
| $options['owner_guids'] = [$owner]; | ||
dploeger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break; | ||
| } | ||
|
|
||
| /** @var Event[] $events */ | ||
| $events = elgg_get_entities($options); | ||
dploeger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| use Kigkonsult\Icalcreator\IcalInterface; | ||
| use Kigkonsult\Icalcreator\Vcalendar; | ||
|
|
||
| try { | ||
| $vcalendar = Vcalendar::factory( | ||
| [ | ||
| IcalInterface::UNIQUE_ID => 'https://github.com/ColdTrick/event_manager', | ||
| ] | ||
| ) | ||
| ->setMethod(IcalInterface::PUBLISH) | ||
| ->setXprop(IcalInterface::X_WR_CALNAME, 'Exported event') | ||
| ->setXprop(IcalInterface::X_WR_CALDESC, 'Exported events from event_manager') | ||
| ->setXprop(IcalInterface::X_WR_RELCALID, elgg_get_site_url()) | ||
| ->setXprop(IcalInterface::X_WR_TIMEZONE, date_default_timezone_get()); | ||
| } catch (Exception $e) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:export:errors:errorinstantiatingcalendar', [$e])); | ||
| } | ||
|
|
||
| foreach ($events as $event) { | ||
| try { | ||
| $vcalendar->setComponent($event->toVEvent()); | ||
| } catch (Exception $e) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:export:errors:erroraddingevent', [$e])); | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| return elgg_download_response($vcalendar->createCalendar(), 'export.ics'); | ||
| } catch (Exception $e) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:export:errors:errorcreatingcalendar', [$e])); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <?php | ||
|
|
||
| use Kigkonsult\Icalcreator\IcalInterface; | ||
| use Kigkonsult\Icalcreator\Vcalendar; | ||
| use Kigkonsult\Icalcreator\Vevent; | ||
|
|
||
| $calendar_type = get_input('calendar_type', 'all'); | ||
|
|
||
| $owner = (array) get_input('owner'); | ||
| $group = (array) get_input('group'); | ||
| $file = elgg_get_uploaded_file('import'); | ||
|
|
||
| if (!$file) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:missingfile')); | ||
| } | ||
|
|
||
| try { | ||
| $vcalendar = Vcalendar::factory( | ||
| [ | ||
| IcalInterface::UNIQUE_ID => 'https://github.com/ColdTrick/event_manager', | ||
| ] | ||
| ); | ||
| } catch (Exception $e) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:errorinstantiatingcalendar', [$e])); | ||
| } | ||
|
|
||
| try { | ||
| $vcalendar->parse($file->getContent()); | ||
| } catch (Exception $e) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:errorpparsingcalendar', [$e])); | ||
| } | ||
|
|
||
| $event_counter = 0; | ||
|
|
||
| /** @var Vevent $component */ | ||
| foreach ($vcalendar->getComponents('Vevent') as $component) { | ||
| try { | ||
| $event = Event::fromVEvent($component); | ||
| } catch (Exception $e) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:errorconvertingevent', [$e])); | ||
| } | ||
|
|
||
| switch ($calendar_type) { | ||
| case 'group': | ||
| if (empty($group)) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:groupempty')); | ||
| } | ||
|
|
||
| $group_guid = $group[0]; | ||
| $group = get_entity($group_guid); | ||
| if (!$group instanceof \ElggGroup) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:invalidgroup')); | ||
| } | ||
|
|
||
| if (elgg_is_admin_logged_in() || $group->canWriteToContainer(elgg_get_logged_in_user_guid())) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:grouppermission')); | ||
| } | ||
|
|
||
| $event->setContainerGUID($group_guid); | ||
| break; | ||
| case 'owner': | ||
| if (empty($owner)) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:ownerempty')); | ||
| } | ||
|
|
||
| $owner_guid = $owner[0]; | ||
| $owner = get_entity($owner_guid); | ||
| if (!$owner instanceof \ElggUser) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:invalidgroup')); | ||
| } | ||
|
|
||
| if (elgg_is_admin_logged_in() || $owner_guid === elgg_get_logged_in_user_guid()) { | ||
| return elgg_error_response(elgg_echo('event_manager:ical_direct:import:errors:ownermismatch')); | ||
| } | ||
|
|
||
| $event->owner_guid = $owner_guid; | ||
| break; | ||
| } | ||
|
|
||
| $event->save(); | ||
| $event_counter++; | ||
| } | ||
|
|
||
| return elgg_ok_response( | ||
| '', | ||
| elgg_echo('event_manager:ical_direct:import:success', [$event_counter]) | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,29 @@ public static function registerEventsList(\Elgg\Event $event): MenuItems { | |
| 'priority' => 400, | ||
| ]); | ||
| } | ||
|
|
||
| if (elgg_get_plugin_setting('ical_direct', 'event_manager')) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you want this as tabs? Why not title menu buttons? |
||
| $result[] = \ElggMenuItem::factory([ | ||
| 'name' => 'export-ical', | ||
| 'text' => elgg_echo('event_manager:ical_direct:export'), | ||
| 'href' => elgg_http_add_url_query_elements(elgg_generate_url('collection:ical:export'), [ | ||
| 'list_route' => elgg_get_current_route_name(), | ||
| 'route_parameters' => elgg_get_current_route()->getMatchedParameters(), | ||
| ]), | ||
| 'priority' => 500, | ||
| 'selected' => $selected === 'export-ical', | ||
| ]); | ||
| $result[] = \ElggMenuItem::factory([ | ||
| 'name' => 'import-ical', | ||
| 'text' => elgg_echo('event_manager:ical_direct:import'), | ||
| 'href' => elgg_http_add_url_query_elements(elgg_generate_url('collection:ical:import'), [ | ||
| 'list_route' => elgg_get_current_route_name(), | ||
| 'route_parameters' => elgg_get_current_route()->getMatchedParameters(), | ||
| ]), | ||
| 'priority' => 500, | ||
| 'selected' => $selected === 'import-ical', | ||
| ]); | ||
| } | ||
|
|
||
| return $result; | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.