ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLMMultiSrt.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
14  protected $lm;
15 
22  {
23  $this->lm = $a_lm;
24  }
25 
32  {
33  return ilUtil::getDataDir()."/lm_data".
34  "/lm_".$this->lm->getId()."/srt_tmp";
35  }
36 
37 
44  function uploadMultipleSubtitleFile($a_file)
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  }
60 
65  {
67  }
68 
72  function getMultiSrtFiles()
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  }
148 
152  function moveMultiSrtFiles()
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  }
168 }
$files
Definition: add-vimline.php:18
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
Class ilObjLearningModule.
moveMultiSrtFiles()
Move all srt files that could be mapped to media objects.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
Base exception class for learning modules.
__construct(ilObjLearningModule $a_lm)
Construcotr.
$mobs
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
$ilUser
Definition: imgupload.php:18
Class ilObjMediaObject.
Create styles array
The data for the language used.
static getDataDir()
get data directory (outside webspace)
global $l
Definition: afr.php:30
global $lng
Definition: privfeed.php:17
getMultiSrtUploadDir()
Get directory for multi srt upload.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
getMultiSrtFiles()
Get all srt files of srt multi upload.
static getPageList($lm_id)
static
uploadMultipleSubtitleFile($a_file)
Upload multi srt file.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
clearMultiSrtDirectory()
Clear multi feedback directory.
Handler class for multi srt upload in learning modules.