student_publication.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <?php
  2. namespace Model;
  3. use Database;
  4. use ResultSet;
  5. /**
  6. * Represent a database "student_publication" object.
  7. *
  8. * Note:
  9. *
  10. * Each database column is mapped to a property.
  11. *
  12. * The item_property table is available through its own property but is loaded
  13. * alongside document data.
  14. *
  15. * Some db query functions exists in this class and would need to be adapted
  16. * to Symphony once it is moved to production. Yet the object structure should
  17. * stay.
  18. *
  19. * @see \Model\ItemProperty
  20. * @see table c_student_publication
  21. * @license see /license.txt
  22. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
  23. */
  24. class StudentPublication
  25. {
  26. public static function void()
  27. {
  28. static $result = null;
  29. if ($result) {
  30. return $result;
  31. }
  32. $result = new self();
  33. return $result;
  34. }
  35. /**
  36. * @return Model\StudentPublicationRepository
  37. */
  38. public static function repository()
  39. {
  40. return StudentPublicationRepository::instance();
  41. }
  42. /**
  43. *
  44. * @param string $where
  45. * @return \ResultSet
  46. */
  47. public static function query($where)
  48. {
  49. return self::repository()->query($where);
  50. }
  51. /**
  52. *
  53. * @param int|Course $c_id
  54. * @param int $id
  55. * @return \Model\StudentPublication
  56. */
  57. public static function get_by_id($c_id, $id)
  58. {
  59. return self::repository()->get_by_id($c_id, $id);
  60. }
  61. protected $c_id = 0;
  62. protected $id = 0;
  63. protected $url = '';
  64. protected $title = '';
  65. protected $description = '';
  66. protected $author = '';
  67. protected $active = null;
  68. protected $accepted = false;
  69. protected $post_group_id = 0;
  70. protected $sent_date = 0;
  71. protected $filetype = '';
  72. protected $has_properties = 0;
  73. protected $view_properties = null;
  74. protected $qualification = 0;
  75. protected $date_of_qualification = 0;
  76. protected $parent_id = 0;
  77. protected $qualificator_id = 0;
  78. protected $weight = 0;
  79. protected $session_id = 0;
  80. protected $user_id = null;
  81. protected $allow_text_assignment = 0;
  82. protected $contains_file = 0;
  83. protected $course = null;
  84. protected $item_property = null;
  85. public function __construct($data)
  86. {
  87. $data = (object) $data;
  88. $this->c_id = (int) $data->c_id;
  89. $this->id = (int) $data->id;
  90. $this->url = $data->url;
  91. $this->title = $data->title;
  92. $this->description = $data->description;
  93. $this->author = $data->author;
  94. $this->active = $data->active;
  95. $this->accepted = $data->accepted;
  96. $this->post_group_id = $data->post_group_id;
  97. $this->sent_date = $data->sent_date;
  98. $this->filetype = $data->filetype;
  99. $this->has_properties = $data->has_properties;
  100. $this->view_properties = $data->view_properties;
  101. $this->qualification = $data->qualification;
  102. $this->date_of_qualification = $data->date_of_qualification;
  103. $this->parent_id = $data->parent_id;
  104. $this->qualificator_id = $data->qualificator_id;
  105. $this->weight = $data->weight;
  106. $this->session_id = $data->session_id;
  107. $this->user_id = $data->user_id;
  108. $this->allow_text_assignment = $data->allow_text_assignment;
  109. $this->contains_file = $data->contains_file;
  110. $this->course = $data->course;
  111. $this->item_property = $data->item_property;
  112. $this->course = null;
  113. if (isset($data->property_id)) {
  114. $property = (array) $data;
  115. $property = (object) $property;
  116. $property->id = $property->property_id;
  117. $this->item_property = ItemProperty::create($property);
  118. } else {
  119. $this->item_property = null;
  120. }
  121. }
  122. public function get_c_id()
  123. {
  124. return $this->c_id;
  125. }
  126. public function set_c_id($value)
  127. {
  128. $this->c_id = $value;
  129. }
  130. public function get_id()
  131. {
  132. return $this->id;
  133. }
  134. public function set_id($value)
  135. {
  136. $this->id = $value;
  137. }
  138. public function get_url()
  139. {
  140. return $this->url;
  141. }
  142. public function set_url($value)
  143. {
  144. $this->url = $value;
  145. }
  146. public function get_title()
  147. {
  148. return $this->title;
  149. }
  150. public function set_title($value)
  151. {
  152. $this->title = $value;
  153. }
  154. public function get_description()
  155. {
  156. return $this->description;
  157. }
  158. public function set_description($value)
  159. {
  160. $this->description = $value;
  161. }
  162. public function get_author()
  163. {
  164. return $this->author;
  165. }
  166. public function set_author($value)
  167. {
  168. $this->author = $value;
  169. }
  170. public function get_active()
  171. {
  172. return $this->active;
  173. }
  174. public function set_active($value)
  175. {
  176. $this->active = $value;
  177. }
  178. public function get_accepted()
  179. {
  180. return $this->accepted;
  181. }
  182. public function set_accepted($value)
  183. {
  184. $this->accepted = $value;
  185. }
  186. public function get_post_group_id()
  187. {
  188. return $this->post_group_id;
  189. }
  190. public function set_post_group_id($value)
  191. {
  192. $this->post_group_id = $value;
  193. }
  194. public function get_sent_date()
  195. {
  196. return $this->sent_date;
  197. }
  198. public function set_sent_date($value)
  199. {
  200. $this->sent_date = $value;
  201. }
  202. public function get_filetype()
  203. {
  204. return $this->filetype;
  205. }
  206. public function set_filetype($value)
  207. {
  208. $this->filetype = $value;
  209. }
  210. public function get_has_properties()
  211. {
  212. return $this->has_properties;
  213. }
  214. public function set_has_properties($value)
  215. {
  216. $this->has_properties = $value;
  217. }
  218. public function get_view_properties()
  219. {
  220. return $this->view_properties;
  221. }
  222. public function set_view_properties($value)
  223. {
  224. $this->view_properties = $value;
  225. }
  226. public function get_qualification()
  227. {
  228. return $this->qualification;
  229. }
  230. public function set_qualification($value)
  231. {
  232. $this->qualification = $value;
  233. }
  234. public function get_date_of_qualification()
  235. {
  236. return $this->date_of_qualification;
  237. }
  238. public function set_date_of_qualification($value)
  239. {
  240. $this->date_of_qualification = $value;
  241. }
  242. public function get_parent_id()
  243. {
  244. return $this->parent_id;
  245. }
  246. public function set_parent_id($value)
  247. {
  248. $this->parent_id = $value;
  249. }
  250. public function get_qualificator_id()
  251. {
  252. return $this->qualificator_id;
  253. }
  254. public function set_qualificator_id($value)
  255. {
  256. $this->qualificator_id = $value;
  257. }
  258. public function get_weight()
  259. {
  260. return $this->weight;
  261. }
  262. public function set_weight($value)
  263. {
  264. $this->weight = $value;
  265. }
  266. public function get_session_id()
  267. {
  268. return $this->session_id;
  269. }
  270. public function set_session_id($value)
  271. {
  272. $this->session_id = $value;
  273. }
  274. public function get_user_id()
  275. {
  276. return $this->user_id;
  277. }
  278. public function set_user_id($value)
  279. {
  280. $this->user_id = $value;
  281. }
  282. public function get_allow_text_assignment()
  283. {
  284. return $this->allow_text_assignment;
  285. }
  286. public function set_allow_text_assignment($value)
  287. {
  288. $this->allow_text_assignment = $value;
  289. }
  290. public function get_contains_file()
  291. {
  292. return $this->contains_file;
  293. }
  294. public function set_contains_file($value)
  295. {
  296. $this->contains_file = $value;
  297. }
  298. public function is_folder()
  299. {
  300. return $this->filetype == 'folder';
  301. }
  302. public function is_file()
  303. {
  304. return $this->filetype == 'file';
  305. }
  306. public function is_visible()
  307. {
  308. $this->get_item_property()->get_visibility() == 1;
  309. }
  310. public function is_accessible($user = null)
  311. {
  312. $user_id = $user ? $user : api_get_user_id();
  313. $result = $this->is_visible() || $this->get_user_id() == $user_id || api_is_allowed_to_edit();
  314. return $result;
  315. }
  316. public function get_absolute_path()
  317. {
  318. return api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/' . $this->get_url();
  319. }
  320. /**
  321. *
  322. * @return \Model\ItemProperty
  323. */
  324. public function get_item_property()
  325. {
  326. if ($this->item_property && $this->item_property->get_c_id() == $this->c_id && $this->item_property->get_ref() == $this->id) {
  327. return $this->item_property;
  328. }
  329. $this->item_property = ItemProperty::get_by_ref($this->id, TOOL_DOCUMENT);
  330. return $this->item_property;
  331. }
  332. /**
  333. *
  334. * @param bool $all
  335. * @return ResultSet|array
  336. */
  337. public function get_children()
  338. {
  339. if (!$this->is_folder()) {
  340. return array();
  341. }
  342. $id = $this->id;
  343. $c_id = $this->c_id;
  344. $where = "pub.c_id = $c_id AND pub.parent_id = $id";
  345. return self::query($where);
  346. }
  347. }
  348. class StudentPublicationRepository
  349. {
  350. /**
  351. *
  352. * @staticvar null $result
  353. * @return StudentPublicationRepository
  354. */
  355. public static function instance()
  356. {
  357. static $result = null;
  358. if (empty($result)) {
  359. $result = new self();
  360. }
  361. return $result;
  362. }
  363. /**
  364. *
  365. * @param string $where
  366. * @return \ResultSet
  367. */
  368. public function query($where)
  369. {
  370. $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  371. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  372. $tool = 'work';
  373. $sql = "SELECT pub.*,
  374. prop.id AS property_id,
  375. prop.tool,
  376. prop.insert_user_id,
  377. prop.insert_date,
  378. prop.lastedit_date,
  379. prop.ref,
  380. prop.lastedit_type,
  381. prop.lastedit_user_id,
  382. prop.to_group_id,
  383. prop.to_user_id,
  384. prop.visibility,
  385. prop.start_visible,
  386. prop.end_visible,
  387. prop.id_session
  388. FROM
  389. $table AS pub,
  390. $table_item_property AS prop
  391. WHERE
  392. (pub.id = prop.ref AND
  393. pub.c_id = prop.c_id AND
  394. prop.tool = '$tool')";
  395. $sql .= $where ? "AND ($where)" : '';
  396. $result = new ResultSet($sql);
  397. return $result->return_type(__CLASS__);
  398. }
  399. /**
  400. *
  401. * @param int|Course $c_id
  402. * @param int $id
  403. * @return \Model\StudentPublication
  404. */
  405. public function get_by_id($c_id, $id)
  406. {
  407. $c_id = is_object($c_id) ? $c_id->get_id() : (int) $c_id;
  408. return $this->query("pub.c_id = $c_id AND pub.id = $id")->first();
  409. }
  410. public function update($pub)
  411. {
  412. }
  413. }