/**
  * Executes the test
  */
 function execute()
 {
     $persistence = new Persistence("Object");
     $persistence->setProperty("ID", 1);
     assert($persistence->getSelectString() == "SELECT * FROM ##Object WHERE ID = 1");
     echo "Select string: " . $persistence->getSelectString();
 }
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new Persistence();
     }
     return self::$_instance;
 }
Exemple #3
0
 static function perform($terms)
 {
     $terms = Search::split_terms($terms);
     $terms_db = Search::db_escape_terms($terms);
     $terms_rx = Search::rx_escape_terms($terms);
     $parts = array();
     foreach ($terms_db as $term_db) {
         array_push($parts, "(summary RLIKE '{$term_db}' OR title RLIKE '{$term_db}')");
     }
     $parts = implode(' AND ', $parts);
     $conn = Persistence::get_database_object();
     $sql = "SELECT id, title, summary, created  FROM postmortems WHERE {$parts}";
     $rows = array();
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $timezone = getUserTimezone();
     $tz = new DateTimeZone($timezone);
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $row['score'] = 0;
         $row['created'] = new DateTime("@{$row['created']}");
         $row['created']->setTimezone($tz);
         $row['created'] = $row['created']->format('m/d/Y G:ia');
         foreach ($terms_rx as $term_rx) {
             $row['score'] += preg_match_all("/{$term_rx}/i", $row['summary'], $null);
             $row['score'] += preg_match_all("/{$term_rx}/i", $row['title'], $null);
         }
         $rows[] = $row;
     }
     uasort($rows, 'Search::sort_results');
     $conn = null;
     return $rows;
 }
Exemple #4
0
 /**
  * Execute action.
  *
  * @param string $mode
  * @param array  $args
  *
  * @return \atk4\dsql\Query
  */
 public function action($mode, $args = [])
 {
     if (!$this->persistence) {
         throw new Exception(['action() requires model to be associated with db']);
     }
     return $this->persistence->action($this, $mode, $args);
 }
 function createUser($username, $password, $role)
 {
     $i = Persistence::getInstance();
     $collection = 'users';
     $document = array('name' => $username, 'password' => $password, 'type' => $role);
     return $i->insertDocument($document, $collection);
 }
Exemple #6
0
 public function __construct()
 {
     $this->db = Singleton::create("DatabaseManager");
     if (is_null(self::$dbCache)) {
         self::$dbCache = BeanLocator::get("DatabaseCache");
     }
 }
 public function eliminarDetalleProductoSucursalByProductolId($id)
 {
     $sql = new Sql();
     $sql->addTable('detalleProductoSucursales');
     $sql->setOpcion('delete');
     $sql->addWhere("`pedidoId =`" . $id);
     Persistence::eliminar($sql);
 }
Exemple #8
0
 public function eliminarCategoria($id)
 {
     $sql = new Sql();
     $sql->addTable('tipos');
     $sql->setOpcion('delete');
     $sql->addWhere("`idTipo =`" . $id);
     Persistence::eliminar($sql);
 }
Exemple #9
0
 public function modificarCategoria($id)
 {
     $sql = new Sql();
     $sql->addTable('categorias');
     $sql->setOpcion('update');
     $sql->addSet("`" . 'nombre' . "`" . "=" . "'" . $this->_nombre . "'");
     $sql->addWhere("`idCategoria =`" . $id);
     Persistence::modificar($sql);
 }
Exemple #10
0
 public function modificar($table)
 {
     $sql = new SQL();
     $sql->addTable($table);
     $sql->setOpcion('update');
     $sql->addSet("`" . 'stock' . "`" . "=" . "'" . $this->_stock . "'");
     $sql->addWhere("`id`= " . $this->_id);
     Persistence::modificar($sql);
 }
Exemple #11
0
 public function ingresar($table, $estado, $fecha, $productoId)
 {
     $sql = new SQL();
     $sql->addTable($table);
     $sql->setOpcion('insert');
     $sql->addInto('id' . "`,`" . 'estado' . "`,`" . 'fecha' . "`,`" . 'idProducto');
     $sql->addValues('NULL' . "','" . $estado . "','" . $fecha . "','" . $productoId);
     Persistence::insertar($sql);
 }
