Forked from
Stud.IP / Stud.IP
1998 commits behind, 186 commits ahead of the upstream repository.
-
Closes #3586 and #3587 Merge request studip/studip!2480
Closes #3586 and #3587 Merge request studip/studip!2480
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
mymaterial.php 12.78 KiB
<?php
class Oer_MymaterialController extends AuthenticatedController
{
protected $_autobind = true;
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
if (
!Config::get()->OERCAMPUS_ENABLED
||
!$GLOBALS['perm']->have_perm(Config::get()->OER_PUBLIC_STATUS)
) {
throw new AccessDeniedException();
}
PageLayout::setTitle(_('Lernmaterialien'));
}
public function index_action()
{
if (Navigation::hasItem("/oer/mymaterial")) {
Navigation::activateItem("/oer/mymaterial");
}
$this->materialien = OERMaterial::findMine();
$this->buildSidebar();
}
public function edit_action(OERMaterial $material = null)
{
PageLayout::setTitle($material->isNew() ? _('Neues Material hochladen') : _('Material bearbeiten'));
if ($material->id && !$material->isMine() && !$GLOBALS['perm']->have_perm('root')) {
throw new AccessDeniedException();
}
$content_types = ['application/x-zip-compressed', 'application/zip', 'application/x-zip'];
$tmp_folder = $GLOBALS['TMP_PATH'] . '/temp_folder_' . md5(uniqid());
if (Request::submitted('delete') && Request::isPost()) {
CSRFProtection::verifyUnsafeRequest();
$material->pushDataToIndexServers('delete');
$material->delete();
PageLayout::postSuccess(_('Das Material wurde gelöscht.'));
$this->redirect('oer/market/index');
return;
} elseif (Request::isPost()) {
CSRFProtection::verifyUnsafeRequest();
$was_new = $material->isNew();
$was_on_twillo = (bool) $material['published_id_on_twillo'];
$data = Request::getArray('data');
$material->setData($data);
if ($data['player_url'] && !$material->hasValidPreviewUrl()) {
PageLayout::postWarning(_('Die angegebene URL muss mit http(s) beginnen.'));
$material->player_url = '';
}
$material['host_id'] = null;
$material['license_identifier'] = Request::get('license', 'CC-BY-SA-4.0');
if (!empty($_FILES['file']['tmp_name'])) {
$material['content_type'] = get_mime_type($_FILES['file']['name']);
if (in_array($material['content_type'], $content_types)) {
mkdir($tmp_folder);
\Studip\ZipArchive::extractToPath($_FILES['file']['tmp_name'], $tmp_folder);
$material['structure'] = $this->getFolderStructure($tmp_folder);
rmdirr($tmp_folder);
} else {
$material['structure'] = null;
}
$material['filename'] = $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $material->getFilePath());
} elseif (!empty($_SESSION['NEW_OER']['tmp_name'])) {
$material['content_type'] = $_SESSION['NEW_OER']['content_type'] ?: get_mime_type($_SESSION['NEW_OER']['tmp_name']);
if (in_array($material['content_type'], $content_types)) {