예제 #1
0
 /**
  * Envía un email a través de la configuración de campanias de la empresa que se pasa como parámetro. Utiliza el plugin sfSwiftPlugin
  * @param id_empresa, identificador de la empresa a través de la que se envia el mensaje.
  * @param asunto, asunto del mensaje
  * @param cuerpo, cuerpo del mensaje
  * @param lista_emails, lista de emails, a los que se envia el mensjae.
  * @return integer, número de mensajes enviados
  * @version 25-02-09
  * @author Ana Martin
  */
 public static function enviarEmailDefault($id_empresa, $asunto, $cuerpo, $lista_emails)
 {
     $empresa = EmpresaPeer::retrievebypk($id_empresa);
     if ($empresa instanceof Empresa) {
         $smtp_server = $empresa->getSmtpServer();
         $smtp_user = $empresa->getSmtpUser();
         $smtp_password = $empresa->getSmtpPassword();
         $smtp_port = $empresa->getSmtpPort();
         $sender_email = $empresa->getSenderAddress();
         $sender_name = $empresa->getSenderName();
         //$c = new Criteria();
         //$c->add(PlantillaPeer::ID_EMPRESA, $empresa->getIdEmpresa());
         //$plantilla = PlantillaPeer::doSelectOne($c);
         $plantilla = "";
         $cuerpo = MensajePeer::prepararMailingCuerpoDefault($cuerpo, $plantilla, $asunto);
         $smtp = new Swift_Connection_SMTP($smtp_server, $smtp_port);
         $smtp->setUsername($smtp_user);
         $smtp->setpassword($smtp_password);
         $mailer = new Swift($smtp);
         $message = new Swift_Message(utf8_decode($asunto));
         $message->attach(new Swift_Message_Part($cuerpo, "text/html"));
         $recipients = new Swift_RecipientList();
         foreach ($lista_emails as $email) {
             $recipients->addTo($email);
         }
         //Load the plugin with these replacements
         /*  $replacaments = array(
                        '{FECHA}' => date('d-m-Y') , 
                        '{ASUNTO}' => utf8_decode($asunto),
                        '{MENSAJE}' => utf8_decode($cuerpo),             
                     );
          	  $mailer->attachPlugin(new Swift_Plugin_Decorator($replacaments), "decorator");*/
         $enviado_por = new Swift_Address($sender_email, $sender_name);
         $cuantos = $mailer->send($message, $recipients, $enviado_por);
         $mailer->disconnect();
         return $cuantos;
     } else {
         return 0;
     }
 }
예제 #2
0
 /**
  * Returns the number of related Mensaje objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Mensaje objects.
  * @throws     PropelException
  */
 public function countMensajes(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(UsuarioPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collMensajes === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(MensajePeer::ID_USUARIO, $this->id_usuario);
             $count = MensajePeer::doCount($criteria, $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(MensajePeer::ID_USUARIO, $this->id_usuario);
             if (!isset($this->lastMensajeCriteria) || !$this->lastMensajeCriteria->equals($criteria)) {
                 $count = MensajePeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collMensajes);
             }
         } else {
             $count = count($this->collMensajes);
         }
     }
     return $count;
 }
