Example #1
0
 public function executeSendStmt()
 {
     if ($this->reviewType == Politico::NUM_ENTITY) {
         $this->politico = PoliticoPeer::retrieveByPK($this->reviewEntityId);
     } else {
         if ($this->reviewType == Partido::NUM_ENTITY) {
             $this->partido = PartidoPeer::retrieveByPK($this->reviewEntityId);
         } else {
             if ($this->reviewType != null) {
                 $type = SfReviewTypePeer::retrieveByPk($this->reviewType);
                 $peer = $type->getModel() . 'Peer';
                 $this->entity = $peer::retrieveByPK($this->reviewEntityId);
             } else {
                 if ($this->reviewType == null) {
                     $review_ = SfReviewPeer::retrieveByPK($this->reviewEntityId);
                     if ($review_) {
                         $this->review = $review_;
                         if ($this->review->getSfReviewTypeId() == Politico::NUM_ENTITY) {
                             $this->politico = PoliticoPeer::retrieveByPK($this->review->getEntityId());
                         } else {
                             if ($this->review->getSfReviewTypeId() == Partido::NUM_ENTITY) {
                                 $this->partido = PartidoPeer::retrieveByPK($this->review->getEntityId());
                             } else {
                                 $type = SfReviewTypePeer::retrieveByPk($this->review->getSfReviewTypeId());
                                 $peer = $type->getModel() . 'Peer';
                                 $this->entity = $peer::retrieveByPK($this->review->getEntityId());
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
 public function executeIndex(sfWebRequest $request)
 {
     $culture = $this->getUser()->getCulture();
     $cpos = new Criteria();
     $cpos->add(SfReviewPeer::VALUE, 1);
     $cpos->add(SfReviewPeer::IS_ACTIVE, 1);
     //$cpos->add(SfReviewPeer::CULTURE, $culture);
     $this->totalUpReviews = SfReviewPeer::doCount($cpos);
     $cneg = new Criteria();
     $cneg->add(SfReviewPeer::VALUE, -1);
     $cneg->add(SfReviewPeer::IS_ACTIVE, 1);
     //$cneg->add(SfReviewPeer::CULTURE, $culture);
     $this->totalDownReviews = SfReviewPeer::doCount($cneg);
     $exclude = "";
     $this->reviewables = EntityManager::getTopEntities(6, $exclude, "WebEntity", true);
     $c = new Criteria();
     $c->addDescendingOrderByColumn(PoliticoPeer::SUMU);
     $c->addAscendingOrderByColumn(PoliticoPeer::SUMD);
     $c->setLimit(5);
     $this->topPoliticos = PoliticoPeer::doSelect($c);
     $c = new Criteria();
     $c->addDescendingOrderByColumn(PartidoPeer::SUMU);
     $c->addAscendingOrderByColumn(PartidoPeer::SUMD);
     $c->setLimit(5);
     $c->add(PartidoPeer::IS_ACTIVE, true);
     $this->partidosMasVotados = PartidoPeer::doSelect($c);
     $c = new Criteria();
     $c->addDescendingOrderByColumn(PropuestaPeer::SUMU);
     $c->addAscendingOrderByColumn(PropuestaPeer::SUMD);
     $c->setLimit(5);
     $c->add(PropuestaPeer::IS_ACTIVE, true);
     $c->add(PropuestaPeer::CULTURE, $culture);
     $this->propuestasMasVotadas = PropuestaPeer::doSelect($c);
     //Totales
     /*
     $c = new Criteria();
     $this->totalPoliticos = PoliticoPeer::doCount($c);
     $c = new Criteria();
     $c->add(PartidoPeer::IS_ACTIVE, true);
     $this->totalPartidos = PartidoPeer::doCount($c);
     $c = new Criteria();
     $c->add(PropuestaPeer::IS_ACTIVE, true);
     $c->add(PropuestaPeer::CULTURE, $culture);
     $this->totalPropuestas = PropuestaPeer::doCount($c);
     */
     $this->response->addMeta('Description', sfContext::getInstance()->getI18N()->__('Comparte opiniones sobre políticos y partidos de España. Ranking de los políticos y partidos más votados.'));
     // Ultimos comentarios
     $filter = array();
     $filter['culture'] = $culture;
     //$this->topReviews = SfReviewManager::getReviews($filter, 1, 5);
     $this->activities = SfReviewManager::getActivities($filter, 1, 5);
     // elecciones destacadas
     $convocatoriaActiva = sfConfig::get('sf_convocatoria_activa');
     $this->convocatoria = ConvocatoriaPeer::retrieveByPk($convocatoriaActiva);
 }
Example #3
0
 public function executeReviews(sfWebRequest $request)
 {
     $op = $request->getParameter('o');
     $this->f = $request->getParameter('f');
     $culture = $this->getUser()->getCulture();
     $this->sfReviewType = $request->getParameter("type_id", false);
     $this->text = $request->getParameter("t", false);
     $this->forward404Unless($this->getUser()->getGuardUser());
     $c = new Criteria();
     $c->add(PropuestaPeer::SF_GUARD_USER_ID, $this->getUser()->getGuardUser()->getId());
     $c->addDescendingOrderByColumn('created_at');
     $this->propuestas = PropuestaPeer::doSelect($c);
     if ($op == 'v' || $op == 'e') {
         $t = $request->getParameter('t');
         $e = $request->getParameter('e');
         $r = $request->getParameter('r');
         if ($t == '') {
             $review = SfReviewPeer::retrieveByPk($e);
             $type = $review->getSfReviewType();
             $peer = $type->getModel() . 'Peer';
             $c = new Criteria();
             $c->addJoin($peer::ID, SfReviewPeer::ENTITY_ID, Criteria::INNER_JOIN);
             $c->add(SfReviewPeer::ID, $e);
             $entity = $peer::doSelectOne($c);
             $dest = $type->getModule() . "/show?id=" . $entity->getVanity();
         } else {
             $type = SfReviewTypePeer::retrieveByPk($t);
             $peer = $type->getModel() . 'Peer';
             $entity = $peer::retrieveByPK($e);
             $dest = $type->getModule() . "/show?id=" . $entity->getVanity();
         }
         if ($op == 'e') {
             $this->getUser()->setAttribute('review_v', 1);
             $this->getUser()->setAttribute('review_e', $entity->getId());
             $this->getUser()->setAttribute('review_c', $e);
         }
         if ($t == '') {
             $dest .= "#subreviews_box{$e}";
         } else {
             if ($op == 'v') {
                 $dest .= "#sf_review_c_m{$r}";
             }
         }
         $this->redirect($dest);
     }
     if (!$this->getUser()->isAuthenticated()) {
         $this->getUser()->setFlash('notice_type', 'warning', true);
         $this->getUser()->setFlash('notice', sfContext::getInstance()->getI18N()->__('¿Nuevo por aquí? Necesitas tener una cuenta Voota (o en Facebook) para continuar. Tu vooto será público o secreto, como gustes.', array()), true);
         $this->getUser()->setAttribute('url_back', '@usuario_votos', 'vo/redir');
     }
     $this->redirectUnless($this->getUser()->isAuthenticated(), "@sf_guard_signin");
     $this->reviews = SfReviewManager::getReviewsByUser($this->getUser()->getGuardUser()->getId(), $this->f);
     $this->user = $this->getUser()->getGuardUser();
 }
Example #4
0
 function getEntity()
 {
     if (!$this->entity) {
         if ($this->getType()) {
             $this->aReview = false;
             $type = SfReviewTypePeer::retrieveByPk($this->getType());
             $peer = $type->getModel() . 'Peer';
             $this->entity = call_user_func("{$peer}::retrieveByPK", $this->entity_id);
         } else {
             $this->aReview = SfReviewPeer::retrieveByPk($this->sf_review_id);
             //$this->aReview = $this->review->getSfReviewRelatedBySfReviewId();
             if ($this->aReview) {
                 $peer = $this->aReview->getSfReviewType()->getModel() . 'Peer';
                 $this->entity = call_user_func("{$peer}::retrieveByPk", $this->aReview->getEntityId());
             }
         }
     }
     return $this->entity;
 }
Example #5
0
 public function executeUsuarioResult()
 {
     $this->quote = '';
     if (SfVoUtil::matches($this->obj->getProfile()->getNombre(), $this->q)) {
     } else {
         if (SfVoUtil::matches($this->obj->getProfile()->getApellidos(), $this->q)) {
         } else {
             if (SfVoUtil::matches($this->obj->getProfile()->getPresentacion(), $this->q)) {
                 $this->quote = $this->obj->getProfile()->getPresentacion();
             }
         }
     }
     $c = new Criteria();
     $c->add(SfReviewPeer::SF_GUARD_USER_ID, $this->obj->getId());
     $c->add(SfReviewPeer::IS_ACTIVE, true);
     $this->numReviews = SfReviewPeer::doCount($c);
     $this->quote = SfVoUtil::highlightWords($this->quote, $this->q);
 }
Example #6
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this sfGuardUser is new, it will return
  * an empty collection; or if this sfGuardUser has previously
  * been saved, it will retrieve related SfReviews from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in sfGuardUser.
  */
 public function getSfReviewsJoinSfReviewRelatedBySfReviewId($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(sfGuardUserPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collSfReviews === null) {
         if ($this->isNew()) {
             $this->collSfReviews = array();
         } else {
             $criteria->add(SfReviewPeer::SF_GUARD_USER_ID, $this->id);
             $this->collSfReviews = SfReviewPeer::doSelectJoinSfReviewRelatedBySfReviewId($criteria, $con, $join_behavior);
         }
     } else {
         // 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 the collection.
         $criteria->add(SfReviewPeer::SF_GUARD_USER_ID, $this->id);
         if (!isset($this->lastSfReviewCriteria) || !$this->lastSfReviewCriteria->equals($criteria)) {
             $this->collSfReviews = SfReviewPeer::doSelectJoinSfReviewRelatedBySfReviewId($criteria, $con, $join_behavior);
         }
     }
     $this->lastSfReviewCriteria = $criteria;
     return $this->collSfReviews;
 }
Example #7
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(SfReviewPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(SfReviewPeer::DATABASE_NAME);
         $criteria->add(SfReviewPeer::ID, $pks, Criteria::IN);
         $objs = SfReviewPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 public function executePreview(sfWebRequest $request)
 {
     if (!$this->getUser()->isAuthenticated()) {
         echo "error";
         die;
     }
     $this->reviewValue = $request->getParameter("v");
     $this->reviewType = $request->getParameter("t");
     $this->reviewEntityId = $request->getParameter("e");
     $this->reviewText = strip_tags($request->getParameter("review_text"));
     $this->reviewBox = $request->getParameter("b");
     $criteria = new Criteria();
     if ($this->reviewType) {
         $criteria->add(SfReviewPeer::SF_REVIEW_TYPE_ID, $this->reviewType);
         $criteria->add(SfReviewPeer::ENTITY_ID, $this->reviewEntityId);
     } else {
         $criteria->add(SfReviewPeer::SF_REVIEW_TYPE_ID, null, Criteria::ISNULL);
         $criteria->add(SfReviewPeer::SF_REVIEW_ID, $this->reviewEntityId);
     }
     $criteria->add(SfReviewPeer::SF_GUARD_USER_ID, $this->getUser()->getGuardUser()->getId());
     $review = SfReviewPeer::doSelectOne($criteria);
     if ($review) {
         $this->reviewValue = $review->getValue();
         $this->reviewText = $review->getText();
         $this->reviewId = $review->getId();
         $this->review = $review;
     }
 }
Example #9
0
 /**
  * Selects a collection of SfReviewAttach objects pre-filled with all related objects.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of SfReviewAttach objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     SfReviewAttachPeer::addSelectColumns($criteria);
     $startcol2 = SfReviewAttachPeer::NUM_COLUMNS - SfReviewAttachPeer::NUM_LAZY_LOAD_COLUMNS;
     SfReviewPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (SfReviewPeer::NUM_COLUMNS - SfReviewPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(SfReviewAttachPeer::SF_REVIEW_ID, SfReviewPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BaseSfReviewAttachPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = SfReviewAttachPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = SfReviewAttachPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = SfReviewAttachPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             SfReviewAttachPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined SfReview rows
         $key2 = SfReviewPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = SfReviewPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = SfReviewPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 SfReviewPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (SfReviewAttach) to the collection in $obj2 (SfReview)
             $obj2->addSfReviewAttach($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #10
0
 public function executeSfrPreview()
 {
     $criteria = new Criteria();
     $criteria->add(SfReviewPeer::IS_ACTIVE, true);
     if ($this->reviewType) {
         $criteria->add(SfReviewPeer::ENTITY_ID, $this->reviewEntityId);
         $criteria->add(SfReviewPeer::SF_REVIEW_TYPE_ID, $this->reviewType);
     } else {
         $criteria->add(SfReviewPeer::SF_REVIEW_ID, $this->reviewEntityId);
     }
     if ($this->getUser()->isAuthenticated()) {
         $criteria->add(SfReviewPeer::SF_GUARD_USER_ID, $this->getUser()->getGuardUser()->getId());
         $this->review = SfReviewPeer::doSelectOne($criteria);
         if ($this->review) {
             if (!$this->reviewValue) {
                 $this->reviewValue = $this->review->getValue();
             }
             $this->reviewText = $this->review->getText();
             $this->reviewId = $this->review->getId();
             $this->reviewToFb = $this->review->getToFb();
         }
     }
 }
Example #11
0
 /**
  * Get the associated SfReview object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     SfReview The associated SfReview object.
  * @throws     PropelException
  */
 public function getSfReview(PropelPDO $con = null)
 {
     if ($this->aSfReview === null && $this->sf_review_id !== null) {
         $this->aSfReview = SfReviewPeer::retrieveByPk($this->sf_review_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aSfReview->addSfReviewAttachs($this);
         		 */
     }
     return $this->aSfReview;
 }
Example #12
0
function changeCulture($culture)
{
    $extensions = array('es' => 'es', 'ca' => 'cat');
    $sf_context = sfContext::getInstance();
    $request = $sf_context->getRequest();
    $module = $request->getParameter('module');
    $action = $request->getParameter('action');
    $parameters = $request->getParameterHolder()->getAll();
    $curCulture = $sf_context->getUser()->getCulture('es');
    $routeName = $sf_context->getRouting()->getCurrentRouteName();
    $routeName = preg_replace("/_{$curCulture}\$/", "_{$culture}", $routeName);
    $params = "";
    foreach ($parameters as $name => $value) {
        if ($name != 'module' && $name != 'action') {
            if ($name == 'institucion') {
                $c = new Criteria();
                $c->addJoin(InstitucionPeer::ID, InstitucionI18nPeer::ID);
                $c->addJoin(array(InstitucionPeer::ID, InstitucionI18nPeer::CULTURE), array(InstitucionI18nPeer::ID, "'{$curCulture}'"), Criteria::INNER_JOIN);
                $c->add(InstitucionI18nPeer::VANITY, $value);
                $aInstitucion = InstitucionPeer::doSelectOne($c);
                if ($aInstitucion) {
                    $value = $aInstitucion->getVanity($culture);
                }
            }
            if ($module == 'sfReviewFront' && $action == 'show' && $name == 'id') {
                $review = SfReviewPeer::retrieveByPk($request->getParameter('id'));
                $value = SfVoUtil::reviewPermalink($review, $culture);
            }
            $params .= ($params == "" ? '?' : '&') . "{$name}={$value}";
        }
    }
    $route = sfContext::getInstance()->getController()->genUrl("@{$routeName}{$params}");
    $host = preg_replace("/\\.[a-zA-Z]*\$/is", "." . $extensions[$culture], $_SERVER['HTTP_HOST']);
    return "http://{$host}{$route}";
}
Example #13
0
 public function sendTasks(sfWebRequest $request)
 {
     $tw_publish = $request->getParameter("tw_publish", 0);
     $t = $request->getParameter("t", false);
     $v = $request->getParameter("v", false);
     $e = $request->getParameter("e", false);
     $review_text = $request->getParameter("review_text", false);
     $this->updateSums($request);
     if ($t) {
         $type = SfReviewTypePeer::retrieveByPk($t);
         $peer = $type->getModel() . "Peer";
         $entity = call_user_func("{$peer}::retrieveByPk", $e);
     } else {
         $review = SfReviewPeer::retrieveByPk($request->getParameter('e'));
         if ($typeId = $review->getSfReviewTypeId()) {
             $type = SfReviewTypePeer::retrieveByPK($typeId);
             $peer = $type->getModule() . 'Peer';
             $entity = call_user_func("{$peer}::retrieveByPk", $review->getEntityId());
         }
     }
     $msg = "";
     if ($tw_publish && TwitterManager::verify($this->getUser())) {
         switch ($t) {
             case Politico::NUM_ENTITY:
                 $entityUrl = sfContext::getInstance()->getController()->genUrl("politico/show?id=" . $entity->getVanity(), true);
                 $msg = sfContext::getInstance()->getI18N()->__('Voto  %1% de %2% en @Voota:  %3%', array('%1%' => $v == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%2%' => $entity, '%3%' => TwitterManager::shorten($entityUrl)));
                 break;
             case Partido::NUM_ENTITY:
                 $entityUrl = sfContext::getInstance()->getController()->genUrl("partido/show?id=" . $entity->getAbreviatura(), true);
                 $msg = sfContext::getInstance()->getI18N()->__('Voto %1% del partido %2% en @Voota: %3%', array('%1%' => $v == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%2%' => $entity->getAbreviatura(), '%3%' => TwitterManager::shorten($entityUrl)));
                 break;
             case Propuesta::NUM_ENTITY:
                 $entityUrl = sfContext::getInstance()->getController()->genUrl("propuesta/show?id=" . $entity->getVanity(), true);
                 $msg = sfContext::getInstance()->getI18N()->__('Voto %1% de la propuesta "%2%" en @Voota: %3%', array('%1%' => $v == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%2%' => SfVoUtil::cutToLength($entity->getTitulo(), 60, '...', true), '%3%' => TwitterManager::shorten($entityUrl)));
                 break;
             case "":
                 $entityUrl = sfContext::getInstance()->getController()->genUrl($type->getModule() . "/show?id=" . $entity->getVanity(), true);
                 $msg = sfContext::getInstance()->getI18N()->__('Vooto %1% de una opinión sobre %2% en @Voota: %3%', array('%1%' => $v == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%2%' => $entity, '%3%' => TwitterManager::shorten($entityUrl)));
                 break;
         }
         TwitterManager::post($this->getUser(), $msg);
     }
     // Enviar email
     if (!$t) {
         //echo $request->getParameter('i');
         $user = $review->getsfGuardUser();
         if ($user->getProfile()->getMailsComentarios()) {
             if ($typeId) {
                 $user->getProfile()->setCodigo(util::generateUID());
                 $user->getProfile()->save();
                 $mailBody = $this->getPartial('reviewLeftMailBody', array('nombre' => $user->getProfile()->getNombre(), 'usuario' => $review->getAnonymous() ? sfContext::getInstance()->getI18N()->__('anónimo (está en su derecho)') : $this->getUser()->getProfile()->getNombre() . ' ' . $this->getUser()->getProfile()->getApellidos(), 'entity' => $typeId == Propuesta::NUM_ENTITY ? "\"{$entity}\"" : $entity, 'texto_ori' => $review->getText(), 'comentario' => $request->getParameter('review_text'), 'vanity' => $entity->getVanity(), 'codigo' => $user->getProfile()->getCodigo(), 'voto' => $request->getParameter('v'), 'module' => $entity->getModule()));
                 VoMail::send(sfContext::getInstance()->getI18N()->__('Tu vooto sobre %1% tiene un comentario', array('%1%' => $entity)), $mailBody, $user->getUsername(), array('*****@*****.**' => 'no-reply Voota'), true);
             }
         }
     }
 }
Example #14
0
 public function executeEdit(sfWebRequest $request)
 {
     $this->hasDeepUpdates = false;
     $c = new Criteria();
     $c->add(PropuestaPeer::IS_ACTIVE, true);
     $this->propuestasCount = PropuestaPeer::doCount($c);
     $this->isCanonicalVootaUser = SfVoUtil::isCanonicalVootaUser($this->getUser()->getGuardUser());
     if ($this->getUser()->isAuthenticated()) {
         $this->lastReview = SfReviewManager::getLastReviewByUserId($this->getUser()->getGuardUser()->getId());
         $this->lastReviewOnReview = SfReviewManager::getLastReviewOnReviewByUserId($this->getUser()->getGuardUser()->getId());
     }
     $this->redirectUnless($this->getUser()->isAuthenticated(), "@sf_guard_signin");
     $formData = sfGuardUserPeer::retrieveByPk($this->getUser()->getGuardUser()->getId());
     if (!SfVoUtil::isEmail($formData->getUsername())) {
         $formData->setUsername('');
     }
     $this->profileEditForm = new ProfileEditForm($formData);
     $this->politico = false;
     $politicos = $this->getUser()->getGuardUser()->getPoliticos();
     if ($politicos && count($politicos) != 0) {
         $this->politico = $politicos[0];
         unset($this->profileEditForm['nombre'], $this->profileEditForm['apellidos']);
     }
     $imagenOri = $formData->getProfile()->getImagen();
     $criteria = new Criteria();
     $criteria->add(SfReviewPeer::IS_ACTIVE, true);
     $criteria->add(SfReviewPeer::SF_GUARD_USER_ID, $this->getUser()->getGuardUser()->getId());
     $this->numReviews = SfReviewPeer::doCount($criteria);
     if ($request->isMethod('post')) {
         $this->profileEditForm->bind($request->getParameter('profile'), $request->getFiles('profile'));
         if ($this->profileEditForm->isValid()) {
             /*if ($this->politico){
             		  	$cacheManager = $this->getContext()->getViewCacheManager();
             		  	if ($cacheManager != null) {
             		  		$politico = $this->getRoute()->getObject();
             		    	$cacheManager->remove("politico/show?id=".$politico->getVanity()."");
             		  	}				
             		}*/
             $profile = $request->getParameter('profile');
             $this->hasDeepUpdates = $profile['presentacion'] != $formData->getProfile()->getPresentacion();
             if ($this->profileEditForm->getValue('imagen_delete') != "") {
                 // Si se elimina la imagen, hay que recargar el formulario para que se refresque
                 $formData->getProfile()->setImagen("");
                 //$formData->getProfile()->save();
                 $this->profileEditForm->setImageSrc("");
                 $this->profileEditForm->resetImageWidget();
                 //$this->profileEditForm = new ProfileEditForm( $formData );
             } else {
                 $imageOri = $this->profileEditForm->getObject()->getProfile()->getImagen();
                 $imagen = $this->profileEditForm->getValue('imagen');
                 $this->profileEditForm->save();
                 if ($imagen) {
                     $arr = array_reverse(explode(".", $imagen->getOriginalName()));
                     $ext = strtolower($arr[0]);
                     if (!$ext || $ext == "") {
                         $ext = "png";
                     }
                     $imageName = $this->profileEditForm->getValue('nombre') ? $this->profileEditForm->getValue('nombre') : $arr[1];
                     if ($this->profileEditForm->getValue('apellidos') != '') {
                         $imageName .= "-" . $this->profileEditForm->getValue('apellidos');
                     }
                     $imageName .= "-" . sprintf("%04d", rand(0, 999));
                     $imageName .= ".{$ext}";
                     $imagen->save(sfConfig::get('sf_upload_dir') . '/usuarios/' . $imageName);
                     $this->profileEditForm->getObject()->getProfile()->setImagen($imageName);
                     $this->profileEditForm->setImageSrc($imageName);
                     $this->profileEditForm->resetImageWidget();
                     $this->hasDeepUpdates = true;
                 } else {
                     $this->profileEditForm->getObject()->getProfile()->setImagen($imagenOri);
                     $this->profileEditForm->setImageSrc($imagenOri);
                 }
             }
             if ($profile['passwordNew'] != '') {
                 // Check old password
                 if ($this->getUser()->checkPassword($profile['passwordOld'])) {
                     $this->getUser()->setPassword($profile['passwordNew']);
                 } else {
                     $this->getUser()->setFlash('notice_type', 'error', false);
                     $this->getUser()->setFlash('notice', sfVoForm::getMissingPasswordMessage(), false);
                     return;
                 }
             }
             $this->getUser()->setFlash('notice_type', 'notice', false);
             $this->getUser()->setFlash('notice', sfVoForm::getFormSavesMessage(), false);
             $this->profileEditForm->save();
             $profile = $this->profileEditForm->getObject()->getProfile();
             $profile->save();
             $aText = utf8_decode($this->profileEditForm->getValue('presentacion'));
             $aText = strip_tags(substr($aText, 0, 280));
             $aText = utf8_encode($aText);
             $profile->setPresentacion($aText);
             $profile->save();
             if ($profile->isColumnModified(SfGuardUserProfileI18nPeer::PRESENTACION)) {
                 $this->hasDeepUpdates = true;
             }
             $this->presentacionValue = $aText;
         } else {
             $this->getUser()->setFlash('notice_type', 'error', false);
             $this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false);
         }
     }
     if (!$this->presentacionValue) {
         $this->presentacionValue = $politicos = $this->getUser()->getGuardUser()->getProfile()->getPresentacion();
     }
 }
Example #15
0
 public static function countReviews()
 {
     $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false;
     if ($cache) {
         $key = md5("reviews_counter");
         $data = unserialize($cache->get($key));
     } else {
         $data = false;
     }
     if (!$data) {
         //$user = sfContext::getInstance()->getUser();
         //$culture = $user->getCulture();
         $cpos = new Criteria();
         $cpos->add(SfReviewPeer::IS_ACTIVE, 1);
         //$cpos->add(SfReviewPeer::CULTURE, $culture);
         $data = SfReviewPeer::doCount($cpos);
         if ($cache) {
             $cache->set($key, serialize($data), 360);
         }
     }
     return $data;
 }
Example #16
0
 public static function postReview($userId, $typeId, $entityId, $value, $text = false, $entity = false, $rm = false, $fb = '?', $source = '', $anonymous = '?', $tw = '?')
 {
     $prevValue = false;
     $guessAnonymous = $anonymous && $anonymous == '?' ? true : false;
     $guessFB = $fb && $fb == '?' ? true : false;
     $guessTW = $tw && $tw == '?' ? true : false;
     if ($guessAnonymous) {
         $user = sfGuardUserPeer::retrieveByPK($userId);
         if ($user) {
             $anonymous = $user->getProfile()->getAnonymous();
         }
     }
     if (!$entityId || !$value) {
         throw new Exception("Not enough parameters.");
     }
     if ($value != -1 && $value != 1) {
         throw new Exception("Invalid data for 'value'.");
     }
     // Check if already exists
     $c = new Criteria();
     if (!$typeId) {
         $c->add(SfReviewPeer::SF_REVIEW_ID, $entityId);
     } else {
         $c->add(SfReviewPeer::ENTITY_ID, $entityId);
     }
     $c->add(SfReviewPeer::SF_GUARD_USER_ID, $userId);
     $c->add(SfReviewPeer::SF_REVIEW_TYPE_ID, $typeId ? $typeId : null);
     $review = SfReviewPeer::doSelectOne($c);
     if (!$review) {
         $review = new SfReview();
         if (!$typeId) {
             $review->setSfReviewId($entityId);
         } else {
             $review->setEntityId($entityId);
         }
         $review->setSfReviewTypeId($typeId ? $typeId : null);
         $review->setSfGuardUserId($userId);
         $review->setCreatedAt(new DateTime());
         $review->setSource($source);
     } else {
         if ($rm && $value == $review->getValue() && $review->getIsActive()) {
             $review->setIsActive(false);
         } else {
             $review->setIsActive(true);
         }
         $review->setModifiedAt(new DateTime());
     }
     $review->setValue($value);
     if ($text) {
         $aText = SfVoUtil::cutToLength($text, self::MAX_LENGTH, '');
         $aText = strip_tags($aText);
         $review->setText($aText);
     }
     $review->setSfReviewStatusId(1);
     $review->setIpAddress($_SERVER['REMOTE_ADDR']);
     $review->setCookie(sfContext::getInstance()->getRequest()->getCookie('symfony'));
     $review->setCulture(sfContext::getInstance()->getUser()->getCulture());
     if (!$guessFB) {
         $review->setToFb($fb);
     }
     if (!$guessTW) {
         $review->setToTw($tw);
     }
     if (!$guessAnonymous || $review->isNew()) {
         $review->setAnonymous($anonymous);
     }
     try {
         $review->save();
         if (!$typeId) {
             $parentReview = SfReviewPeer::retrieveByPk($entityId);
             $parentReview->setBalance(SfReviewManager::getBalanceByReviewId($entityId));
             $parentReview->save();
         }
         if (!$entity) {
             if (!$typeId) {
                 $aEntityId = $parentReview->getEntityId();
                 $aTypeId = $parentReview->getSfReviewTypeId();
             } else {
                 $aTypeId = $typeId;
                 $aEntityId = $entityId;
             }
             $reviewType = SfReviewTypePeer::retrieveByPK($aTypeId);
             $peer = $reviewType->getModel() . 'Peer';
             $entity = $peer::retrieveByPK($aEntityId);
         }
         $entity->updateCalcs();
         $entity->save();
     } catch (Exception $e) {
         throw new Exception('Error writing review.');
     }
     return $review->getIsActive() ? $review : false;
 }