Changeset 2591 for cpc/trunk/project


Ignore:
Timestamp:
Jan 9, 2012, 5:58:18 PM (9 years ago)
Author:
teymour
Message:

Si une seance existe déjà sans commentaire, on la supprime pour pouvoir la recharger correcrtement

Location:
cpc/trunk/project/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpc/trunk/project/lib/model/doctrine/Intervention.class.php

    r2422 r2591  
    5959  public function setSeance($type, $date, $heure, $session, $commission = null) {
    6060    $this->setType($type);
    61     if ($type == 'commission') {
    62       $commission = Doctrine::getTable('Organisme')->findOneByNomOrCreateIt($commission, 'parlementaire');
    63       $seance = $commission->getSeanceByDateAndMomentOrCreateIt($date, $heure, $session);
    64       $commission->free();
    65     } else{
    66       $seance = Doctrine::getTable('Seance')->findOneOrCreateIt('hemicycle', $date, $heure, $session);
    67     }
     61    $seance = Doctrine::getTable('Seance')->getOrCreateItFromSeanceArgs($type, $date, $heure, $session, $commission);
    6862    $id = $this->_set('seance_id', $seance->id);
    6963    $seance->free();
  • cpc/trunk/project/lib/model/doctrine/Seance.class.php

    r2336 r2591  
    120120  }
    121121
     122  public function deleteInterventions() {
     123    if ($this->countComments()) {
     124      throw new Exception('Il existe des commentaires');
     125    }
     126    foreach (Doctrine::getTable('Intervention')->createQuery('i')->where('i.seance_id = ?', $this->id)->execute() as $i) {
     127      $i->delete();
     128    }
     129  }
     130
     131  public function countComments() {
     132    $interventions = Doctrine::getTable('Intervention')->createQuery('i')->where('i.seance_id = ?', $this->id)->select('i.id')->fetchArray();
     133    return Doctrine::getTable('Commentaire')->createQuery('c')->whereIN('object_id', $interventions)->andWhere('object_type = ?', 'Intervention')->count();
     134  }
     135
    122136  public function getTitre($miniature = 0, $hemicycle = 0, $ref = '') {
    123137    $titre = '';
  • cpc/trunk/project/lib/model/doctrine/SeanceTable.class.php

    r1254 r2591  
    55class SeanceTable extends Doctrine_Table
    66{
     7  public function getFromSeanceArgs($type, $date, $heure, $session, $commission = null) {
     8    if ($type == 'commission') {
     9      $commission = Doctrine::getTable('Organisme')->findOneByNomOrCreateIt($commission, 'parlementaire');
     10      return $commission->getSeanceByDateAndMoment($date, $heure, $session);
     11    }
     12    return Doctrine::getTable('Seance')->findOneByTypeDateHeureSession('hemicycle', $date, $heure, $session);
     13  }
     14
     15  public function getOrCreateItFromSeanceArgs($type, $date, $heure, $session, $commission = null) {
     16    if ($type == 'commission') {
     17      $commission = Doctrine::getTable('Organisme')->findOneByNomOrCreateIt($commission, 'parlementaire');
     18      return $commission->getSeanceByDateAndMomentOrCreateIt($date, $heure, $session);
     19    }
     20    return Doctrine::getTable('Seance')->findOneOrCreateIt('hemicycle', $date, $heure, $session);
     21  }
     22
     23  public function findOneByTypeDateHeureSession($type, $date, $heure, $session) {
     24    return $this->createQuery('s')->where('type = ?', $type)->andWhere('date = ?', $date)->andWhere('moment = ?', $heure)->fetchOne();
     25  }
     26
    727  public function findOneOrCreateIt($type, $date, $heure, $session) {
    8     $s = $this->createQuery('s')->where('type = ?', $type)->andWhere('date = ?', $date)->andWhere('moment = ?', $heure)->fetchOne();
     28    $s = findOneByTypeDateHeureSession($type, $date, $heure, $session);
    929    if (!$s) {
    1030      if ($type != 'hemicycle')
  • cpc/trunk/project/lib/task/loadCommissionTask.class.php

    r890 r2591  
    2424            continue;
    2525          echo "$dir$file\n";
     26          $first = 1;
    2627          foreach(file($dir.$file) as $line) {
    2728            $json = json_decode($line);
     
    3738            }
    3839
     40            if ($first) { #On teste si la séance existe déjà.
     41                $first = 0;
     42                $seance = Doctrine::getTable('Seance')->getFromSeanceArgs('commission', $json->date, $json->heure, $json->session, $json->commission);
     43                if ($seance) {
     44                  try {
     45                    $seance->deleteInterventions();
     46                  }catch(Exception $e) {
     47                    echo "ERROR: Séance exists (".$e->getMessage().")\n";
     48                    continue 2;
     49                  }
     50                }
     51            }
    3952
    4053            $id = md5($json->intervention.$json->date.$json->heure.$json->commission);
     
    5366            }
    5467            $intervention->save();
    55         $intervention->free();
     68            $intervention->free();
    5669          }
    5770          unlink($dir.$file);
Note: See TracChangeset for help on using the changeset viewer.