Beispiel #1
0
 /**
  * @param User $user
  * @param Invitation $invitation
  * @return void
  * @throws Runtime\DuplicateUsernameException
  * @throws Runtime\DuplicateEmailException
  * @throws Runtime\InvitationNotFoundException
  * @throws Runtime\InvitationExpiredException
  * @throws Runtime\InvitationTokenMatchException
  * @throws \DibiException
  */
 public function registerNewUser(User $user, Invitation $invitation)
 {
     if (!$user->isDetached()) {
         throw new InvalidArgumentException('Only detached instances of Entity ' . User::class . ' can pass.');
     }
     $this->checkInvitation($user->email, $invitation->token);
     try {
         $this->transaction->begin();
         $this->userRepository->persist($user);
         $this->removeInvitation($invitation);
         $this->transaction->commit();
     } catch (\DibiException $e) {
         if ($e->getCode() == 1062) {
             try {
                 $this->userRepository->checkUsername($user->username);
             } catch (Runtime\UserAlreadyExistsException $usernameException) {
                 $this->transaction->rollback();
                 throw new Runtime\DuplicateUsernameException();
             }
             try {
                 $this->userRepository->checkEmail($user->email);
             } catch (Runtime\UserAlreadyExistsException $emailException) {
                 $this->transaction->rollback();
                 throw new Runtime\DuplicateEmailException();
             }
         }
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
 /**
  * Override BundlableLabelableBaseModelWithAttributes::changeType() to update
  * current location "subclass" (ie. type) value when type change is used.
  * This should be invoked by any model that can be used to indicate object
  * storage location. This includes, for now at least, ca_loans, ca_movements, 
  * ca_occurrences and ca_objects_x_storage_locations.
  *
  * @param mixed $pm_type The type_id or code to change the current type to
  * @return bool True if change succeeded, false if error
  */
 public function changeType($pm_type)
 {
     if (!$this->getPrimaryKey()) {
         return false;
     }
     // row must be loaded
     if (!($vb_already_in_transaction = $this->inTransaction())) {
         $this->setTransaction($o_t = new Transaction($this->getDb()));
     }
     if ($vn_rc = parent::changeType($pm_type)) {
         $o_db = $this->getDb();
         $o_db->query("\n\t\t\t\t\tUPDATE ca_objects SET current_loc_subclass = ? \n\t\t\t\t\tWHERE \n\t\t\t\t\t\tcurrent_loc_class = ? AND current_loc_id = ?\n\t\t\t\t", array($this->get('type_id'), $this->tableNum(), $this->getPrimaryKey()));
         if ($o_db->numErrors()) {
             $this->errors = $o_db->errors;
             if (!$vb_already_in_transaction) {
                 $o_t->rollback();
             }
             return false;
         }
     }
     if (!$vb_already_in_transaction) {
         $o_t->commit();
     }
     return $vn_rc;
 }
Beispiel #3
0
 /**
  * @param ListingItem $listingItem
  * @return ListingItem
  * @throws ListingItemDayAlreadyExistsException
  * @throws \DibiException
  */
 public function saveListingItem(ListingItem $listingItem)
 {
     try {
         $this->transaction->begin();
         $this->listingItemRepository->persist($listingItem);
         $this->localityRepository->saveLocalityToUserList($listingItem->locality, $listingItem->listing->getRowData()['userID']);
         $this->transaction->commit();
         return $listingItem;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         if ($e->getCode() == 1062) {
             throw new ListingItemDayAlreadyExistsException();
         }
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
 public function commit()
 {
     $atomDao = new BaseDao("CertifierTransactionAtom");
     $atom = $atomDao->getPattern();
     $atom->transFid = $this->getId();
     $list = $atomDao->search($atom);
     foreach ($list as $element) {
         $element->delete();
     }
     parent::commit();
 }
Beispiel #5
0
 public function report($wins, $opponentWins)
 {
     if (!$this->awaitingResult()) {
         $msg = 'Tried to report when not awaiting result.';
         throw new IllegalStateException($msg);
     }
     $t = new Transaction();
     $entries = [$this->playerId => $wins, $this->opponentId => $opponentWins];
     foreach ($entries as $playerId => $playerWins) {
         $sql = 'UPDATE player_match SET wins = ' . Q($playerWins) . ' WHERE match_id = ' . Q($this->matchId) . ' AND player_id = ' . Q($playerId);
         $t->execute($sql);
     }
     $t->commit();
 }
Beispiel #6
0
function deleteWidget($id)
{
    try {
        $transaction = new Transaction();
        $result = DAOFactory::getAfiliadoWidgetDAO()->delete($id);
        $transaction->commit();
        return $result;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #7
0
function insertBusquedaDisponibilidad($data)
{
    try {
        $transaction = new Transaction();
        $busqueda = DAOFactory::getBusquedaDisponibilidadDAO()->prepare($data);
        $id = DAOFactory::getBusquedaDisponibilidadDAO()->insert($busqueda);
        $transaction->commit();
        return $id;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #8
0
function deleteFaq($id)
{
    try {
        $transaction = new Transaction();
        $faq = DAOFactory::getFaqDAO()->load($id);
        DAOFactory::getFaqDAO()->delete($id);
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #9
0
 /**
  * @param array $messages Key => recipientID, Value = Message entity or array of messages
  * @throws InvalidArgumentException
  * @throws \DibiException
  * @return array
  */
 public function sendMessages(array $messages)
 {
     $ex = new InvalidArgumentException('Only non-persisted instances of ' . Message::class . ' can pas.');
     $msgs = [];
     foreach ($messages as $recipientID => $recipientMessages) {
         Validators::assert($recipientID, 'numericint');
         if (is_array($recipientMessages)) {
             foreach ($recipientMessages as $message) {
                 if (!($message instanceof Message and $message->isDetached())) {
                     throw $ex;
                 }
                 $msgs[] = $message;
             }
         } else {
             // recipientMessages contains only one message
             if (!($recipientMessages instanceof Message and $recipientMessages->isDetached())) {
                 throw $ex;
             }
             $msgs[] = $recipientMessages;
         }
     }
     try {
         $this->transaction->begin();
         $this->messageRepository->saveMessages($msgs);
         unset($msgs);
         $usersMessages = [];
         foreach ($messages as $recipientID => $recipientMessages) {
             if (is_array($recipientMessages)) {
                 foreach ($recipientMessages as $message) {
                     $recipientMessage = new UserMessage($message, $recipientID);
                     $usersMessages[] = $recipientMessage;
                 }
             } else {
                 $recipientMessage = new UserMessage($recipientMessages, $recipientID);
                 $usersMessages[] = $recipientMessage;
             }
         }
         $this->userMessageRepository->sendMessagesToRecipients($usersMessages);
         $this->transaction->commit();
         return $usersMessages;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
 public function commit($auth = NULL)
 {
     $args = func_get_args();
     if ($auth != Transaction::SIGNATURE) {
         return Transaction::commit();
     }
     if (!$this->txn) {
         return FALSE;
     }
     if ($this->lock) {
         return FALSE;
     }
     $res = (bool) $this->__call(__FUNCTION__, array());
     if (!$res) {
         return $res;
     }
     $this->txn = FALSE;
     return $res;
 }
Beispiel #11
0
function deleteCondicion($id, $transactional = true)
{
    try {
        if ($transactional) {
            $transaction = new Transaction();
        }
        DAOFactory::getHotelCondicionDAO()->deleteByCondicionId($id);
        DAOFactory::getCondicionDAO()->delete($id);
        if ($transactional) {
            $transaction->commit();
        }
        return $id;
    } catch (Exception $e) {
        var_dump($e);
        if ($transactional && $transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #12
0
 public function drop($playerId)
 {
     $t = new Transaction();
     // Award any outstanding match to the opposing player.
     $sql = 'SELECT match_id ' . 'FROM player_match ' . 'WHERE wins IS NULL AND player_id = ' . Q($playerId);
     $matchId = D()->value($sql, null);
     if ($matchId !== null) {
         $sql = 'UPDATE player_match ' . 'SET wins = 0 ' . 'WHERE match_id = ' . Q($matchId) . ' AND player_id = ' . Q($playerId);
         $t->execute($sql);
         $sql = 'UPDATE player_match ' . 'SET wins = 1 ' . 'WHERE match_id = ' . Q($matchId) . ' AND player_id <> ' . Q($playerId);
         $t->execute($sql);
     }
     // Drop player from any unstarted events.
     $sql = 'DELETE pe ' . 'FROM player_event AS pe ' . 'INNER JOIN event AS e ON pe.event_id = e.id ' . 'WHERE NOT started AND player_id = ' . Q($playerId);
     $t->execute($sql);
     // Drop player from any started events.
     $sql = 'UPDATE player_event ' . 'SET dropped = TRUE ' . 'WHERE player_id = ' . Q($playerId) . ' AND event_id IN (SELECT event_id FROM event WHERE NOT finished)';
     $t->execute($sql);
     return $t->commit();
 }
Beispiel #13
0
 public function action_update(Params $param)
 {
     $this->content->bind('form', $torn);
     $project = Jelly::select('project')->link($param->id)->load();
     if (!$project->loaded()) {
         throw new Error404_Exception();
     }
     $torn = new Torn($project);
     if ($torn->check()) {
         try {
             Transaction::begin();
             $project->set($_FILES + $_POST);
             $project->save();
             Transaction::commit();
             $this->request->redirect(Route::get('protected')->uri(array('controller' => 'project')));
         } catch (Validate_Exception $e) {
             Transaction::rollback();
             $torn->catch_errors($e);
         }
     }
 }
Beispiel #14
0
function updateFactura($id, $data = array(), $trasactional = true)
{
    try {
        if ($trasactional) {
            $transaction = new Transaction();
        }
        $factura = getFactura($id);
        $factura = DAOFactory::getFacturaDAO()->prepare($data, $id);
        DAOFactory::getFacturaDAO()->update($factura);
        if ($trasactional) {
            $transaction->commit();
        }
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #15
0
function updatePromocionPalabrasClave($id, $data = array(), $data_hoteles = array())
{
    try {
        $transaction = new Transaction();
        $promocion = DAOFactory::getPromocionPalabrasClavesDAO()->prepare($data, $id);
        DAOFactory::getPromocionPalabrasClavesDAO()->update($promocion);
        DAOFactory::getPromocionPalabrasClavesHotelDAO()->deleteByPromocionId($id);
        if ($data_hoteles && is_array($data_hoteles) && count($data_hoteles)) {
            foreach ($data_hoteles as $hid) {
                $hotel_promo = DAOFactory::getPromocionPalabrasClavesHotelDAO()->prepare(array('promocionId' => $id, 'hotelId' => $hid));
                DAOFactory::getPromocionPalabrasClavesHotelDAO()->insert($hotel_promo);
            }
        }
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        error_log($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #16
0
function updateDireccionByHotelId($idHotel, $data = array())
{
    try {
        $transaction = new Transaction();
        $hotel = getHotelById($idHotel);
        if ($hotel->direccion) {
            updateDireccion($hotel->direccion->id, $data);
        } else {
            $dir = DAOFactory::getDireccionDAO()->prepare($data);
            $dir_id = DAOFactory::getDireccionDAO()->insert($dir);
            $hd = DAOFactory::getHotelDireccionDAO()->prepare(array('hotelId' => $hotel->id, 'direccionId' => $dir_id));
            DAOFactory::getHotelDireccionDAO()->insert($hd);
        }
        $transaction->commit();
        return $idDireccion;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #17
0
function updateCart($idCart, $data = array())
{
    try {
        $transaction = new Transaction();
        if (isset($data['apartamento'])) {
            $data['apartamento'] = json_encode($data['apartamento']);
        }
        if (isset($data['excursiones'])) {
            $data['excursiones'] = json_encode($data['excursiones']);
        }
        //print_r($data);
        $cart = DAOFactory::getShoppingCartDAO()->prepare($data, $idCart);
        DAOFactory::getShoppingCartDAO()->update($cart);
        $transaction->commit();
        return $idCart;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #18
0
 /**
  * @param Listing $baseListing
  * @param Listing $listingToMerge
  * @param array $selectedCollisionItems
  * @param \App\Model\Entities\User|int|null $user
  * @return Listing
  * @throws NoCollisionListingItemSelectedException
  * @throws \DibiException
  */
 public function mergeListings(Listing $baseListing, Listing $listingToMerge, array $selectedCollisionItems = [], $user = null)
 {
     $this->checkListingValidity($baseListing);
     $this->checkListingValidity($listingToMerge);
     if (!$this->haveListingsSamePeriod($baseListing, $listingToMerge)) {
         throw new InvalidArgumentException('Given Listings must have same Period(Year and Month).');
     }
     $userID = $this->getIdOfSignedInUserOnNull($user);
     $items = $this->itemService->getMergedListOfItems($baseListing, $listingToMerge, $selectedCollisionItems);
     try {
         $this->transaction->begin();
         $newListing = new Listing($baseListing->year, $baseListing->month, $userID);
         $this->saveListing($newListing);
         $this->itemService->setListingForGivenItems($items, $newListing);
         $this->listingItemRepository->saveListingItems($items);
         $this->transaction->commit();
         return $newListing;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
Beispiel #19
0
function validarReservas($reservas, $importes)
{
    try {
        $transaction = new Transaction();
        foreach ($importes as $rid => $imp) {
            $status = in_array($rid, $reservas) ? 'Stayed' : 'No show';
            $reserva = DAOFactory::getReservaDAO()->prepare(array('estado' => $status), $rid);
            DAOFactory::getReservaDAO()->update($reserva);
            //estado actualizado
            $moneda = getMoneda($reserva->monedaId);
            $productos = DAOFactory::getReservaProductoDAO()->queryByReservaId($rid);
            foreach ($productos as $p) {
                if ($p->tipo == 'apartamento') {
                    $precio = $imp;
                    if ($moneda->codigo != 'EUR') {
                        $precio = convertFromMonedaToMoneda($imp, 'EUR', $moneda->codigo);
                    }
                    $producto = DAOFactory::getReservaProductoDAO()->prepare(array('precioUnitario' => $precio), $p->id);
                    DAOFactory::getReservaProductoDAO()->update($producto);
                    break;
                }
            }
        }
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #20
0
if ($action == "edit") {
    try {
        $transaction = new Transaction();
        $Bannerinferior = new Bannerinferior();
        $Bannerinferior->id = $_POST['id'];
        $Bannerinferior->datadecriacao = $datainicial;
        $Bannerinferior->datainicial = $datainicial;
        $Bannerinferior->datafinal = $datafinal;
        $Bannerinferior->link = $link;
        if (trim($foto1) == "") {
            $Bannerinferior->imagem = $_POST['foto1only'];
        } else {
            $Bannerinferior->imagem = $foto1;
        }
        DAOFactory::getBannerinferiorDAO()->update($Bannerinferior);
        $transaction->commit();
        echo "<meta http-equiv='refresh' content=3;url='bannerinferior.php'>";
    } catch (Exception $exc) {
        //header('location: login.php?msg=error');
        echo $exc;
    }
}
?>


<!DOCTYPE html>
<html>

    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
Beispiel #21
0
function updateAdwordHotel($idAdword, $idHotel)
{
    try {
        $transaction = new Transaction();
        $adwords = DAOFactory::getAdwordDAO()->queryByHotelId($idHotel);
        if ($adwords) {
            foreach ($adwords as $adword) {
                $adword->hotelId = NULL;
                DAOFactory::getAdwordDAO()->update($adword);
            }
        }
        if (strlen(trim($idAdword))) {
            $adword = DAOFactory::getAdwordDAO()->load($idAdword);
            $adword->hotelId = $idHotel;
            DAOFactory::getAdwordDAO()->update($adword);
        }
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #22
0
function updateDominioCampania($idCampania, $dominio)
{
    try {
        $transaction = new Transaction();
        $data = array('subdominio' => $dominio);
        $campania = DAOFactory::getCampaniaDAO()->prepare($data, $idCampania);
        DAOFactory::getCampaniaDAO()->update($campania);
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #23
0
function deleteTicketsByEvento($eventoId, $transactional = true)
{
    try {
        if ($transactional) {
            $transaction = new Transaction();
        }
        $tickets = DAOFactory::getTicketDAO()->queryByEventoId($eventoId);
        if ($tickets && is_array($tickets)) {
            foreach ($tickets as $ticket) {
                DAOFactory::getTicketFechaDAO()->deleteByTicketId($ticket->id);
            }
        }
        DAOFactory::getTicketDAO()->deleteByEventoId($eventoId);
        if ($transactional) {
            $transaction->commit();
        }
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
 /**
  * Applies specified update to system
  *
  * @param int $pn_version Version number of update to apply
  * @param array $pa_options Array of options. Supported options are:
  *		cleanCache = Remove all application caches after database update if true. Default is false.
  * @return bool
  */
 static function performDatabaseUpdate($pn_version, $pa_options = null)
 {
     if (($pn_version = (int) $pn_version) <= 0) {
         return null;
     }
     $va_messages = array();
     $t = new Transaction();
     $o_db = $t->getDb();
     if (!file_exists(__CA_BASE_DIR__ . "/support/sql/migrations/{$pn_version}.sql")) {
         return null;
     }
     $o_handle = fopen(__CA_BASE_DIR__ . "/support/sql/migrations/{$pn_version}.sql", "r");
     $vn_query_total_nb = 0;
     $vs_query = '';
     while (!feof($o_handle)) {
         $vs_line = fgets($o_handle, 8128);
         // $vs_query gets a concat of lines while a ; is not met
         $vs_query .= $vs_line;
         // Reading 1 character before the EOL
         $vs_before_eol = substr(rtrim($vs_line), -1);
         if ($vs_before_eol == ';') {
             //If the line ends with a ; then we will take all what's before and execute it
             //Counts the number of requests contained in the SQL file
             $vn_query_total_nb++;
             //Launching the query
             $o_db->query($vs_query);
             if ($o_db->numErrors() > 0) {
                 // temp array to catch the errors
                 $va_error_array_for_printing = $o_db->getErrors();
                 $va_messages['error_' . $pn_version] = _t("Error applying database migration %1: %2; error was at query %3; query was %4", $pn_version, join('; ', $va_error_array_for_printing), $vn_query_total_nb, $vs_query);
                 $o_db->clearErrors();
                 $t->rollback();
                 return $va_messages;
             }
             // Reset variable
             $vs_query = '';
         }
         $t->commit();
     }
     if (isset($pa_options['cleanCache']) && $pa_options['cleanCache']) {
         // Clean cache
         caRemoveDirectory(__CA_APP_DIR__ . '/tmp', false);
     }
     return $va_messages;
 }
 public function delete()
 {
     $tx = new Transaction();
     try {
         $this->title->delete();
         $this->text->delete();
         $this->excerpt->delete();
         foreach ($this->get_comments() as $comment) {
             $comment->delete();
         }
         qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `article` = ?", $this->id);
         qdb("DELETE FROM `PREFIX_article_extradata` WHERE `article` = ?", $this->id);
         qdb("DELETE FROM `PREFIX_articles` WHERE `id` = ?", $this->id);
         $tx->commit();
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
 }
 /**
  * Change type of record, removing any metadata that is invalid for the new type
  *
  * @param mixed $pm_type The type_id or code to change the current type to
  * @return bool True if change succeeded, false if error
  */
 public function changeType($pm_type)
 {
     if (!$this->getPrimaryKey()) {
         return false;
     }
     // row must be loaded
     if (!method_exists($this, 'getTypeID')) {
         return false;
     }
     // model must be type-able
     unset($_REQUEST['form_timestamp']);
     if (!($vb_already_in_transaction = $this->inTransaction())) {
         $this->setTransaction($o_t = new Transaction($this->getDb()));
     }
     $vn_old_type_id = $this->getTypeID();
     $this->setMode(ACCESS_WRITE);
     $this->set($this->getTypeFieldName(), $pm_type, array('allowSettingOfTypeID' => true));
     // remove attributes that are not valid for new type
     $va_old_elements = $this->getApplicableElementCodes($vn_old_type_id);
     $va_new_elements = $this->getApplicableElementCodes($this->getTypeID());
     foreach ($va_old_elements as $vn_old_element_id => $vs_old_element_code) {
         if (!isset($va_new_elements[$vn_old_element_id])) {
             $this->removeAttributes($vn_old_element_id, array('force' => true));
         }
     }
     if ($this->update()) {
         if (!$vb_already_in_transaction) {
             $o_t->commit();
         }
         return true;
     }
     if (!$vb_already_in_transaction) {
         $o_t->rollback();
     }
     return false;
 }
Beispiel #27
0
function deleteAfiliado($idAfiliado)
{
    try {
        $transaction = new Transaction();
        DAOFactory::getAfiliadoHotelDAO()->deleteByAfiliadoId($idAfiliado);
        DAOFactory::getAfiliadoEventoDAO()->deleteByAfiliadoId($idAfiliado);
        $afiliado = DAOFactory::getAfiliadoDAO()->load($idAfiliado);
        $cuenta = array_pop(DAOFactory::getUsuarioCuentaDAO()->queryByUsuarioId($afiliado->usuarioId));
        if ($cuenta) {
            DAOFactory::getUsuarioCuentaDAO()->deleteByUsuarioId($afiliado->usuarioId);
            DAOFactory::getDireccionDAO()->delete($cuenta->direccionId);
        }
        DAOFactory::getAfiliadoDAO()->delete($idAfiliado);
        $result = DAOFactory::getUsuarioDAO()->delete($afiliado->usuarioId);
        $transaction->commit();
        return $result;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #28
0
function completarCampania($idUsuario, $data_hotel, $data_empresa, $data_direccion, $idiomas, $monedas, $promociones)
{
    try {
        $transaction = new Transaction();
        $empresas = getEmpresasByUsuario($idUsuario);
        $empresa = $empresas[0];
        $emp = updateEmpresa($empresa->id, $data_empresa, $data_direccion, false);
        if (!$emp) {
            throw new Exception('No se guardaron los datos de la empresa');
        }
        $hoteles = getHotelesByUsuario($idUsuario);
        $idHotel = $hoteles[0]->id;
        $hotel = DAOFactory::getHotelDAO()->prepare($data_hotel, $idHotel);
        DAOFactory::getHotelDAO()->update($hotel);
        getClaveByHotel($idHotel);
        DAOFactory::getHotelIdiomaDAO()->deleteByHotelId($idHotel);
        if (count($idiomas)) {
            foreach ($idiomas as $idioma) {
                $id = DAOFactory::getHotelIdiomaDAO()->prepare(array('hotelId' => $idHotel, 'idiomaId' => $idioma));
                DAOFactory::getHotelIdiomaDAO()->insert($id);
            }
        }
        DAOFactory::getHotelMonedaDAO()->deleteByHotelId($idHotel);
        if (count($monedas)) {
            foreach ($monedas as $moneda) {
                $mon = DAOFactory::getHotelMonedaDAO()->prepare(array('hotelId' => $idHotel, 'monedaId' => $moneda));
                DAOFactory::getHotelMonedaDAO()->insert($mon);
            }
        }
        DAOFactory::getPromocionDAO()->deleteByHotelId($idHotel);
        foreach ($promociones as $data_promocion) {
            $data_promocion['hotelId'] = $idHotel;
            $promocion = DAOFactory::getPromocionDAO()->prepare($data_promocion);
            DAOFactory::getPromocionDAO()->insert($promocion);
        }
        $usuario = DAOFactory::getUsuarioDAO()->prepare(array('status' => 'activo'), $idUsuario);
        DAOFactory::getUsuarioDAO()->update($usuario);
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #29
0
function deleteEmpresa($idEmpresa, $transactional = true)
{
    try {
        if ($transactional) {
            $transaction = new Transaction();
        }
        $empresa = DAOFactory::getEmpresaDAO()->load($idEmpresa);
        $hoteles = DAOFactory::getHotelDAO()->queryByEmpresaId($idEmpresa);
        if ($hoteles) {
            foreach ($hoteles as $hotel) {
                $el = deleteHotel($hotel->id, false);
                if (!$el) {
                    throw new Exception('No se pudo eliminar el hotel');
                }
            }
        }
        $campanias = DAOFactory::getCampaniaDAO()->queryByEmpresaId($idEmpresa);
        if ($campanias && count($campanias)) {
            foreach ($campanias as $c) {
                $d = eliminarCampania($c->id, false);
                if (!$d) {
                    throw new Exception('No se pudo borrar la campaña ' . $c->id);
                }
            }
        }
        $campanias = DAOFactory::getCampaniaDAO()->queryByEmpresaDistribuidoraId($idEmpresa);
        if ($campanias && count($campanias)) {
            foreach ($campanias as $c) {
                $d = eliminarCampania($c->id, false);
                if (!$d) {
                    throw new Exception('No se pudo borrar la campaña ' . $c->id);
                }
            }
        }
        DAOFactory::getUsuarioEmpresaDAO()->deleteByEmpresaId($idEmpresa);
        DAOFactory::getEmpresaDAO()->delete($idEmpresa);
        DAOFactory::getDireccionDAO()->delete($empresa->direccionId);
        if ($transactional) {
            $transaction->commit();
        }
        return true;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
Beispiel #30
0
function actualizarCambioMoneda()
{
    try {
        set_time_limit(0);
        $moneda = getMonedaByCodigo('USD');
        $hoy = strtotime(date('Y-m-d'));
        $lastUpdate = strtotime(date('Y-m-d', $moneda->ultimaModificacion ? strtotime($moneda->ultimaModificacion) : 0));
        if ($hoy > $lastUpdate) {
            $monedas = getAllMonedas();
            $transaction = new Transaction();
            $change_url = 'https://www.google.com/finance/converter';
            $cant = 1;
            $from = 'EUR';
            foreach ($monedas as $moneda) {
                $content = file_get_contents($change_url . '?a=' . $cant . '&from=' . $from . '&to=' . $moneda->codigo);
                $dom = new DOMDocument();
                @$dom->loadHTML($content);
                $x = new DOMXPath($dom);
                foreach ($x->query('//span[@class="bld"]') as $node) {
                    $rate = floatval(trim(str_replace($moneda->codigo, '', $node->nodeValue)));
                    $m = DAOFactory::getMonedaDAO()->prepare(array('tasaCambio' => $rate, 'ultimaModificacion' => date('Y-m-d')), $moneda->id);
                    DAOFactory::getMonedaDAO()->update($m);
                }
            }
            $transaction->commit();
        }
        return true;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}