コード例 #1
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];
         }
     }
 }
コード例 #2
0
 public function run($context)
 {
     $notification_count = 0;
     $user_count = 0;
     $users = array();
     foreach ($context->stocks as $stock) {
         if ($stock->attivo == 0) {
             // printf("%s stock %s is inactive or not a bond.\n", get_called_class(), $stock->isin);
             continue;
         }
         $item_factory = new WatchlistItem();
         $items = $item_factory->find_all(array('where_clause' => "`isin` = '{$stock->isin}'"));
         if (count($items) > 0) {
             foreach ($items as $item) {
                 $notification_count++;
                 if (!in_array($item->utente, $users)) {
                     $users[] = $item->utente;
                     $user_count++;
                 }
                 // print_r($item);
             }
         }
     }
     switch ($notification_count) {
         case 0:
             $str = "%s did not issue notifications to any user\n";
             break;
         case 1:
             $str = "%s issued 1 notification to 1 user\n";
             break;
         default:
             if ($user_count == 1) {
                 $str = "%s issued %d notifications to 1 user\n";
             } else {
                 $str = "%s issued %d notifications to %d users\n";
             }
             break;
     }
     printf($str, get_called_class(), $notification_count, $user_count);
 }