PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/controller/dashboard/activity.php

https://github.com/alugo/Goteo
PHP | 164 lines | 91 code | 28 blank | 45 comment | 25 complexity | 94abf1bc02b7bce552a93d60ea2a8fd3 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\Dashboard {
  21. use Goteo\Model,
  22. Goteo\Core\Redirection,
  23. Goteo\Library\Message,
  24. Goteo\Library\Text,
  25. Goteo\Library\Listing;
  26. class Activity {
  27. // listados de proyectos a mostrar (proyectos que cofinancia y proyectos suyos)
  28. public static function projList ($user) {
  29. $lists = array();
  30. // mis proyectos
  31. $projects = Model\Project::ofmine($user->id);
  32. if (!empty($projects)) {
  33. $lists['my_projects'] = Listing::get($projects);
  34. }
  35. // proyectos que cofinancio
  36. $invested = Model\User::invested($user->id, false);
  37. if (!empty($invested)) {
  38. $lists['invest_on'] = Listing::get($invested);
  39. }
  40. return $lists;
  41. }
  42. // eventos a mostrar en su muro
  43. public static function wall ($user) {
  44. return null;
  45. /*
  46. * Depurar antes de poner esto
  47. *
  48. // eventos privados del usuario
  49. $items['private'] = Feed::getUserItems($_SESSION['user']->id, 'private');
  50. // eventos de proyectos que he cofinanciado
  51. $items['supported'] = Feed::getUserItems($_SESSION['user']->id, 'supported');
  52. // eventos de proyectos donde he mensajeado o comentado
  53. $items['comented'] = Feed::getUserItems($_SESSION['user']->id, 'comented');
  54. *
  55. */
  56. }
  57. // acciones de certificado de donativo
  58. public static function donor ($user) {
  59. // ver si es donante, cargando sus datos
  60. $donation = Model\User\Donor::get($user->id);
  61. $donation->dates = Model\User\Donor::getDates($donation->user, $donation->year);
  62. $donation->userData = Model\User::getMini($donation->user);
  63. if (!$donation || !$donation instanceof Model\User\Donor) {
  64. Message::Error(Text::get('dashboard-donor-no_donor'));
  65. throw new Redirection('/dashboard/activity');
  66. }
  67. if ($action == 'edit' && $donation->confirmed) {
  68. Message::Error(Text::get('dashboard-donor-confirmed'));
  69. throw new Redirection('/dashboard/activity/donor');
  70. }
  71. // si están guardando, actualizar los datos y guardar
  72. if ($action == 'save' && $_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['save'] == 'donation') {
  73. $donation->edited = 1;
  74. $donation->confirmed = 0;
  75. $donation->name = $_POST['name'];
  76. $donation->nif = $_POST['nif'];
  77. $donation->address = $_POST['address'];
  78. $donation->zipcode = $_POST['zipcode'];
  79. $donation->location = $_POST['location'];
  80. $donation->country = $_POST['country'];
  81. if ($donation->save()) {
  82. Message::Info(Text::get('dashboard-donor-saved'));
  83. throw new Redirection('/dashboard/activity/donor');
  84. } else {
  85. Message::Error(Text::get('dashboard-donor-save_fail'));
  86. throw new Redirection('/dashboard/activity/donor/edit');
  87. }
  88. }
  89. if ($action == 'confirm') {
  90. // marcamos que los datos estan confirmados
  91. Model\User\Donor::setConfirmed($user->id);
  92. Message::Info(Text::get('dashboard-donor-confirmed'));
  93. throw new Redirection('/dashboard/activity/donor');
  94. }
  95. if ($action == 'download') {
  96. // preparamos los datos para el pdf
  97. // generamos el pdf y lo mosteramos con la vista específica
  98. // estos pdf se guardan en /data/pdfs/donativos
  99. // el formato del archivo es: Ymd_nif_userid
  100. // se genera una vez, si ya está generado se abre directamente
  101. if (!empty($donation->pdf) && file_exists('data/pdfs/donativos/' . $donation->pdf)) {
  102. // forzar descarga
  103. header('Content-type: application/pdf');
  104. header("Content-disposition: attachment; filename={$donation->pdf}");
  105. header("Content-Transfer-Encoding: binary");
  106. echo file_get_contents('data/pdfs/donativos/' . $donation->pdf);
  107. die();
  108. } else {
  109. $objeto = new \Goteo\Library\Num2char($donation->amount, null);
  110. $donation->amount_char = $objeto->getLetra();
  111. $filename = "certificado_" . date('Ymd') . "_{$donation->nif}_{$donation->user}.pdf";
  112. $debug = false;
  113. if ($debug)
  114. header('Content-type: text/html');
  115. require_once 'library/pdf.php'; // Libreria pdf
  116. $pdf = donativeCert($donation);
  117. if ($debug) {
  118. echo 'FIN';
  119. echo '<hr><pre>' . print_r($pdf, 1) . '</pre>';
  120. } else {
  121. $pdf->Output('data/pdfs/donativos/' . $filename, 'F');
  122. $donation->setPdf($filename);
  123. // throw new Redirection('/dashboard/activity/donor/download/'.$donation->pdf);
  124. header('Content-type: application/pdf');
  125. header("Content-disposition: attachment; filename={$donation->pdf}");
  126. header("Content-Transfer-Encoding: binary");
  127. echo $pdf->Output('', 'S');
  128. die;
  129. }
  130. }
  131. }
  132. // fin action download
  133. return $donation;
  134. }
  135. }
  136. }