Exemple #12
0
 public function invoke()
 {
     $p = Persistence::getInstance();
     $_model = $this->get_called_class();
     $params = $this->getArray();
     $resp = $p->invoke($_model, $params);
     $arrayo = array();
     if ($resp) {
         foreach ($resp as $array) {
             array_push($arrayo, $array);
         }
     }
     return $arrayo;
 }
Exemple #13
0
 public function listar($table)
 {
     $sql = new SQL();
     $sql->addTable($table);
     $sql->setOpcion('listar');
     $usuarios = array();
     $lista = Persistence::consultar($sql);
     foreach ($lista as $usuario) {
         $id = $usuario['id'];
         $nombre = $usuario['nombre'];
         $apellido = $usuario['apellido'];
         $usuario = $usuario['correo'];
         $contrasenha = $usuario['contrasenha'];
         $usuarios[] = new usuario($id, $nombre, $apellido, $usuario, $contrasenha);
     }
     return $usuarios;
 }
 public function insertar($_name, $_address, $_city, $_province, $_email, $_country, $_shippingMethod, $_paymentMethod, $_zipCode, $_phone)
 {
     $instance = Persistence::getInstance();
     $arregloCabeza = array("price" => $this->_price);
     $arregloCuerpo = array("productos" => $this->_productos);
     $name = array('name' => $_name);
     $address = array('address' => $_address);
     $city = array('city' => $_city);
     $province = array('city' => $_province);
     $email = array('email' => $_email);
     $country = array('country' => $_country);
     $shippingMethod = array('shippingMethod' => $_shippingMethod);
     $paymentMethod = array('paymentMethod' => $_paymentMethod);
     $zipCode = array('zipCode' => $_zipCode);
     $phone = array('phone' => $_phone);
     $arregloFinal = array_merge($arregloCabeza, $arregloCuerpo, $name, $address, $city, $province, $email, $country, $shippingMethod, $paymentMethod, $zipCode, $phone);
     $instance->insertDocument($arregloFinal, 'orders');
 }
Exemple #15
0
 public function get()
 {
     $user = Session::get_user();
     $p = Persistence::getInstance();
     $_model = $this->model->get_called_class();
     $array = $this->filter;
     if ($this->model instanceof User) {
         $_packa = null;
         $array['hashtype'] = $this->model->getHashType()->val();
     } else {
         $_packa = $this->model->get_package();
     }
     $resp = $p->filter($user, $_packa, strtolower($_model), $array);
     $arrayo = array();
     $class = get_class($this->model);
     if ($resp) {
         foreach ($resp as $array) {
             $object = new $class();
             $object->setArray($array);
             array_push($arrayo, $object);
         }
     }
     return $arrayo;
 }
Exemple #16
0
 public static function modificar(Sql $sql)
 {
     $db = Persistence::_conectarBD();
     $db->ejecutar($sql);
 }
