public function executeManageItem()
 {
     $this->item_model = get_class($this->item);
     switch ($this->item_model) {
         case 'OppPolitico':
             $this->item_type = 'politico';
             break;
         case 'OppAtto':
             $this->item_type = 'atto';
             break;
         case 'Tag':
             $this->item_type = 'argomento';
             break;
     }
     if ($this->item_type == 'atto' || $this->item_type == 'politico') {
         $this->nMonitoringUsers = $this->item->countAllMonitoringUsers();
     } else {
         $this->nMonitoringUsers = count($this->item->getMonitoringUsersPKs());
     }
     if ($this->getUser()->isAuthenticated()) {
         $user = OppUserPeer::retrieveByPK($this->getUser()->getId());
         $this->item_pk = $this->item->getPrimaryKey();
         $this->is_monitoring = $user->isMonitoring($this->item_model, $this->item_pk);
     }
 }
 /**
  * pre-execution: 
  *  - get the request parameters, 
  *  - check if the user has the 'right' to bookmark, 
  *  - prepare variables
  */
 public function preExecute()
 {
     $item_model = $this->getRequestParameter('item_model');
     $item_pk = $this->getRequestParameter('item_pk');
     $this->user_id = deppPropelActAsBookmarkableToolkit::getUserId();
     $user = OppUserPeer::retrieveByPK($this->user_id);
     $this->item = deppPropelActAsBookmarkableToolkit::retrieveBookmarkableObject($item_model, $item_pk);
 }
 /**
  * pre-execution: 
  *  - get the request parameters, 
  *  - check if the user has the 'right' to bookmark, 
  *  - prepare variables
  */
 public function preExecute()
 {
     $item_model = $this->getRequestParameter('item_model');
     $item_pk = $this->getRequestParameter('item_pk');
     $this->user_id = deppPropelActAsBookmarkableToolkit::getUserId();
     $user = OppUserPeer::retrieveByPK($this->user_id);
     $this->item = deppPropelActAsBookmarkableToolkit::retrieveBookmarkableObject($item_model, $item_pk);
     // go to error page if user is not monitoring the object (security)
     $this->forward404Unless($user->isMonitoring($item_model, $item_pk) || $user->isIndirectlyMonitoringAct($item_pk) || $this->item->hasBeenPositivelyBookmarked($this->user_id));
     // an object was bookmarked, clear the acts cache
     $cacheManager = $this->getContext()->getViewCacheManager();
     $user_token = $this->getUser()->getToken();
     if (!is_null($cacheManager)) {
         $cacheManager->remove('monitoring/acts?user_token=' . $user_token);
     }
 }
 public function executeTagsAutocomplete()
 {
     $this->my_str = $this->getRequestParameter('q');
     $limit = $this->getRequestParameter('limit');
     $caller = $this->getRequestParameter('caller');
     // estrazione elementi che iniziano per ...
     $c = new Criteria();
     $c->add(TagPeer::TRIPLE_VALUE, $this->my_str . "%", Criteria::LIKE);
     $opp_user = OppUserPeer::retrieveByPK($this->getUser()->getId());
     // esclusione tag già monitorati se chiamta da addToMonitored
     if ($caller == 'addToMonitored' && $opp_user instanceof OppUser) {
         $c->add(TagPeer::ID, $opp_user->getMonitoredPks('Tag'), Criteria::NOT_IN);
     }
     if (isset($limit)) {
         $c->setLimit($limit);
     }
     $tags_starting = TagPeer::getAll($c, array('is_triple' => true, 'return' => 'value'));
     $tags_ids = array();
     foreach ($tags_starting as $tag) {
         $tags_ids[] = $tag->getId();
     }
     // estrazione elementi che contengono ... (tranne quelli che iniziano per)
     $c = new Criteria();
     $c->add(TagPeer::TRIPLE_VALUE, "%" . $this->my_str . "%", Criteria::LIKE);
     $c1 = $c->getNewCriterion(TagPeer::ID, $tags_ids, Criteria::NOT_IN);
     // esclusione tag già monitorati se chiamata da addToMonitored
     if ($caller == 'addToMonitored' && $opp_user instanceof OppUser) {
         $c2 = $c->getNewCriterion(TagPeer::ID, $opp_user->getMonitoredPks('Tag'), Criteria::NOT_IN);
         $c1->addAnd($c2);
     }
     $c->add($c1);
     if (isset($limit)) {
         $c->setLimit($limit - count($tags_starting));
     }
     $tags_ending = TagPeer::getAll($c, array('is_triple' => true, 'return' => 'value'));
     // costruzione array totale dei tag estratti
     $tags = $tags_starting;
     foreach ($tags_ending as $tag) {
         $tags[] = $tag;
         // $tags_ids []= $tag->getId();
     }
     $this->tags = $tags;
 }
 public function executeUserNews()
 {
     $this->session = $this->getUser();
     // legge sempre i filtri dalla sessione utente
     $filters['tag_id'] = $this->session->getAttribute('tag_id', '0', 'monitoring_filter');
     $filters['act_type_id'] = $this->session->getAttribute('act_type_id', '0', 'monitoring_filter');
     $filters['act_ramo'] = $this->session->getAttribute('act_ramo', '0', 'monitoring_filter');
     $filters['date'] = $this->session->getAttribute('date', '0', 'monitoring_filter');
     $filters['main_all'] = $this->session->getAttribute('main_all', 'main', 'news_filter');
     $token = $this->getRequestParameter('token');
     // se utente non loggato, cerca l'id con il token
     if (!$this->session->isAuthenticated()) {
         $remote_guard_host = sfConfig::get('sf_remote_guard_host', 'op_accesso.openpolis.it');
         $key = sfConfig::get('sf_internal_api_key', 'XXX');
         $api_uri = "http://{$remote_guard_host}/index.php/getUserIdFromToken/{$token}/{$key}";
         $xml = simplexml_load_file($api_uri);
         if ($xml->user instanceof SimpleXMLElement && $xml->user->asXML() != '') {
             $user_id = $xml->user->id;
         } else {
             $this->forward404("Utente non loggato e token non riconosciuto: {$api_uri}");
         }
     } else {
         $user_id = $this->session->getId();
     }
     $user = OppUserPeer::retrieveByPK($user_id);
     // costruisce criterio di fetch delle news relative agli oggetti monitorati, con filtro
     $c = oppNewsPeer::getMyMonitoredItemsNewsWithFiltersCriteria($user, $filters);
     $c->setLimit(50);
     $this->pager = new deppNewsPager('News', 50);
     $this->pager->setCriteria($c);
     $this->pager->setPage($this->getRequestParameter('page', 1));
     $this->pager->init();
     $feed = $this->_make_feed_from_pager('Ultime notizie per te', '@monitoring_news?user_token=' . $this->getUser()->getToken(), $this->pager);
     $this->_send_output($feed);
     return sfView::NONE;
 }
 public function executeSottoscrizionePremiumDemo()
 {
     if ($this->getUser()->hasCredential('premium')) {
         $this->redirect('@homepage');
     }
     // processes the form if posted
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $this->redirect_to = $this->getUser()->getAttribute('page_before_buy', '@homepage');
         $user = OppUserPeer::retrieveByPK($this->getUser()->getAttribute('subscriber_id', 0, 'subscriber'));
         // DB Storage for form data
         // with some server-validation
         $premium_form = new OppPremiumDemo();
         $premium_form->setEta($this->getRequestParameter('eta'));
         $attivitas = $this->getRequestParameter('attivita');
         $att = $attivitas[0];
         $premium_form->setAttivita($att);
         if ($this->getRequestParameter('attivita_aut_desc') != '' && $att == 8) {
             $premium_form->setAttivitaAutDesc(strip_tags($this->getRequestParameter('attivita_aut_desc')));
         }
         if ($this->getRequestParameter('attivita_dip_desc') != '' && $att > 8 && $att < 12) {
             $premium_form->setAttivitaDipDesc(strip_tags($this->getRequestParameter('attivita_dip_desc')));
         }
         if ($this->getRequestParameter('attivita_amm_desc') != '' && $att > 11 && $att < 17) {
             $premium_form->setAttivitaAmmDesc(strip_tags($this->getRequestParameter('attivita_amm_desc')));
         }
         $perches = $this->getRequestParameter('perche');
         $perche = $perches[0];
         $premium_form->setPerche($perche);
         if ($this->getRequestParameter('perche_altro_desc') != '' && $perche == 4) {
             $premium_form->setPercheAltroDesc($this->getRequestParameter('perche_altro_desc'));
         }
         $premium_form->setOppUser($user);
         $premium_form->save();
         // richiesta di upgrade della sottoscrizione utente
         $token = $this->getUser()->getToken();
         $opaccesso_key = sfConfig::get('api_opaccesso_key', '--XXX(-:-)XXX--');
         $remote_guard_host = sfConfig::get('sf_remote_guard_host', 'op_accesso.openpolis.it');
         // finezza: se sono in dev, rimane in dev
         if (sfConfig::get('sf_environment') == 'dev') {
             $controller = 'be_dev.php';
         } else {
             $controller = 'index.php';
         }
         $xml = simplexml_load_file("http://{$remote_guard_host}/{$controller}/promoteUserDemo/{$token}/{$opaccesso_key}");
         // show message if something really wrong happens (could not write last_login to db)
         if (!$xml->ok instanceof SimpleXMLElement) {
             sfLogger::getInstance()->info('xxx: user promotion failed: ' . (string) $xml->error);
             $this->error = (string) $xml->error;
             return sfView::ERROR;
         } else {
             // modify monitoring limits
             $user->setNMaxMonitoredItems(sfConfig::get('app_premium_max_items', 10));
             $user->setNMaxMonitoredTags(sfConfig::get('app_premium_max_tags', 5));
             $user->setNMaxMonitoredAlerts(sfConfig::get('app_premium_max_alerts', 3));
             $user->save();
             // add credential to the user
             $this->getUser()->addCredential('premium');
             // set the flash message for the promotion
             $this->setFlash('subscription_promotion', sfConfig::get('app_subscription_civicus_promoted'));
         }
         // clean session variable and redirect
         $this->getUser()->getAttributeHolder()->remove('page_before_buy');
         $this->redirect($this->redirect_to);
     }
 }
