Select Git revision
OERMaterial.php
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
-
Moritz Strohm authored
Closes #3253 Merge request studip/studip!2209
Moritz Strohm authoredCloses #3253 Merge request studip/studip!2209
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
OERMaterial.php 24.08 KiB
<?php
class OERMaterial extends SimpleORMap
{
protected static function configure($config = [])
{
$config['db_table'] = 'oer_material';
$config['belongs_to']['host'] = [
'class_name' => OERHost::class,
'foreign_key' => 'host_id'
];
$config['has_many']['reviews'] = [
'class_name' => OERReview::class,
'order_by' => 'ORDER BY mkdate DESC',
'on_delete' => 'delete'
];
$config['has_many']['users'] = [
'class_name' => OERMaterialUser::class,
'order_by' => 'ORDER BY position ASC'
];
$config['belongs_to']['license'] = [
'class_name' => License::class,
'foreign_key' => 'license_identifier'
];
$config['serialized_fields']['structure'] = 'JSONArrayObject';
$config['registered_callbacks']['before_store'][] = "cbHashURI";
$config['registered_callbacks']['before_delete'][] = "cbDeleteFile";
parent::configure($config);
}
public static function findAll()
{
return self::findBySQL("draft = '0'");
}
public static function findMine($user_id = null)
{
$user_id = $user_id ?: $GLOBALS['user']->id;
return self::findBySQL("INNER JOIN `oer_material_users` USING (material_id)
WHERE `oer_material_users`.user_id = ?
AND external_contact = '0'
ORDER BY mkdate DESC", [$user_id]
);
}
public static function findByTag($tag_name)
{
self::fetchRemoteSearch($tag_name, true);
$statement = DBManager::get()->prepare("
SELECT oer_material.*
FROM oer_material
INNER JOIN oer_tags_material USING (material_id)
INNER JOIN oer_tags USING (tag_hash)
LEFT JOIN oer_hosts ON (oer_hosts.host_id = oer_material.host_id)
WHERE oer_tags.name = :tag
AND oer_material.draft = '0'
AND (oer_material.host_id IS NULL OR oer_hosts.`active` = '1')
GROUP BY oer_material.material_id
ORDER BY oer_material.mkdate DESC
");
$statement->execute(['tag' => $tag_name]);
$material_data = $statement->fetchAll(PDO::FETCH_ASSOC);
$materials = [];
foreach ($material_data as $data) {
$materials[] = OERMaterial::buildExisting($data);
}
return $materials;
}
public static function findByText($text)