/** * This method will clear the quotation cache generated by this module for a site and page * @todo implement something to call this */ function clear_cache($site_id = '', $page_id = '') { $site_id = $site_id ? $site_id : $this->site_id; $page_id = $page_id ? $page_id : $this->page_id; if ($site_id && $page_id) { $qh = new QuoteHelper($site_id, $page_id); $qh->clear_cache(); } else { trigger_error('clear_cache needs a site_id and page_id'); } }
<?php /** * @package reason * @subpackage scripts * * @todo this script should probably move into lib/core/scripts, leaving just a stub here */ include_once 'reason_header.php'; reason_include_once('classes/quote_helper.php'); $site_id = !empty($_REQUEST['site_id']) ? $_REQUEST['site_id'] : ''; $page_id = !empty($_REQUEST['page_id']) ? $_REQUEST['page_id'] : '5'; $cleanup_rules = array('site_id' => array('function' => 'turn_into_int'), 'page_id' => array('function' => 'turn_into_int'), 'page_category_mode' => array('function' => 'turn_into_int'), 'prefer_short_quotes' => array('function' => 'turn_into_int'), 'cache_lifespan' => array('function' => 'turn_into_int'), 'viewed_quote_ids' => array('function' => 'populate_viewed_quote_ids')); $request = carl_clean_vars($_REQUEST, $cleanup_rules); $qh = new QuoteHelper(); if (isset($request['site_id'])) { $qh->set_site_id($request['site_id']); } if (isset($request['page_id'])) { $qh->set_page_id($request['page_id']); } if (isset($request['cache_lifespan'])) { $qh->set_cache_lifespan($request['cache_lifespan']); } if (isset($request['page_category_mode'])) { $qh->set_page_category_mode($request['page_category_mode']); } if (isset($request['viewed_quote_ids'])) { $qh->set_unavailable_quote_ids($request['viewed_quote_ids']); } // this should be able to support quotes when not in random mode as well probably
private function get_roi() { if (!isset($_REQUEST['base'])) { $_REQUEST['base'] = 1000; } if (!isset($_REQUEST['month-to'])) { $_REQUEST['month-to'] = date('Y-m-d', mktime(0, 0, 0, date('m') + self::DEFAULT_ROI_HORIZON_MONTHS, 0, date('Y'))); } $this->roi = array(); // $this->stocks = array(); // This to ensure we get latest quote from today $today = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'))); $last_month = date('Y-m-d', mktime(0, 0, 0, date('m') - 1, date('d'), date('Y'))); // print_r($_REQUEST['isin']); foreach ($this->isins as $isin) { $quote = QuoteHelper::latest_for_range($isin, $last_month, $today); // print_r($quote); $stock = new Stock(); if (!$stock->find_by_id($isin)) { continue; } // $this->stocks[$isin] = $stock; $investito = Change::convert($quote->quotazione * $_REQUEST['base'] / 100, $stock->divisa); $this->roi[$isin] = PianificatoreHelper::roi_with_timeline($isin, $_REQUEST['base'], $today, $_REQUEST['month-to'], $investito); unset($this->roi[$isin]->payments); $this->roi[$isin]->stock = $stock; } // print_r($this->roi); uasort($this->roi, $this->get_sorter()); }