ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMobMultiSrtUpload Class Reference

Handler class for multi srt upload. More...

+ Collaboration diagram for ilMobMultiSrtUpload:

Public Member Functions

 __construct (ilMobMultiSrtInt $a_multi_srt)
 
 getMultiSrtUploadDir ()
 Get directory for multi srt upload. More...
 
 uploadMultipleSubtitleFile (array $a_file)
 Upload multi srt file. More...
 
 clearMultiSrtDirectory ()
 Clear multi feedback directory. More...
 
 getMultiSrtFiles ()
 Get all srt files of srt multi upload. More...
 
 moveMultiSrtFiles ()
 Move all srt files that could be mapped to media objects. More...
 

Protected Attributes

ZipAdapter $zip
 
ilMobMultiSrtInt $multi_srt
 
ilLanguage $lng
 
MetadataManager $md
 

Detailed Description

Handler class for multi srt upload.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e

Definition at line 27 of file class.ilMobMultiSrtUpload.php.

Constructor & Destructor Documentation

◆ __construct()

ilMobMultiSrtUpload::__construct ( ilMobMultiSrtInt  $a_multi_srt)
Parameters
ilMobMultiSrtInt$a_multi_srtadapter implementation

Definition at line 37 of file class.ilMobMultiSrtUpload.php.

References $DIC, $lng, and ILIAS\Repository\lng().

