本文整理汇总了PHP中Stock::persist方法的典型用法代码示例。如果您正苦于以下问题:PHP Stock::persist方法的具体用法?PHP Stock::persist怎么用?PHP Stock::persist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stock
的用法示例。
在下文中一共展示了Stock::persist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_stocks
/**
* Use this method to update our master list of stocks. The file supplied should
* have one stock name per separator.
* @param String $filename The filename including location
* @param String $separator The separator used between each stock.
* @return void Return nothing.
**/
function update_stocks($filename, $separator)
{
$file = file_get_contents($filename);
$sArray = explode($separator, $file);
//Lets first populate an array with all stocks from DB so we don't
//have to make a DB call for each stock in file.
$query = mysql_query("SELECT * FROM stocks");
$current_stocks = array();
while ($array = mysql_fetch_array($query)) {
$current_stocks[$array['name']] = true;
}
//Now lets cycle through ones to add
foreach ($sArray as $i => $value) {
if (array_key_exists($value, $current_stocks) == false && $value != "") {
echo "Adding " . $value . " <br />";
$stock = new Stock(null);
$stock->setName($value);
$stock->persist();
} else {
echo "Skipped " . $value . "<br />";
}
}
}
示例2: deactivateStock
/**
* Will only deactivate if latest trade was 0 and last 5 days was also 0.
*/
function deactivateStock($stock_id)
{
$stock = new Stock($stock_id, false);
//Make sure stock exists.
if ($stock->getId() < 0) {
return "";
}
//Don't do anything if already inactive
if ($stock->getStatus() == STATUS_INACTIVE) {
return $stock->getTicker() . "(" . $stock->getId() . ") was already inactive.";
}
if (update_stock_info($stock->getTicker())) {
//Only need to get new data if was updated.
$stock = new Stock($stock_id, false);
}
if ($stock->getLastTrade() > 0.05) {
return "";
}
update_stock_daily($stock->getTicker());
$stock = new Stock($stock_id, true);
$arr = $stock->getDailyData();
if (sizeof($arr) < 5) {
//If in here, we don't have enough data which means stock is probably a weird derivative.
$stock->setStatus(STATUS_INACTIVE);
$stock->persist();
return "Removed Stock " . $stock->getTicker() . " (" . $stock->getId() . ") due to not enough daily data.";
}
//Make sure has been less than 0.05 for quite some time.
if ($arr[0]->getClose() < 0.05 && $arr[1]->getClose() < 0.05 && $arr[2]->getClose() < 0.05 && $arr[3]->getClose() < 0.05) {
$stock->setStatus(STATUS_INACTIVE);
$stock->persist();
return "Removed Stock " . $stock->getTicker() . " (" . $stock->getId() . ") due to a last closing price of \$" . $stock->getLastTrade();
}
return "";
}