Example #1
0
 /**
  * Returns a new EspecialidadQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   EspecialidadQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return EspecialidadQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof EspecialidadQuery) {
         return $criteria;
     }
     $query = new EspecialidadQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Example #2
0
 /**
  * Get the associated Especialidad object
  *
  * @param PropelPDO $con Optional Connection object.
  * @return Especialidad The associated Especialidad object.
  * @throws PropelException
  */
 public function getEspecialidad(PropelPDO $con = null)
 {
     if ($this->aEspecialidad === null && $this->servicio !== null) {
         $this->aEspecialidad = EspecialidadQuery::create()->findPk($this->servicio, $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->aEspecialidad->addAgendas($this);
            */
     }
     return $this->aEspecialidad;
 }
Example #3
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(EspecialidadPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = EspecialidadQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Example #4
0
 /**
  * Deletes all descendants for the given node
  * Instance pooling is wiped out by this command,
  * so existing Especialidad instances are probably invalid (except for the current one)
  *
  * @param      PropelPDO $con Connection to use.
  *
  * @return     int 		number of deleted nodes
  */
 public function deleteDescendants(PropelPDO $con = null)
 {
     if ($this->isLeaf()) {
         // save one query
         return;
     }
     if ($con === null) {
         $con = Propel::getConnection(EspecialidadPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $left = $this->getLeftValue();
     $right = $this->getRightValue();
     $scope = $this->getScopeValue();
     $con->beginTransaction();
     try {
         // delete descendant nodes (will empty the instance pool)
         $ret = EspecialidadQuery::create()->descendantsOf($this)->delete($con);
         // fill up the room that was used by descendants
         EspecialidadPeer::shiftRLValues($left - $right + 1, $right, null, $scope, $con);
         // fix the right value for the current node, which is now a leaf
         $this->setRightValue($left + 1);
         $con->commit();
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
     return $ret;
 }
Example #5
0
 public function editarAction()
 {
     $request = $this->getRequest();
     //Cachamos el valor desde nuestro params
     $id = (int) $this->params()->fromRoute('id');
     //Verificamos que el Id medico que se quiere modificar exista
     if (!MedicoQuery::create()->filterByIdmedico($id)->exists()) {
         $id = 0;
     }
     //Si es incorrecto redireccionavos al action nuevo
     if (!$id) {
         return $this->redirect()->toRoute('medico', array('action' => 'nuevo'));
     }
     //Instanciamos nuestro medico
     $medico = MedicoQuery::create()->findPk($id);
     //Almacenamos en un arreglo todas las especialidades
     $especialidadCollection = \EspecialidadQuery::create()->find();
     $especialidadArray = array();
     foreach ($especialidadCollection as $especialidad) {
         $especialidadArray[$especialidad->getIdespecialidad()] = $especialidad->getEspecialidadNombre();
     }
     //Instanciamos nuestro formulario
     $medicoForm = new MedicoForm($especialidadArray);
     //Le ponemos los datos de nuestro medico a nuestro formulario
     $medicoForm->setData($medico->toArray(BasePeer::TYPE_FIELDNAME));
     //La imagen del empleado
     $medico_imagen = $medico->getMedicoFotografia();
     if (is_null($medico_imagen)) {
         $medico_imagen = '/img/empleados/default_profile.jpg';
     }
     if ($request->isPost()) {
         //Si hicieron POST
         //Instanciamos nuestro filtro
         $medicoFilter = new MedicoFilter();
         //Le ponemos nuestro filtro a nuesto fromulario
         $medicoForm->setInputFilter($medicoFilter->getInputFilter());
         //Le ponemos los datos a nuestro formulario
         $medicoForm->setData($request->getPost());
         //Validamos nuestro formulario
         if ($medicoForm->isValid()) {
             //Recorremos nuestro formulario y seteamos los valores a nuestro objeto Medico
             foreach ($medicoForm->getData() as $medicoKey => $medicoValue) {
                 $medico->setByName($medicoKey, $medicoValue, \BasePeer::TYPE_FIELDNAME);
             }
             //La imagen
             if (!empty($_FILES["medico_imagen"]["name"])) {
                 $date = new \DateTime();
                 $upload_folder = '/img/medicos/';
                 $tipo_archivo = $_FILES['medico_imagen']['type'];
                 $tipo_archivo = explode('/', $tipo_archivo);
                 $tipo_archivo = $tipo_archivo[1];
                 $nombre_archivo = 'medico-' . $date->getTimestamp() . '.' . $tipo_archivo;
                 $tmp_archivo = $_FILES['medico_imagen']['tmp_name'];
                 $archivador = $upload_folder . $nombre_archivo;
                 if (!move_uploaded_file($tmp_archivo, $_SERVER["DOCUMENT_ROOT"] . $archivador)) {
                     return $this->getResponse()->setContent(\Zend\Json\Json::encode(array('response' => false, 'msg' => 'Ocurrio un error al subir el archivo. No pudo guardarse.', 'status' => 'error')));
                 }
                 //Tiene alguna imagen actualmente?
                 if (!is_null($medico->getMedicoFotografia())) {
                     $medico_imagen = $medico->getMedicoFotografia();
                     unlink($_SERVER["DOCUMENT_ROOT"] . $medico_imagen);
                 }
                 $medico->setMedicoFotografia($archivador);
             }
             //Guardamos en nuestra base de datos
             $medico->save();
             //Verificamos si el perfil esta competo
             $perfilcompleto = true;
             $excludedColumns = array('medico_perfilcompleto', 'medico_nointerior');
             foreach ($medico->toArray(BasePeer::TYPE_FIELDNAME) as $key => $value) {
                 if (empty($value) && !in_array($key, $excludedColumns)) {
                     $perfilcompleto = false;
                 }
             }
             $medico->setMedicoPerfilcompleto($perfilcompleto);
             $medico->save();
             //Agregamos un mensaje
             $this->flashMessenger()->addMessage('Medico guardado exitosamente!');
             //Redireccionamos a nuestro list
             return $this->redirect()->toRoute('medico');
         } else {
         }
     }
     return new ViewModel(array('id' => $id, 'medicoForm' => $medicoForm, 'medico_imagen' => $medico_imagen));
 }