/**
 * Genera un elenco csv di atti con i loro tag (id)
 * ATTO_ID, N_TAG, TAG_ID_1, TAG_ID_2, ...
 */
function run_stlab_genera_atti_tags_csv($task, $args, $options)
{
    static $loaded;
    // load application context
    if (!$loaded) {
        _loader();
    }
    $file_path = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . "stlab" . DIRECTORY_SEPARATOR . "atti_tags.csv";
    $act_types = array();
    if (array_key_exists('file_path', $options)) {
        $file_path = strtolower($options['file_path']);
    }
    if (array_key_exists('types', $options)) {
        $act_types = explode(",", $options['types']);
    }
    echo "memory usage: " . memory_get_usage() . "\n";
    $start_time = time();
    $msg = sprintf("generazione csv tag di ogni atto\n");
    echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
    $fh = fopen($file_path, 'w');
    // estrae tutti i DDL
    $c = new Criteria();
    if (count($act_types)) {
        $c->add(OppAttoPeer::TIPO_ATTO_ID, $act_types, Criteria::IN);
    }
    $atti = OppAttoPeer::doSelect($c);
    $n_atti = count($atti);
    foreach ($atti as $cnt => $atto) {
        $tags_ids = $atto->getTagsIds();
        if (count($tags_ids)) {
            $row = sprintf("%d,%d,%s", $atto->getId(), count($tags_ids), implode(",", $tags_ids));
            printf("%5d/%5d: %s\n", $cnt, $n_atti, $row);
            fprintf($fh, "%s\n", $row);
        }
    }
    fclose($fh);
    $msg = sprintf("%d atti elaborati\n", $cnt);
    echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
    $msg = sprintf(" [%4d sec] [%10d bytes]\n", time() - $start_time, memory_get_usage());
    echo pakeColor::colorize($msg, array('fg' => 'red', 'bold' => false));
}
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'test');
define('SF_DEBUG', true);
include dirname(__FILE__) . '/../bootstrap/unit.php';
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
$t = new lime_test(14, new lime_output_color());
$test_user_id = 8;
$t->diag('unit test for the sending of the newsletter');
$t->diag('Tests beginning');
// clean the database
$t->diag('Cleaning previously created test records');
$c = new Criteria();
$c->add(OppAttoPeer::PARLAMENTO_ID, 999999);
$existing_records = OppAttoPeer::doSelect($c);
foreach ($existing_records as $rec) {
    $t->diag('Cleaning record ' . get_class($rec) . "(" . $rec->getId() . ")");
    $rec->delete();
}
$c = new Criteria();
$c->add(OppPoliticoPeer::ID, 999999);
$existing_records = OppPoliticoPeer::doSelect($c);
foreach ($existing_records as $rec) {
    $t->diag('Cleaning record ' . get_class($rec) . "(" . $rec->getId() . ")");
    $rec->delete();
}
$t->diag('Create the test act object');
$obj = new OppAtto();
$obj->setTipoAttoId(1);
$obj->setParlamentoId(999999);
<?php

define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
$c = new Criteria();
//$c->add(OppAttoPeer::ID, 8333);
$atti = OppAttoPeer::doSelect($c);
foreach ($atti as $atto) {
    $ctrl = 0;
    $fase_iter = "ok";
    $c1 = new Criteria();
    $c1->addJoin(OppAttoPeer::ID, OppAttoHasIterPeer::ATTO_ID);
    $c1->addJoin(OppIterPeer::ID, OppAttoHasIterPeer::ITER_ID);
    $c1->add(OppAttoPeer::ID, $atto->getId());
    $iters = OppAttoHasIterPeer::doSelect($c1);
    foreach ($iters as $iter) {
        if ($atto->getStatoCod() == 'IC' and $iter->getOppIter()->getCacheCod() == 'CO' || $iter->getOppIter()->getCacheCod() == 'RE' || $iter->getOppIter()->getCacheCod() == 'AP') {
            $ctrl = $iter->getOppIter()->getCacheCod();
            $fase_iter = $iter->getOppIter()->getFase();
            $data = $iter->getData();
            break;
        }
        if ($atto->getStatoCod() == 'CO' and $iter->getOppIter()->getCacheCod() == 'RE' || $iter->getOppIter()->getCacheCod() == 'AP') {
            $ctrl = $iter->getOppIter()->getCacheCod();
            $fase_iter = $iter->getOppIter()->getFase();
            $data = $iter->getData();
            break;
/*
 * This file is part of the Openpolis project
 *
 * (c) 2008 Guglielmo Celata <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Sets the values of the cache fields (stato_cod, stato_fase, stato_last_date)
 * for the opp_atto table, starting from the already inserted opp_atto_has_iter files
 *
 * This can also be used to re-create the cache
 */
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', true);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
$attos = OppAttoPeer::doSelect(new Criteria());
$cnt = 0;
foreach ($attos as $atto) {
    $cnt++;
    $iter_steps = $atto->getOppAttoHasIters();
    echo "{$cnt}) " . $atto->getId() . "(" . count($iter_steps) . ")\n";
    foreach ($iter_steps as $step) {
        $step->save();
    }
}
echo "{$cnt} total\n";
 public function executeDdl2legge()
 {
     if ($this->gruppo != NULL) {
         $c = new Criteria();
         $c->add(OppGruppoPeer::ACRONIMO, $this->gruppo);
         $gruppo = OppGruppoPeer::doSelectOne($c);
         $cariche = OppCaricaHasGruppoPeer::getCarichePerGruppo($gruppo->getId(), 1);
         foreach ($cariche as $carica) {
             $componenti_gruppo[] = $carica->getCaricaId();
         }
     }
     if ($this->gruppo != NULL) {
         $c = new Criteria();
         $c->add(OppGruppoPeer::ACRONIMO, $this->gruppo);
         $gruppo = OppGruppoPeer::doSelectOne($c);
         $cariche = OppCaricaHasGruppoPeer::getCaricheGovernoPerGruppo($gruppo->getId(), 1);
         foreach ($cariche as $carica) {
             $componenti_gruppo[] = $carica;
         }
     }
     $arrs = array();
     $arr_alls = array();
     foreach (array(1, 2, 4) as $i) {
         $c = new Criteria();
         if ($this->gruppo != NULL) {
             $c->addJoin(OppAttoPeer::ID, OppCaricaHasAttoPeer::ATTO_ID);
             $c->add(OppCaricaHasAttoPeer::CARICA_ID, $componenti_gruppo, Criteria::IN);
             $c->add(OppCaricaHasAttoPeer::TIPO, 'P');
         }
         $c->add(OppAttoPeer::TIPO_ATTO_ID, 1);
         $c->add(OppAttoPeer::LEGISLATURA, $this->leg);
         $c->add(OppAttoPeer::INIZIATIVA, $i);
         $c->setDistinct(OppAttoPeer::ID);
         $atti = OppAttoPeer::doSelect($c);
         $c = new Criteria();
         if ($this->gruppo != NULL) {
             $c->addJoin(OppAttoPeer::ID, OppCaricaHasAttoPeer::ATTO_ID);
             $c->add(OppCaricaHasAttoPeer::CARICA_ID, $componenti_gruppo, Criteria::IN);
             $c->add(OppCaricaHasAttoPeer::TIPO, 'P');
         }
         $c->addJoin(OppAttoPeer::ID, OppAttoHasIterPeer::ATTO_ID);
         $c->add(OppAttoPeer::TIPO_ATTO_ID, 1);
         $c->add(OppAttoPeer::LEGISLATURA, $this->leg);
         $c->add(OppAttoPeer::INIZIATIVA, $i);
         $c->add(OppAttoHasIterPeer::ITER_ID, 16);
         $c->setDistinct(OppAttoPeer::ID);
         $leggi = OppAttoHasIterPeer::doSelect($c);
         $tempo_medio = 0;
         foreach ($leggi as $legge) {
             $ddl = $legge->getOppAtto();
             while ($ddl->getPred() != NULL) {
                 $ddl = OppAttoPeer::retrieveByPk($ddl->getPred());
             }
             //$this->data_pres=$ddl->getDataPres();
             //$this->data_appr=$legge->getData();
             $data_pres = strtotime($ddl->getDataPres());
             $data_appr = strtotime($legge->getData());
             $tempo_medio = $tempo_medio + ($data_appr - $data_pres) / 86400;
             $arr_alls[] = array($legge->getOppAtto(), ($data_appr - $data_pres) / 86400);
         }
         if (count($leggi) > 0) {
             $tempo_medio = intval($tempo_medio / count($leggi));
         } else {
             $tempo_medio = $tempo_medio;
         }
         $arrs[] = array(count($atti), count($leggi), $tempo_medio);
     }
     $this->arrs = $arrs;
     function cmp($a, $b)
     {
         if ($a[1] == $b[1]) {
             return 0;
         }
         return $a[1] < $b[1] ? -1 : 1;
     }
     usort($arr_alls, "cmp");
     $this->arr_alls = $arr_alls;
 }
 /**
  * torna gli atti presentati da questa carica (primo firmatario)
  * fino a una certa data
  *
  * @param string $settimana
  * @return array of Opp
  * @author Guglielmo Celata
  */
 public function getPresentedAttos($data = '')
 {
     // quando l'incarico è appena stato creato, non ci sono ancora atti
     if (!$this->isNew()) {
         $c = new Criteria();
         $c->addJoin(OppCaricaHasAttoPeer::ATTO_ID, OppAttoPeer::ID);
         $c->add(OppCaricaHasAttoPeer::TIPO, 'P');
         $c->add(OppCaricaHasAttoPeer::CARICA_ID, $this->getId());
         if ($data != '') {
             $c->add(OppCaricaHasAttoPeer::DATA, $data, Criteria::LESS_THAN);
             $c->add(OppAttoPeer::LEGISLATURA, OppLegislaturaPeer::getCurrent($data));
         } else {
             $c->add(OppAttoPeer::LEGISLATURA, OppLegislaturaPeer::getCurrent());
         }
         $res = OppAttoPeer::doSelect($c);
         return $res;
     }
     return null;
 }
 public static function getAttiPerCommissioneLastIter($sede_id, $stato, $leg)
 {
     $c = new Criteria();
     $c->addJoin(OppAttoPeer::ID, OppAttoHasSedePeer::ATTO_ID);
     $c->add(OppAttoPeer::LEGISLATURA, $leg);
     if ($stato != 'approvato definitivamente') {
         $c->add(OppAttoPeer::STATO_FASE, $stato);
     } else {
         $c->add(OppAttoPeer::STATO_FASE, '%approvato definitivamente%', Criteria::LIKE);
     }
     $c->add(OppAttoPeer::TIPO_ATTO_ID, 1);
     $c->add(OppAttoHasSedePeer::SEDE_ID, $sede_id);
     $c->add(OppAttoHasSedePeer::TIPO, 'Referente');
     $c->addDescendingOrderByColumn(OppAttoPeer::STATO_LAST_DATE);
     return OppAttoPeer::doSelect($c);
 }
<?php

define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/../..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', true);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
$testo = "";
$c = new Criteria();
$c->add(OppAttoPeer::TIPO_ATTO_ID, 1);
$c->add(OppAttoPeer::RAMO, 'C');
$rss = OppAttoPeer::doSelect($c);
foreach ($rss as $rs) {
    $c = new Criteria();
    $c->add(OppDocumentoPeer::ATTO_ID, $rs->getId());
    $docs = OppDocumentoPeer::doSelect($c);
    if (count($docs) > 1) {
        foreach ($docs as $doc) {
            $testo = $testo . $rs->getId() . " - " . $doc->getTitolo() . "\n";
        }
        $testo = $testo . "------------ \n";
    }
}
echo $testo;
mail("*****@*****.**", "ERRORE - Comunicati Governo", $testo, "From: ScriptVotazioniSenato");
?>