Changeset 2681


Ignore:
Timestamp:
May 13, 2012, 3:25:57 PM (8 years ago)
Author:
goya
Message:

donne date début législature dans config et calcule le nombre de mois de mandat pendant que l'assemblée est active d'un député

Location:
cpc/trunk/project
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpc/trunk/project/config/app.yml.example

    r2680 r2681  
    44  secret_key: _______PUT_YOUR_KEY_HERE________
    55  legislature: 13
     6  debut_legislature: "2007-06-20"
    67  fin_legislature: true
    78  groupes_actuels: >
  • cpc/trunk/project/lib/model/doctrine/Parlementaire.class.php

    r2612 r2681  
    614614  }
    615615
     616  public function getNbMois() {
     617    $vacs = Doctrine::getTable('VariableGlobale')->findOneByChamp('vacances');
     618    $vacances = array();
     619    if ($vacs) {
     620      $vacances = unserialize($vacs->value);
     621      unset($vacs);
     622    }
     623    $debut = strtotime(myTools::getDebutLegislature());
     624    $fin = $debut + (5*365-31)*24*3600;  # fin législature définie à 4 ans et 11 mois)
     625    $semaines = 0;
     626    foreach (unserialize($this->getAnciensMandats()) as $m) {
     627      if (preg_match("/^(.*) \/ (.*) \/ (.*)$/", $m, $match)) {
     628        $match[1] = preg_replace("#^(\d+)/(\d+)/(\d+)$#", "\\3-\\2-\\1", $match[1]);
     629        $sta = strtotime($match[1]);
     630        if ($match[2] != "") {
     631          $match[2] = preg_replace("#^(\d+)/(\d+)/(\d+)$#", "\\3-\\2-\\1", $match[2]);
     632          $end = strtotime($match[2]);
     633        } else $end = $fin;
     634        if ($sta < $debut || $end > $fin)
     635          continue;
     636        $semaines += ($end - $sta)/(3600*24*7);
     637        foreach ($vacances as $vacance) {
     638          $week = strtotime($vacance["annee"]."0104 +".($vacance["semaine"] - 1)." weeks");
     639          if ($week >= $sta && $week <= $end)
     640            $semaines--;
     641        }
     642      }
     643    }
     644    return round($semaines*12/53);
     645  }
     646
    616647  private function setInternalPhoto($photo) {
    617648    $this->photo = $photo;
  • cpc/trunk/project/lib/model/doctrine/myTools.class.php

    r2680 r2681  
    1616    $string = preg_replace('/",\s+"/', '","', $string);
    1717    return explode('","', $string);
     18  }
     19
     20  public static function getDebutLegislature() {
     21    $date = sfConfig::get('app_debut_legislature');
     22    if (!$date)
     23      $date = "2007-06-20";
     24    return $date;
    1825  }
    1926
Note: See TracChangeset for help on using the changeset viewer.