social_lms_integrator-1.0.0-beta4/modules/social_lms_integrator_iteration_enrollments_req/social_lms_integrator_iteration_enrollments_req.module
modules/social_lms_integrator_iteration_enrollments_req/social_lms_integrator_iteration_enrollments_req.module
<?php
/**
* @file
* The Social LMS Integrator Iteration Enrollments Requests Export module.
*/
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\social_lms_integrator_enrollment\IterationEnrollmentInterface;
use Drupal\node\Entity\Node;
use Drupal\social_lms_integrator_enrollment\Entity\IterationEnrollment;
/**
* Implements hook_file_download().
*/
function social_lms_integrator_iteration_enrollments_req_file_download($uri) {
$scheme = StreamWrapperManager::getScheme($uri);
$target = \Drupal::service('stream_wrapper_manager')->getTarget($uri);
$access = \Drupal::currentUser()->hasPermission('administer users');
if ($scheme === 'private' && preg_match('/^csv\/export-iteration-enrollment-requests-([a-f0-9]{12})\.csv$/i', $target) && $access) {
return [
'Content-disposition' => 'attachment; filename="' . basename($target) . '"',
];
}
}
/**
* Implements hook_social_lms_integrator_iteration_managers_action_ACTION_ID_finish().
*/
function social_lms_integrator_iteration_enrollments_req_social_lms_integrator_iteration_managers_action_social_lms_integrator_iteration_enrollments_export_enrollments_action_finish($success) {
if ($success) {
return [
'singular' => '1 selected enrollee has been exported successfully',
'plural' => '@count selected enrollees have been exported successfully',
];
}
return [
'singular' => '1 selected enrollee has not been exported successfully',
'plural' => '@count selected enrollees have not been exported successfully',
];
}
/**
* Implements hook_social_user_export_plugin_info_alter().
*/
function social_lms_integrator_iteration_enrollments_req_social_lms_integrator_export_plugin_info_alter(array &$plugins) {
// Remove the following plugins
// we do not need them here!
$plugins_exclusion = [
'iteration_enrollment_invited_on',
'iteration_enrollment_invite_status',
];
foreach ($plugins_exclusion as $plugin) {
if ($plugins[$plugin]) {
unset($plugins[$plugin]);
}
}
}
/**
* Provide a method to alter data when get activity related entity.
*
* @param array $related_object
* Activity related entity object.
* @param array $data
* Activity related entity data.
*
* @ingroup activity_creator_api
*/
function social_lms_integrator_iteration_enrollments_req_activity_creator_related_entity_object_alter(array &$related_object, array &$data) {
// We return Iteration as related object for all Iteration Enrollments.
if (isset($related_object['target_type']) && $related_object['target_type'] === 'iteration_enrollment') {
$entity_storage = \Drupal::entityTypeManager()
->getStorage($related_object['target_type']);
$entity = $entity_storage->load($related_object['target_id']);
if ($entity instanceof IterationEnrollmentInterface) {
/** @var \Drupal\social_lms_integrator_enrollment\Entity\IterationEnrollment $entity */
$iteration_id = $entity->getFieldValue('field_iteration', 'target_id');
if (!empty($iteration_id)) {
$related_object['target_type'] = 'node';
$related_object['target_id'] = $iteration_id;
}
}
}
}
/**
* Implements hook_activity_recipient_iteration_organizer_alter().
*/
/*
function social_lms_integrator_iteration_enrollments_req_activity_recipient_iteration_organizers_alter(array &$recipients, Node $iteration, $data) {
$receiver = '';
$organizers = $iteration->get('field_iteration_managers')->getValue();
if ($data['target_type'] === 'iteration_enrollment' && !empty($data['target_id'])) {
$enrollment = IterationEnrollment::load($data['target_id']);
$receiver = $enrollment->getAccount();
}
// If there are more organizers we want them to receive a notification too
// so we add them to the array of recipients.
if (!empty($organizers)) {
foreach ($organizers as $organizer) {
// We don't want Organizers to receive activity_on_iterations_im_organizing.
// It will already receive it as part of a different context.
if (!empty($receiver) && $organizer['target_id'] === $receiver) {
continue;
}
// Make sure we don't add the people twice.
if (!in_array($organizer['target_id'], array_column($recipients, 'target_id'))) {
$recipients[] = [
'target_type' => 'user',
'target_id' => $organizer['target_id'],
];
}
}
}
}
*/
/**
* Implements hook_activity_send_email_notifications_alter().
*/
function social_lms_integrator_iteration_enrollments_req_activity_send_email_notifications_alter(array &$items, array $email_message_templates) {
if (isset($email_message_templates['request_iteration_enrollment'])) {
$items['what_manage']['templates'][] = 'request_iteration_enrollment';
}
}