Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
 function add()
 {
     if ($this->request->is_post()) {
         $item = new WatchlistItem($_POST);
         $item->utente = $_COOKIE['username'];
         $item->save();
         $this->redirect_to(array('action' => 'index'));
     } else {
         if (!empty($_GET['id'])) {
             $this->stock = new Stock();
             $this->stock->find_by_id($_GET['id']);
             $this->render(array('action' => 'add_by_isin'));
         } else {
             $stock_factory = new Stock();
             $stocks = $stock_factory->find_all(array('where_clause' => '`attivo` = 1', 'order_by' => '`title` ASC'));
             $this->stocks = array('-1' => 'Scegli...');
             foreach ($stocks as $stock) {
                 $this->stocks[$stock->isin] = $stock->title;
             }
         }
     }
 }