/**
  * return all news generated by generator model and keys
  *
  * @param  String generator_model - the PhpName of the model
  * @param  String generator_keys  - the primary keys (serialized, of the generator)
  * @return array of News
  * @author Guglielmo Celata
  **/
 public static function getNewsGeneratedByGeneratorModelAndPrimaryKeys($generator_model, $generator_keys)
 {
     $c = new Criteria();
     $c->add(NewsPeer::GENERATOR_MODEL, $generator_model);
     $c->add(NewsPeer::GENERATOR_PRIMARY_KEYS, $generator_keys);
     return NewsPeer::doSelect($c);
 }
Example #2
0
 public function executeDelete()
 {
     $news = NewsPeer::retrieveByPk($this->getRequestParameter('id'));
     $this->forward404Unless($news);
     $news->delete();
     return $this->redirect('news/list');
 }
/**
* Check and remove news related to non-existing objects
*/
function run_opp_news_clean($task, $args)
{
    static $loaded;
    // load application context
    if (!$loaded) {
        define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
        define('SF_APP', 'fe');
        define('SF_ENVIRONMENT', 'task');
        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();
        sfConfig::set('pake', true);
        error_reporting(E_ALL);
        $loaded = true;
    }
    $start_time = microtime(true);
    $c = new Criteria();
    $c->clearSelectColumns();
    $c->addSelectColumn(NewsPeer::ID);
    $c->addSelectColumn(NewsPeer::RELATED_MONITORABLE_MODEL);
    $c->addSelectColumn(NewsPeer::RELATED_MONITORABLE_ID);
    $n_news = NewsPeer::doCount($c);
    $rs = NewsPeer::doSelectRS($c);
    $k = 0;
    $newsids_to_remove = array();
    $removed_news = 0;
    while ($rs->next()) {
        $news = array();
        $news['id'] = $rs->getInt(1);
        $news['rel_model'] = $rs->getString(2);
        $news['rel_id'] = $rs->getInt(3);
        if (opp_check_single_news($news)) {
            $newsids_to_remove[] = $news['id'];
            $removed_news++;
        }
        $k++;
        if ($k % 100 == 0) {
            print ".";
        }
        if ($k > 0 && $k % 1000 == 0) {
            $rem = count($newsids_to_remove);
            NewsPeer::doDelete($newsids_to_remove);
            print "processed: {$k}/{$n_news} removed: {$rem} ({$removed_news})\n";
            $newsids_to_remove = array();
        }
    }
    $total_time = microtime(true) - $start_time;
    echo pakeColor::colorize('All done! ', array('fg' => 'red', 'bold' => true));
    echo 'Processed ';
    echo pakeColor::colorize(count($n_news), array('fg' => 'cyan'));
    echo ' news in ';
    echo pakeColor::colorize(sprintf("%f", $total_time), array('fg' => 'cyan'));
    echo " seconds\n";
}
 /**
  * build and return criteria to fetch all news related to items monitored by a user,
  * filtered with a given filter
  *
  * @param string $user 
  * @param hash $filters 
  * @return Propel Criteria
  * @author Guglielmo Celata
  */
 public static function getMyMonitoredItemsNewsWithFiltersCriteria($user, $filters)
 {
     // fetch degli oggetti monitorati (se c'è il filtro sui tag, fetch solo di quelli associati a questo tag)
     if ($filters['tag_id'] != '0') {
         $filter_criteria = new Criteria();
         $filter_criteria->add(TagPeer::ID, $filters['tag_id']);
         $monitored_objects = $user->getMonitoredObjects('Tag', $filter_criteria);
     } else {
         $monitored_objects = $user->getMonitoredObjects();
     }
     // criterio di selezione delle news dagli oggetti monitorati
     $c = self::getMyMonitoredItemsNewsCriteria($monitored_objects);
     // eliminazione delle notizie relative agli oggetti bookmarkati negativamente (bloccati)
     $blocked_items_ids = sfBookmarkingPeer::getAllNegativelyBookmarkedIds($user->getId());
     if (array_key_exists('OppAtto', $blocked_items_ids) && count($blocked_items_ids['OppAtto'])) {
         $blocked_news_ids = array();
         $bc = new Criteria();
         $bc->add(NewsPeer::RELATED_MONITORABLE_MODEL, 'OppAtto');
         $bc->add(NewsPeer::RELATED_MONITORABLE_ID, $blocked_items_ids['OppAtto'], Criteria::IN);
         $bc->clearSelectColumns();
         $bc->addSelectColumn(NewsPeer::ID);
         $rs = NewsPeer::doSelectRS($bc);
         while ($rs->next()) {
             array_push($blocked_news_ids, $rs->getInt(1));
         }
         $c0 = $c->getNewCriterion(NewsPeer::ID, $blocked_news_ids, Criteria::NOT_IN);
         $c->addAnd($c0);
     }
     // le news di gruppo non sono considerate, perché ridondanti (#247)
     $c->add(NewsPeer::GENERATOR_PRIMARY_KEYS, null, Criteria::ISNOTNULL);
     // aggiunta filtri su tipi di atto, ramo e data
     if ($filters['act_type_id'] != '0') {
         $c->add(NewsPeer::TIPO_ATTO_ID, $filters['act_type_id']);
     }
     if ($filters['act_ramo'] != '0') {
         $c->add(NewsPeer::RAMO_VOTAZIONE, $filters['act_ramo']);
     }
     if ($filters['date'] != '0') {
         if ($filters['date'] == 'W') {
             $c->add(NewsPeer::CREATED_AT, date('Y-m-d H:i', strtotime('-1 week')), Criteria::GREATER_THAN);
         } elseif ($filters['date'] == 'M') {
             $c->add(NewsPeer::CREATED_AT, date('Y-m-d H:i', strtotime('-1 month')), Criteria::GREATER_THAN);
         }
     }
     if ($filters['main_all'] == 'main') {
         $c->add(NewsPeer::PRIORITY, 2, Criteria::LESS_EQUAL);
     }
     return $c;
 }
 public function executeNew(sfWebRequest $request)
 {
     $this->menu = MenuPeer::doSelect(new Criteria());
     $c = new Criteria();
     $c->add(PartsPeer::IS_ACTIVE, 1);
     $this->parts = PartsPeer::doSelect($c);
     unset($c);
     $id = $request->getParameter('id');
     $c0 = new Criteria();
     $c0->add(NewsPeer::IS_ACTIVE, 1);
     $c0->add(NewsPeer::ID, $id);
     $this->new = NewsPeer::doSelect($c0);
     $this->new = $this->new[0];
     unset($c0);
 }
Example #6
0
 /**
  * Returns the number of related News objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related News objects.
  * @throws     PropelException
  */
 public function countNewss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(ImagesPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collNewss === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(NewsPeer::IMAGES_ID, $this->id);
             $count = NewsPeer::doCount($criteria, false, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(NewsPeer::IMAGES_ID, $this->id);
             if (!isset($this->lastNewsCriteria) || !$this->lastNewsCriteria->equals($criteria)) {
                 $count = NewsPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collNewss);
             }
         } else {
             $count = count($this->collNewss);
         }
     }
     return $count;
 }
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Import into sf_news_cache, starting from already populated tables.
 * Since this script cleans the sf_news_cache table, use with extreme care.
 * It can be used in order to re-build all the news.
 */
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'prod');
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();
// uncomment to clean all news
NewsPeer::doDeleteAll();
// define all news generators and the corresponding date fields (null = no field) for sorting purposes
$generators = array('OppCaricaHasAtto' => OppCaricaHasAttoPeer::DATA, 'OppVotazioneHasAtto' => null, 'OppDocumento' => OppDocumentoPeer::DATA, 'OppAttoHasIter' => OppAttoHasIterPeer::DATA, 'OppAttoHasSede' => null, 'OppIntervento' => OppInterventoPeer::DATA, 'OppAtto' => OppAttoPeer::DATA_PRES, 'OppCaricaHasGruppo' => OppCaricaHasGruppoPeer::DATA_INIZIO, 'OppCarica' => OppCaricaPeer::DATA_INIZIO);
$tot_cnt = 0;
foreach ($generators as $model => $date_field) {
    echo "Importing from {$model} ";
    $c = new Criteria();
    // extract the number of items to process for the generator
    $n_todo = call_user_func_array(array($model . 'Peer', 'doCount'), array($c));
    echo "({$n_todo}) ";
    // get table map and columns map for this generator
    $model_table = call_user_func($model . 'Peer::getTableMap');
    $model_columns = $model_table->getColumns();
    // find and store primary keys
    $pks = array();
    foreach ($model_columns as $column) {
 /**
  * delete all news related to this object before deleting the object
  *
  * @param string $con 
  * @return void
  * @author Guglielmo Celata
  */
 public function delete($con = null)
 {
     try {
         $c = new Criteria();
         $c->add(NewsPeer::RELATED_MONITORABLE_MODEL, 'OppAtto');
         $c->add(NewsPeer::RELATED_MONITORABLE_ID, $this->getPrimaryKey());
         NewsPeer::doDelete($c);
     } catch (Exception $e) {
         throw new deppPropelActAsNewsGeneratorException('Unable to delete related monitorable object records');
     }
     parent::delete($con);
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = NewsPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setMetaId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setTitle($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setAnnounce($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setText($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setOrd($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setIsActive($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setCreatedAt($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setId($arr[$keys[7]]);
     }
 }
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(NewsPeer::ID, $pks, Criteria::IN);
         $objs = NewsPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * Deletes all news originated from a generator object (delete cascade emulation)
  * 
  * @param  BaseObject  $object
  */
 public function preDelete(BaseObject $object)
 {
     try {
         $c = new Criteria();
         $c->add(NewsPeer::GENERATOR_MODEL, get_class($object));
         $c->add(NewsPeer::GENERATOR_PRIMARY_KEYS, serialize($this->getPrimaryKeysArray($object)));
         NewsPeer::doDelete($c);
     } catch (Exception $e) {
         throw new deppPropelActAsNewsGeneratorException('Unable to delete related monitorable object records');
     }
 }
Example #12
0
 public function executeShow()
 {
     $this->news = NewsPeer::retrieveByPK($this->getRequestParameter('id'));
 }
 /**
  * last news (ordered by creation time) related to the politician
  *
  * @return date(d/m/Y h:m)
  * @author Guglielmo Celata
  **/
 public function getLastNews(BaseObject $object)
 {
     $c = new Criteria();
     $c->add(NewsPeer::RELATED_MONITORABLE_MODEL, get_class($object));
     $c->add(NewsPeer::RELATED_MONITORABLE_ID, $this->getReferenceKey($object));
     $c->addDescendingOrderByColumn(NewsPeer::CREATED_AT);
     return NewsPeer::doSelectOne($c);
 }
Example #14
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = NewsPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setLabel($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setShortDescription($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setImage($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setDownload($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setContent($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setStartDate($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setEndDate($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setRds($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setKeywords($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setCreatedAt($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setUpdatedAt($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setPublicationStatus($arr[$keys[12]]);
     }
 }
<?php

/*
controlla le news che fanno riferimento a tag che non esistono e le cancella
*/
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(NewsPeer::RELATED_MONITORABLE_MODEL, 'Tag');
$news = NewsPeer::doSelect($c);
foreach ($news as $n) {
    $tag = TagPeer::retrieveByPk($n->getRelatedMonitorableId());
    if (!$tag) {
        echo "tag id=" . $n->getRelatedMonitorableId() . ", trovato nelle news id=" . $n->getId() . " non esiste. Cancello la news\n";
        $n->delete();
    }
}
/**
 * get all the news in sf_news_cache, related to a given object
 *
 * @return array of News objects
 * @author Guglielmo Celata
 **/
function getRelatedNews($obj)
{
    $c = new Criteria();
    $c->add(NewsPeer::RELATED_MONITORABLE_MODEL, get_class($obj));
    $c->add(NewsPeer::RELATED_MONITORABLE_ID, $obj->getPrimaryKey());
    $related_news = NewsPeer::doSelect($c);
    return $related_news;
}
                if (!$r) {
                    $rs->setMonitorableId($tag_new[$k]);
                    $rs->save();
                    echo "Monitoraggio cambiato: " . $old . " con " . $tag_new[$k] . " per utente " . $rs->getUserId() . "\n";
                    $number_monitor_ok = $number_monitor_ok + 1;
                } else {
                    $rs->delete();
                    $number_monitor_no = $number_monitor_no + 1;
                    echo "!!!! DOPPIONE" . $old . " con " . $tag_new[$k] . " per utente " . $rs->getUserId() . "\n";
                }
            }
        }
    }
    //Cancella tutte le news legate ai vecchi tags
    foreach ($tag_old as $k => $old) {
        $news = NewsPeer::getNewsRelatedToMonitorableModelAndId('Tag', $old);
        foreach ($news as $new) {
            $new->delete();
            echo "cancello news \n";
        }
    }
    //Cancella i tag vecchi
    foreach ($tag_old as $k => $old) {
        $tag = TagPeer::retrieveByPk($old);
        if ($tag) {
            $tag->delete();
            echo "cancello tag \n";
        }
    }
} else {
    echo "!!!!! Gli array hanno un numero di elementi diversi!";
Example #18
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = NewsPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setName($arr[$keys[1]]);
     }
 }
Example #19
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = NewsPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setTitle($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setCreatedAt($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setTextDes($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setImage($arr[$keys[4]]);
     }
 }