PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/controller/ws.php

https://github.com/alugo/Goteo
PHP | 179 lines | 112 code | 33 blank | 34 comment | 20 complexity | 85aa3dcd84cf07d966772a5b01437d74 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /*
  3. * Copyright (C) 2012 Platoniq y Fundacič´¸n Fuentes Abiertas (see README for details)
  4. * This file is part of Goteo.
  5. *
  6. * Goteo is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Goteo is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with Goteo. If not, see <http://www.gnu.org/licenses/agpl.txt>.
  18. *
  19. */
  20. namespace Goteo\Controller {
  21. use Goteo\Model;
  22. class Ws extends \Goteo\Core\Controller {
  23. public function get_home_post($id) {
  24. $Post = Model\Post::get($id);
  25. header ('HTTP/1.1 200 Ok');
  26. echo <<< EOD
  27. <h3>{$Post->title}</h3>
  28. <div class="embed">{$Post->media->getEmbedCode()}</div>
  29. <div class="description">{$Post->text}</div>
  30. EOD;
  31. die;
  32. }
  33. public function get_faq_order($section) {
  34. $next = Model\Faq::next($section);
  35. header ('HTTP/1.1 200 Ok');
  36. echo $next;
  37. die;
  38. }
  39. public function get_criteria_order($section) {
  40. $next = Model\Criteria::next($section);
  41. header ('HTTP/1.1 200 Ok');
  42. echo $next;
  43. die;
  44. }
  45. public function set_review_criteria($user, $review) {
  46. // comprobar que tiene asignada esta revision
  47. if (Model\User\Review::is_legal($user, $review)) {
  48. $score = new Model\User\Review (array (
  49. 'user' => $user,
  50. 'id' => $review
  51. ));
  52. $parts = explode('-', $_POST['campo']);
  53. if ($parts[0] == 'criteria') {
  54. $criteria = $parts[1];
  55. } else {
  56. header ('HTTP/1.1 400 Bad request');
  57. die;
  58. }
  59. $value = $_POST['valor'];
  60. // puntuamos
  61. if ($score->setScore($criteria, $value)) {
  62. $result = 'Ok';
  63. } else {
  64. $result = 'fail';
  65. }
  66. // recalculamos
  67. $new_score = $score->recount();
  68. header ('HTTP/1.1 200 Ok');
  69. echo $new_score->score.'/'.$new_score->max;
  70. /*
  71. echo "Usuario: $user<br />";
  72. echo "Revision: $review<br />";
  73. echo "Criterio: {$criteria}<br />";
  74. echo "Valor: {$value}<br />";
  75. echo "Resulta: $result<br />";
  76. echo "<pre>".print_r($new_score, 1)."</pre>";
  77. *
  78. */
  79. die;
  80. } else {
  81. header ('HTTP/1.1 403 Forbidden');
  82. die;
  83. }
  84. }
  85. public function set_review_comment($user, $review) {
  86. // comprobar que tiene asignada esta revision
  87. if (Model\User\Review::is_legal($user, $review)) {
  88. $comment = new Model\User\Review (array (
  89. 'user' => $user,
  90. 'id' => $review
  91. ));
  92. $parts = explode('-', $_POST['campo']);
  93. if (in_array($parts[0], array('project', 'owner', 'reward')) &&
  94. in_array($parts[1], array('evaluation', 'recommendation'))) {
  95. $section = $parts[0];
  96. $field = $parts[1];
  97. $text = $_POST['valor'];
  98. if ($comment->setComment($section, $field, $text)) {
  99. $result = 'Grabado';
  100. } else {
  101. $result = 'Error';
  102. }
  103. header ('HTTP/1.1 200 Ok');
  104. echo $result;
  105. die;
  106. } else {
  107. header ('HTTP/1.1 400 Bad request');
  108. die;
  109. }
  110. } else {
  111. header ('HTTP/1.1 403 Forbidden');
  112. die;
  113. }
  114. }
  115. public function get_template_content($id) {
  116. $Template = \Goteo\Library\Template::get($id);
  117. header ('HTTP/1.1 200 Ok');
  118. echo $Template->title . '#$#$#' . $Template->text;
  119. die;
  120. }
  121. /*
  122. * Marcar recompensa cumplida
  123. */
  124. public function fulfill_reward($project, $user) {
  125. if (Model\Project::isMine($project, $user)) {
  126. $parts = explode('-', $_POST['token']);
  127. if ($parts[0] == 'ful_reward') {
  128. if (Model\Invest::setFulfilled($parts[1], $parts[2])) {
  129. header ('HTTP/1.1 200 Ok');
  130. echo 'Recompensa '.$_POST['token'].' marcada como cumplida por '.$user;
  131. die;
  132. } else {
  133. header ('HTTP/1.1 200 Ok');
  134. die;
  135. }
  136. } else {
  137. header ('HTTP/1.1 400 Bad request');
  138. die;
  139. }
  140. } else {
  141. header ('HTTP/1.1 403 Forbidden');
  142. die;
  143. }
  144. }
  145. }
  146. }