ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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
 

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 26 of file class.ilMobMultiSrtUpload.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

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

37  {
38  global $DIC;
39 
40  $lng = $DIC->language();
41  $this->zip = $DIC->mediaObjects()->internal()->domain()->resources()->zip();
42 
43  $this->lng = $lng;
44  $this->multi_srt = $a_multi_srt;
45  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ clearMultiSrtDirectory()

ilMobMultiSrtUpload::clearMultiSrtDirectory ( )

Clear multi feedback directory.

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

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

80  : void
81  {
83  }
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 88 of file class.ilMobMultiSrtUpload.php.

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

Referenced by moveMultiSrtFiles().

88  : array
89  {
90  $items = array();
91 
93 
94  $dir = $this->getMultiSrtUploadDir();
95  $files = ilFileUtils::getDir($dir);
96  foreach ($files as $k => $i) {
97  // check directory
98  if ($i["type"] == "file" && !in_array($k, array(".", ".."))) {
99  if (pathinfo($k, PATHINFO_EXTENSION) == "srt") {
100  $lang = "";
101  if (substr($k, strlen($k) - 7, 1) == "_") {
102  $lang = substr($k, strlen($k) - 6, 2);
103  if (!in_array($lang, $lang_codes)) {
104  $lang = "";
105  }
106  }
107  $items[] = array("filename" => $k, "lang" => $lang);
108  }
109  }
110  }
111 
112  foreach ($this->multi_srt->getMobIds() as $mob) {
113  $m = new ilObjMediaObject($mob);
114  $mi = $m->getMediaItem("Standard");
115  if ($mi->getLocationType() == "LocalFile" && is_int(strpos($mi->getFormat(), "video"))) {
116  // $loc is e.g. "echo-hereweare.mp4", we not look for
117  // "echo-hereweare_<langcode>.srt" files
118  $loc = pathinfo($mi->getLocation(), PATHINFO_FILENAME);
119  foreach ($items as $i => $item) {
120  if (substr($item["filename"], 0, strlen($loc)) == $loc &&
121  substr($item["filename"], strlen($loc), 1) == "_" &&
122  pathinfo($item["filename"], PATHINFO_EXTENSION) == "srt") {
123  $l = substr($item["filename"], strlen($loc) + 1, 2);
124  if (in_array($l, $lang_codes)) {
125  $items[$i]["lang"] = $l;
126  $items[$i]["mob"] = $mob;
127  $items[$i]["mob_title"] = $m->getTitle();
128  }
129  }
130  }
131  }
132  }
133 
134  return $items;
135  }
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:26
+ 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 50 of file class.ilMobMultiSrtUpload.php.

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

50  : string
51  {
52  return $this->multi_srt->getUploadDir();
53  }
+ 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 140 of file class.ilMobMultiSrtUpload.php.

References getMultiSrtFiles(), and getMultiSrtUploadDir().

140  : int
141  {
142  $items = $this->getMultiSrtFiles();
143  $cnt = 0;
144  foreach ($items as $i) {
145  if ($i["mob"] > 0 && $i["lang"] != "") {
146  $mob = new ilObjMediaObject($i["mob"]);
147  $mob->uploadSrtFile($this->getMultiSrtUploadDir() . "/" . $i["filename"], $i["lang"], "rename");
148  $cnt++;
149  }
150  }
151  return $cnt;
152  }
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 63 of file class.ilMobMultiSrtUpload.php.

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

65  : void {
66  if (!is_file($a_file["tmp_name"])) {
67  throw new ilMobSrtUploadException($this->lng->txt("cont_srt_zip_file_could_not_be_uploaded"));
68  }
69 
70  $dir = $this->getMultiSrtUploadDir();
71  ilFileUtils::delDir($dir, true);
73  ilFileUtils::moveUploadedFile($a_file["tmp_name"], "multi_srt.zip", $dir . "/" . "multi_srt.zip");
74  $this->zip->unzipFile($dir . "/multi_srt.zip");
75  }
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 30 of file class.ilMobMultiSrtUpload.php.

Referenced by __construct().

◆ $multi_srt

ilMobMultiSrtInt ilMobMultiSrtUpload::$multi_srt
protected

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

◆ $zip

ZipAdapter ilMobMultiSrtUpload::$zip
protected

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


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