本文整理汇总了PHP中Date::setHour方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::setHour方法的具体用法?PHP Date::setHour怎么用?PHP Date::setHour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date
的用法示例。
在下文中一共展示了Date::setHour方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSpan
/**
* A method that can be inherited and used by children classes to get the
* required date span of a statistics page.
*
* @param object $oCaller The calling object. Expected to have the
* the following class variables:
* $oCaller->aPlugins - An array of statistics fields plugins
* $oCaller->oStartDate - Will be set by method
* $oCaller->spanDays - Will be set by method
* $oCaller->spanWeeks - Will be set by method
* $oCaller->spanMonths - Will be set by method
* @param array $aParams An array of query parameters for
* {@link Admin_DA::fromCache()}.
*/
function getSpan(&$oCaller, $aParams)
{
$oStartDate = new Date(date('Y-m-d'));
$oStartDate->setHour(0);
$oStartDate->setMinute(0);
$oStartDate->setSecond(0);
// Check span using all plugins
foreach ($oCaller->aPlugins as $oPlugin) {
$aPluginParams = call_user_func(array($oPlugin, 'getHistorySpanParams'));
$aSpan = Admin_DA::fromCache('getHistorySpan', $aParams + $aPluginParams);
if (!empty($aSpan['start_date'])) {
$oDate = new Date($aSpan['start_date']);
$oDate->setTZbyID('UTC');
if ($oDate->before($oStartDate)) {
$oDate->convertTZ($oStartDate->tz);
$oStartDate = new Date($oDate);
}
}
}
$oStartDate->setHour(0);
$oStartDate->setMinute(0);
$oStartDate->setSecond(0);
$oNow = new Date();
$oSpan = new Date_Span(new Date($oStartDate), new Date($oNow->format('%Y-%m-%d')));
// Store the span data required for stats display
$oCaller->oStartDate = $oStartDate;
$oCaller->spanDays = (int) ceil($oSpan->toDays());
$oCaller->spanWeeks = (int) ceil($oCaller->spanDays / 7) + ($oCaller->spanDays % 7 ? 1 : 0);
$oCaller->spanMonths = ($oNow->getYear() - $oStartDate->getYear()) * 12 + ($oNow->getMonth() - $oStartDate->getMonth()) + 1;
// Set the caller's aDates span in the event that it's empty
if (empty($oCaller->aDates)) {
$oCaller->aDates['day_begin'] = $oStartDate->format('%Y-%m-%d');
$oCaller->aDates['day_end'] = $oNow->format('%Y-%m-%d');
}
}
示例2: create
static public function create($year=0, $month=0, $day=0, $hour=0, $minute=0, $second=0)
{
$d = new Date();
$d->setYear($year);
$d->setMonth($month);
$d->setDay($day);
$d->setHour($hour);
$d->setMinute($minute);
$d->setSecond($second);
return $d;
}
示例3: getStats
function getStats()
{
// Set time zone to local
OA_setTimeZoneLocal();
$oEnd = new Date();
$oEnd->setHour(0);
$oEnd->setMinute(0);
$oEnd->setSecond(0);
$oEnd->toUTC();
$oStart = new Date($oEnd);
$oStart->subtractSpan(new Date_Span('7-0-0-0'));
$oStart->toUTC();
$doDsah = OA_Dal::factoryDO('data_summary_ad_hourly');
$doDsah->selectAdd();
$doDsah->selectAdd("DATE_FORMAT(date_time, '%Y-%m-%d') AS day");
$doDsah->selectAdd('SUM(' . $doDsah->tableName() . '.impressions) AS total_impressions');
$doDsah->selectAdd('SUM(' . $doDsah->tableName() . '.clicks) AS total_clicks');
$doDsah->whereAdd("date_time >= '" . $doDsah->escape($oStart->format('%Y-%m-%d %H:%M:%S')) . "'");
$doDsah->whereAdd("date_time < '" . $doDsah->escape($oEnd->format('%Y-%m-%d %H:%M:%S')) . "'");
if (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
$doBanners = OA_Dal::factoryDO('banners');
$doCampaigns = OA_Dal::factoryDO('campaigns');
$doClients = OA_Dal::factoryDO('clients');
$doClients->agencyid = OA_Permission::getEntityId();
$doCampaigns->joinAdd($doClients);
$doBanners->joinAdd($doCampaigns);
$doBanners->selectAdd();
$doBanners->selectAdd("bannerid");
$doBanners->find();
$ad_ids = array();
while ($doBanners->fetch()) {
$ad_ids[] = $doBanners->bannerid;
}
if (empty($ad_ids)) {
return array();
}
$doDsah->whereAdd("ad_id IN (" . implode(",", $ad_ids) . ")");
}
$doDsah->groupBy('day');
$doDsah->orderBy('day');
$doDsah->find();
$aStats = array();
while ($doDsah->fetch()) {
$row = $doDsah->toArray();
$aStats[0][date('D', strtotime($row['day']))] = $row['total_impressions'];
$aStats[1][date('D', strtotime($row['day']))] = $row['total_clicks'];
}
return $aStats;
}
示例4: checkDates
/**
* Check start/end dates - note that check is the reverse of normal check:
* if the operation interval is <= 60, must be start/end of an hour, to
* make sure we update all the operation intervals in the hour, and if
* the operation interval > 60, must be the start/end of an operation
* interval, to make sure we update all the hours in the operation interval.
*
* @static
* @param Date $oStartDate
* @param Date $oEndDate
* @return boolean
*/
function checkDates($oStartDate, $oEndDate)
{
$aConf = $GLOBALS['_MAX']['CONF'];
$operationInterval = $aConf['maintenance']['operation_interval'];
if ($operationInterval <= 60) {
// Must ensure that only one hour is being summarised
if (!OX_OperationInterval::checkDatesInSameHour($oStartDate, $oEndDate)) {
return false;
}
// Now check that the start and end dates are match the start and
// end of the hour
$oHourStart = new Date();
$oHourStart->setYear($oStartDate->getYear());
$oHourStart->setMonth($oStartDate->getMonth());
$oHourStart->setDay($oStartDate->getDay());
$oHourStart->setHour($oStartDate->getHour());
$oHourStart->setMinute('00');
$oHourStart->setSecond('00');
$oHourEnd = new Date();
$oHourEnd->setYear($oEndDate->getYear());
$oHourEnd->setMonth($oEndDate->getMonth());
$oHourEnd->setDay($oEndDate->getDay());
$oHourEnd->setHour($oEndDate->getHour());
$oHourEnd->setMinute('59');
$oHourEnd->setSecond('59');
if (!$oStartDate->equals($oHourStart)) {
return false;
}
if (!$oEndDate->equals($oHourEnd)) {
return false;
}
} else {
// Must ensure that only one operation interval is being summarised
$operationIntervalID = OX_OperationInterval::convertDaySpanToOperationIntervalID($oStartDate, $oEndDate, $operationInterval);
if (is_bool($operationIntervalID) && !$operationIntervalID) {
return false;
}
// Now check that the start and end dates match the start and end
// of the operation interval
list($oOperationIntervalStart, $oOperationIntervalEnd) = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStartDate, $operationInterval);
if (!$oStartDate->equals($oOperationIntervalStart)) {
return false;
}
if (!$oEndDate->equals($oOperationIntervalEnd)) {
return false;
}
}
return true;
}
示例5: _setPeriodFilter
protected function _setPeriodFilter($request)
{
$locale = Limb::toolkit()->getLocale();
$start_date = new Date();
$start_date->setHour(0);
$start_date->setMinute(0);
$start_date->setSecond(0);
if ($stats_start_date = $request->get('stats_start_date')) {
$start_date->setByLocaleString($locale, $stats_start_date, $locale->getShortDateTimeFormat());
}
$finish_date = new Date();
if ($stats_finish_date = $request->get('stats_finish_date')) {
$finish_date->setByLocaleString($locale, $stats_finish_date, $locale->getShortDateTimeFormat());
}
$finish_date->setHour(23);
$finish_date->setMinute(59);
$finish_date->setSecond(59);
$this->_stats_report->setPeriodFilter($start_date, $finish_date);
}
示例6: process
function process(&$sql)
{
$toolkit =& Limb::toolkit();
$request =& $toolkit->getRequest();
$start_date = new Date();
$start_date->setHour(0);
$start_date->setMinute(0);
$start_date->setSecond(0);
if ($stats_start_date = $request->get('start_date')) {
$start_date->setByString($stats_start_date);
}
$finish_date = new Date();
if ($stats_finish_date = $request->get('finish_date')) {
$finish_date->setByString($stats_finish_date);
}
$finish_date->setHour(23);
$finish_date->setMinute(59);
$finish_date->setSecond(59);
$start_stamp = $start_date->getStamp();
$finish_stamp = $finish_date->getStamp();
$sql->addCondition("master.time BETWEEN {$start_stamp} AND {$finish_stamp}");
}
示例7: isMidnightMaintenance
/**
* A method to check if midnight tasks should run
*
* @param Date $oLastRun
* @return boolean
*/
function isMidnightMaintenance($oLastRun)
{
global $serverTimezone;
if (empty($oLastRun)) {
return true;
}
$oServiceLocator =& OA_ServiceLocator::instance();
$lastMidnight = new Date($oServiceLocator->get('now'));
if (!empty($serverTimezone)) {
$lastMidnight->convertTZbyID($serverTimezone);
}
$lastMidnight->setHour(0);
$lastMidnight->setMinute(0);
$lastMidnight->setSecond(0);
$oLastRunCopy = new Date($oLastRun);
return $oLastRunCopy->before($lastMidnight);
}
示例8: uniqid
/**
* Tests that an e-mail reporting on impending campaign expiration
* is able to be generated correctly.
*/
function testSendAndPrepareCampaignImpendingExpiryEmail()
{
$adminContact = 'Andrew Hill';
$adminName = 'OpenX Limited';
$adminMail = 'send@example.com';
$adminCompany = 'Admin company name';
$adminAccountId = 100;
$agencyName = 'Agency Ltd.';
$agencyContact = 'Mr. Foo Bar Agency';
$agencyMail = 'send@agency.com';
$advertiserName = 'Foo Client';
$advertiserMail = 'advertiser@example.com';
$advertiserUsername = 'advertiserusername';
$aConf =& $GLOBALS['_MAX']['CONF'];
$aConf['webpath']['admin'] = 'example.com';
$aConf['email']['fromAddress'] = $adminMail;
$aConf['email']['fromName'] = $adminName;
$aConf['email']['fromCompany'] = $adminCompany;
$aConf['email']['useManagerDetails'] = true;
$aConf['email']['logOutgoing'] = true;
$mockName = uniqid('PartialMockOA_Email_');
Mock::generatePartial('OA_Email', $mockName, array('sendMail'));
$oEmail = new $mockName();
$oEmail->setReturnValue('sendMail', true);
// Prepare valid test data
$dateReason = 'date';
$dateValue = '2007-05-15';
$impReason = 'impressions';
$impValue = 100;
// The tests below assume that the number of days before a campaign expires when the
$oCampaignDate = new Date($dateValue);
$oCampaignDate->setHour(23);
$oCampaignDate->setMinute(59);
$oCampaignDate->setSecond(59);
$oCampaignDate->toUTC();
$oTwoDaysPriorDate = new Date($dateValue);
$oTwoDaysPriorDate->subtractSeconds(2 * 24 * 60 * 60 - 10);
$oNowDate = new Date($dateValue);
// Prepare an admin user
// Create the admin account
$doAccounts = OA_Dal::factoryDO('accounts');
$doAccounts->account_name = 'System Administrator';
$doAccounts->account_type = OA_ACCOUNT_ADMIN;
$adminAccountId = DataGenerator::generateOne($doAccounts);
// Setup the admin account id
$doAppVar = OA_Dal::factoryDO('application_variable');
$doAppVar->name = 'admin_account_id';
$doAppVar->value = $adminAccountId;
// Create an user
$doAdminUser = OA_Dal::factoryDO('users');
$doAdminUser->contact_name = $adminContact;
$doAdminUser->email_address = $adminMail;
$doAdminUser->username = $adminName;
$doAdminUser->password = md5('password');
$doAdminUser->language = 'en';
$doAdminUser->default_account_id = $adminAccountId;
$adminUserId = DataGenerator::generateOne($doAdminUser);
$doAdminUser = OA_Dal::staticGetDO('users', $adminUserId);
$aAdminUser = $doAdminUser->toArray();
// Create admin account-user association
$doAUA = OA_Dal::factoryDO('account_user_assoc');
$doAUA->account_id = $adminAccountId;
$doAUA->user_id = $adminUserId;
$doAUA->insert();
// Prepare an agency
$doAgency = OA_Dal::factoryDO('agency');
$doAgency->name = $agencyName;
$doAgency->contact = $agencyContact;
$doAgency->email = $agencyMail;
$agencyId = DataGenerator::generateOne($doAgency);
$doAgency = OA_Dal::staticGetDO('agency', $agencyId);
//get('agencyid', $agencyId);
$agencyAccountId = $doAgency->account_id;
// Prepare an agency user
$doUser = OA_Dal::factoryDO('users');
$doUser->contact_name = $agencyContact;
$doUser->email_address = $agencyMail;
$doUser->username = $agencyName;
$doUser->language = 'en';
$agencyUserId = DataGenerator::generateOne($doUser);
$doAgencyUser = OA_Dal::staticGetDO('users', $agencyUserId);
$aAgencyUser = $doAgencyUser->toArray();
$oUserAccess = new OA_Admin_UI_UserAccess();
// Agency user
$oUserAccess->linkUserToAccount($agencyUserId, $doAgency->account_id, array(), array());
// Generate an advertiser owned by the agency with no email adddress,
// but no placements, and ensure false is returned
$doClients = OA_Dal::factoryDO('clients');
$doClients->agencyid = $agencyId;
$doClients->clientname = $advertiserName;
$doClients->email = '';
$advertiserId1 = DataGenerator::generateOne($doClients);
$doClients = OA_Dal::staticGetDO('clients', 'clientid', $advertiserId1);
// ->get('clientid', $advertiserId1);
$advertiserAccountId = $doClients->account_id;
// Create an advertiser user
//.........这里部分代码省略.........
示例9: modify
/**
* This method modifies an existing campaign. Undefined fields do not change
* and defined fields with a NULL value also remain unchanged.
*
* @access public
*
* @param OA_Dll_CampaignInfo &$oCampaign <br />
* <b>For adding</b><br />
* <b>Required properties:</b> advertiserId<br />
* <b>Optional properties:</b> campaignName, startDate, endDate, impressions, clicks, priority, weight<br />
*
* <b>For modify</b><br />
* <b>Required properties:</b> campaignId<br />
* <b>Optional properties:</b> advertiserId, campaignName, startDate, endDate, impressions, clicks, priority, weight, viewWindow, clickWindow<br />
*
* @return boolean True if the operation was successful
*
*/
function modify(&$oCampaign)
{
if (!isset($oCampaign->campaignId)) {
// Add
$oCampaign->setDefaultForAdd();
if (!$this->checkPermissions(array(OA_ACCOUNT_ADMIN, OA_ACCOUNT_MANAGER), 'clients', $oCampaign->advertiserId)) {
return false;
}
} else {
// Edit
if (!$this->checkPermissions(array(OA_ACCOUNT_ADMIN, OA_ACCOUNT_MANAGER), 'campaigns', $oCampaign->campaignId)) {
return false;
}
}
$oStartDate = $oCampaign->startDate;
$oEndDate = $oCampaign->endDate;
$campaignData = (array) $oCampaign;
$campaignData['campaignid'] = $oCampaign->campaignId;
$campaignData['campaignname'] = $oCampaign->campaignName;
$campaignData['clientid'] = $oCampaign->advertiserId;
$oNow = new Date();
if (is_object($oStartDate)) {
$oDate = new Date($oStartDate);
$oDate->setTZ($oNow->tz);
$oDate->setHour(0);
$oDate->setMinute(0);
$oDate->setSecond(0);
$oDate->toUTC();
$campaignData['activate_time'] = $oDate->getDate(DATE_FORMAT_ISO);
}
if (is_object($oEndDate)) {
$oDate = new Date($oEndDate);
$oDate->setTZ($oNow->tz);
$oDate->setHour(23);
$oDate->setMinute(59);
$oDate->setSecond(59);
$oDate->toUTC();
$campaignData['expire_time'] = $oDate->getDate(DATE_FORMAT_ISO);
}
$campaignData['views'] = $oCampaign->impressions;
$campaignData['target_impression'] = $oCampaign->targetImpressions;
$campaignData['target_click'] = $oCampaign->targetClicks;
$campaignData['target_conversion'] = $oCampaign->targetConversions;
$campaignData['revenue_type'] = $oCampaign->revenueType;
$campaignData['capping'] = $oCampaign->capping > 0 ? $oCampaign->capping : 0;
$campaignData['session_capping'] = $oCampaign->sessionCapping > 0 ? $oCampaign->sessionCapping : 0;
$campaignData['block'] = $oCampaign->block > 0 ? $oCampaign->block : 0;
$campaignData['viewwindow'] = $oCampaign->viewWindow;
$campaignData['clickwindow'] = $oCampaign->clickWindow;
if ($this->_validate($oCampaign)) {
$doCampaign = OA_Dal::factoryDO('campaigns');
if (!isset($oCampaign->campaignId)) {
$doCampaign->setFrom($campaignData);
$oCampaign->campaignId = $doCampaign->insert();
} else {
$doCampaign->get($campaignData['campaignid']);
$doCampaign->setFrom($campaignData);
$doCampaign->update();
}
return true;
} else {
return false;
}
}
示例10: getDaysLeftString
/**
* A method to determine how long it will be until a campaign "expires".
*
* Returns the earliest possible date from the following values:
* - The campaign's expiration date, if set.
* - The eStimated expiration date based on lifetime impression delivery
* rate, if applicable.
* - The eStimated expiration date based on lifetime click delivery rate
* if applicable.
* - The eStimated expiration date based on lifetime conversion rate,
* if applicable.
*
* Usage:
* $desc = $dalCampaigns->getDaysLeftString($campaignid);
*
* Where:
* $desc is a string to display giving how the expiration was calculated
* eg. "Estimated expiration", or that there is no expiration date
*
* @param integer $campaignId The campaign ID.
* @return string
*/
function getDaysLeftString($campaignId)
{
global $date_format, $strNoExpiration, $strDaysLeft, $strEstimated, $strExpirationDate, $strNoExpirationEstimation, $strDaysAgo, $strCampaignStop;
$prefix = $this->getTablePrefix();
// Define array to store possible expiration date results
$aExpiration = array();
// Get the campaign target info
$now = OA::getNow('Y-m-d');
$doCampaigns = OA_Dal::factoryDO('campaigns');
$doCampaigns->selectAdd("views AS impressions");
$doCampaigns->get($campaignId);
$aCampaignData = $doCampaigns->toArray();
if (!empty($aCampaignData['expire_time'])) {
$oNow = new Date($now);
$oNow->setHour(0);
$oNow->setMinute(0);
$oNow->setSecond(0);
$oDate = new Date($aCampaignData['expire_time']);
$oDate->setTZbyID('UTC');
$oDate->convertTZ($oNow->tz);
$oDate->setHour(0);
$oDate->setMinute(0);
$oDate->setSecond(0);
$oSpan = new Date_Span();
$oSpan->setFromDateDiff($oNow, $oDate);
$aCampaignData['expire_f'] = $oDate->format($date_format);
$aCampaignData['days_left'] = $oSpan->toDays() * ($oDate->before($oNow) ? -1 : 1);
}
$oDbh = OA_DB::singleton();
$tableB = $oDbh->quoteIdentifier($prefix . 'banners', true);
$tableD = $oDbh->quoteIdentifier($prefix . 'data_intermediate_ad', true);
// Define array to return the expiration dates (if they exist)
$aReturn = array('estimatedExpiration' => '', 'campaignExpiration' => '');
// Does the campaign have lifetime impression targets?
// If yes, try to get a stimated expiration date
if ($aCampaignData['impressions'] > 0) {
$query = "\n \t SELECT\n \t SUM(dia.impressions) AS delivered,\n \t DATE_FORMAT(MIN(dia.date_time), '%Y-%m-%d') AS day_of_first\n \t FROM\n \t {$tableD} AS dia,\n \t {$tableB} AS b\n \t WHERE\n \t dia.ad_id = b.bannerid\n \t AND\n \t b.campaignid = " . DBC::makeLiteral($campaignId);
$rsImpressions = DBC::FindRecord($query);
if ($rsImpressions) {
$aImpressions = $rsImpressions->toArray();
// Get the number of days until the campaign will end
// based on the impression target delivery data
$aExpiration = $this->_calculateRemainingDays($aImpressions, $aCampaignData['impressions']);
}
} elseif ($aCampaignData['clicks'] > 0) {
$query = "\n \t SELECT\n \t SUM(dia.clicks) AS delivered,\n \t DATE_FORMAT(MIN(dia.date_time), '%Y-%m-%d') AS day_of_first\n \t FROM\n \t {$tableD} AS dia,\n \t {$tableB} AS b\n \t WHERE\n \t dia.ad_id = b.bannerid\n \t AND\n \t b.campaignid = " . DBC::makeLiteral($campaignId);
$rsClicks = DBC::FindRecord($query);
if ($rsClicks) {
$aClicks = $rsClicks->toArray();
// Get the number of days until the campaign will end
// based on the click target delivery data
$aExpiration = $this->_calculateRemainingDays($aClicks, $aCampaignData['clicks']);
}
} elseif ($aCampaignData['conversions'] > 0) {
$query = "\n \t SELECT\n \t SUM(dia.conversions) AS delivered,\n \t DATE_FORMAT(MIN(dia.date_time), '%Y-%m-%d') AS day_of_first\n \t FROM\n \t {$tableD} AS dia,\n \t {$tableB} AS b\n \t WHERE\n \t dia.ad_id = b.bannerid\n \t AND\n \t b.campaignid = " . DBC::makeLiteral($campaignId);
$rsConversions = DBC::FindRecord($query);
if ($rsConversions) {
$aConversions = $rsConversions->toArray();
// Get the number of days until the campaign will end
// based on the conversion target delivery data
$aExpiration = $this->_calculateRemainingDays($aConversions, $aCampaignData['conversions']);
}
}
// flags to control if the campaign expiration date and
// the estimated expiration date are going to be showed
$existExpirationDate = false;
$showEtimatedDate = false;
// is there a expiration date?
if (!empty($aCampaignData['expire_time'])) {
$existExpirationDate = true;
}
if ($existExpirationDate) {
// has the expiration date been reached?
if ((int) $aCampaignData['days_left'] < 0) {
$aReturn['campaignExpiration'] = $strCampaignStop . ": " . $aCampaignData['expire_f'];
$aReturn['campaignExpiration'] = $aReturn['campaignExpiration'] . " (" . abs((int) round($aCampaignData['days_left'])) . " {$strDaysAgo})";
} else {
$aReturn['campaignExpiration'] = $strExpirationDate . ": " . $aCampaignData['expire_f'];
//.........这里部分代码省略.........
示例11: showTrendData
function showTrendData()
{
global $badgerDb;
global $logger;
$logger->log('statistics::showTrendData: REQUEST_URI: ' . $_SERVER['REQUEST_URI']);
if (!isset($_GET['accounts']) || !isset($_GET['startDate']) || !isset($_GET['endDate'])) {
throw new BadgerException('statistics', 'missingParameter');
}
$accountIds = explode(';', $_GET['accounts']);
foreach ($accountIds as $key => $val) {
settype($accountIds[$key], 'integer');
}
$startDate = new Date($_GET['startDate']);
$endDate = new Date($_GET['endDate']);
$now = new Date();
$now->setHour(0);
$now->setMinute(0);
$now->setSecond(0);
if ($endDate->after($now)) {
$endDate = $now;
}
$accountManager = new AccountManager($badgerDb);
$totals = array();
$accounts = array();
$currentAccountIndex = 0;
foreach ($accountIds as $currentAccountId) {
$currentAccount = $accountManager->getAccountById($currentAccountId);
$accounts[$currentAccountIndex][0] = $currentAccount->getTitle();
$currentBalances = getDailyAmount($currentAccount, $startDate, $endDate);
foreach ($currentBalances as $balanceKey => $balanceVal) {
if (isset($totals[$balanceKey])) {
$totals[$balanceKey]->add($balanceVal);
} else {
$totals[$balanceKey] = $balanceVal;
}
$accounts[$currentAccountIndex][] = $balanceVal->get();
}
$currentAccountIndex++;
}
$numDates = count($totals);
$chart = array();
//for documentation for the following code see: http://www.maani.us/charts/index.php?menu=Reference
$chart['chart_type'] = "line";
$chart['axis_category'] = array('skip' => $numDates / 12, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 100, 'orientation' => "horizontal");
$chart['axis_ticks'] = array('value_ticks' => true, 'category_ticks' => true, 'position' => "centered", 'major_thickness' => 2, 'major_color' => "000000", 'minor_thickness' => 1, 'minor_color' => "000000", 'minor_count' => 4);
$chart['axis_value'] = array('min' => 0, 'max' => 0, 'steps' => 10, 'prefix' => "", 'suffix' => "", 'decimals' => 0, 'decimal_char' => ".", 'separator' => "", 'show_min' => true, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 75, 'orientation' => "horizontal");
$chart['chart_border'] = array('top_thickness' => 1, 'bottom_thickness' => 1, 'left_thickness' => 1, 'right_thickness' => 1, 'color' => "000000");
$chart['chart_pref'] = array('line_thickness' => 1, 'point_shape' => "none", 'fill_shape' => false);
$chart['chart_grid_h'] = array('thickness' => 1, 'color' => "000000", 'alpha' => 15, 'type' => "solid");
$chart['chart_grid_v'] = array('thickness' => 1, 'color' => "000000", 'alpha' => 5, 'type' => "dashed");
$chart['chart_rect'] = array('x' => 50, 'y' => 50, 'width' => 700, 'height' => 300, 'positive_color' => "ffffff", 'negative_color' => "000000", 'positive_alpha' => 100, 'negative_alpha' => 10);
$chart['chart_value'] = array('prefix' => "", 'suffix' => "", 'decimals' => 0, 'decimal_char' => ".", 'separator' => "", 'position' => "cursor", 'hide_zero' => true, 'as_percentage' => false, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 90);
$chart['chart_transition'] = array('type' => "none", 'delay' => 1, 'duration' => 1, 'order' => "all");
$chart['legend_rect'] = array('x' => 50, 'y' => 5, 'width' => 700, 'height' => 5, 'margin' => 5, 'fill_color' => "FFFFFF", 'fill_alpha' => 100, 'line_color' => "000000", 'line_alpha' => 100, 'line_thickness' => 1);
$chart['legend_label'] = array('layout' => "horizontal", 'bullet' => "circle", 'font' => "Arial", 'bold' => false, 'size' => 11, 'color' => "000000", 'alpha' => 90);
$chart['legend_transition'] = array('type' => "none", 'delay' => 1, 'duration' => 1);
$chart['series_color'] = array("FF0000", "00FF00", "0000FF", "FF8000", "404040", "800040");
$chart['chart_data'] = array();
$chart['chart_data'][0][0] = '';
if (count($accounts) > 1) {
$chart['chart_data'][1][0] = getBadgerTranslation2('statistics', 'trendTotal');
} else {
$chart['chart_data'][1][0] = utf8_encode($accounts[0][0]);
}
foreach ($totals as $key => $val) {
$tmp = new Date($key);
$chart['chart_data'][0][] = $tmp->getFormatted();
$chart['chart_data'][1][] = $val->get();
}
if (count($accounts) > 1) {
foreach ($accounts as $val) {
$chart['chart_data'][] = $val;
}
}
SendChartData($chart);
}
示例12: create_conference
function create_conference() {
global $log, $spUser,$_POST,$data;
$msgs = array();
// check the title
if (!$_POST[conference_name] ) {
$msgs[] = "Conference must have a title";
return $msgs ;
}
// validate the date ...
if (($conference_uts = strtotime($_POST[conference_date]))===false ) {
$msgs[] = "Conference date is an Invalid date.";
return $msgs ;
}
list ($m,$d,$y) = split('-',$_POST[conference_date]);
// Make date objects...
$confDate = new Date();
$confDate->setMonth($m);
$confDate->setYear($y);
$confDate->setDay($d);
$confDate->setHour(0);
$confDate->setMinute(0);
$confDate->setSecond(0);
$beginTime = $confDate;
$endTime = $confDate;
list ($beginHour,$beginMinute) = split(':', $_POST[begin_time] );
list ($endHour,$endMinute) = split(':', $_POST[end_time] );
$beginTime->setHour($beginHour);
$beginTime->setMinute($beginMinute);
$endTime->setHour($endHour);
$endTime->setMinute($endMinute);
// see if it's the past
if ($endTime->isPast() ){
$msgs[] = "Conference date is in the Past.";
return $msgs ;
}
// Make sure the end time is not less than the begin time
if (Date::compare($endTime, $beginTime) != 1 ){
$msgs[] = "Start time must be before end time.";
return $msgs ;
}
// create a new Conference object
$conference = new Conference($data->db, $spUser->username,$spUser->domain);
// get the user's company Id and load the companies constraints
$conference->getCompanyId();
$conference->loadConstraints() ;
// set the date objects.
$conference->conferenceDate = $confDate;
$conference->beginTime = $beginTime;
$conference->endTime = $endTime;
$conference->conferenceName = $_POST[conference_name] ;
// Is the conference too long
if (!$conference->isMaxTime()) {
$msgs[] = "Your conference exceeds the maximum amount of minutes.";
return $msgs ;
}
// Are there other conferences scheduled for this time.
if (!$conference->isMaxConcurrent()) {
$msgs[] = "Your company has other conferences scheduled for this time.";
return $msgs ;
}
$error = "nay!";
if ($conference->create($error) ) {
$msgs[] = "Conference created id = " . $conference->conferenceId;
Header("Location: conference.php?msg=Conference created ") ;
} else {
$msgs[] = "Failed to create conference. ";
$msgs[] = "$error";
}
$owner = new Invitee($data->db, $conference->conferenceId);
$owner->domain = $spUser->domain;
$owner->username = $spUser->username;
$owner->companyId = $conference->companyId;
$owner->inviteeEmail = $spUser->dbFields[email_address] ;
$owner->ownerFlag = 1;
$owner->inviteeName = $spUser->dbFields[first_name] . " " . $spUser->dbFields[last_name] ;
// genereate that unique code
$owner->generateInviteeCode();
$owner->create();
$owner->sendNotify();
return $msgs ;
}
示例13: Date
function _midnight($date)
{
$processed_date = new Date($date);
$processed_date->setHour(0);
$processed_date->setMinute(0);
$processed_date->setSecond(0);
return $processed_date;
}
示例14: getAdLifetimeZoneImpressionsRemaining
/**
* A method to obtain the sum of the zone forecast impression value, for all the zones
* an advertisement is linked to, cloned out over the advertisement's entire remaining
* lifetime in the campaign, with any blocked operation intervals removed.
*
* Requires that the getActiveAdOperationIntervals() method have previously been
* called to function correctly.
*
* @param PEAR::Date $oNowDate The current date.
* @param PEAR::Date $oEndDate The end date of the campaign. Note that if the end
* date supplied is not at the end of a day, it will be
* converted to be treated as such.
* @param array $aCumulativeZoneForecast The cumulative forecast impressions, indexed
* by operation interval ID, of all the zones the
* advertisement is linked to.
* array(
* [operation_interval_id] => forecast_impressions,
* [operation_interval_id] => forecast_impressions
* .
* .
* .
* )
* @return integer The ad's total remaining zone impression forecast for all zone for
* the remaining life of the ad.
*/
function getAdLifetimeZoneImpressionsRemaining($oNowDate, $oEndDate, $aCumulativeZoneForecast)
{
$totalAdLifetimeZoneImpressionsRemaining = 0;
// Test the parameters, if invalid, return zero
if (!is_a($oNowDate, 'date') || !is_a($oEndDate, 'date') || !is_array($aCumulativeZoneForecast) || count($aCumulativeZoneForecast) != OX_OperationInterval::operationIntervalsPerWeek()) {
OA::debug(' - Invalid parameters to getAdLifetimeZoneImpressionsRemaining, returning 0', PEAR_LOG_ERR);
return $totalAdLifetimeZoneImpressionsRemaining;
}
// Ensure that the end of campaign date is at the end of the day
$oEndDateCopy = new Date($oEndDate);
$oEndDateCopy->setHour(23);
$oEndDateCopy->setMinute(59);
$oEndDateCopy->setSecond(59);
// Ensure that the $aCumulativeZoneForecast array is sorted by key, so that it can
// be accessed by array_slice, regardless of the order that the forecast data was added
// to the array
ksort($aCumulativeZoneForecast);
// Step 1: Calculate the sum of the forecast values from "now" until the end of "today"
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNowDate);
$oEndOfToday = new Date($aDates['start']);
$oEndOfToday->setTZ($oEndDate->tz);
$oEndOfToday->setHour(23);
$oEndOfToday->setMinute(59);
$oEndOfToday->setSecond(59);
$oStart = $aDates['start'];
while ($oStart->before($oEndOfToday)) {
// Find the Operation Interval ID for this Operation Interval
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oStart);
// As iteration over every OI is required anyway, test to see if
// the ad is blocked in this OI; if not, add the forecast values to the
// running total
if (empty($this->aBlockedOperationIntervalDates[$oStart->format('%Y-%m-%d %H:%M:%S')])) {
$totalAdLifetimeZoneImpressionsRemaining += $aCumulativeZoneForecast[$operationIntervalID];
}
// Go to the next operation interval in "today"
$oStart = OX_OperationInterval::addOperationIntervalTimeSpan($oStart);
}
// Step 2: Calculate how many times each day of the week occurs between the end of
// "today" (i.e. starting "tomorrow morning") and the last day the ad can run
$aDays = array();
$oStartOfTomorrow = new Date($oEndOfToday);
$oStartOfTomorrow->addSeconds(1);
$oTempDate = new Date();
$oTempDate->copy($oStartOfTomorrow);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oTempDate);
while ($aDates['start']->before($oEndDateCopy)) {
// Increase the count for this day of the week
$aDays[$aDates['start']->getDayOfWeek()]++;
// Go to the next day
$oTempDate->addSeconds(SECONDS_PER_DAY);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oTempDate);
}
// Step 3: For every possible day of the week (assuming that day of the week is in the
// ad's remaining lifetime), calculate the sum of the forecast values for every
// operation interval in that day
if (!empty($aDays)) {
$operationIntervalsPerDay = OX_OperationInterval::operationIntervalsPerDay();
$oTempDate = new Date($oStartOfTomorrow);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oTempDate);
for ($counter = 0; $counter < 7; $counter++) {
// Are there any instances of this day in the campaign?
if ($aDays[$oTempDate->getDayOfWeek()] > 0) {
// Calculate the sum of the zone forecasts for this day of week
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oTempDate);
$dayStartOperationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
$aDayCumulativeZoneForecast = array_slice($aCumulativeZoneForecast, $dayStartOperationIntervalId, $operationIntervalsPerDay);
$forecastSum = array_sum($aDayCumulativeZoneForecast);
// Multiply this day's forecast sum value by the number of times this
// day of week appears in the remainder of the campaign and add the
// value to the running total
$totalAdLifetimeZoneImpressionsRemaining += $forecastSum * $aDays[$oTempDate->getDayOfWeek()];
}
// Go to the next day
$oTempDate->addSeconds(SECONDS_PER_DAY);
}
//.........这里部分代码省略.........
示例15: testGetDaysLeftString
//.........这里部分代码省略.........
// Insert conversion delivery data occurring today
$oDate = new Date();
$impressions = 50;
$clicks = 5;
$conversions = 1;
$doDSAH = OA_Dal::factoryDO('data_intermediate_ad');
$doDSAH->day = $oDate->format('%Y-%m-%d');
$doDSAH->hour = 10;
$doDSAH->ad_id = $bannerId;
$doDSAH->impressions = $impressions;
$doDSAH->clicks = $clicks;
$doDSAH->conversions = $conversions;
$dsahId = DataGenerator::generateOne($doDSAH);
// Delivered 50 impressions in 1 day. So, expect to take 19 days to
// deliver remaining 950
// Delivered 5 clicks in 1 day. So, expect to take 99 days to deliver
// remaining 495
// Delivered 1 conversion in 1 day. So, expect to take 9 days to deliver
// remaining 9
// The estimated expiration will be calucalated based on impression targets
// or based on click targets or based on conversion targets (following this order).
$daysLeft = 19;
$oExpirationDate = new Date();
$oExpirationDate->copy($oDate);
$oExpirationDate->addSeconds($daysLeft * SECONDS_PER_DAY);
$expected = array('estimatedExpiration' => $GLOBALS['strEstimated'] . ": " . $oExpirationDate->format('%d.%m.%Y') . " (" . $GLOBALS['strDaysLeft'] . ": " . $daysLeft . ")", 'campaignExpiration' => $GLOBALS['strNoExpiration']);
$actual = $this->oDalCampaigns->getDaysLeftString($campaignId);
$this->assertEqual($actual, $expected);
// Case 3
// Test a campaign with expiration date and without a estimated expiration date
// Prepare a date 10 days in the future
$daysLeft = 10;
$oDate = new Date();
$oDate->setHour(23);
$oDate->setMinute(59);
$oDate->setSecond(59);
$oDate->addSeconds($daysLeft * SECONDS_PER_DAY);
$oDate->toUTC();
// Test an unlimited campaign which expires 10 days in the future
$doCampaigns = OA_Dal::factoryDO('campaigns');
$doCampaigns->views = 0;
$doCampaigns->clicks = 0;
$doCampaigns->conversions = 0;
$doCampaigns->expire_time = $oDate->getDate(DATE_FORMAT_ISO);
$aData = array('reportlastdate' => array('2007-04-03 18:39:45'));
$dg = new DataGenerator();
$dg->setData('clients', $aData);
$aCampaignIds = $dg->generate($doCampaigns, 1, true);
$campaignId = $aCampaignIds[0];
// Link a banner to this campaign
$doBanners = OA_Dal::factoryDO('banners');
$doBanners->campaignid = $campaignId;
$doBanners->acls_updated = '2007-04-03 18:39:45';
$bannerId = DataGenerator::generateOne($doBanners);
$expected = array('estimatedExpiration' => $GLOBALS['strEstimated'] . ": " . $GLOBALS['strNoExpirationEstimation'], 'campaignExpiration' => $GLOBALS['strExpirationDate'] . ": " . $oDate->format('%d.%m.%Y') . " (" . $GLOBALS['strDaysLeft'] . ": " . $daysLeft . ")");
$actual = $this->oDalCampaigns->getDaysLeftString($campaignId);
$this->assertEqual($actual, $expected);
// Case 4
// Campaign with expiration date reached
// Prepare a campaign with expiration date reached
$daysExpired = 5;
$oDate = new Date();
$oDate->setHour(23);
$oDate->setMinute(59);
$oDate->setSecond(59);
$oDate->subtractSeconds($daysExpired * SECONDS_PER_DAY);