Exemple #17
0
        echo "Mail sent!";
    } else {
        echo "Error sending mail";
    }
    return;
});
$app->get("/calendar/facilitators/add/:id", function ($id) use($app) {
    $config = Configuration::get_configuration('calendar');
    if (!$config["facilitator"]) {
        return;
    }
    $user = MorgueAuth::get_auth_data();
    $facilitator = array();
    $facilitator['name'] = $user['username'];
    $facilitator['email'] = Contact::get_email_for_user($user['username']);
    $conn = Persistence::get_database_object();
    $error = Calendar::set_facilitator($id, $facilitator, $conn);
    if (!$error) {
        $userHtml = Contact::get_html_for_user($user['username']);
        $to = implode(", ", $config["facilitators_email"]);
        $from = "Morgue <*****@*****.**>";
        $subject = "Facilitator needed [PM-{$id}]";
        $message = '
            <html>
            <head>
              <title>Facilitator Needed for PM-' . $id . '</title>
            </head>
            <body style="font-family: \'Helvetica Neue\', Helvetica,Arial, sans-serif;">
              <h3>' . $userHtml . ' will facilitate this post-mortem!</h3>
            </body>
            </html>';
Exemple #18
0
 /**
  * function to get all history records for a postmortem
  *
  * @param $event_id - ID of the postmortem
  * @param $conn - PDO connection object
  *
  * @returns array - Array containing an entry for each
  * associated history record
  */
 static function get_history($event_id, $conn = null)
 {
     $conn = $conn ?: Persistence::get_database_object();
     if (is_null($conn)) {
         return array("status" => self::ERROR, "error" => "Couldn't get connection object.");
     }
     $sql = "SELECT * FROM postmortem_history WHERE postmortem_id=:pid";
     $stmt = $conn->prepare($sql);
     $stmt->execute(array("pid" => $event_id));
     return $stmt->fetchAll();
 }
Exemple #19
0
<?php

require 'Persistence.php';
$comment_post_ID = 1;
$db = new Persistence();
$comments = $db->get_comments($comment_post_ID);
$has_comments = count($comments) > 0;
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
	<title>Smashing HTML5!</title>
	<meta charset="utf-8" />
	
	<link rel="stylesheet" href="css/main.css" type="text/css" />

	<!--[if IE]>
	  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
	<!--[if lte IE 7]>
		<link rel="stylesheet" type="text/css" media="all" href="css/ie.css"/>
		<script src="js/IE8.js" type="text/javascript"></script><![endif]-->	
	<!--[if lt IE 7]>
		<link rel="stylesheet" type="text/css" media="all" href="css/ie6.css"/><![endif]-->

</head>

<body id="index" class="home">
	
	<header id="banner" class="body">
		<h1><a href="#">Smashing HTML5! <strong>HTML5 in the year <del>2022</del> <ins>2012</ins></strong></a></h1>
		<nav><ul>
Exemple #20
0
 /**
  * Get a postmortem from the database
  *
  * @param $postmortem_id - id of the postmortem to get
  * @param $conn          - PDO connection object, will be newly instantiated when
  *                         null (default: null)
  *
  * @returns a postmortem map including an "id" field on success or a map of the
  * form ( "id" => null, "error" => "an error message" ) on failure
  */
 static function get_postmortem($postmortem_id, $conn = null)
 {
     $conn = $conn ?: Persistence::get_database_object();
     try {
         $sql = "SELECT id, title, summary, why_surprised, starttime, endtime, statustime,\n                    detecttime,severity, contact, gcal, created, modified, modifier, deleted \n                    FROM postmortems WHERE id = :id LIMIT 1";
         $stmt = $conn->prepare($sql);
         $stmt->execute(array('id' => $postmortem_id));
         $postmortem = $stmt->fetch(PDO::FETCH_ASSOC);
         return $postmortem;
     } catch (PDOException $e) {
         return array("id" => null, "error" => $e->getMessage());
     }
 }
Exemple #21
0
 $content = "anniversary/views/anniversary-mail";
 $show_sidebar = false;
 $page_title = "Today in Post Mortem History";
 $today = date("Y-m-d", time());
 $get_date = trim($app->request->get('date'));
 if ($get_date) {
     $get_date = date("Y-m-d", strtotime($get_date));
     $today = $get_date;
 }
 $conn = Persistence::get_database_object();
 $pm_ids = Anniversary::get_ids($today, $conn);
 $human_readable_date = date("F jS", strtotime($today));
 $pms = array();
 if ($pm_ids['status'] === 0) {
     foreach ($pm_ids['values'] as $k => $v) {
         $pm = Persistence::get_postmortem($v['id'], $conn);
         $pms[] = $pm;
     }
 } else {
     $message = $pm_ids['error'];
     $content = "error";
     include 'views/page.php';
     return;
 }
 if (count($pms)) {
     // get the tags for each PM we found so we can display them
     foreach ($pms as $k => $pm) {
         $tags = Postmortem::get_tags_for_event($pm['id'], null);
         $pms[$k]['tags'] = $tags['values'];
     }
 }
Exemple #22
0
 /**
  * function to UNdelete a channel from the association table
  *
  * @param $id - ID to delete
  * @param $conn - PDO connection object (default: null)
  *
  * @returns ( "status" => self::OK ) on success
  * or ( "status" => self::ERROR, "error" => "an error message" ) on failure
  */
 static function undelete_channel($theid, $conn = null)
 {
     $conn = $conn ?: Persistence::get_database_object();
     $table_name = 'irc';
     if (is_null($conn)) {
         return array("status" => self::ERROR, "error" => "Couldn't get connection object.");
     }
     return Persistence::flag_as_undeleted($table_name, 'postmortem_id', $theid, $conn);
 }
Exemple #23
0
 public function autenticate()
 {
     $p = Persistence::getInstance();
     return $p->autenticate($this);
 }
Exemple #24
0
<?php

require 'Persistence.php';
$db = new Persistence();
$db->delete_all();
print_r($db->get_all_comments());
Exemple #25
0
 public function eliminarPedido($id)
 {
     $sql = new Sql();
     $sql->addTable('pedidos');
     $sql->setOpcion('delete');
     $sql->addWhere("`idPedido =`" . $id);
     Persistence::eliminar($sql);
 }
 /**
  * @dataProvider persistanceInstanceProvider
  */
 public function testDetach(Persistence $persistence)
 {
     $document = $this->collection->createDocument(array('param' => 'value'));
     $this->assertFalse($persistence->contains($document));
     // attach document
     $persistence->persist($document);
     // check if document in persistence
     $this->assertTrue($persistence->contains($document));
     // detach document
     $persistence->detach($document);
     // check if document in persistence
     $this->assertFalse($persistence->contains($document));
 }
<?php

namespace Components;

Annotations::registerAnnotations([Annotation_Cache::NAME => Annotation_Cache::TYPE, Annotation_Collection::NAME => Annotation_Collection::TYPE, Annotation_Id::NAME => Annotation_Id::TYPE, Annotation_Transient::NAME => Annotation_Transient::TYPE]);
Resource_Type::registerResourceType('mysql', Persistence_Resource_Pdo_Mysql::type());
Resource_Type::registerResourceType('mongodb', Persistence_Resource_Mongodb::type());
Persistence_Resource_Schema::serve('schema');
Persistence::registerResource('nosql', ['mongodb://127.0.0.1/' . COMPONENTS_INSTANCE_CODE]);
Debug::addFlagListener(function ($active_, array $flags_) {
    if ($active_) {
        $bits = [];
        if (isset($flags_[Persistence::LOG_STATEMENTS])) {
            $bits[] = Persistence::BIT_LOG_STATEMENTS;
        }
        if (isset($flags_[Persistence::LOG_QUERIES])) {
            $bits[] = Persistence::BIT_LOG_QUERIES;
        }
        if (isset($flags_[Persistence::PROFILE])) {
            $bits[] = Persistence::BIT_PROFILE;
        }
        Persistence::$debugMode = Bitmask::getBitmaskForBits($bits);
    } else {
        Persistence::$debugMode = Persistence::BIT_NO_DEBUG;
    }
});
<?php

require 'Persistence.php';
$ajax = $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
$db = new Persistence();
$added = $db->add_comment($_POST);
if ($ajax) {
    sendAjaxResponse($added);
} else {
    sendStandardResponse($added);
}
function sendAjaxResponse($added)
{
    header("Content-Type: application/x-javascript");
    if ($added) {
        header('Status: 201');
        echo json_encode($added);
    } else {
        header('Status: 400');
    }
}
function sendStandardResponse($added)
{
    if ($added) {
        header('Location: index.php');
    } else {
        header('Location: index.php?error=Your comment was not posted due to errors in your form submission');
    }
}
 public function loadImage($id)
 {
     return $image = Persistence::getImagen($id);
 }
Exemple #30
0
 public function modificarProveedor($id)
 {
     $sql = new Sql();
     $sql->addTable('proveedores');
     $sql->setOpcion('update');
     $sql->addSet("`" . 'nombre' . "`" . "=" . "'" . $this->_nombreContacto . "'");
     $sql->addSet("`" . 'apellido' . "`" . "=" . "'" . $this->_apellidoContacto . "'");
     $sql->addSet("`" . 'dni' . "`" . "=" . "'" . $this->_dniContacto . "'");
     $sql->addSet("`" . 'telefono' . "`" . "=" . "'" . $this->_telefonoContacto . "'");
     $sql->addSet("`" . 'empresa' . "`" . "=" . "'" . $this->_nombreEmpresa . "'");
     $sql->addSet("`" . 'ruc' . "`" . "=" . "'" . $this->_ruc . "'");
     $sql->addSet("`" . 'correo' . "`" . "=" . "'" . $this->_correo . "'");
     $sql->addWhere("`idProveedor` =" . $id);
     Persistence::modificar($sql);
 }