当前位置: 首页>>代码示例>>PHP>>正文


PHP Stock::setName方法代码示例

本文整理汇总了PHP中Stock::setName方法的典型用法代码示例。如果您正苦于以下问题:PHP Stock::setName方法的具体用法?PHP Stock::setName怎么用?PHP Stock::setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stock的用法示例。


在下文中一共展示了Stock::setName方法的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 />";
        }
    }
}
开发者ID:WealthCity,项目名称:ktrader,代码行数:30,代码来源:init_functions.php

示例2: update_stock_info

/**
 * Will update details about stock including EPS/PPE/Stock Price/Capitilization etc...
 * from Yahoo Finance. Can call many times, but will only actually ping yahoo if its been
 * 16 hours since last update.
 * */
function update_stock_info($ticker)
{
    $stock = new Stock($ticker, false);
    if ($stock->getId() < 0) {
        return false;
    }
    //Only update stocks that haven't been updated in 16 hours.
    if (time() - $stock->getInfoDate() < TIME_HOUR * 16) {
        return false;
    }
    /**
     *s = stock, n = name, l1 = last trade, e = earnings per share, r = price per earings ration
     *x = stock exchange, t8 = 1 yr target price, j1 = market cap
     */
    $url = 'http://finance.yahoo.com/d/quotes.csv?s=' . $stock->getTicker() . '&f=snl1erxt8j1';
    //Set timeout for fetching url
    $ctx = stream_context_create(array('http' => array('timeout' => 3)));
    $file = @file_get_contents($url, 0, $ctx);
    if ($file == false) {
        return false;
    }
    /**
     *$array[0] = Ticker
     *$array[1] = Name
     *$array[2] = Last Trade Price
     *$array[3] = Earnings/Share
     *$array[4] = Price/Earnings
     *$array[5] = Stock Exchange
     *$array[6] = Year Target Price
     *$array[7] = Market Cap
     */
    //File should only be one line, explode into array
    $array = explode(',', $file);
    //No Name means stock doesn't exist.
    if ($array[1] == "") {
        $stock->setStatus(STATUS_INACTIVE);
        $stock->persist();
        return false;
    }
    $stock->setName(addslashes(str_replace('"', '', $array[1])));
    $stock->setLastTrade($array[2]);
    $stock->setEarningsPerShare($array[3]);
    $stock->setPricePerEarnings($array[4]);
    $array[5] = strtoupper(str_replace('"', '', $array[5]));
    if ($array[5] == "") {
        //5 is our index N/A
        $stock->setStockExchangeId(5);
    } else {
        //Check to see if stock exchange exists, if it doesnt insert into database.
        $query = mysql_query("SELECT * FROM exchanges WHERE ticker = '" . $array[5] . "'");
        if (mysql_num_rows($query) < 1) {
            mysql_query("INSERT INTO exchanges\r\n                        (ticker)\r\n                        VALUES\r\n                        ('" . $array[5] . "')");
            $stock->setStockExchangeId(mysql_insert_id());
        } else {
            $mysql_array = mysql_fetch_array($query);
            $stock->setStockExchangeId($mysql_array['id']);
        }
    }
    $stock->setTargetPrice($array[6]);
    //Get rid of any whitespace
    $array[7] = trim($array[7]);
    if (substr($array[7], strlen($array[7]) - 1, 1) == 'M') {
        $stock->setMarketCap($array[7] / 1000);
    } else {
        if (substr($array[7], strlen($array[7]) - 1, 1) == 'K') {
            $stock->setMarketCap($array[7] / 1000000);
        } else {
            $stock->setMarketCap($array[7] / 1);
        }
    }
    //Set time of this update, so we dont' do it again for another 16 hrs minimum.
    $stock->setInfoDate(time());
    $stock->persist();
    return true;
}
开发者ID:WealthCity,项目名称:ktrader,代码行数:80,代码来源:model.php


注:本文中的Stock::setName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。