ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilLMMultiSrt Class Reference

Handler class for multi srt upload in learning modules. More...

+ Collaboration diagram for ilLMMultiSrt:

Public Member Functions

 __construct (ilObjLearningModule $a_lm)
 Construcotr. More...
 
 getMultiSrtUploadDir ()
 Get directory for multi srt upload. More...
 
 uploadMultipleSubtitleFile ($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

 $lm
 

Detailed Description

Handler class for multi srt upload in learning modules.

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

Definition at line 12 of file class.ilLMMultiSrt.php.

Constructor & Destructor Documentation

◆ __construct()

ilLMMultiSrt::__construct ( ilObjLearningModule  $a_lm)

Construcotr.

Parameters
ilObjLearningModule$a_lmlearning module

Definition at line 21 of file class.ilLMMultiSrt.php.

22  {
23  $this->lm = $a_lm;
24  }

Member Function Documentation

◆ clearMultiSrtDirectory()

ilLMMultiSrt::clearMultiSrtDirectory ( )

Clear multi feedback directory.

Definition at line 64 of file class.ilLMMultiSrt.php.

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

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

◆ getMultiSrtFiles()

ilLMMultiSrt::getMultiSrtFiles ( )

Get all srt files of srt multi upload.

Definition at line 72 of file class.ilLMMultiSrt.php.

References $files, $l, $lang, $mobs, ilObjMediaObject\_getMobsOfObject(), ilMDLanguageItem\_getPossibleLanguageCodes(), array, ilUtil\getDir(), getMultiSrtUploadDir(), and ilLMPageObject\getPageList().

Referenced by moveMultiSrtFiles().

73  {
74  $items = array();
75 
76  include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
78 
79  $dir = $this->getMultiSrtUploadDir();
80  $files = ilUtil::getDir($dir);
81  foreach ($files as $k => $i)
82  {
83  // check directory
84  if ($i["type"] == "file" && !in_array($k, array(".", "..")))
85  {
86  if (pathinfo($k, PATHINFO_EXTENSION) == "srt")
87  {
88  $lang = "";
89  if (substr($k, strlen($k) - 7, 1) == "_")
90  {
91  $lang = substr($k, strlen($k) - 6, 2);
92  if (!in_array($lang, $lang_codes))
93  {
94  $lang = "";
95  }
96  }
97  $items[] = array("filename" => $k, "lang" => $lang);
98  }
99  }
100  }
101 
102  // add mob information to items
103  // all pages
104  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
105  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
106  $pages = ilLMPageObject::getPageList($this->lm->getId());
107  $mobs = array();
108  foreach ($pages as $page)
109  {
110  // all media objects
111  $pg_mobs = ilObjMediaObject::_getMobsOfObject("lm:pg", $page["obj_id"], 0, "");
112  foreach ($pg_mobs as $k => $pg_mob)
113  {
114  $mobs[$k] = $pg_mob;
115  }
116  }
117  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
118  foreach ($mobs as $mob)
119  {
120  $m = new ilObjMediaObject($mob);
121  $mi = $m->getMediaItem("Standard");
122  if ($mi->getLocationType() == "LocalFile" && is_int(strpos($mi->getFormat(), "video")))
123  {
124  // $loc is e.g. "echo-hereweare.mp4", we not look for
125  // "echo-hereweare_<langcode>.srt" files
126  $loc = pathinfo($mi->getLocation(), PATHINFO_FILENAME);
127  foreach ($items as $i => $item)
128  {
129  if (substr($item["filename"], 0, strlen($loc)) == $loc &&
130  substr($item["filename"], strlen($loc), 1) == "_" &&
131  pathinfo($item["filename"], PATHINFO_EXTENSION) == "srt")
132  {
133  $l = substr($item["filename"], strlen($loc)+1, 2);
134  if (in_array($l, $lang_codes))
135  {
136  $items[$i]["lang"] = $l;
137  $items[$i]["mob"] = $mob;
138  $items[$i]["mob_title"] = $m->getTitle();
139  }
140  }
141  }
142  }
143 
144  }
145 
146  return $items;
147  }
$files
Definition: add-vimline.php:18
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
$mobs
Class ilObjMediaObject.
Create styles array
The data for the language used.
global $l
Definition: afr.php:30
getMultiSrtUploadDir()
Get directory for multi srt upload.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
static getPageList($lm_id)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMultiSrtUploadDir()

ilLMMultiSrt::getMultiSrtUploadDir ( )

Get directory for multi srt upload.

Returns
string diretory

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

References ilUtil\getDataDir().

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

32  {
33  return ilUtil::getDataDir()."/lm_data".
34  "/lm_".$this->lm->getId()."/srt_tmp";
35  }
static getDataDir()
get data directory (outside webspace)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moveMultiSrtFiles()

ilLMMultiSrt::moveMultiSrtFiles ( )

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

Definition at line 152 of file class.ilLMMultiSrt.php.

References getMultiSrtFiles(), and getMultiSrtUploadDir().

153  {
154  $items = $this->getMultiSrtFiles();
155  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
156  $cnt = 0;
157  foreach ($items as $i)
158  {
159  if ($i["mob"] > 0 && $i["lang"] != "")
160  {
161  $mob = new ilObjMediaObject($i["mob"]);
162  $mob->uploadSrtFile($this->getMultiSrtUploadDir()."/".$i["filename"], $i["lang"], "rename");
163  $cnt++;
164  }
165  }
166  return $cnt;
167  }
Class ilObjMediaObject.
getMultiSrtUploadDir()
Get directory for multi srt upload.
getMultiSrtFiles()
Get all srt files of srt multi upload.
+ Here is the call graph for this function:

◆ uploadMultipleSubtitleFile()

ilLMMultiSrt::uploadMultipleSubtitleFile (   $a_file)

Upload multi srt file.

Parameters
array$a_filefile info array
Exceptions
ilLMException

Definition at line 44 of file class.ilLMMultiSrt.php.

References $ilUser, $lng, ilUtil\delDir(), getMultiSrtUploadDir(), ilUtil\makeDirParents(), ilUtil\moveUploadedFile(), and ilUtil\unzip().

45  {
46  global $lng, $ilUser;
47 
48  include_once("./Modules/LearningModule/exceptions/class.ilLMException.php");
49  if (!is_file($a_file["tmp_name"]))
50  {
51  throw new ilLMException($lng->txt("cont_srt_zip_file_could_not_be_uploaded"));
52  }
53 
54  $dir = $this->getMultiSrtUploadDir();
55  ilUtil::delDir($dir, true);
57  ilUtil::moveUploadedFile($a_file["tmp_name"], "multi_srt.zip", $dir."/"."multi_srt.zip");
58  ilUtil::unzip($dir."/multi_srt.zip", true);
59  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
Base exception class for learning modules.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
$ilUser
Definition: imgupload.php:18
global $lng
Definition: privfeed.php:17
getMultiSrtUploadDir()
Get directory for multi srt upload.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:

Field Documentation

◆ $lm

ilLMMultiSrt::$lm
protected

Definition at line 14 of file class.ilLMMultiSrt.php.


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