$object2->unpublishComment($comments[0]['Id']);
$t->ok(call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == 1 && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) != $object2->getNbComments() && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbPublicComments(), 'unpublishing works fine (and cache is ok)');
$object2->publishComment($comments[0]['Id']);
$t->ok(call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == 2 && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbComments() && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbPublicComments(), 'publishing works fine (and cache is ok)');
$t->diag('removal');
$object2->removeComment($comments[0]['Id']);
$t->ok(call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == 1 && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbComments() && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbPublicComments(), 'removing works fine (and cache is ok)');
$object2->clearComments();
$t->ok(call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == 0 && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbComments() && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbPublicComments(), 'clearing all comments fine (and cache is ok)');
// these tests check for comments inserted by authenticated users
$t->diag('comments by authenticated users');
// autenticazione (user_id = 8, è un utenza con mail e website)
// bisogna settare
//  enabled: true
//  name_method, email_method, website_method
$user = OppUserPeer::retrieveByPK(8);
sfContext::getInstance()->getUser()->signIn($user);
$object1 = _create_object();
$object1->setName('oggetto per commento autenticato');
$object1->save();
$object1->addComment('My first comment.');
$comments = $object1->getComments();
$t->ok($comments[0]['AuthorId'] != null && $comments[0]['AuthorName'] != null && $comments[0]['AuthorWebsite'] != null, 'comments by authenticated users have an author_id field');
// logout
sfContext::getInstance()->getUser()->signOut();
// test object creation
function _create_object()
{
    $classname = TEST_CLASS;
    if (!class_exists($classname)) {
        throw new Exception(sprintf('Unknow class "%s"', $classname));
 protected static function _getMyTags()
 {
     // fetch tags I am monitoring
     $opp_user = OppUserPeer::retrieveByPK(sfContext::getInstance()->getUser()->getId());
     return $opp_user->getMonitoredObjects('Tag');
 }
 /**
  * generate a removal community news (a user has un-done something on an object)
  *
  * @return the number of generated news
  * @author Guglielmo Celata
  **/
 public function generateRemovalCommunityNews(BaseObject $object)
 {
     try {
         // fetch the object related to this generator
         $mobj = $this->getRelatedObject($object);
         $n = new CommunityNews();
         $n->setGeneratorModel(get_class($object));
         $n->setGeneratorPrimaryKeys(serialize($this->getPrimaryKeysArray($object)));
         $n->setRelatedModel(get_class($mobj));
         $n->setRelatedId($mobj->getPrimaryKey());
         $n->setType('D');
         // fetch and set of the user name (wiki case and the rest)
         if ($object instanceof nahoWikiRevision) {
             $username = $object->getUserName();
         } else {
             if ($object instanceof sfComment || $object instanceof sfEmendComment) {
                 $username = $object->getAuthorName();
             } else {
                 $user = OppUserPeer::retrieveByPK($object->getUserId());
                 $username = $user->__toString();
             }
         }
         $n->setUsername($username);
         $n->save();
     } catch (Exception $e) {
         throw new deppPropelActAsNewsGeneratorException($e->getMessage());
     }
 }
 /**
  * estrae i tag relativi al top tem
  *
  * @return void
  * @author Guglielmo Celata
  */
 public function executeAjaxTagsForTopTerm()
 {
     $isAjax = $this->getRequest()->isXmlHttpRequest();
     if (!$isAjax) {
         return sfView::noAjax;
     }
     $opp_user = OppUserPeer::retrieveByPK($this->getUser()->getId());
     $top_term_id = $this->getRequestParameter('tt_id');
     $c = new Criteria();
     $c->add(OppTagHasTtPeer::TESEOTT_ID, $top_term_id);
     $c->addJoin(OppTagHasTtPeer::TAG_ID, TagPeer::ID);
     $c->addAscendingOrderByColumn(TagPeer::TRIPLE_VALUE);
     $this->tags = TagPeer::getPopulars($c);
 }
/**
 * fetch today's news regarding objects monitored by the user
 *
 * @param string $user - OppUser object
 * @return void
 * @author Guglielmo Celata
 */
function downgrade($user_id, $user_email)
{
    $start_time = microtime(true);
    $success = true;
    echo pakeColor::colorize(sprintf('Processing user %s...', $user_email), array('fg' => 'red', 'bold' => true));
    # rimozione della credential 'premium'
    # set a NULL della data di scadenza
    # downgrade on op_accesso
    $opaccesso_key = sfConfig::get('api_opaccesso_key', '--XXX(-:-)XXX--');
    $remote_guard_host = sfConfig::get('sf_remote_guard_host', 'op_accesso.openpolis.it');
    if (sfConfig::get('sf_environment') == 'dev') {
        $controller = 'be_dev.php';
    } else {
        $controller = 'index.php';
    }
    $xml = simplexml_load_file("http://{$remote_guard_host}/{$controller}/downgradePremium/{$user_id}/{$opaccesso_key}");
    echo "opaccessokey: {$opaccesso_key}\n";
    $success = false;
    if ($xml->ok) {
        try {
            # rimozione di tutti i monitoraggi attivi
            # set a 5/0 del n. max di item e argomenti monitorabili
            $opp_user = OppUserPeer::retrieveByPK($user_id);
            $opp_user->removeAllMonitoredObjects();
            $opp_user->setNMaxMonitoredItems(5);
            $opp_user->setNMaxMonitoredTags(0);
            $opp_user->save();
            $success = true;
        } catch (Exception $e) {
            $err = $e->getMessage();
        }
    } else {
        if ($xml->error) {
            $err = (string) $xml->error;
        } else {
            $err = "Errore sconosciuto";
        }
    }
    $execution_time = microtime(true) - $start_time;
    if ($success) {
        echo " ok (";
    } else {
        echo " {$err} (";
    }
    echo pakeColor::colorize(sprintf("%f", $execution_time), array('fg' => 'cyan'));
    echo ")\n";
}
 public static function getMyMonitoredItemsNewsCriteria($monitored_objects)
 {
     $opp_user = OppUserPeer::retrieveByPK(sfContext::getInstance()->getUser()->getId());
     return self::getUserMonitoredItemsNewsCriteria($opp_user, $monitored_objects);
 }
예제 #13
0
<?php

if ($sf_flash->has('notice')) {
    ?>
  <div class="flash-messages" style="background-color: #afa">
    <?php 
    echo $sf_flash->get('notice');
    ?>
  </div>
<?php 
}
?>

<?php 
if ($sf_user->isAuthenticated() && ($sf_user->hasCredential('amministratore') || $sf_user->hasCredential('adhoc')) && !OppAlertUserPeer::hasAlert($query, OppUserPeer::retrieveByPK($sf_user->getId()), $type_filters)) {
    ?>
  <h4 style="margin-left: 0.5em">
    <?php 
    echo link_to("avvisami quando questa espressione viene usata alla Camera o al Senato" . ($type_filters != '' ? ", con questi filtri: {$type_filters_label}" : ""), 'monitoring/addAlert?term=' . str_replace("/", "|", $query) . "&type_filters={$type_filters}");
    ?>
  </h4>        
<?php 
}