PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/core/class/Utente.php

https://github.com/lincetto/gaia
PHP | 1674 lines | 1456 code | 115 blank | 103 comment | 145 complexity | 22b3ca974d1dff63a9b89fe6a7f7c56b MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. * ©2012 Croce Rossa Italiana
  4. */
  5. class Utente extends Persona {
  6. /*
  7. * @param string $password dell'utente
  8. * @return bool
  9. */
  10. public function login($password) {
  11. if ( $this->password == criptaPassword($password) ) {
  12. $this->ultimoAccesso = time();
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }
  18. public static function sesso($cf) {
  19. if (intval(substr($cf, 9, 2)) < 40)
  20. return 'M';
  21. else
  22. return 'F';
  23. }
  24. public static function listaAdmin() {
  25. global $db;
  26. $q = $db->prepare("
  27. SELECT
  28. id
  29. FROM
  30. anagrafica
  31. WHERE
  32. admin > 0
  33. ORDER BY
  34. nome ASC, cognome ASC");
  35. $q->execute();
  36. $r = [];
  37. while ( $k = $q->fetch(PDO::FETCH_NUM) ) {
  38. $r[] = Utente::id($k[0]);
  39. }
  40. return $r;
  41. }
  42. public static function senzaSesso() {
  43. global $db;
  44. $q = $db->prepare("
  45. SELECT
  46. id
  47. FROM
  48. anagrafica
  49. WHERE
  50. sesso IS NULL");
  51. $q->execute();
  52. $r = [];
  53. while ( $k = $q->fetch(PDO::FETCH_NUM) ) {
  54. $r[] = $k[0];
  55. }
  56. return $r;
  57. }
  58. public function nomeCompleto() {
  59. return $this->nome . ' ' . $this->cognome;
  60. }
  61. public function cambiaPassword($nuova) {
  62. $this->password = criptaPassword($nuova);
  63. return true;
  64. }
  65. public function appartenenze() {
  66. $a = Appartenenza::filtra([
  67. ['volontario', $this->id]
  68. ]);
  69. return $a;
  70. }
  71. public function numAppartenenzeTotali($stato = SOGLIA_APPARTENENZE) {
  72. $q = $this->db->prepare("
  73. SELECT
  74. COUNT(*)
  75. FROM
  76. appartenenza
  77. WHERE
  78. volontario = :me
  79. AND
  80. stato > :stato");
  81. $q->bindParam(':me', $this->id);
  82. $q->bindParam(':stato', $stato);
  83. $q->execute();
  84. $q = $q->fetch(PDO::FETCH_NUM);
  85. return $q[0];
  86. }
  87. public function storico() {
  88. return Appartenenza::filtra([
  89. ['volontario', $this->id]
  90. ], 'INIZIO DESC');
  91. }
  92. public function appartenenzePendenti() {
  93. $r = [];
  94. foreach ( Appartenenza::filtra([
  95. ['volontario', $this->id],
  96. ['stato', MEMBRO_PENDENTE]
  97. ]) as $a ) {
  98. if ( !$a->attuale() ) { continue; }
  99. $r[] = $a;
  100. }
  101. return $r;
  102. }
  103. public function in(Comitato $c) {
  104. $a = Appartenenza::filtra([
  105. ['volontario', $this->id],
  106. ['comitato', $c->id]
  107. ]);
  108. foreach ($a as $_a) {
  109. if ($_a->stato >= MEMBRO_ESTESO)
  110. return True;
  111. }
  112. return False;
  113. }
  114. public function volontario() {
  115. return new Volontario($this->id);
  116. }
  117. public function admin() {
  118. global $sessione;
  119. if ( $this->admin && $sessione->adminMode ) {
  120. return true;
  121. } else {
  122. return false;
  123. }
  124. }
  125. public function titoli() {
  126. return TitoloPersonale::filtra([
  127. ['volontario', $this->id]
  128. ]);
  129. }
  130. public function titoliPersonali() {
  131. $r = [];
  132. foreach (TitoloPersonale::filtra([
  133. ['volontario', $this->id]
  134. ]) as $titolo) {
  135. if ( $titolo->titolo()->tipo == TITOLO_PERSONALE ) {
  136. $r[] = $titolo;
  137. }
  138. }
  139. return $r;
  140. }
  141. public function titoliTipo( $tipoTitoli ) {
  142. $r = [];
  143. foreach (TitoloPersonale::filtra([
  144. ['volontario', $this->id]
  145. ]) as $titolo) {
  146. if ( $titolo->titolo()->tipo == $tipoTitoli ) {
  147. $r[] = $titolo;
  148. }
  149. }
  150. return $r;
  151. }
  152. public function haTitolo ( Titolo $titolo ) {
  153. $t = $this->titoli();
  154. foreach ( $t as $x ) {
  155. if ( $x->titolo() == $titolo ) {
  156. return true;
  157. }
  158. }
  159. return false;
  160. }
  161. public function toJSON() {
  162. return [
  163. 'id' => $this->id,
  164. 'nome' => $this->nome,
  165. 'cognome' => $this->cognome,
  166. 'nomeCompleto' => $this->nomeCompleto(),
  167. 'avatar' => $this->avatar()->URL()
  168. ];
  169. }
  170. public function toJSONRicerca() {
  171. if($this->stato == VOLONTARIO) {
  172. $comitato = $this->unComitato();
  173. } else {
  174. $comitato = $this->unComitato(MEMBRO_ORDINARIO);
  175. }
  176. if ( $comitato ) {
  177. $comitato = $comitato->toJSONRicerca();
  178. } else {
  179. $comitato = false;
  180. }
  181. return [
  182. 'id' => $this->id,
  183. 'cognome' => $this->cognome,
  184. 'nome' => $this->nome,
  185. 'email' => $this->email,
  186. 'codiceFiscale' => $this->codiceFiscale,
  187. 'comitato' => $comitato
  188. ];
  189. }
  190. public function calendarioAttivita(DT $inizio, DT $fine) {
  191. $c = $this->comitati();
  192. $t = [];
  193. foreach ( $c as $x ) {
  194. foreach ( $x->calendarioAttivitaPrivate($inizio, $fine) as $a ) {
  195. $t[] = $a;
  196. }
  197. }
  198. foreach ( Attivita::filtra([['pubblica', ATTIVITA_PUBBLICA]]) as $a ) {
  199. $t[] = $a;
  200. }
  201. return $t;
  202. }
  203. public function appartenenzeAttuali($tipo = MEMBRO_ESTESO) {
  204. $q = $this->db->prepare("
  205. SELECT
  206. appartenenza.id
  207. FROM
  208. appartenenza
  209. WHERE
  210. stato >= :tipo
  211. AND
  212. volontario = :me
  213. AND
  214. ( appartenenza.fine < 1
  215. OR
  216. appartenenza.fine > :ora
  217. OR
  218. appartenenza.fine IS NULL)");
  219. $q->bindParam(':tipo', $tipo);
  220. $ora = time();
  221. $q->bindParam(':ora', $ora);
  222. $q->bindParam(':me', $this->id);
  223. $q->execute();
  224. $r = [];
  225. while ( $x = $q->fetch(PDO::FETCH_NUM ) ) {
  226. $r[] = Appartenenza::id($x[0]);
  227. }
  228. return $r;
  229. }
  230. public function comitati($tipo = MEMBRO_ESTESO) {
  231. $c = [];
  232. foreach ( $this->appartenenzeAttuali($tipo) as $a ) {
  233. $c[] = $a->comitato();
  234. }
  235. return $c;
  236. }
  237. public function unComitato($tipo = MEMBRO_VOLONTARIO) {
  238. $c = $this->comitati($tipo);
  239. if (!$c) { return false; }
  240. return $c[0];
  241. }
  242. public function numeroAppartenenzeAttuali($tipo = MEMBRO_VOLONTARIO) {
  243. $q = $this->db->prepare("
  244. SELECT
  245. COUNT( appartenenza.id )
  246. FROM
  247. appartenenza
  248. WHERE
  249. stato >= :tipo
  250. AND
  251. volontario = :me
  252. AND
  253. ( appartenenza.fine < 1
  254. OR
  255. appartenenza.fine > :ora )");
  256. $q->bindParam(':tipo', $tipo);
  257. $q->bindParam(':me', $this->id);
  258. $ora = time();
  259. $q->bindParam(':ora', $ora);
  260. $q->execute();
  261. $q = $q->fetch(PDO::FETCH_NUM);
  262. return $q[0];
  263. }
  264. public function primaAppartenenza() {
  265. $p = Appartenenza::filtra([
  266. ['volontario', $this->id]
  267. ], 'inizio ASC');
  268. if ( !$p ) { return false; }
  269. foreach ($p as $_p){
  270. if ($this->stato == VOLONTARIO) {
  271. if($_p->validaPerAnzianita()) {
  272. return $_p;
  273. }
  274. } elseif ($this->stato == PERSONA) {
  275. if($_p->validaPerAnzianita(PERSONA)) {
  276. return $_p;
  277. }
  278. }
  279. }
  280. return null;
  281. }
  282. public function ultimaAppartenenza($stato = MEMBRO_VOLONTARIO) {
  283. $p = Appartenenza::filtra([
  284. ['volontario', $this->id],
  285. ['stato', $stato]
  286. ], 'inizio DESC');
  287. if ( !$p ) { return false; }
  288. return $p[0];
  289. }
  290. public function appartenenzaAttuale() {
  291. if($this->stato == VOLONTARIO
  292. && $this->ultimaAppartenenza(MEMBRO_VOLONTARIO)
  293. && $this->ultimaAppartenenza(MEMBRO_VOLONTARIO)->attuale()) {
  294. return $this->ultimaAppartenenza(MEMBRO_VOLONTARIO);
  295. } elseif ($this->stato == PERSONA
  296. && $this->ultimaAppartenenza(MEMBRO_ORDINARIO)
  297. && $this->ultimaAppartenenza(MEMBRO_ORDINARIO)->attuale()) {
  298. return $this->ultimaAppartenenza(MEMBRO_ORDINARIO);
  299. }
  300. return null;
  301. }
  302. public function ingresso() {
  303. $p = $this->primaAppartenenza();
  304. if ( !$p ) { return false; }
  305. return $p->inizio();
  306. }
  307. /*
  308. * Ritorna le appartenenze delle quali si è presidente.
  309. */
  310. public function presidenziante() {
  311. return $this->delegazioni(APP_PRESIDENTE);
  312. }
  313. public function comitatiPresidenzianti() {
  314. return $this->comitatiDelegazioni(APP_PRESIDENTE);
  315. }
  316. public function comitatiApp( $app , $soloComitati = true) {
  317. if (!is_array($app)) {
  318. $app = [$app];
  319. }
  320. if ( $this->admin() ) {
  321. return $this->comitatiDiCompetenza();
  322. }
  323. $r = [];
  324. foreach ( $app as $k ) {
  325. $r = array_merge($r, $this->comitatiDelegazioni($k, $soloComitati));
  326. }
  327. $r = array_unique($r);
  328. return $r;
  329. }
  330. public function comitatiAppComma ( $app ) {
  331. $app = $this->comitatiApp($app);
  332. return implode(', ', $app);
  333. }
  334. public function numVolontariDiCompetenza() {
  335. $n = 0;
  336. $comitati = $this->comitatiApp([ APP_SOCI, APP_PRESIDENTE, APP_CO, APP_OBIETTIVO ]);
  337. foreach($comitati as $_c) {
  338. $n += $_c->numMembriAttuali(MEMBRO_VOLONTARIO);
  339. }
  340. return $n;
  341. }
  342. public function numOrdinariDiCompetenza() {
  343. $n = 0;
  344. $comitati = $this->comitatiApp([ APP_SOCI, APP_PRESIDENTE, APP_CO, APP_OBIETTIVO ]);
  345. foreach($comitati as $_c) {
  346. $n += $_c->numMembriOrdinari();
  347. }
  348. return $n;
  349. }
  350. public function presiede( $comitato = null ) {
  351. if ( $comitato ) {
  352. if($comitato->unPresidente() == $this->id) {
  353. return true;
  354. }
  355. } else {
  356. return (bool) $this->comitatiApp([APP_PRESIDENTE], false);
  357. }
  358. return false;
  359. }
  360. /* Avatar */
  361. public function avatar() {
  362. $a = Avatar::by('utente', $this->id);
  363. if ( $a ) {
  364. return $a;
  365. } else {
  366. $a = new Avatar();
  367. $a->utente = $this->id;
  368. return $a;
  369. }
  370. }
  371. public function comitatiDiCompetenza() {
  372. if ( $this->admin() ) {
  373. return Comitato::elenco('locale ASC');
  374. } else {
  375. return $this->comitatiPresidenzianti();
  376. }
  377. }
  378. public function unitaDiCompetenza() {
  379. $c = $this->comitatiDiCompetenza();
  380. $r = [];
  381. foreach($c as $_c) {
  382. if($_c instanceof Comitato) {
  383. $r[] = $_c;
  384. }
  385. }
  386. return $r;
  387. }
  388. public function miCompete(Comitato $c) {
  389. return (bool) in_array($c, $this->comitatiDiCompetenza());
  390. }
  391. public function commenti ( $limita = null ) {
  392. if ( $limita ) {
  393. $limita = (int) $limita;
  394. return Commento::filtra([
  395. ['volontario', $this]
  396. ], "tCommenta DESC LIMIT 0, {$limita}");
  397. } else {
  398. return Commento::filtra([
  399. ['volontario', $this]
  400. ], "tCommenta DESC");
  401. }
  402. }
  403. public function cancella() {
  404. // 1. Cancella il mio avatar
  405. $this->avatar()->cancella();
  406. // 2. Cancella le mie appartenenze ai gruppi
  407. foreach ( $this->appartenenze() as $a ) {
  408. $a->cancella();
  409. }
  410. // 3. Cancella le mie partecipazioni
  411. foreach ( $this->partecipazioni() as $p ) {
  412. $p->cancella();
  413. }
  414. // 4. Elimina le autorizzazioni che mi sono state chieste
  415. foreach ( $this->autorizzazioniPendenti() as $a ) {
  416. $a->cancella();
  417. }
  418. // 5. Elimina tutte le delegazioni che mi sono associate
  419. foreach ( $this->storicoDelegazioni() as $d ) {
  420. $d->cancella();
  421. }
  422. // 6. Riassegna le Aree al primo presidente a salire l'albero
  423. foreach ( $this->areeDiResponsabilita() as $a ) {
  424. $a->responsabile = $a->comitato()->primoPresidente();
  425. }
  426. // 7. Commenti lasciati in giro
  427. foreach ( $this->commenti() as $c ) {
  428. $c->cancella();
  429. }
  430. // 8. Gruppi di cui sono referente
  431. foreach ( Gruppo::filtra([['referente',$this]]) as $g ) {
  432. $g->cancella();
  433. }
  434. // 9. Mie estensioni
  435. foreach ( Estensione::filtra([['volontario',$this]]) as $g ) {
  436. $g->cancella();
  437. }
  438. // 10. Mie Riserve
  439. foreach ( Riserva::filtra([['volontario',$this]]) as $g ) {
  440. $g->cancella();
  441. }
  442. // 11. Mie reperibilita'
  443. foreach ( Reperibilita::filtra([['volontario',$this]]) as $g ) {
  444. $g->cancella();
  445. }
  446. // 12. Sessioni in corso
  447. /*foreach ( Sessione::filtra([['utente',$this]]) as $g ) {
  448. $g->cancella();
  449. }*/
  450. // 13. Titoli personali
  451. foreach ( TitoloPersonale::filtra([['volontario',$this]]) as $g ) {
  452. $g->cancella();
  453. }
  454. parent::cancella();
  455. }
  456. public function numTitoliPending( $app = [ APP_PRESIDENTE ] ) {
  457. $comitati = $this->comitatiAppComma( $app );
  458. $q = $this->db->prepare("
  459. SELECT COUNT(titoliPersonali.id)
  460. FROM titoliPersonali, appartenenza
  461. WHERE ( titoliPersonali.tConferma < 1 OR titoliPersonali.tConferma IS NULL )
  462. AND titoliPersonali.volontario = appartenenza.volontario
  463. AND ( appartenenza.fine < 1
  464. OR
  465. appartenenza.fine > :ora
  466. OR
  467. appartenenza.fine is NULL)
  468. AND appartenenza.comitato IN
  469. ( {$comitati} )");
  470. $ora = time();
  471. $q->bindParam(':ora', $ora);
  472. $q->execute();
  473. $r = $q->fetch(PDO::FETCH_NUM);
  474. return (int) $r[0];
  475. }
  476. public function numAppPending( $app = [ APP_PRESIDENTE ] ) {
  477. $comitati = $this->comitatiAppComma( $app );
  478. $q = $this->db->prepare("
  479. SELECT COUNT(id)
  480. FROM appartenenza
  481. WHERE stato = :statoPendente
  482. AND ( appartenenza.fine < 1
  483. OR
  484. appartenenza.fine > :ora
  485. OR
  486. appartenenza.fine is NULL)
  487. AND appartenenza.comitato IN
  488. ( {$comitati} )");
  489. $q->bindValue(':statoPendente', MEMBRO_PENDENTE);
  490. $ora = time();
  491. $q->bindParam(':ora', $ora);
  492. $q->execute();
  493. $r = $q->fetch(PDO::FETCH_NUM);
  494. return (int) $r[0];
  495. }
  496. public function numTrasfPending( $app = [ APP_PRESIDENTE ] ) {
  497. $comitati = $this->comitatiAppComma ( $app );
  498. $q = $this->db->prepare("
  499. SELECT COUNT(trasferimenti.id)
  500. FROM trasferimenti, appartenenza
  501. WHERE trasferimenti.volontario = appartenenza.volontario
  502. AND appartenenza.stato = :stato
  503. AND trasferimenti.stato = :statoTrasferimento
  504. AND appartenenza.comitato IN
  505. ( {$comitati} )");
  506. $q->bindValue(':stato', MEMBRO_VOLONTARIO);
  507. $q->bindValue(':statoTrasferimento', TRASF_INCORSO);
  508. $q->execute();
  509. $r = $q->fetch(PDO::FETCH_NUM);
  510. return (int) $r[0];
  511. }
  512. public function numEstPending( $app = [ APP_PRESIDENTE ] ) {
  513. $comitati = $this->comitatiAppComma ( $app );
  514. $q = $this->db->prepare("
  515. SELECT COUNT(estensioni.id)
  516. FROM estensioni, appartenenza
  517. WHERE estensioni.volontario = appartenenza.volontario
  518. AND appartenenza.stato = :stato
  519. AND estensioni.stato = :statoEstensione
  520. AND ( appartenenza.fine < 1
  521. OR
  522. appartenenza.fine > :ora
  523. OR
  524. appartenenza.fine IS NULL)
  525. AND appartenenza.comitato IN
  526. ( {$comitati} )");
  527. $q->bindValue(':stato', MEMBRO_VOLONTARIO);
  528. $q->bindValue(':statoEstensione', EST_INCORSO);
  529. $ora = time();
  530. $q->bindParam(':ora', $ora);
  531. $q->execute();
  532. $r = $q->fetch(PDO::FETCH_NUM);
  533. return (int) $r[0];
  534. }
  535. public function numRisPending( $app = [ APP_PRESIDENTE ] ) {
  536. $comitati = $this->comitatiAppComma ( $app );
  537. $q = $this->db->prepare("
  538. SELECT COUNT(riserve.id)
  539. FROM riserve, appartenenza
  540. WHERE riserve.stato = :statoPendente
  541. AND riserve.volontario = appartenenza.volontario
  542. AND appartenenza.stato = :stato
  543. AND ( appartenenza.fine < 1
  544. OR
  545. appartenenza.fine > :ora
  546. OR
  547. appartenenza.fine is NULL)
  548. AND appartenenza.comitato IN
  549. ( {$comitati} )");
  550. $q->bindValue(':statoPendente', RISERVA_INCORSO);
  551. $q->bindValue(':stato', MEMBRO_VOLONTARIO);
  552. $ora = time();
  553. $q->bindParam(':ora', $ora);
  554. $q->execute();
  555. $r = $q->fetch(PDO::FETCH_NUM);
  556. return (int) $r[0];
  557. }
  558. public function documento($tipo = DOC_CARTA_IDENTITA) {
  559. $d = Documento::filtra([
  560. ['tipo', $tipo],
  561. ['volontario', $this->id]
  562. ]);
  563. if ( !$d ) { return false; }
  564. return $d[0];
  565. }
  566. public function documenti() {
  567. global $conf;
  568. $r = [];
  569. foreach ( $conf['docs_tipologie'] as $k => $doc ) {
  570. $d = $this->documento($k);
  571. if ( $d ) {
  572. $r[] = $d;
  573. }
  574. }
  575. return $r;
  576. }
  577. public function zipDocumenti() {
  578. $z = new Zip();
  579. foreach ( $this->documenti() as $d ) {
  580. $z->aggiungi ( $d->creaFile() );
  581. }
  582. $nome = $this->nomeCompleto();
  583. $z->comprimi("Documenti {$nome}.zip");
  584. return $z;
  585. }
  586. public function autorizzazioniPendenti() {
  587. return Autorizzazione::filtra([
  588. ['volontario', $this->id],
  589. ['stato', AUT_PENDING]
  590. ], 'timestamp ASC');
  591. }
  592. public function storicoDelegazioni($app = null, $comitato = null) {
  593. if ( $app ) {
  594. $app = (int) $app;
  595. if ( $comitato ) {
  596. return Delegato::filtra([
  597. ['volontario', $this->id],
  598. ['applicazione', $app],
  599. ['comitato', $comitato]
  600. ]);
  601. } else {
  602. return Delegato::filtra([
  603. ['volontario', $this->id],
  604. ['applicazione', $app]
  605. ]);
  606. }
  607. } else {
  608. if ( $comitato ) {
  609. return Delegato::filtra([
  610. ['volontario', $this->id],
  611. ['comitato', $comitato]
  612. ]);
  613. } else {
  614. return Delegato::filtra([
  615. ['volontario', $this->id]
  616. ]);
  617. }
  618. }
  619. }
  620. public function delegazioni($app = null, $comitato = null) {
  621. $t = $this->storicoDelegazioni($app, $comitato);
  622. $r = [];
  623. foreach ( $t as $k ) {
  624. if ( $k->attuale() ) {
  625. $r[] = $k;
  626. }
  627. }
  628. return $r;
  629. }
  630. /**
  631. * Restituisce i comitati che mi competono per una determinata delega
  632. * @return array di geopolitiche
  633. * @param $app array di delegazioni
  634. * @param $soloComitati per far restituire solo i comitati e non il resto
  635. * @param $espandi default ritorna le geopolitiche e la loro espansione
  636. */
  637. public function comitatiDelegazioni($app = null, $soloComitati = false, $espandi = true) {
  638. //$d = $this->delegazioni($app);
  639. $d = $this->delegazioneAttuale();
  640. $c = [];
  641. //if ( $d as $_d ) {
  642. if (!$app || $d->applicazione == $app) {
  643. $comitato = $d->comitato();
  644. if (!$soloComitati || $comitato instanceof Comitato) {
  645. $c[] = $comitato;
  646. }
  647. if ($espandi && !$comitato instanceof Comitato) {
  648. $c = array_merge($comitato->estensione(), $c);
  649. }
  650. }
  651. return array_unique($c);
  652. }
  653. /**
  654. * Controlla se l'utente ha i permessi di lettura dei dati dei volontari
  655. * @param GeoPolitica $g la geopolitica contenente i volontari
  656. * @return bool
  657. */
  658. public function puoLeggereDati(GeoPolitica $g) {
  659. if ( $this->admin ) { // ->admin e non ->admin() di proposito
  660. // in quanto questa roba viene usata in API
  661. return true;
  662. }
  663. return (bool) in_array(
  664. $g,
  665. array_merge(
  666. $this->comitatiApp([
  667. APP_PRESIDENTE,
  668. APP_SOCI,
  669. APP_OBIETTIVO
  670. ], false),
  671. $this->geopoliticheAttivitaReferenziate(),
  672. $this->geopoliticheGruppiReferenziati (),
  673. $this->comitatiAreeDiCompetenza ()
  674. )
  675. );
  676. }
  677. public function entitaDelegazioni($app = null) {
  678. /* Qualora fossi admin, ho tutto il nazionale... */
  679. if (
  680. $this->admin()
  681. ) {
  682. return Nazionale::elenco('nome ASC');
  683. }
  684. //$d = $this->delegazioni($app);
  685. $d = $this->delegazioneAttuale();
  686. $c = [];
  687. //foreach ( $d as $k ) {
  688. if(!$app || $d->applicazione == $app) {
  689. $c[] = $d->comitato();
  690. }
  691. return array_unique($c);
  692. }
  693. public function dominiDelegazioni($app) {
  694. $d = $this->delegazioni($app);
  695. $c = [];
  696. foreach ( $d as $k ) {
  697. $c[] = $k->dominio;
  698. }
  699. return array_unique($c);
  700. }
  701. public function partecipazioni( $stato = false ) {
  702. if ( $stato ) {
  703. return Partecipazione::filtra([
  704. ['volontario', $this->id],
  705. ['stato', $stato]
  706. ], 'timestamp DESC');
  707. } else {
  708. return Partecipazione::filtra([
  709. ['volontario', $this->id]
  710. ], 'timestamp DESC');
  711. }
  712. }
  713. public function trasferimenti($stato = null) {
  714. if ( $stato ) {
  715. return Trasferimento::filtra([
  716. ['volontario', $this->id],
  717. ['stato', $stato]
  718. ]);
  719. } else {
  720. return Trasferimento::filtra([
  721. ['volontario', $this->id]
  722. ]);
  723. }
  724. }
  725. public function inRiserva() {
  726. $rok = Riserva::filtra([
  727. ['volontario', $this->id],
  728. ['stato', RISERVA_OK]
  729. ]);
  730. $rauto = Riserva::filtra([
  731. ['volontario', $this->id],
  732. ['stato', RISERVA_AUTO]
  733. ]);
  734. $r = array_merge($rok, $rauto);
  735. foreach ($r as $_r) {
  736. if ($_r->inizio < time() && $_r->fine > time())
  737. return True;
  738. }
  739. return False;
  740. }
  741. public function riserve() {
  742. return Riserva::filtra([
  743. ['volontario', $this->id]
  744. ]);
  745. }
  746. public function unaRiserva() {
  747. $r = $this->riserve();
  748. foreach ($r as $_r) {
  749. if ($_r->stato == RISERVA_OK || $_r->stato == RISERVA_AUTO)
  750. return $_r;
  751. }
  752. return NULL;
  753. }
  754. public function unaRiservaInSospeso() {
  755. $r = $this->riserve();
  756. foreach ($r as $_r) {
  757. if ($_r->stato == RISERVA_INCORSO)
  758. return $_r;
  759. }
  760. return NULL;
  761. }
  762. /**
  763. * Restituisce l'elenco dei gruppi a cui un volontario si può iscrivere
  764. * @return Array(Gruppo) restituisce un array di gruppi
  765. */
  766. public function gruppiDisponibili() {
  767. $app = $this->appartenenzeAttuali();
  768. $r = [];
  769. foreach($app as $_a) {
  770. $comitato = $_a->comitato();
  771. $r = array_merge($r, $comitato->gruppi());
  772. while($comitato = $comitato->superiore()) {
  773. $r = array_merge($r, $comitato->gruppi());
  774. }
  775. }
  776. return $r;
  777. }
  778. /**
  779. * Restituisce l'elenco dei a cui il volontario è attualmente iscritto
  780. * @return Array(Gruppo) restituisce un array di gruppi
  781. */
  782. public function gruppiAttuali() {
  783. $g = $this->mieiGruppi();
  784. $r = [];
  785. foreach($g as $_g) {
  786. if($_g->attuale()) {
  787. $r[] = $_g;
  788. }
  789. }
  790. return $r;
  791. }
  792. public function mieiGruppi() {
  793. return AppartenenzaGruppo::filtra([
  794. ['volontario', $this->id]
  795. ]);
  796. }
  797. public function contaGruppi() {
  798. $q = $this->db->prepare("
  799. SELECT
  800. COUNT(volontario)
  801. FROM
  802. gruppiPersonali
  803. WHERE
  804. ( fine >= :ora OR fine IS NULL OR fine = 0)
  805. AND
  806. volontario = :volontario
  807. ORDER BY
  808. inizio ASC");
  809. $q->bindValue(':ora', time());
  810. $q->bindParam(':volontario', $this->id);
  811. $q->execute();
  812. $r = $q->fetch(PDO::FETCH_NUM);
  813. return (int) $r[0];
  814. }
  815. public function gruppoAttuale($g) {
  816. $q = $this->db->prepare("
  817. SELECT
  818. id
  819. FROM
  820. gruppiPersonali
  821. WHERE
  822. ( fine >= :ora OR fine IS NULL OR fine = 0)
  823. AND
  824. volontario = :volontario
  825. AND
  826. gruppo = :gruppo
  827. ORDER BY
  828. inizio ASC");
  829. $q->bindValue(':ora', time());
  830. $q->bindParam(':volontario', $this->id);
  831. $q->bindParam(':gruppo', $g);
  832. $q->execute();
  833. $r = $q->fetch();
  834. $r = new AppartenenzaGruppo($r[0]);
  835. return $r;
  836. }
  837. public function mieReperibilita() {
  838. return Reperibilita::filtra([
  839. ['volontario', $this->id]
  840. ]);
  841. }
  842. public function areeDiResponsabilita() {
  843. return Area::filtra([
  844. ['responsabile', $this->id]
  845. ]);
  846. }
  847. public function areeDiCompetenza( $c = null , $espandiLocale = false) {
  848. if ( $c ) {
  849. if ( $this->admin() || $this->presiede($c) ) {
  850. return $c->aree();
  851. } elseif ( $o = $this->delegazioni(APP_OBIETTIVO, $c) ) {
  852. $r = [];
  853. foreach ( $o as $io ) {
  854. $r = array_merge($r, $c->aree($io->dominio, $espandiLocale));
  855. }
  856. $r = array_unique($r);
  857. return $r;
  858. } else {
  859. return $this->areeDiResponsabilita();
  860. }
  861. } else {
  862. $r = [];
  863. foreach ( $this->comitatiDiCompetenza() as $c ) {
  864. $r = array_merge($r, $c->aree());
  865. }
  866. foreach ( $this->delegazioni(APP_OBIETTIVO) as $d ) {
  867. $comitato = $d->comitato();
  868. $r = array_merge($r, $comitato->aree($d->dominio));
  869. if ($comitato instanceof Locale) {
  870. $comitati = $comitato->estensione();
  871. foreach ($comitati as $_c) {
  872. $r = array_merge($r, $_c->aree($d->dominio));
  873. }
  874. }
  875. }
  876. $r = array_merge($r, $this->areeDiResponsabilita());
  877. $r = array_unique($r);
  878. return $r;
  879. }
  880. }
  881. public function comitatiAreeDiCompetenza($soloLocali = false) {
  882. $a = $this->areeDiCompetenza(null, true);
  883. $r = [];
  884. foreach ($a as $_a) {
  885. $comitato = $_a->comitato();
  886. if(!$soloLocali || $comitato instanceof Comitato) {
  887. $r[] = $comitato;
  888. }
  889. if (!$comitato instanceof Comitato) {
  890. $r = array_merge($r, $comitato->estensione());
  891. }
  892. }
  893. $r = array_unique($r);
  894. return $r;
  895. }
  896. public function attivitaReferenziate() {
  897. return Attivita::filtra([
  898. ['referente', $this->id]
  899. ], 'nome ASC');
  900. }
  901. public function gruppiReferenziati() {
  902. return Gruppo::filtra([
  903. ['referente', $this->id]
  904. ], 'nome ASC');
  905. }
  906. public function attivitaReferenziateDaCompletare() {
  907. return Attivita::filtra([
  908. ['referente', $this->id],
  909. ['stato', ATT_STATO_BOZZA]
  910. ]);
  911. }
  912. /**
  913. * Ottiene le GeoPolitiche delle Attivita referenziate dall'utente
  914. * @return array(GeoPolitica*)
  915. */
  916. public function geopoliticheAttivitaReferenziate() {
  917. $a = $this->attivitaReferenziate();
  918. $r = [];
  919. foreach($a as $_a) {
  920. $r[] = $_a->comitato();
  921. }
  922. return array_unique($r);
  923. }
  924. /**
  925. * Ottiene i Comitati delle Attivita referenziate dall'utente
  926. * Equivale ad estendere tutte le GeoPolitiche di
  927. * Utente->geopoliticheAttivitaReferenziate()
  928. * @return array(Comitato)
  929. */
  930. public function comitatiAttivitaReferenziate() {
  931. $a = $this->geopoliticheAttivitaReferenziate();
  932. $r = [];
  933. foreach($a as $_a) {
  934. $r = array_merge($r, $_a->estensione());
  935. }
  936. return array_unique($r);
  937. }
  938. public function geopoliticheGruppiReferenziati() {
  939. $g = $this->gruppiReferenziati();
  940. $r = [];
  941. foreach($g as $_g) {
  942. $r[] = $_g->comitato();
  943. }
  944. return array_unique($r);
  945. }
  946. public function comitatiGruppiReferenziati() {
  947. $g = $this->geopoliticheGruppiReferenziati();
  948. $r = [];
  949. foreach($g as $_g) {
  950. $r = array_merge($r, $_g->estensione());
  951. }
  952. return array_unique($r);
  953. }
  954. public function attivitaAreeDiCompetenza() {
  955. $r = [];
  956. foreach ( $this->areeDiCompetenza() as $area ) {
  957. $r = array_merge($r, $area->attivita());
  958. }
  959. $r = array_unique($r);
  960. return $r;
  961. }
  962. public function attivitaDiGestione() {
  963. $a = array_merge($this->attivitaReferenziate(), $this->attivitaAreeDiCompetenza());
  964. foreach ( $this->comitatiDiCompetenza() as $c ) {
  965. $a = array_merge($a, $c->attivita());
  966. }
  967. return array_unique($a);
  968. }
  969. /**
  970. * Restituisce l'elenco dei corsi base che gestisco
  971. * @return CorsoBase elenco dei corsi gestiti
  972. */
  973. public function corsiBaseDiGestione() {
  974. $a = $this->corsiBaseDiretti();
  975. foreach ( $this->comitatiApp([APP_PRESIDENTE, APP_FORMAZIONE], false) as $c ) {
  976. $a = array_merge($a, $c->CorsiBase());
  977. }
  978. return array_unique($a);
  979. }
  980. /**
  981. * Restituisce l'elenco dei corsi base di cui sono direttore
  982. * @return CorsoBase elenco dei corsi diretti
  983. */
  984. public function corsiBaseDiretti() {
  985. return CorsoBase::filtra([
  986. ['direttore', $this->id]
  987. ]);
  988. }
  989. /**
  990. * Restituisce l'elenco dei corsi base di cui sono direttore e devo completare
  991. * @return CorsoBase elenco dei corsi diretti da completare
  992. */
  993. public function corsiBaseDirettiDaCompletare() {
  994. return CorsoBase::filtra([
  995. ['direttore', $this->id],
  996. ['stato', CORSO_S_DACOMPLETARE]
  997. ]);
  998. }
  999. public function cellulare() {
  1000. if($this->cellulareServizio){
  1001. return $this->cellulareServizio;
  1002. }
  1003. return $this->cellulare;
  1004. }
  1005. public function email() {
  1006. if($this->emailServizio){
  1007. return $this->emailServizio;
  1008. }
  1009. return $this->email;
  1010. }
  1011. public function giovane() {
  1012. $u = time()-GIOVANI;
  1013. if($u <= $this->dataNascita){
  1014. return true;
  1015. }else{
  1016. return false;
  1017. }
  1018. }
  1019. public function gruppiDiCompetenza( $app = [ APP_PRESIDENTE, APP_SOCI, APP_OBIETTIVO ] ) {
  1020. $gruppi = [];
  1021. $comitati = $this->comitatiApp($app, false);
  1022. if ( !$this->admin() && !$this->presidenziante() ){
  1023. $gruppi = array_merge(
  1024. $gruppi,
  1025. Gruppo::filtra([
  1026. ['referente',$this]
  1027. ])
  1028. );
  1029. $gruppi = array_unique($gruppi);
  1030. }else{
  1031. foreach ($comitati as $comitato) {
  1032. $gruppi = array_merge($gruppi, $comitato->gruppi());
  1033. }
  1034. $gruppi = array_merge(
  1035. $gruppi,
  1036. Gruppo::filtra([
  1037. ['referente',$this]
  1038. ])
  1039. );
  1040. $gruppi = array_unique($gruppi);
  1041. }
  1042. return $gruppi;
  1043. }
  1044. public function inEstensione($c) {
  1045. $app = Appartenenza::filtra([
  1046. ['volontario', $this->id],
  1047. ['stato', MEMBRO_ESTESO],
  1048. ['comitato', $c]
  1049. ]);
  1050. return Estensione::filtra([
  1051. ['appartenenza', $app[0]->id],
  1052. ['stato', EST_OK]
  1053. ]);
  1054. }
  1055. public function quote() {
  1056. $q = [];
  1057. foreach ( $this->storico() as $app ) {
  1058. $q = array_merge($q, Quota::filtra([
  1059. ['appartenenza', $app]],
  1060. 'timestamp DESC'));
  1061. }
  1062. return $q;
  1063. }
  1064. public function quota($anno = null) {
  1065. if (!$anno)
  1066. $anno = date('Y');
  1067. $q = $this->quote();
  1068. foreach ($q as $_q) {
  1069. if ($_q->anno == $anno && !$_q->annullata())
  1070. return $_q;
  1071. }
  1072. return false;
  1073. }
  1074. public static function elencoId() {
  1075. global $db;
  1076. $q = $db->prepare("
  1077. SELECT
  1078. id
  1079. FROM
  1080. anagrafica
  1081. WHERE
  1082. stato >= :stato
  1083. ORDER BY
  1084. id ASC");
  1085. $q->bindValue(':stato', PERSONA);
  1086. $q->execute();
  1087. $r = [];
  1088. while ( $k = $q->fetch(PDO::FETCH_NUM) ) {
  1089. $r[] = $k[0];
  1090. }
  1091. return $r;
  1092. }
  1093. public function privacy() {
  1094. $privacy = Privacy::by('volontario', $this);
  1095. if ( !$privacy ) {
  1096. $privacy = new Privacy;
  1097. $privacy->volontario = $this;
  1098. $privacy->contatti = PRIVACY_COMITATO;
  1099. $privacy->mess = PRIVACY_COMITATO;
  1100. $privacy->curriculum = PRIVACY_PRIVATA;
  1101. $privacy->incarichi = PRIVACY_PRIVATA;
  1102. }
  1103. return $privacy;
  1104. }
  1105. public function consenso() {
  1106. if(!$this->consenso) {
  1107. return false;
  1108. }
  1109. return true;
  1110. }
  1111. public function pri_delegato() {
  1112. if($this->presidenziante() || $this->attivitaReferenziate() || $this->delegazioni()){
  1113. return true;
  1114. }
  1115. return false;
  1116. }
  1117. public function pri_smistatore($altroutente){
  1118. if($this->admin()) {
  1119. return PRIVACY_RISTRETTA;
  1120. }
  1121. if( $this->presidenziante() || in_array($this->delegazioneAttuale()->applicazione, [APP_PRESIDENTE, APP_SOCI, APP_OBIETTIVO])){
  1122. $comitati = $this->comitatiApp([APP_PRESIDENTE, APP_SOCI, APP_OBIETTIVO]);
  1123. foreach ($comitati as $comitato){
  1124. echo $altroutente;
  1125. echo $comitato;
  1126. echo $altroutente->in($comitato);
  1127. if($altroutente->in($comitato)){
  1128. return PRIVACY_RISTRETTA;
  1129. }
  1130. }
  1131. }
  1132. if($this->areeDiResponsabilita()){
  1133. $ar = $this->areeDiResponsabilita();
  1134. foreach( $ar as $_a ){
  1135. $c = $_a->comitato()->estensione();
  1136. foreach ($c as $_c) {
  1137. if($altroutente->in($_c)){
  1138. return PRIVACY_RISTRETTA;
  1139. }
  1140. }
  1141. }
  1142. }
  1143. if($this->attivitaReferenziate()){
  1144. $a = $this->attivitaReferenziate();
  1145. $partecipazioni = $this->partecipazioni(PART_OK);
  1146. foreach( $partecipazioni as $p ){
  1147. if (in_array($p->attivita(), $a)) {
  1148. return PRIVACY_RISTRETTA;
  1149. }
  1150. }
  1151. }
  1152. return PRIVACY_PUBBLICA;
  1153. }
  1154. /*
  1155. * @return età utente
  1156. */
  1157. public function eta(){
  1158. $anno = date('Y', $this->dataNascita);
  1159. $ora = date('Y', time());
  1160. return $ora-$anno;
  1161. }
  1162. /*
  1163. * @return bool restituisce true se oggi è il compleanno dell'utente
  1164. */
  1165. public function compleanno(){
  1166. if( date('m', $this->dataNascita)==date('m', time()) && date('d', $this->dataNascita)==date('d', time())){
  1167. return true;
  1168. }else{
  1169. return false;
  1170. }
  1171. }
  1172. /*
  1173. * @return true se se si è in una situazione in cui le appartenenze assegnate hanno senso.
  1174. * Anche se la gestione del false non è fatta in maniera corretta nella pagina.
  1175. */
  1176. public function appartenenzaValida(){
  1177. $attuali = $this->appartenenzeAttuali();
  1178. $pendenti = $this->appartenenzePendenti();
  1179. $inGenerale = $this->appartenenze();
  1180. if(($attuali || $pendenti) && $this->stato == VOLONTARIO){
  1181. return true;
  1182. } elseif($inGenerale && $this->stato == PERSONA) {
  1183. return true;
  1184. } elseif (!$attuali && !$pendenti && $this->stato == ASPIRANTE) {
  1185. return true;
  1186. }
  1187. return false;
  1188. }
  1189. /*
  1190. * Verifica se un altro utente ha permessi in scrittura su me
  1191. * @return bool modifica o non modifica
  1192. * @param $altroUtente il modificatore
  1193. */
  1194. public function modificabileDa(Utente $altroUtente) {
  1195. if (!$altroUtente) {
  1196. return false;
  1197. }
  1198. if ($altroUtente->admin()) {
  1199. return true;
  1200. }
  1201. $comitatiGestiti = array_merge($altroUtente->comitatiDelegazioni(APP_PRESIDENTE, false, false),
  1202. $altroUtente->comitatiDelegazioni(APP_SOCI, false, false)
  1203. );
  1204. $comitatiGestiti = array_unique($comitatiGestiti);
  1205. if ($this->stato == PERSONA) {
  1206. $c = $this->unComitato(MEMBRO_ORDINARIO);
  1207. } else {
  1208. $c = $this->unComitato(MEMBRO_PENDENTE);
  1209. }
  1210. if($c) {
  1211. if(($c instanceof Comitato && in_array($c->locale(), $comitatiGestiti) )
  1212. || in_array($c, $comitatiGestiti)) {
  1213. return true;
  1214. }
  1215. }
  1216. /* Il foreach seguente serve per risolvere
  1217. * temporaneamente i problemi di permessi
  1218. * fino alla corretta implementazione di copernico
  1219. * #970
  1220. */
  1221. foreach ($comitatiGestiti as $com) {
  1222. if ($c instanceof Comitato && $c->locale()->nome == $com->nome) {
  1223. return true;
  1224. }
  1225. if ($c->nome == $com->nome) {
  1226. return true;
  1227. }
  1228. }
  1229. return false;
  1230. }
  1231. /*
  1232. * Controlla la riammissibilità entro l'anno solare di un volontario
  1233. * @return true se volontario riammissible false se non riammissibile
  1234. */
  1235. public function riammissibile() {
  1236. $dimissione = $this->ultimaAppartenenza(MEMBRO_DIMESSO);
  1237. $ultimo = $dimissione->fine+ANNO;
  1238. if ($ultimo >= time()){
  1239. return true;
  1240. }
  1241. return false;
  1242. }
  1243. /*
  1244. * Visualizza ultimo accesso dell'utente
  1245. * @return recentemente<5gg, 5gg< ultimo mese <30gg, piu di un mese >30gg
  1246. */
  1247. public function ultimoAccesso() {
  1248. if(!$this->ultimoAccesso){
  1249. return "Mai";
  1250. } elseif ($this->ultimoAccesso >= time()-GIORNO*5) {
  1251. return "Recentemente";
  1252. } elseif ($this->ultimoAccesso >= time()-MESE) {
  1253. return "Nell'ultimo mese";
  1254. }
  1255. return "Più di un mese fà";
  1256. }
  1257. public function ordinario() {
  1258. $r = [];
  1259. foreach ( Appartenenza::filtra([
  1260. ['volontario', $this->id],
  1261. ['stato', MEMBRO_ORDINARIO]
  1262. ]) as $a ) {
  1263. if ( !$a->attuale() ) { continue; }
  1264. $r[] = $a;
  1265. }
  1266. return $r;
  1267. }
  1268. public function ordinarioDimesso() {
  1269. $r = [];
  1270. foreach ( Appartenenza::filtra([
  1271. ['volontario', $this->id],
  1272. ['stato', MEMBRO_ORDINARIO_DIMESSO]
  1273. ]) as $a ) {
  1274. if ( !$a->attuale() ) { continue; }
  1275. $r[] = $a;
  1276. }
  1277. return $r;
  1278. }
  1279. /**
  1280. * Dice se un socio è benemerito per un dato anno
  1281. * @param $anno int Anno su cui voglio fare il controllo
  1282. * @return Quota|bool Quota se benemerito, false altrimenti
  1283. */
  1284. public function benemerito($anno = null) {
  1285. if (!$anno)
  1286. $anno = date('Y');
  1287. $q = Quota::filtra([
  1288. ['anno', $anno],
  1289. ['benemerito', BENEMERITO_SI]
  1290. ]);
  1291. foreach ($q as $_q) {
  1292. if ($_q->volontario()->id == $this->id)
  1293. return $_q;
  1294. }
  1295. return false;
  1296. }
  1297. /**
  1298. * Restituscie l'ultima delegazione selezionata dall'utente
  1299. * @return Delegato Ritorna un delegato se delegazione selezionata, errore altrimenti
  1300. */
  1301. public function delegazioneAttuale() {
  1302. global $sessione;
  1303. $r = $sessione->ambito;
  1304. if($r) {
  1305. $d = Delegato::id($r);
  1306. if($d && $d->attuale() && $d->volontario == $this->id) {
  1307. return $d;
  1308. }
  1309. throw new Errore(1015);
  1310. }
  1311. return null;
  1312. }
  1313. /* Se volontario è IV
  1314. * @return true se iv
  1315. */
  1316. public function iv() {
  1317. if($this->iv){
  1318. return true;
  1319. }else{
  1320. return false;
  1321. }
  1322. }
  1323. /* Se volontario è CM
  1324. * @return true se CM
  1325. */
  1326. public function cm() {
  1327. if($this->cm){
  1328. return true;
  1329. }else{
  1330. return false;
  1331. }
  1332. }
  1333. /*
  1334. * Funzione che non funziona correttamente
  1335. */
  1336. public static function limbo() {
  1337. global $db;
  1338. $q = $db->prepare("
  1339. SELECT
  1340. anagrafica.id
  1341. FROM
  1342. anagrafica
  1343. WHERE
  1344. ( anagrafica.id NOT IN
  1345. ( SELECT
  1346. volontario
  1347. FROM
  1348. appartenenza
  1349. )
  1350. )
  1351. ORDER BY
  1352. anagrafica.cognome ASC,
  1353. anagrafica.nome ASC");
  1354. $q->execute();
  1355. $r = [];
  1356. while ( $k = $q->fetch(PDO::FETCH_NUM) ) {
  1357. $r[] = Utente::id($k[0]);
  1358. }
  1359. return $r;
  1360. }
  1361. public function cancellaUtente(){
  1362. $t = Utente::id($this);
  1363. $f = Annunci::filtra([
  1364. ['autore', $t]
  1365. ]);
  1366. foreach($f as $_f){
  1367. $_f->cancella();
  1368. }
  1369. $app = Appartenenza::filtra([
  1370. ['volontario', $t]
  1371. ]);
  1372. $a = $t->appartenenzaAttuale();
  1373. if($a) {
  1374. $c = $a->comitato();
  1375. $a = $a->id;
  1376. }
  1377. // roba legata ad appartenenza attuale
  1378. if($a) {
  1379. $f = Attivita::filtra([
  1380. ['referente', $t]
  1381. ]);
  1382. foreach($f as $_f){
  1383. $_f->referente = $c->unPresidente();
  1384. }
  1385. $f = Autorizzazione::filtra([
  1386. ['volontario', $t]
  1387. ]);
  1388. foreach($f as $_f){
  1389. $_f->volontario = $c->unPresidente();
  1390. }
  1391. if($c) {
  1392. $f = Gruppo::filtra([
  1393. ['referente', $t]
  1394. ]);
  1395. foreach($f as $_f){
  1396. $_f->referente = $c->unPresidente();
  1397. }
  1398. }
  1399. }
  1400. // roba generica
  1401. $f = Avatar::filtra([
  1402. ['utente', $t]
  1403. ]);
  1404. foreach ($f as $_f) {
  1405. $_f->cancella();
  1406. }
  1407. $f = Area::filtra([
  1408. ['responsabile', $t]
  1409. ]);
  1410. foreach($f as $_f){
  1411. $_f->dimettiReferente();
  1412. }
  1413. $f = Commento::filtra([
  1414. ['volontario', $t]
  1415. ]);
  1416. foreach ($f as $_f) {
  1417. $_f->cancella();
  1418. }
  1419. $f = Coturno::filtra([
  1420. ['volontario', $t]
  1421. ]);
  1422. foreach ($f as $_f) {
  1423. $_f->cancella();
  1424. }
  1425. $f = Delegato::filtra([
  1426. ['volontario', $t]
  1427. ]);
  1428. foreach ($f as $_f) {
  1429. $_f->cancella();
  1430. }
  1431. $f = Dimissione::filtra([
  1432. ['volontario', $t]
  1433. ]);
  1434. foreach ($f as $_f) {
  1435. $_f->cancella();
  1436. }
  1437. $f = Documento::filtra([
  1438. ['volontario', $t]
  1439. ]);
  1440. foreach ($f as $_f) {
  1441. $_f->cancella();
  1442. }
  1443. $f = Estensione::filtra([
  1444. ['volontario', $t]
  1445. ]);
  1446. foreach ($f as $_f) {
  1447. $_f->cancella();
  1448. }
  1449. $f = File::filtra([
  1450. ['autore', $t]
  1451. ]);
  1452. foreach ($f as $_f) {
  1453. $_f->cancella();
  1454. }
  1455. $f = AppartenenzaGruppo::filtra([
  1456. ['volontario', $t]
  1457. ]);
  1458. foreach ($f as $_f) {
  1459. $_f->cancella();
  1460. }
  1461. $f = Partecipazione::filtra([
  1462. ['volontario', $t]
  1463. ]);
  1464. foreach ($f as $_f) {
  1465. $_f->cancella();
  1466. }
  1467. $f = Privacy::filtra([
  1468. ['volontario', $t]
  1469. ]);
  1470. foreach ($f as $_f) {
  1471. $_f->cancella();
  1472. }
  1473. $f = Reperibilita::filtra([
  1474. ['volontario', $t]
  1475. ]);
  1476. foreach ($f as $_f) {
  1477. $_f->cancella();
  1478. }
  1479. $f = Riserva::filtra([
  1480. ['volontario', $t]
  1481. ]);
  1482. foreach ($f as $_f) {
  1483. $_f->cancella();
  1484. }
  1485. $f = Sessione::filtra([
  1486. ['utente', $t]
  1487. ]);
  1488. foreach ($f as $_f) {
  1489. $_f->cancella();
  1490. }
  1491. $f = TitoloPersonale::filtra([
  1492. ['volontario', $t]
  1493. ]);
  1494. foreach ($f as $_f) {
  1495. $_f->cancella();
  1496. }
  1497. $f = Trasferimento::filtra([
  1498. ['volontario', $t]
  1499. ]);
  1500. foreach ($f as $_f) {
  1501. $_f->cancella();
  1502. }
  1503. // roba legata a tutte le appartenenza
  1504. foreach($app as $_app) {
  1505. $f = Quota::filtra([
  1506. ['appartenenza', $_app]
  1507. ]);
  1508. foreach ($f as $_f) {
  1509. $_f->cancella();
  1510. }
  1511. }
  1512. // cancella appartenenza
  1513. foreach($app as $_app){
  1514. $_app->cancella();
  1515. }
  1516. // cancella anagrafica
  1517. $t->cancella();
  1518. return;
  1519. }
  1520. }