39  {
40  global $DIC;
41 
42  $lng = $DIC->language();
43  $this->zip = $DIC->mediaObjects()->internal()->domain()->resources()->zip();
44  $this->md = $DIC->mediaObjects()->internal()->domain()->metadata();
45 
46  $this->lng = $lng;
47  $this->multi_srt = $a_multi_srt;
48  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ clearMultiSrtDirectory()

ilMobMultiSrtUpload::clearMultiSrtDirectory ( )

Clear multi feedback directory.

Definition at line 83 of file class.ilMobMultiSrtUpload.php.

References ilFileUtils\delDir(), and getMultiSrtUploadDir().

83  : void
84  {
86  }
getMultiSrtUploadDir()
Get directory for multi srt upload.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:

◆ getMultiSrtFiles()

ilMobMultiSrtUpload::getMultiSrtFiles ( )

Get all srt files of srt multi upload.

Definition at line 91 of file class.ilMobMultiSrtUpload.php.

References $lang, ilFileUtils\getDir(), and getMultiSrtUploadDir().

Referenced by moveMultiSrtFiles().

91  : array
92  {
93  $items = array();
94 
95  $lang_codes = $this->md->getLOMLanguageCodes();
96 
97  $dir = $this->getMultiSrtUploadDir();
98  $files = ilFileUtils::getDir($dir);
99  foreach ($files as $k => $i) {
100  // check directory
101  if ($i["type"] == "file" && !in_array($k, array(".", ".."))) {
102  if (pathinfo($k, PATHINFO_EXTENSION) == "srt") {
103  $lang = "";
104  if (substr($k, strlen($k) - 7, 1) == "_") {
105  $lang = substr($k, strlen($k) - 6, 2);
106  if (!in_array($lang, $lang_codes)) {
107  $lang = "";
108  }
109  }
110  $items[] = array("filename" => $k, "lang" => $lang);
111  }
112  }
113  }
114 
115  foreach ($this->multi_srt->getMobIds() as $mob) {
116  $m = new ilObjMediaObject($mob);
117  $mi = $m->getMediaItem("Standard");
118  if ($mi->getLocationType() == "LocalFile" && is_int(strpos($mi->getFormat(), "video"))) {
119  // $loc is e.g. "echo-hereweare.mp4", we not look for
120  // "echo-hereweare_<langcode>.srt" files
121  $loc = pathinfo($mi->getLocation(), PATHINFO_FILENAME);
122  foreach ($items as $i => $item) {
123  if (substr($item["filename"], 0, strlen($loc)) == $loc &&
124  substr($item["filename"], strlen($loc), 1) == "_" &&
125  pathinfo($item["filename"], PATHINFO_EXTENSION) == "srt") {
126  $l = substr($item["filename"], strlen($loc) + 1, 2);
127  if (in_array($l, $lang_codes)) {
128  $items[$i]["lang"] = $l;
129  $items[$i]["mob"] = $mob;
130  $items[$i]["mob_title"] = $m->getTitle();
131  }
132  }
133  }
134  }
135  }
136 
137  return $items;
138  }
getMultiSrtUploadDir()
Get directory for multi srt upload.
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory
$lang
Definition: xapiexit.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMultiSrtUploadDir()

ilMobMultiSrtUpload::getMultiSrtUploadDir ( )

Get directory for multi srt upload.

Definition at line 53 of file class.ilMobMultiSrtUpload.php.

Referenced by clearMultiSrtDirectory(), getMultiSrtFiles(), moveMultiSrtFiles(), and uploadMultipleSubtitleFile().

53  : string
54  {
55  return $this->multi_srt->getUploadDir();
56  }
+ Here is the caller graph for this function:

◆ moveMultiSrtFiles()

ilMobMultiSrtUpload::moveMultiSrtFiles ( )

Move all srt files that could be mapped to media objects.

Definition at line 143 of file class.ilMobMultiSrtUpload.php.

References getMultiSrtFiles(), and getMultiSrtUploadDir().

143  : int
144  {
145  $items = $this->getMultiSrtFiles();
146  $cnt = 0;
147  foreach ($items as $i) {
148  if ($i["mob"] > 0 && $i["lang"] != "") {
149  $mob = new ilObjMediaObject($i["mob"]);
150  $mob->uploadSrtFile($this->getMultiSrtUploadDir() . "/" . $i["filename"], $i["lang"], "rename");
151  $cnt++;
152  }
153  }
154  return $cnt;
155  }
getMultiSrtFiles()
Get all srt files of srt multi upload.
getMultiSrtUploadDir()
Get directory for multi srt upload.
+ Here is the call graph for this function:

◆ uploadMultipleSubtitleFile()

ilMobMultiSrtUpload::uploadMultipleSubtitleFile ( array  $a_file)

Upload multi srt file.

Parameters
array$a_filefile info array
Exceptions
ilException
ilMobSrtUploadException

Definition at line 66 of file class.ilMobMultiSrtUpload.php.

References ilFileUtils\delDir(), getMultiSrtUploadDir(), ILIAS\Repository\lng(), ilFileUtils\makeDirParents(), and ilFileUtils\moveUploadedFile().

68  : void {
69  if (!is_file($a_file["tmp_name"])) {
70  throw new ilMobSrtUploadException($this->lng->txt("cont_srt_zip_file_could_not_be_uploaded"));
71  }
72 
73  $dir = $this->getMultiSrtUploadDir();
74  ilFileUtils::delDir($dir, true);
76  ilFileUtils::moveUploadedFile($a_file["tmp_name"], "multi_srt.zip", $dir . "/" . "multi_srt.zip");
77  $this->zip->unzipFile($dir . "/multi_srt.zip");
78  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
getMultiSrtUploadDir()
Get directory for multi srt upload.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

Field Documentation

◆ $lng

ilLanguage ilMobMultiSrtUpload::$lng
protected

Definition at line 31 of file class.ilMobMultiSrtUpload.php.

Referenced by __construct().

◆ $md

MetadataManager ilMobMultiSrtUpload::$md
protected

Definition at line 32 of file class.ilMobMultiSrtUpload.php.

◆ $multi_srt

ilMobMultiSrtInt ilMobMultiSrtUpload::$multi_srt
protected

Definition at line 30 of file class.ilMobMultiSrtUpload.php.

◆ $zip

ZipAdapter ilMobMultiSrtUpload::$zip
protected

Definition at line 29 of file class.ilMobMultiSrtUpload.php.


The documentation for this class was generated from the following file: