PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/core/Services/Kaltura/Controller.php

https://gitlab.com/ElvisAns/tiki
PHP | 94 lines | 63 code | 13 blank | 18 comment | 5 complexity | 4fb6ff61f8cb9a205c9f5edf3af2f90a MD5 | raw file
  1. <?php
  2. // (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
  3. //
  4. // All Rights Reserved. See copyright.txt for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  6. // $Id$
  7. class Services_Kaltura_Controller
  8. {
  9. public function setUp()
  10. {
  11. Services_Exception_Disabled::check('feature_kaltura');
  12. }
  13. public function action_upload($input)
  14. {
  15. $perms = Perms::get();
  16. if (! $perms->upload_videos) {
  17. throw new Services_Exception_Denied('Not allowed to upload videos');
  18. }
  19. global $user, $prefs;
  20. $kalturalib = TikiLib::lib('kalturauser');
  21. $identifier = uniqid();
  22. $cwflashVars = [
  23. 'uid' => $user ? $user : 'Anonymous',
  24. 'partnerId' => $prefs['kaltura_partnerId'],
  25. 'ks' => $kalturalib->getSessionKey(),
  26. 'afterAddEntry' => 'afterAddEntry_' . $identifier,
  27. 'close' => 'onContributionWizardClose',
  28. 'showCloseButton' => false,
  29. 'Permissions' => 1, // 1=public, 2=private, 3=group, 4=friends
  30. ];
  31. $entries = $input->entryId->word();
  32. $message = null;
  33. if ($entries) {
  34. if (count($entries) > 1) {
  35. $message = tr('You have successfully added %0 new media items', count($entries));
  36. } else {
  37. $message = tr('You have successfully added one new media item');
  38. }
  39. }
  40. return [
  41. 'identifier' => $identifier,
  42. 'flashVars' => json_encode($cwflashVars),
  43. 'message' => $message,
  44. 'entries' => $entries,
  45. ];
  46. }
  47. /**
  48. * @param $input JitFilter
  49. * sort_mode string default desc_createdAt
  50. * find string unusued
  51. * maxRecords int entries per page
  52. * offset int for paging
  53. * formId string id of the form to add the media to
  54. * targetName string name of the target hidden input
  55. *
  56. * @return array
  57. * @throws Exception
  58. * @throws Services_Exception_Denied
  59. */
  60. public function action_list($input)
  61. {
  62. $perms = Perms::get();
  63. if (! $perms->upload_videos) {
  64. throw new Services_Exception_Denied('Not allowed to upload videos');
  65. }
  66. $sort_mode = $input->sort_mode->word() ?: 'desc_createdAt';
  67. $find = $input->find->text(); // TODO
  68. $page_size = $input->maxRecords->int() ?: -1; // TODO paging $prefs['maxRecords'];
  69. $offset = max(0, $input->offset->int());
  70. $page = ($offset / $page_size) + 1;
  71. $kalturaadminlib = TikiLib::lib('kalturaadmin');
  72. $kmedialist = $kalturaadminlib->listMedia($sort_mode, $page, $page_size, $find);
  73. $out = [
  74. 'entries' => $kmedialist->objects,
  75. 'totalCount' => $kmedialist->totalCount,
  76. 'formId' => $input->formId->text(),
  77. 'targetName' => $input->targetName->text(),
  78. ];
  79. return $out;
  80. }
  81. }