예제 #3
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(MensajePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(MensajePeer::DATABASE_NAME);
         $criteria->add(MensajePeer::ID, $pks, Criteria::IN);
         $objs = MensajePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #4
0
 protected function enviarAvisoRelDocumentoTrabajadores($documento = null)
 {
     //Enviar mensaje a los trabajadores relacionados con el documento.
     if (!$documento instanceof Documento) {
         throw new Exception("No ha facilitado un documento");
     }
     //Para crear enlaces:
     $params_show = "documentos/show?id_documento=" . $documento->getPrimaryKey();
     $params_download = "historico_documentos/descargar";
     $params_download .= "?id_documento=" . $documento->getPrimaryKey();
     $params_download .= "&version=" . $documento->getUltimaVersion();
     $url_show = $this->getController()->genUrl($params_show, true);
     $url_download = $this->getController()->genUrl($params_download, true);
     $link_show = "<a href=\"" . $url_show . "\">pulse aquí</a>";
     $link_download = "<a href=\"" . $url_download . "\">pulse aquí</a>";
     $proyecto = $documento->getProyecto();
     $fase = $documento->getFase();
     $nombre_proyecto = $proyecto ? $proyecto->__toString() : "Sin definir";
     $nombre_fase = $fase ? $fase->__toString() : "Sin definir";
     $parametros = array('nombre' => $documento->__toString(), 'version' => $documento->getUltimaVersion(), 'link_show' => $link_show, 'link_download' => $link_download, 'proyecto' => $nombre_proyecto, 'fase' => $nombre_fase);
     $rels_documento_trabajador = $documento->getRelDocumentoTrabajadorsJoinTrabajador();
     $destinatarios = array();
     foreach ($rels_documento_trabajador as $rel) {
         $trabajador = $rel->getTrabajador();
         $usuario = $trabajador ? $trabajador->getUsuario() : null;
         if ($usuario instanceof Usuario) {
             $destinatarios[] = $usuario->getPrimaryKey();
         }
     }
     $resultado = MensajePeer::enviarMensajeAvisarRelDocumentoTrabajadores($parametros, $destinatarios, array('enviar_email' => true));
     return $resultado;
 }
예제 #5
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 = MensajePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setIdMensaje($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setIdUsuario($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setAsunto($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setCuerpo($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setFecha($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setEmail($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setCreatedAt($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setUpdatedAt($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setBorrado($arr[$keys[8]]);
     }
 }
 /**
  * Get the associated Mensaje object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Mensaje The associated Mensaje object.
  * @throws     PropelException
  */
 public function getMensaje(PropelPDO $con = null)
 {
     if ($this->aMensaje === null && $this->id_mensaje !== null) {
         $c = new Criteria(MensajePeer::DATABASE_NAME);
         $c->add(MensajePeer::ID_MENSAJE, $this->id_mensaje);
         $this->aMensaje = MensajePeer::doSelectOne($c, $con);
         /* 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->aMensaje->addMensajeDestinos($this);
         		 */
     }
     return $this->aMensaje;
 }
예제 #7
0
 public function executeEnviar_alarmas()
 {
     set_time_limit(0);
     $fecha = new Date();
     $fecha_uno = $fecha->toString(FMT_DATEMYSQL);
     $c1 = new Criteria();
     $crit0 = $c1->getNewCriterion(TareaPeer::FECHA_INICIO, $fecha_uno . " 00:00:00", Criteria::GREATER_EQUAL);
     $crit1 = $c1->getNewCriterion(TareaPeer::FECHA_INICIO, $fecha_uno . " 23:59:59", Criteria::LESS_EQUAL);
     $crit4 = $c1->getNewCriterion(TareaPeer::AVISAR_EMAIL, true, Criteria::EQUAL);
     $crit0->addAnd($crit1);
     $crit0->addAnd($crit4);
     $crit2 = $c1->getNewCriterion(TareaPeer::FECHA_VENCIMIENTO, $fecha_uno . " 00:00:00", Criteria::GREATER_EQUAL);
     $crit3 = $c1->getNewCriterion(TareaPeer::FECHA_VENCIMIENTO, $fecha_uno . " 23:59:59", Criteria::LESS_EQUAL);
     $crit5 = $c1->getNewCriterion(TareaPeer::AVISAR_EMAIL_FIN, true, Criteria::EQUAL);
     $crit2->addAnd($crit3);
     $crit2->addAnd($crit5);
     $crit0->addOr($crit2);
     $c1->add($crit0);
     $c1->setDistinct();
     $tareas_hoy = TareaPeer::doSelect($c1);
     foreach ($tareas_hoy as $tarea) {
         $asunto = $tarea->getResumen();
         $fecha_uno = $tarea->getFechaInicio('d/m/Y');
         $fecha_dos = $tarea->getFechaVencimiento('d/m/Y');
         if ($fecha_uno != $fecha_dos && $fecha_uno == date('d/m/Y')) {
             $cuerpo .= "<strong>Legedia</strong> - Inicio de ";
             $cuerpo .= $tarea->getEsEvento() ? "evento: " : "tarea: ";
         } elseif ($fecha_uno != $fecha_dos && $fecha_dos == date('d/m/Y')) {
             $cuerpo = "<strong>Legedia</strong> - Vencimiento de ";
             $cuerpo .= $tarea->getEsEvento() ? "evento: " : "tarea: ";
         } else {
             $cuerpo = "<strong>Legedia</strong> - " . $tarea->getEsEvento() ? "Evento:" : "Tarea: ";
         }
         $cuerpo .= $tarea->getResumen() . "<br />";
         $cuerpo .= "Inicio: " . $fecha_uno . "<br />";
         $cuerpo .= "Fin: " . $fecha_dos . "<br />";
         $cuerpo .= $tarea->getDescripcion();
         if ($tarea->getIdFormulario() != 0) {
             $form = FormularioPeer::retrieveByPK($tarea->getIdFormulario());
             if ($form instanceof Formulario) {
                 $cuerpo .= "Objeto relacionado: <a href=\"" . UsuarioPeer::getRuta() . "formularios/edit?id_formulario=" . $tarea->getIdFormulario() . "\">" . $form->__toString() . "</a>";
             }
         }
         $cuerpo .= "<br /><br />Muchas gracias<br /><br />Un Saludo<br />Administrador <strong>LEGEDIA</strong>\n";
         $mens = new Mensaje();
         $mens->setAsunto($asunto);
         $mens->setCuerpo($cuerpo);
         $mens->setEmail(true);
         $mens->setFecha(time());
         $mens->save();
         $c = new Criteria();
         $c->addAnd(MensajeDestinoPeer::ID_MENSAJE, $mens->getPrimaryKey());
         MensajeDestinoPeer::doDelete($c);
         $mensajeDestino = new MensajeDestino();
         $mensajeDestino->setIdMensaje($mens->getPrimaryKey());
         $mensajeDestino->setIdUsuario($tarea->getUsuario()->getIdUsuario());
         $mensajeDestino->save();
         echo $tarea->getUsuario()->getEmail() . "::" . $asunto . "<br />" . $cuerpo . "<br /><br />";
         if (trim($tarea->getUsuario()->getEmail()) != "") {
             $enviado = MensajePeer::enviarEmailDefault($tarea->getIdEmpresa(), $asunto, $cuerpo, array($tarea->getUsuario()->getEmail()));
         }
     }
     echo "ENVIADOS: " . $enviado;
     return sfView::NONE;
 }
예제 #8
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return    Mensaje A model object, or null if the key is not found
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `ID`, `ID_USUARIO_DESTINATARIO`, `ID_USUARIO_REMITENTE`, `MENSAJE`, `LEIDO` FROM `mensaje` WHERE `ID` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new Mensaje();
         $obj->hydrate($row);
         MensajePeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
예제 #9
0
 protected function getMensajeOrCreate($id_mensaje = 'id_mensaje')
 {
     $usuario_actual = Usuario::getUsuarioActual();
     if (!$this->getRequestParameter($id_mensaje)) {
         $mensaje = new Mensaje();
         $mensaje->setIdUsuario($usuario_actual->getPrimaryKey());
     } else {
         $c = new Criteria();
         $c->add(MensajePeer::ID_MENSAJE, $this->getRequestParameter($id_mensaje));
         $c->addAnd(MensajePeer::ID_USUARIO, $usuario_actual->getPrimaryKey());
         $mensaje = MensajePeer::doSelectOne($c);
         $this->forward404Unless($mensaje);
     }
     return $mensaje;
 }
예제 #10
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 = MensajePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setId_usuario_destinatario($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setId_usuario_remitente($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setMensaje($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setLeido($arr[$keys[4]]);
     }
 }
 /**
  * Selects a collection of MensajeDestino objects pre-filled with all related objects except Usuario.
  *
  * @param      Criteria  $c
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of MensajeDestino objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptUsuario(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     // $c->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     MensajeDestinoPeer::addSelectColumns($c);
     $startcol2 = MensajeDestinoPeer::NUM_COLUMNS - MensajeDestinoPeer::NUM_LAZY_LOAD_COLUMNS;
     MensajePeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (MensajePeer::NUM_COLUMNS - MensajePeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(MensajeDestinoPeer::ID_MENSAJE), array(MensajePeer::ID_MENSAJE), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = MensajeDestinoPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = MensajeDestinoPeer::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 {
             $omClass = MensajeDestinoPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             MensajeDestinoPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Mensaje rows
         $key2 = MensajePeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = MensajePeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = MensajePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 MensajePeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (MensajeDestino) to the collection in $obj2 (Mensaje)
             $obj2->addMensajeDestino($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }