PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/www/extensions/SemanticResultFormats/formats/slideshow/SRF_SlideShow.php

https://bitbucket.org/Vanjajanezic/katja
PHP | 178 lines | 107 code | 26 blank | 45 comment | 3 complexity | aa28a3730a104aa72475887dbbc630e0 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, CC0-1.0, LGPL-3.0, Apache-2.0, JSON, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * File holding the SRF_SlideShow class
  4. *
  5. * @author Stephan Gambke
  6. * @file
  7. * @ingroup SemanticResultFormats
  8. */
  9. /**
  10. * The SRF_SlideShow class.
  11. *
  12. * @ingroup SemanticResultFormats
  13. */
  14. class SRFSlideShow extends SMWResultPrinter {
  15. /**
  16. * Get a human readable label for this printer.
  17. *
  18. * @return string
  19. */
  20. public function getName() {
  21. return wfMessage( 'srf-printername-slideshow' )->text();
  22. }
  23. /**
  24. * Return serialised results in specified format.
  25. * Implemented by subclasses.
  26. */
  27. protected function getResultText( SMWQueryResult $res, $outputmode ) {
  28. $html = '';
  29. $id = uniqid();
  30. // build an array of article IDs contained in the result set
  31. $objects = [];
  32. foreach ( $res->getResults() as $key => $object ) {
  33. $objects[] = [ $object->getTitle()->getArticleId() ];
  34. $html .= $key . ': ' . $object->getSerialization() . "<br>\n";
  35. }
  36. // build an array of data about the printrequests
  37. $printrequests = [];
  38. foreach ( $res->getPrintRequests() as $key => $printrequest ) {
  39. $data = $printrequest->getData();
  40. if ( $data instanceof SMWPropertyValue ) {
  41. $name = $data->getDataItem()->getKey();
  42. } else {
  43. $name = null;
  44. }
  45. $printrequests[] = [
  46. $printrequest->getMode(),
  47. $printrequest->getLabel(),
  48. $name,
  49. $printrequest->getOutputFormat(),
  50. $printrequest->getParameters(),
  51. ];
  52. }
  53. // write out results and query params into JS arrays
  54. // Define the srf_filtered_values array
  55. SMWOutputs::requireScript( 'srf_slideshow', Html::inlineScript(
  56. 'srf_slideshow = {};'
  57. )
  58. );
  59. SMWOutputs::requireScript( 'srf_slideshow' . $id, Html::inlineScript(
  60. 'srf_slideshow["' . $id . '"] = ' . json_encode(
  61. [
  62. $objects,
  63. $this->params['template'],
  64. $this->params['delay'] * 1000,
  65. $this->params['height'],
  66. $this->params['width'],
  67. $this->params['nav controls'],
  68. $this->params['effect'],
  69. json_encode( $printrequests ) ,
  70. ]
  71. ) . ';'
  72. )
  73. );
  74. SMWOutputs::requireResource( 'ext.srf.slideshow' );
  75. if ( $this->params['nav controls'] ) {
  76. SMWOutputs::requireResource( 'jquery.ui.slider' );
  77. }
  78. return Html::element(
  79. 'div',
  80. [
  81. 'id' => $id,
  82. 'class' => 'srf-slideshow ' . $id . ' ' . $this->params['class']
  83. ]
  84. );
  85. }
  86. /**
  87. * Check whether a "further results" link would normally be generated for this
  88. * result set with the given parameters.
  89. *
  90. * @param SMWQueryResult $results
  91. *
  92. * @return boolean
  93. */
  94. protected function linkFurtherResults( SMWQueryResult $results ) {
  95. return false;
  96. }
  97. /**
  98. * @see SMWResultPrinter::getParamDefinitions
  99. *
  100. * @since 1.8
  101. *
  102. * @param $definitions array of IParamDefinition
  103. *
  104. * @return array of IParamDefinition|array
  105. */
  106. public function getParamDefinitions( array $definitions ) {
  107. $params = parent::getParamDefinitions( $definitions );
  108. $params['template'] = [
  109. 'default' => '',
  110. 'message' => 'smw_paramdesc_template',
  111. ];
  112. // TODO: Implement named args
  113. // $params['named args'] = new Parameter( 'named args', Parameter::TYPE_BOOLEAN, false );
  114. // $params['named args']->setMessage( 'smw_paramdesc_named_args' );
  115. $params['class'] = [
  116. 'default' => '',
  117. 'message' => 'srf-paramdesc-class',
  118. ];
  119. $params['height'] = [
  120. 'default' => '100px',
  121. 'message' => 'srf-paramdesc-height',
  122. ];
  123. $params['width'] = [
  124. 'default' => '200px',
  125. 'message' => 'srf-paramdesc-width',
  126. ];
  127. $params['delay'] = [
  128. 'type' => 'integer',
  129. 'default' => 5,
  130. 'message' => 'srf-paramdesc-delay',
  131. ];
  132. $params['nav controls'] = [
  133. 'type' => 'boolean',
  134. 'default' => false,
  135. 'message' => 'srf-paramdesc-navigation-controls',
  136. ];
  137. $params['effect'] = [
  138. 'default' => 'none',
  139. 'message' => 'srf-paramdesc-effect',
  140. 'values' => [
  141. 'none',
  142. 'slide left',
  143. 'slide right',
  144. 'slide up',
  145. 'slide down',
  146. 'fade',
  147. 'hide',
  148. ],
  149. ];
  150. return $params;
  151. }
  152. }