Beispiel #1
0
 function _min_max($date)
 {
     $conn = $this->get_connection();
     $quote = new Quote();
     $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($_GET['isin'])}' " . "AND `data` >= '{$conn->escape($date)}' " . 'ORDER BY `quotazione` DESC ' . 'LIMIT 1');
     $max_quote = $quotes[0]->quotazione;
     $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($_GET['isin'])}' " . "AND `data` >= '{$conn->escape($date)}' " . 'ORDER BY `quotazione` ASC ' . 'LIMIT 1');
     $min_quote = $quotes[0]->quotazione;
     die('({min:' . $min_quote . ',max:' . $max_quote . '})');
 }
Beispiel #2
0
 public static function for_range_and_order($isin, $date_from, $date_to, $order_by, $sort_dir)
 {
     $conn = Db::get_connection();
     $quote = new Quote();
     $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($isin)}' " . "AND `data` > '{$conn->escape($date_from)}' " . "AND `data` < '{$conn->escape($date_to)}' " . "ORDER BY `{$conn->escape($order_by)}` {$conn->escape(strtoupper($sort_dir))} " . 'LIMIT 1');
     // print_r($quotes);
     Db::close_connection($conn);
     return $quotes[0];
 }
 function index()
 {
     $conn = $this->get_connection();
     $item_factory = new WatchlistItem();
     $this->items = $item_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($_COOKIE['username'])}' ", 'order_by' => sprintf('`%s` %s', $this->get_sort('isin'), $this->get_dir()), 'limit' => $this->get_limit()));
     if (count($this->items) > 0) {
         foreach ($this->items as $item) {
             $item->stock = new Stock();
             $item->stock->find_by_id($item->isin);
             $quote = new Quote();
             $quotes = $quote->find_all(array('where_clause' => "`isin` = '{$conn->escape($item->isin)}' ", 'order_by' => '`data` DESC, `ora` DESC', 'limit' => 1));
             $item->quote = $quotes[0];
             $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($item->isin)}' " . "AND `data` >= '{$conn->escape(date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y') - 1)))}' " . 'ORDER BY `quotazione` DESC ' . 'LIMIT 1');
             $item->max_quote = $quotes[0];
             $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($item->isin)}' " . "AND `data` >= '{$conn->escape(date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y') - 1)))}' " . 'ORDER BY `quotazione` ASC ' . 'LIMIT 1');
             $item->min_quote = $quotes[0];
         }
     }
 }
Beispiel #4
0
 /**
  *  @fn inspect
  *  @short Inspects an instrument
  *  @details Action to inspect an instrument, used internally by #browse to
  *  render the main view.
  */
 public function inspect()
 {
     $conn = $this->get_connection();
     $isin = isset($_REQUEST['id']) ? $_REQUEST['id'] : $_REQUEST['isin'];
     $this->stock = new Stock();
     $this->stock->find_by_id($isin);
     $yesterday = date('Y-m-d', mktime(0, 0, 0, isset($_REQUEST['month']) ? $_REQUEST['month'] : date('m'), (isset($_REQUEST['day']) ? $_REQUEST['day'] : date('d')) - 1, isset($_REQUEST['year']) ? $_REQUEST['year'] : date('Y')));
     $tomorrow = date('Y-m-d', mktime(0, 0, 0, isset($_REQUEST['month']) ? $_REQUEST['month'] : date('m'), (isset($_REQUEST['day']) ? $_REQUEST['day'] : date('d')) + 1, isset($_REQUEST['year']) ? $_REQUEST['year'] : date('Y')));
     $quote = new Quote();
     $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($this->stock->isin)}' " . "AND `data` > '{$conn->escape($yesterday)}' " . "AND `data` < '{$conn->escape($tomorrow)}' " . 'ORDER BY `quotazione` DESC ' . 'LIMIT 1');
     $this->stock->day_max = count($quotes) > 0 ? $quotes[0] : $quote;
     $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($this->stock->isin)}' " . "AND `data` > '{$conn->escape($yesterday)}' " . "AND `data` < '{$conn->escape($tomorrow)}' " . 'ORDER BY `quotazione` ASC ' . 'LIMIT 1');
     $this->stock->day_min = count($quotes) > 0 ? $quotes[0] : $quote;
     $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($this->stock->isin)}' " . "AND `data` > '{$conn->escape($yesterday)}' " . "AND `data` < '{$conn->escape($tomorrow)}' " . 'ORDER BY `data` ASC, `ora` ASC ' . 'LIMIT 1');
     $this->stock->open = count($quotes) > 0 ? $quotes[0] : $quote;
     $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($this->stock->isin)}' " . "AND `data` > '{$conn->escape($yesterday)}' " . "AND `data` < '{$conn->escape($tomorrow)}' " . 'ORDER BY `data` DESC, `ora` DESC ' . 'LIMIT 1');
     $this->stock->last = count($quotes) > 0 ? $quotes[0] : $quote;
 }