Ejemplo n.º 1
0
function MAX_getDatesByPeriodLimitStart($period, $limit, $start)
{
    $begin = $limit + $start - 1;
    $end = $start;
    switch ($period) {
        case 'daily':
            $dayBegin = new Date();
            $dayBegin->subtractSpan(new Date_Span("{$begin}, 0, 0, 0"));
            $dayEnd = new Date();
            $dayBegin->subtractSpan(new Date_Span("{$end}, 0, 0, 0"));
            break;
        case 'weekly':
            $dayBegin = new Date(Date_Calc::prevDay());
            $dayEnd = new Date(Date_Calc::prevDay());
            break;
        case 'monthly':
            $dayBegin = new Date();
            $dayBegin->subtractSpan(new Date_Span('6, 0, 0, 0'));
            $dayEnd = new Date();
            break;
        case 'allstats':
        default:
            $dayBegin = null;
            $dayEnd = null;
    }
    $aDates = array();
    $aDates['day_begin'] = is_object($dayBegin) ? $dayBegin->format('%Y-%m-%d') : '';
    $aDates['day_end'] = is_object($dayEnd) ? $dayEnd->format('%Y-%m-%d') : '';
    return $aDates;
}
Ejemplo n.º 2
0
 function __construct()
 {
     // Check auto-maintenance settings
     $aConf = $GLOBALS['_MAX']['CONF'];
     $this->isAutoMaintenanceEnabled = !empty($aConf['maintenance']['autoMaintenance']);
     // Get time 1 hour ago
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oNow = $oServiceLocator->get('now');
     if ($oNow) {
         $oOneHourAgo = new Date($oNow);
     } else {
         $oOneHourAgo = new Date();
     }
     $oOneHourAgo->subtractSpan(new Date_Span('0-1-0-0'));
     // Get last runs
     $oLastCronRun = OX_Maintenance::getLastScheduledRun();
     $oLastRun = OX_Maintenance::getLastRun();
     // Reset minutes and seconds
     if (isset($oLastCronRun)) {
         $oLastCronRun->setMinute(0);
         $oLastCronRun->setSecond(0);
     }
     if (isset($oLastRun)) {
         $oLastRun->setMinute(0);
         $oLastRun->setSecond(0);
     }
     // Check if any kind of maintenance was run
     if (isset($oLastCronRun) && !$oOneHourAgo->after($oLastCronRun)) {
         $this->isScheduledMaintenanceRunning = true;
     } elseif (isset($oLastRun) && !$oOneHourAgo->after($oLastRun)) {
         $this->isAutoMaintenanceRunning = true;
     }
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 public function getLinks()
 {
     $oDate = new Date($this->oStart);
     $oNow = new Date();
     $aLinks = array();
     $baseUrl = parent::getUrl(false);
     $date = $oDate->format('%Y-%m');
     $aLinks['up'] = array('label' => $date, 'url' => $this->appendToUrl($baseUrl, 'month=' . $date));
     $oDate->subtractSpan(new Date_Span('1-0-0-0'));
     $date = $oDate->format('%Y-%m-%d');
     $aLinks['prev'] = array('label' => '< ' . $date, 'url' => $this->appendToUrl($baseUrl, 'day=' . $date));
     $oDate->addSpan(new Date_Span('2-0-0-0'));
     $date = $oDate->format('%Y-%m-%d');
     $aLinks['next'] = array('label' => $date . ' >');
     if ($oNow->after($oDate)) {
         $aLinks['next']['url'] = $this->appendToUrl($baseUrl, 'day=' . $date);
     }
     return $aLinks;
 }
Ejemplo n.º 5
0
 function _subtractDays($base_date, $days)
 {
     $modified_date = new Date($base_date);
     $span = new Date_Span((string) $days, '%D');
     $modified_date->subtractSpan($span);
     return $modified_date;
 }
 /**
  * A method to generate data for testing.
  *
  * @access private
  */
 function _generateStatsOne()
 {
     $oDate = new Date();
     $oDate->setHour(23);
     $oDate->setMinute(59);
     $oDate->setSecond(59);
     $oDate->addSpan(new Date_Span('4-0-0-0'));
     $expiryDate1 = $oDate->getDate(DATE_FORMAT_ISO);
     $oDate->addSpan(new Date_Span('4-0-0-0'));
     $expiryDate2 = $oDate->getDate(DATE_FORMAT_ISO);
     $oDate->subtractSpan(new Date_Span('2-0-0-0'));
     $expiryDateLessTwoDays = $oDate->getDate(DATE_FORMAT_ISO);
     $doAcls = OA_Dal::factoryDO('acls');
     $doBanners = OA_Dal::factoryDO('banners');
     // default values
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->contenttype = 'gif';
     $doBanners->pluginversion = 0;
     $doBanners->storagetype = 'sql';
     $doBanners->filename = '468x60_4.gif';
     $doBanners->imageurl = '';
     $doBanners->htmltemplate = '';
     $doBanners->htmlcache = '';
     $doBanners->width = 468;
     $doBanners->height = 60;
     $doBanners->weight = 1;
     $doBanners->seq = 0;
     $doBanners->target = '';
     $doBanners->url = 'http://www.example.com';
     $doBanners->alt = 'Campaign Alt Text';
     $doBanners->statustext = '';
     $doBanners->bannertext = '';
     $doBanners->description = '';
     $doBanners->adserver = '';
     $doBanners->block = 0;
     $doBanners->capping = 0;
     $doBanners->session_capping = 0;
     $doBanners->compiledlimitation = '';
     $doBanners->prepend = '';
     $doBanners->append = '';
     $doBanners->bannertype = 0;
     $doBanners->alt_filename = '';
     $doBanners->alt_imageurl = '';
     $doBanners->alt_contenttype = '';
     $clientId = DataGenerator::generateOne('clients', true);
     // Add 3 campaigns - haha!
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->campaignname = 'Test Campaign 1';
     $doCampaigns->clientid = $clientId;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 400;
     $doCampaigns->conversions = 0;
     $doCampaigns->expire_time = $expiryDate1;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->priority = '3';
     $doCampaigns->weight = 1;
     $doCampaigns->target_impression = 0;
     $doCampaigns->anonymous = 'f';
     $doCampaigns->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idCampaign1 = DataGenerator::generateOne($doCampaigns, true);
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->campaignname = 'Test Campaign 2';
     $doCampaigns->clientid = $clientId;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 400;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->priority = '2';
     $doCampaigns->weight = 1;
     $doCampaigns->target_impression = 0;
     $doCampaigns->anonymous = 'f';
     $doCampaigns->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idCampaign2 = DataGenerator::generateOne($doCampaigns, true);
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->campaignname = 'Test Campaign 3';
     $doCampaigns->clientid = $clientId;
     $doCampaigns->views = 500;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 0;
     $doCampaigns->expire = $expiryDate2;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->priority = '3';
     $doCampaigns->weight = 1;
     $doCampaigns->target_impression = 0;
     $doCampaigns->anonymous = 'f';
     $doCampaigns->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idCampaign3 = DataGenerator::generateOne($doCampaigns, true);
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->campaignname = 'Test Campaign 4';
     $doCampaigns->clientid = $clientId;
     $doCampaigns->views = 500;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 401;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->priority = '4';
     $doCampaigns->weight = 2;
     $doCampaigns->target_impression = 0;
     $doCampaigns->anonymous = 'f';
     $doCampaigns->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idCampaign4 = DataGenerator::generateOne($doCampaigns, true);
     $clientId2 = DataGenerator::generateOne('clients', true);
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->campaignname = 'Test Campaign 5';
     $doCampaigns->clientid = $clientId2;
     $doCampaigns->views = 500;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 401;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->priority = '3';
     $doCampaigns->weight = 2;
     $doCampaigns->target_impression = 0;
     $doCampaigns->anonymous = 'f';
     $doCampaigns->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idCampaign5 = DataGenerator::generateOne($doCampaigns);
     // Add 1st banner to campaign 1
     $doBanners->campaignid = $idCampaign1;
     $doBanners->alt = 'Campaign1 - Banner 1';
     $doBanners->acls_updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idBanner1 = DataGenerator::generateOne($doBanners);
     // Banner 1, Campaign 1 - acls delivery restrictions
     $doAcls->bannerid = $idBanner1;
     $doAcls->logical = 'and';
     $doAcls->type = 'Time:Date';
     $doAcls->comparison = '!=';
     $doAcls->data = $expiryDateLessTwoDays;
     $doAcls->executionorder = 0;
     $idAcls1 = DataGenerator::generateOne($doAcls);
     $doAcls->bannerid = $idBanner1;
     $doAcls->logical = 'and';
     $doAcls->type = 'Time:Hour';
     $doAcls->comparison = '!=';
     $doAcls->data = 1;
     $doAcls->executionorder = 1;
     $idAcls2 = DataGenerator::generateOne($doAcls);
     // Add 2nd banner to campaign 1
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $idCampaign1;
     $doBanners->alt = 'Campaign1 - Banner 2';
     $doBanners->acls_updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idBanner2 = DataGenerator::generateOne($doBanners);
     // Banner 2, Campaign 1 - acls delivery restrictions
     $doAcls->bannerid = $idBanner2;
     $doAcls->logical = 'and';
     $doAcls->type = 'Time:Date';
     $doAcls->comparison = '!=';
     $doAcls->data = $expiryDateLessTwoDays;
     $doAcls->executionorder = 0;
     $idAcls3 = DataGenerator::generateOne($doAcls);
     $doAcls->bannerid = $idBanner2;
     $doAcls->logical = 'and';
     $doAcls->type = 'Time:Hour';
     $doAcls->comparison = '!=';
     $doAcls->data = '1,2';
     $doAcls->executionorder = 1;
     $idAcls4 = DataGenerator::generateOne($doAcls);
     // Add 1st banner to campaign 2  ????
     $doBanners->campaignid = $idCampaign2;
     $doBanners->alt = 'Campaign2 - Banner 1';
     $doBanners->acls_updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idBanner3 = DataGenerator::generateOne($doBanners);
     $doBanners->campaignid = $idCampaign2;
     $doBanners->alt = 'Campaign2 - Banner 2';
     $doBanners->acls_updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idBanner4 = DataGenerator::generateOne($doBanners);
     // Banner 1, Campaign 2 - acls delivery restrictions
     $doAcls->bannerid = $idBanner4;
     $doAcls->logical = 'and';
     $doAcls->type = 'Time:Date';
     $doAcls->comparison = '!=';
     $doAcls->data = $expiryDateLessTwoDays;
     $doAcls->executionorder = 0;
     $idAcls5 = DataGenerator::generateOne($doAcls);
     $doAcls->bannerid = $idBanner4;
     $doAcls->logical = 'and';
     $doAcls->type = 'Time:Day';
     $doAcls->comparison = '!=';
     $doAcls->data = '5';
     $doAcls->executionorder = 1;
     $idAcls6 = DataGenerator::generateOne($doAcls);
     // Add 2nd banner to campaign 2
     $doBanners->campaignid = $idCampaign2;
     $doBanners->alt = 'Campaign2 - Banner 3';
     $doBanners->acls_updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idBanner5 = DataGenerator::generateOne($doBanners);
     // Banner 2, Campaign 2 - acls delivery restrictions
     $doAcls->bannerid = $idBanner5;
     $doAcls->logical = 'or';
     $doAcls->type = 'Time:Date';
     $doAcls->comparison = '!=';
     $doAcls->data = $expiryDateLessTwoDays;
     $doAcls->executionorder = 0;
     $idAcls7 = DataGenerator::generateOne($doAcls);
     $doAcls->bannerid = $idBanner5;
     $doAcls->logical = 'or';
     $doAcls->type = 'Time:Day';
     $doAcls->comparison = '==';
     $doAcls->data = '1,2';
     $doAcls->executionorder = 1;
     $idAcls8 = DataGenerator::generateOne($doAcls);
     // Add 1st banner to campaign 3
     $doBanners->campaignid = $idCampaign3;
     $doBanners->alt = 'Campaign3 - Banner 1';
     $doBanners->acls_updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idBanner6 = DataGenerator::generateOne($doBanners);
     // Banner 1, Campaign 3 - acls delivery restrictions
     $doAcls->bannerid = $idBanner6;
     $doAcls->logical = 'and';
     $doAcls->type = 'Time:Date';
     $doAcls->comparison = '!=';
     $doAcls->data = $expiryDateLessTwoDays;
     $doAcls->executionorder = 0;
     $idAcls9 = DataGenerator::generateOne($doAcls);
     $doAcls->bannerid = $idBanner6;
     $doAcls->logical = 'or';
     $doAcls->type = 'Time:Day';
     $doAcls->comparison = '==';
     $doAcls->data = '5';
     $doAcls->executionorder = 1;
     $idAcls10 = DataGenerator::generateOne($doAcls);
     // Add 2nd banner to campaign 3
     $doBanners->campaignid = $idCampaign3;
     $doBanners->alt = 'Campaign3 - Banner 2';
     $doBanners->acls_updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oDate->format('%Y-%m-%d %H:%M:%S');
     $idBanner7 = DataGenerator::generateOne($doBanners);
     // Banner 2, Campaign 3 - acls delivery restrictions
     $doAcls->bannerid = $idBanner7;
     $doAcls->logical = 'or';
     $doAcls->type = 'Time:Date';
     $doAcls->comparison = '!=';
     $doAcls->data = $expiryDateLessTwoDays;
     $doAcls->executionorder = 0;
     $idAcls11 = DataGenerator::generateOne($doAcls);
     $doAcls->bannerid = $idBanner7;
     $doAcls->logical = 'or';
     $doAcls->type = 'Time:Hour';
     $doAcls->comparison = '1=';
     $doAcls->data = '1,2';
     $doAcls->executionorder = 1;
     $idAcls12 = DataGenerator::generateOne($doAcls);
 }
Ejemplo n.º 7
0
 /**
  * Build the internal arrays that contain data about the calculated holidays
  *
  * @access   protected
  * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  * @throws   object PEAR_ErrorStack
  */
 function _buildHolidays()
 {
     /**
      * New Year's Day
      */
     $this->_addHoliday('newYearsDay', $this->_year . '-01-01', 'New Year\'s Day');
     /**
      * Epiphanias
      */
     $this->_addHoliday('epiphany', $this->_year . '-01-06', 'Epiphany');
     /**
      * Easter Sunday
      */
     $easterDate = Date_Holidays_Driver_Sweden::calcEaster($this->_year);
     $this->_addHoliday('easter', $easterDate, 'Easter Sunday');
     /**
      * Good Friday / Black Friday
      */
     $goodFridayDate = new Date($easterDate);
     $goodFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0'));
     $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday');
     /**
      * Easter Monday
      */
     $this->_addHoliday('easterMonday', $easterDate->getNextDay(), 'Easter Monday');
     /**
      * May Day
      */
     $this->_addHoliday('mayDay', $this->_year . '-05-01', 'May Day');
     /**
      * Pentecost (determines Whit Monday, Ascension Day and Feast of Corpus Christi)
      */
     $pentecostDate = new Date($easterDate);
     $pentecostDate->addSpan(new Date_Span('49, 0, 0, 0'));
     $this->_addHoliday('pentecost', $pentecostDate, 'Pentecost');
     /**
      * Ascension Day
      */
     $ascensionDayDate = new Date($pentecostDate);
     $ascensionDayDate->subtractSpan(new Date_Span('10, 0, 0, 0'));
     $this->_addHoliday('ascensionDay', $ascensionDayDate, 'Ascension Day');
     /**
      * Swedish National Day and the Swedish Flag's Day
      */
     $this->_addHoliday('swedenNationalDay', $this->_year . '-06-06', 'Swedish National Day and the Swedish Flag\'s Day');
     /**
      * Midsummer
      * Saturday past 20th, June
      */
     $juneDate = new Date($this->_year . '-06-20');
     $dayOfWeek = $juneDate->getDayOfWeek();
     $juneDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0', 6 - $dayOfWeek)));
     $midSummerDate = $juneDate;
     $this->_addHoliday('midSummer', $midSummerDate, 'Midsummer Day');
     /**
      * Midsummer Eve
      * Day before Midsummer.
      */
     $this->_addHoliday('midSummerEve', $midSummerDate->getPrevDay(), 'Midsummer Eve');
     /**
      * All Saints' Day
      */
     $saintspanDate = new Date($this->_year . '-10-31');
     $dayOfWeek = $saintspanDate->getDayOfWeek();
     $saintspanDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0', 6 - $dayOfWeek)));
     $allSaintsDate = $saintspanDate;
     $this->_addHoliday('allSaintsDay', $allSaintsDate, 'All Saints\' Day');
     /**
      * Christmas Eve
      */
     $this->_addHoliday('xmasEve', $this->_year . '-12-24', 'Christmas Eve');
     /**
      * Christmas day
      */
     $this->_addHoliday('xmasDay', $this->_year . '-12-25', 'Christmas Day');
     /**
      * Boxing day
      */
     $this->_addHoliday('boxingDay', $this->_year . '-12-26', 'Boxing Day');
     /**
      * New Year's Eve
      */
     $this->_addHoliday('newYearsEve', $this->_year . '-12-31', 'New Year\'s Eve');
     if (Date_Holidays::errorsOccurred()) {
         return Date_Holidays::getErrorStack();
     }
     return true;
 }
 /**
  * A method to test the sending of emails from the
  * manageCampaigns() method - tests the sending of
  * the "campaign activated" emails.
  */
 function testManageCampaignsEmailsPlacementActivated()
 {
     // Set now as 1 week before
     $oDateNow = new Date();
     $oDateNow->subtractSpan(new Date_Span('7-0-0-0'));
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oServiceLocator->register('now', $oDateNow);
     // Create the required accounts & set the various ID values
     $aValues = $this->_createAccounts();
     $managerAgencyId = $aValues['managerAgency'];
     // Prepare a single placement that is inactive, and has an old
     // activation date (so that it will need to be activated)
     $aData = array('agencyid' => $managerAgencyId, 'contact' => 'Test Placement Activated Contact', 'email' => '*****@*****.**', 'reportdeactivate' => 't');
     $advertiserId = $this->_insertAdvertiser($aData);
     $oDate = new Date();
     $oDateStart = new Date();
     $oDateStart->copy($oDate);
     $oDateStart->subtractSeconds(SECONDS_PER_HOUR + 1);
     $aData = array('clientid' => $advertiserId, 'status' => OA_ENTITY_STATUS_AWAITING, 'activate_time' => $oDateStart->format('%Y-%m-%d 00:00:00'));
     $campaignId = $this->_insertPlacement($aData);
     // Reset now
     $oServiceLocator->remove('now');
     $aData = array('campaignid' => $campaignId);
     $adId = $this->_insertAd($aData);
     // Create an instance of the mocked OA_Email class, and set
     // expectations on how the class' methods should be called
     // based on the above
     Mock::generate('OA_Email');
     $oEmailMock = new MockOA_Email($this);
     $oEmailMock->expectOnce('sendCampaignActivatedDeactivatedEmail', array("{$campaignId}"));
     // Register the mocked OA_Email class in the service locator
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oServiceLocator->register('OA_Email', $oEmailMock);
     // Run the manageCampaigns() method and ensure that the correct
     // calls to OA_Email were made
     $oDate = new Date();
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatistics = $oFactory->factory();
     $report = $oDalMaintenanceStatistics->manageCampaigns($oDate);
     $oEmailMock->tally();
     // Clean up
     DataGenerator::cleanUp();
 }
Ejemplo n.º 9
0
 /**
  * Build the internal arrays that contain data about the calculated holidays
  *
  * @access   protected
  * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  * @throws   object PEAR_ErrorStack
  */
 function _buildHolidays()
 {
     /**
      * New Year's Day
      */
     $this->_addHoliday('newYearsDay', $this->_year . '-01-01', 'New Year\'s Day');
     /**
      * Easter Sunday
      */
     $easterDate = Date_Holidays_Driver_Norway::calcEaster($this->_year);
     $this->_addHoliday('easter', $easterDate, 'Easter Sunday');
     /**
      * Good Friday / Black Friday
      */
     $goodFridayDate = new Date($easterDate);
     $goodFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0'));
     $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday');
     /**
      * Easter Monday
      */
     $this->_addHoliday('easterMonday', $easterDate->getNextDay(), 'Easter Monday');
     /**
      * May Day
      */
     $this->_addHoliday('mayDay', $this->_year . '-05-01', 'May Day');
     /**
      * Pentecost (determines Whit Monday, Ascension Day and Feast of Corpus Christi)
      */
     $pentecostDate = new Date($easterDate);
     $pentecostDate->addSpan(new Date_Span('49, 0, 0, 0'));
     $this->_addHoliday('pentecost', $pentecostDate, 'Pentecost');
     /**
      * Ascension Day
      */
     $ascensionDayDate = new Date($pentecostDate);
     $ascensionDayDate->subtractSpan(new Date_Span('10, 0, 0, 0'));
     $this->_addHoliday('ascensionDay', $ascensionDayDate, 'Ascension Day');
     /**
      * Norwegian National Day
      */
     $this->_addHoliday('norwayNationalDay', $this->_year . '-05-17', 'Norwegian National Day');
     /**
      * Christmas Eve
      */
     $this->_addHoliday('xmasEve', $this->_year . '-12-24', 'Christmas Eve');
     /**
      * Christmas day
      */
     $this->_addHoliday('xmasDay', $this->_year . '-12-25', 'Christmas Day');
     /**
      * Boxing day
      */
     $this->_addHoliday('boxingDay', $this->_year . '-12-26', 'Boxing Day');
     /**
      * New Year's Eve
      */
     $this->_addHoliday('newYearsEve', $this->_year . '-12-31', 'New Year\'s Eve');
     if (Date_Holidays::errorsOccurred()) {
         return Date_Holidays::getErrorStack();
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * This method returns performance statistics for a given zones.
  *
  * @access public
  *
  * @param array $aZonesIds array of IDs of the zones to view statistics
  * @param int $campaignId The ID of the campaing for which zones statistic are calculated (if null, then global zone statistic are calculated)
  * @param PEAR::Date $oStartDate The date from which to get statistics (inclusive)
  * @param PEAR::Date $oEndDate The date to which to get statistics (inclusive)
  * @param int $impressionsThreshold  Minimum number of impressions needed to calculate performance statistics (eCPM, CR, CTR)
  * @param int $daysIntervalThreshold  Minimum period of time (in days) needed to calculate performance statistics (eCPM, CR, CTR)
  * @return array 
  *   <ul>
  *   <li><b>zone_id integer</b> key The ID of the zone
  *   <li><b>array<b> with statistics
  *      <ul>
  *      <li><b>CTR decimal</b> CTR - Click Through Rate
  *      <li><b>eCPM decimal</b> eCPM - effective cost per mille
  *      <li><b>CR decimal</b> CR - Conversion Rate
  *      </ul>
  *   </li>
  *   </ul>
  */
 function getZonesPerformanceStatistics($aZonesIds, $campaignId = null, $oStartDate = null, $oEndDate = null, $impressionsThreshold = null, $daysIntervalThreshold = null)
 {
     if (!is_array($aZonesIds) || count($aZonesIds) == 0) {
         return array();
     }
     if (is_null($oEndDate)) {
         $oEndDate = new Date();
     }
     if (is_null($oStartDate)) {
         $oStartDate = new Date($oEndDate);
         $oStartDate->subtractSpan(new Date_Span("30, 0, 0, 0"));
         // Set start date to 30 days before end date is start date is null
     }
     // Initial setting of result array
     $aZonesStatistics = array();
     foreach ($aZonesIds as $zoneId) {
         $aZonesStatistics[$zoneId] = array('CTR' => null, 'eCPM' => null, 'CR' => null);
     }
     // If time span for given dates is greater that daysIntervalThreshold there isn't any statistics to calculate
     if ($this->_checkDaysIntervalThreshold($oStartDate, $oEndDate, $daysIntervalThreshold) == false) {
         return $aZonesStatistics;
     }
     // Query DB for all statistics and catch errors if any
     $rsZonesConversionRateStatistics = $this->getZonesConversionRateStatistics($aZonesIds, $oStartDate, $oEndDate, $campaignId, $impressionsThreshold, $daysIntervalThreshold);
     if (PEAR::isError($rsZonesConversionRateStatistics)) {
         return $rsZonesConversionRateStatistics;
     }
     $rsZonesEcpmStatistics = $this->getZonesEcpmStatistics($aZonesIds, $oStartDate, $oEndDate, $campaignId, $impressionsThreshold, $daysIntervalThreshold);
     if (PEAR::isError($rsZonesEcpmStatistics)) {
         return $rsZonesEcpmStatistics;
     }
     $rsZonesCtrStatistics = $this->getZonesCtrStatistics($aZonesIds, $oStartDate, $oEndDate, $campaignId, $impressionsThreshold, $daysIntervalThreshold);
     if (PEAR::isError($rsZonesCtrStatistics)) {
         return $rsZonesCtrStatistics;
     }
     // fill result array with statistics
     $aZonesEcpmStatistics = $rsZonesEcpmStatistics->getAll();
     foreach ($aZonesEcpmStatistics as $aZoneStatistics) {
         if (!is_null($aZoneStatistics['total_revenue']) && !is_null($aZoneStatistics['impressions']) && $aZoneStatistics['impressions'] != 0) {
             $aZonesStatistics[$aZoneStatistics['zone_id']]['eCPM'] = $aZoneStatistics['total_revenue'] * 1000 / $aZoneStatistics['impressions'];
         }
     }
     $aZonesConversionRateStatistics = $rsZonesConversionRateStatistics->getAll();
     foreach ($aZonesConversionRateStatistics as $aZoneStatistics) {
         if (!is_null($aZoneStatistics['conversions']) && !is_null($aZoneStatistics['impressions']) && $aZoneStatistics['impressions'] != 0) {
             $aZonesStatistics[$aZoneStatistics['zone_id']]['CR'] = $aZoneStatistics['conversions'] / $aZoneStatistics['impressions'];
         }
     }
     $aZonesCtrStatistics = $rsZonesCtrStatistics->getAll();
     foreach ($aZonesCtrStatistics as $aZoneStatistics) {
         if (!is_null($aZoneStatistics['clicks']) && !is_null($aZoneStatistics['impressions']) && $aZoneStatistics['impressions'] != 0) {
             $aZonesStatistics[$aZoneStatistics['zone_id']]['CTR'] = $aZoneStatistics['clicks'] / $aZoneStatistics['impressions'];
         }
     }
     return $aZonesStatistics;
 }
Ejemplo n.º 11
0
 /**
  * Prune all entries where the ad_id is for a banner in a High Priority Campaign where:
  * The campaign does not have any booked lifetime target values AND the capaign has an end date AND the end date has been passed AND the campaign is not active.
  *
  */
 function testpruneDataSummaryAdZoneAssocInactiveExpired()
 {
     $oToday = new Date();
     $oToday->setHour(23);
     $oToday->setMinute(59);
     $oToday->setSecond(59);
     $oExpire = new Date($oToday);
     $oExpire->subtractSpan(new Date_Span('10-0-0-0'));
     $today = $oToday->getDate(DATE_FORMAT_ISO);
     $expire = $oExpire->getDate(DATE_FORMAT_ISO);
     $oDal = new OA_Maintenance_Pruning();
     $doDSAZA = OA_Dal::factoryDO('data_summary_ad_zone_assoc');
     // generate 2 summary ad_zone records for an active campaign ad_id
     $doDSAZA->ad_id = $this->idBanner1;
     $aIds = DataGenerator::generate($doDSAZA, 2);
     // generate 7 summary ad_zone records for an inactive campaign ad_id
     $doDSAZA->ad_id = $this->idBanner2;
     $aIds = DataGenerator::generate($doDSAZA, 7);
     // make sure 9 rows in table
     $this->assertEqual($this->_countRowsInDSAZA(), 9);
     // ad_id 1 => campaignid 1 => active, high priority, not expired
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign1);
     $doCampaigns->priority = 5;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->target_impression = 0;
     $doCampaigns->target_click = 0;
     $doCampaigns->target_conversion = 0;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 0;
     $doCampaigns->update();
     // ad_id 2 => campaignid 2 => not active, high priority, expired
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign2);
     $doCampaigns->priority = 5;
     $doCampaigns->status = OA_ENTITY_STATUS_EXPIRED;
     $doCampaigns->target_impression = 0;
     $doCampaigns->target_click = 0;
     $doCampaigns->target_conversion = 0;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 0;
     $doCampaigns->expire_time = $expire;
     $doCampaigns->update();
     $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveExpired();
     // 7 records were deleted
     $this->assertEqual($result, 7);
     // 2 records remain
     $this->assertEqual($this->_countRowsInDSAZA(), 2);
     // ad_id 1 => campaignid 1 => not active, override (low priority)
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign1);
     $doCampaigns->priority = -1;
     $doCampaigns->status = OA_ENTITY_STATUS_EXPIRED;
     $doCampaigns->target_impression = 0;
     $doCampaigns->target_click = 0;
     $doCampaigns->target_conversion = 0;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 0;
     $doCampaigns->expire_time = $expire;
     $doCampaigns->update();
     $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveExpired();
     // 0 records were deleted
     $this->assertEqual($result, 0);
     // 2 records remain
     $this->assertEqual($this->_countRowsInDSAZA(), 2);
     // ad_id 1 => campaignid 1 => not active, high priority, not expired
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign1);
     $doCampaigns->priority = 5;
     $doCampaigns->status = OA_ENTITY_STATUS_EXPIRED;
     $doCampaigns->target_impression = 0;
     $doCampaigns->target_click = 0;
     $doCampaigns->target_conversion = 0;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 0;
     $doCampaigns->expire_time = OX_DATAOBJECT_NULL;
     $doCampaigns->update();
     $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveExpired();
     // 0 records were deleted
     $this->assertEqual($result, 0);
     // 2 records remain
     $this->assertEqual($this->_countRowsInDSAZA(), 2);
     // ad_id 1 => campaignid 1 => not active, high priority, expired
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign1);
     $doCampaigns->priority = 5;
     $doCampaigns->status = OA_ENTITY_STATUS_EXPIRED;
     $doCampaigns->target_impression = 0;
     $doCampaigns->target_click = 0;
     $doCampaigns->target_conversion = 0;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 0;
     $doCampaigns->expire_time = $expire;
     $doCampaigns->update();
     $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveExpired();
     // 2 records were deleted
     $this->assertEqual($result, 2);
     // 0 records remain
     $this->assertEqual($this->_countRowsInDSAZA(), 0);
     // generate 2 summary ad_zone records for an active campaign that expires today
     $doDSAZA->ad_id = 1;
     $aIds = DataGenerator::generate($doDSAZA, 2);
     $this->assertEqual($this->_countRowsInDSAZA(), 2);
     // ad_id 1 => campaignid 1 => active, high priority, expires today
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign1);
     $doCampaigns->priority = 5;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->target_impression = 0;
     $doCampaigns->target_click = 0;
     $doCampaigns->target_conversion = 0;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 0;
     $doCampaigns->expire_time = $today;
     $doCampaigns->update();
     $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveExpired();
     // 0 records were deleted
     $this->assertEqual($result, 0);
     // 2 records remain
     $this->assertEqual($this->_countRowsInDSAZA(), 2);
     // ad_id 1 => campaignid 1 => active, high priority, expired
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign1);
     $doCampaigns->priority = 5;
     $doCampaigns->status = OA_ENTITY_STATUS_EXPIRED;
     $doCampaigns->target_impression = 0;
     $doCampaigns->target_click = 0;
     $doCampaigns->target_conversion = 0;
     $doCampaigns->views = 0;
     $doCampaigns->clicks = 0;
     $doCampaigns->conversions = 0;
     $doCampaigns->expire_time = $expire;
     $doCampaigns->update();
     $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveExpired();
     // 2 records were deleted
     $this->assertEqual($result, 2);
     // 0 records remain
     $this->assertEqual($this->_countRowsInDSAZA(), 0);
 }
Ejemplo n.º 12
0
// | If you did not receive a copy of the new BSDlicense and are unable   |
// | to obtain it through the world-wide-web, please send a note to       |
// | pear-dev@lists.php.net so we can mail you a copy immediately.        |
// +----------------------------------------------------------------------+
// | Author: Leandro Lucarella <*****@*****.**>                           |
// +----------------------------------------------------------------------+
//
// $Id$
//
require_once 'Date.php';
require_once 'Date/Span.php';
$date = new Date();
$tmp = new Date($date);
printf("Actual date: %s\n", $date->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:00:00:05'));
printf("Subtracting 5 seconds: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:00:20:00'));
printf("Subtracting 20 minutes: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:10:00:00'));
printf("Subtracting 10 hours: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('3:00:00:00'));
printf("Subtracting 3 days: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('3:10:20:05'));
printf("Subtracting 3 days, 10 hours, 20 minutes and 5 seconds: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:00:00:05'));
Ejemplo n.º 13
0
 /**
  * Build global statistics array to be sent through Sync
  *
  * @return array
  */
 function buildStats()
 {
     $lastRun = OA_Dal_ApplicationVariables::get('sync_last_run');
     if ($lastRun) {
         $oStart = new Date($lastRun);
     } else {
         $oStart = new Date();
         $oStart->subtractSpan(new Date_Span('1-0-0-0'));
     }
     $oStart->setMinute(0);
     $oStart->setSecond(0);
     $oEnd = new Date();
     $oEnd->setMinute(0);
     $oEnd->setSecond(0);
     $doDsah = OA_Dal::factoryDO('data_summary_ad_hourly');
     $doDsah->selectAdd();
     $doDsah->selectAdd('date_time');
     $doDsah->selectAdd('SUM(impressions) AS total_impressions');
     $doDsah->selectAdd('SUM(clicks) AS total_clicks');
     $doDsah->whereAdd("date_time >= " . $this->oDbh->quote($oStart->format('%Y-%m-%d %H:%M:%S')));
     $doDsah->whereAdd("date_time < " . $this->oDbh->quote($oEnd->format('%Y-%m-%d %H:%M:%S')));
     $doDsah->groupBy('date_time');
     $doDsah->orderBy('date_time');
     $doDsah->find();
     $aStats = array();
     while ($doDsah->fetch()) {
         $row = $doDsah->toArray();
         $aStats[$row['date_time']] = array('impressions' => $row['total_impressions'], 'clicks' => $row['total_clicks']);
     }
     return $aStats;
 }
Ejemplo n.º 14
0
 /**
  * A private method that returns the start and end dates
  * that bound the span, based based on a pre-defined 'friendly'
  * value.
  *
  * See the {@link OA_Admin_DaySpan::setSpanPresetValue()} method
  * for the pre-defined values.
  *
  * @param string $presetValue The preset value string.
  * @return array An array of two elements, "start" and "end",
  *               representing the start and end dates of
  *               the span, respectively.
  */
 function _getSpanDates($presetValue)
 {
     switch ($presetValue) {
         case 'today':
             $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             break;
         case 'yesterday':
             $oDateStart = new Date(Date_Calc::prevDay($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date(Date_Calc::prevDay($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             break;
         case 'this_week':
             $oDateStart = new Date(Date_Calc::beginOfWeek($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oSixDaySpan = new Date_Span();
             $oSixDaySpan->setFromDays(6);
             $oSevenDaySpan = new Date_Span();
             $oSevenDaySpan->setFromDays(7);
             // Now have week start and end when week starts on Sunday
             // Does the user want to start on a different day?
             $beginOfWeek = OA_Admin_DaySpan::getBeginOfWeek();
             if ($beginOfWeek > 0) {
                 $oRequiredDaysSpan = new Date_Span();
                 $oRequiredDaysSpan->setFromDays($beginOfWeek);
                 $oDateStart->addSpan($oRequiredDaysSpan);
                 $oDateToday = new Date($this->oNowDate->format('%Y-%m-%d'));
                 if ($oDateToday->getDayOfWeek() < $beginOfWeek) {
                     $oDateStart->subtractSpan($oSevenDaySpan);
                 }
             }
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             break;
         case 'last_week':
             $oDateStart = new Date(Date_Calc::beginOfPrevWeek($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oSixDaySpan = new Date_Span();
             $oSixDaySpan->setFromDays(6);
             $oSevenDaySpan = new Date_Span();
             $oSevenDaySpan->setFromDays(7);
             // Now have week start and end when week starts on Sunday
             // Does the user want to start on a different day?
             $beginOfWeek = OA_Admin_DaySpan::getBeginOfWeek();
             if ($beginOfWeek > 0) {
                 $oRequiredDaysSpan = new Date_Span();
                 $oRequiredDaysSpan->setFromDays($beginOfWeek);
                 $oDateStart->addSpan($oRequiredDaysSpan);
                 $oDateToday = new Date($this->oNowDate->format('%Y-%m-%d'));
                 if ($oDateToday->getDayOfWeek() < $beginOfWeek) {
                     $oDateStart->subtractSpan($oSevenDaySpan);
                 }
             }
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oDateEnd->copy($oDateStart);
             $oDateEnd->addSpan($oSixDaySpan);
             break;
         case 'last_7_days':
             $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oOneDaySpan = new Date_Span();
             $oOneDaySpan->setFromDays(1);
             $oSevenDaySpan = new Date_Span();
             $oSevenDaySpan->setFromDays(7);
             $oDateStart->subtractSpan($oSevenDaySpan);
             $oDateEnd->subtractSpan($oOneDaySpan);
             break;
         case 'this_month':
             $oDateStart = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             break;
         case 'this_month_full':
             $oDateStart = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oOneDaySpan = new Date_Span();
             $oOneDaySpan->setFromDays(1);
             $oDateEnd->subtractSpan($oOneDaySpan);
             break;
         case 'this_month_remainder':
             $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oDateEnd = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oOneDaySpan = new Date_Span();
             $oOneDaySpan->setFromDays(1);
             $oDateEnd->subtractSpan($oOneDaySpan);
             break;
         case 'next_month':
             $oDateStart = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date(Date_Calc::endOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             break;
         case 'last_month':
             $oDateStart = new Date(Date_Calc::beginOfPrevMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oOneDaySpan = new Date_Span();
             $oOneDaySpan->setFromDays(1);
             $oDateEnd->subtractSpan($oOneDaySpan);
             break;
         case 'all_stats':
             $oDateStart = null;
             $oDateEnd = null;
             break;
         case 'specific':
             $startDate = MAX_getStoredValue('startDate', date('Y-m-d'));
             $oDateStart = new Date($startDate);
             $endDate = MAX_getStoredValue('endDate', date('Y-m-d'));
             $oDateEnd = new Date($endDate);
             break;
     }
     $this->_setStartDate($oDateStart);
     $this->_setEndDate($oDateEnd);
     $aDates = array('start' => $oDateStart, 'end' => $oDateEnd);
     return $aDates;
 }
Ejemplo n.º 15
0
 function convertStartEndDate(&$oStartDate, &$oEndDate, $oTimezone)
 {
     if (isset($oStartDate)) {
         $oStartTz = new Date($oStartDate);
         $oStartTz->convertTZ($oTimezone);
         $oStartTz->setHour(0);
         $oStartTz->setMinute(0);
         $oStartTz->setSecond(0);
         if ($oStartTz->after($oStartDate)) {
             $oStartTz->subtractSpan(new Date_Span('1-0-0-0'));
         }
     } else {
         $oStartTz = null;
     }
     if (!isset($oEndDate)) {
         $oEndDate = new Date();
     }
     $oEndTz = new Date($oEndDate);
     $oEndTz->convertTZ($oTimezone);
     $oEndTz->setHour(0);
     $oEndTz->setMinute(0);
     $oEndTz->setSecond(0);
     $oEndTz->subtractSeconds(1);
     if ($oEndTz->after($oEndDate)) {
         $oEndTz->subtractSpan(new Date_Span('1-0-0-0'));
     }
     $oStartDate = $oStartTz;
     $oEndDate = $oEndTz;
 }
Ejemplo n.º 16
0
 function test_getAuditLogForAuditWidget()
 {
     $dllAuditPartialMock = new PartialMockOA_Dll_Audit($this);
     $oSpanDay = new Date_Span('1-0-0-0');
     $oDate = new Date(OA::getNow());
     $oDate->toUTC();
     $oDate->subtractSpan(new Date_Span('8-0-0-0'));
     // add 1 hour to make sure that the test passes even if it takes some time
     $oDate->addSpan(new Date_Span('0-1-0-0'));
     // record 1 - more than 7 days old so should not be returned
     $oAudit = OA_Dal::factoryDO('audit');
     $oAudit->account_id = 1;
     $oAudit->context = 'campaigns';
     $oAudit->contextid = 1;
     $oAudit->parentid = null;
     $oAudit->username = '******';
     $oAudit->actionid = OA_AUDIT_ACTION_UPDATE;
     $oAudit->updated = $oDate->getDate();
     $aDetails['campaignname'] = 'Campaign 1';
     $aDetails['status'] = OA_ENTITY_STATUS_EXPIRED;
     $oAudit->details = serialize($aDetails);
     $oAudit->insert();
     // record 2
     $oDate->addSpan($oSpanDay);
     $oAudit->updated = $oDate->getDate();
     $oAudit->username = '******';
     $aDetails['status'] = OA_ENTITY_STATUS_RUNNING;
     $oAudit->details = serialize($aDetails);
     $idAudit = $oAudit->insert();
     $aExpect[$idAudit] = $oAudit->toArray();
     $aExpect[$idAudit]['details'] = $aDetails;
     // record 3
     $oDate->addSpan($oSpanDay);
     $oAudit->updated = $oDate->getDate();
     $oAudit->username = '******';
     $aDetails['status'] = OA_ENTITY_STATUS_PAUSED;
     $oAudit->details = serialize($aDetails);
     $idAudit = $oAudit->insert();
     $aExpect[$idAudit] = $oAudit->toArray();
     $aExpect[$idAudit]['details'] = $aDetails;
     // record 4
     $oDate->addSpan($oSpanDay);
     $oAudit->contextid = 2;
     $oAudit->updated = $oDate->getDate();
     $aDetails['campaignname'] = 'Campaign 2';
     $aDetails['status'] = OA_ENTITY_STATUS_RUNNING;
     $oAudit->details = serialize($aDetails);
     $idAudit = $oAudit->insert();
     $aExpect[$idAudit] = $oAudit->toArray();
     $aExpect[$idAudit]['details'] = $aDetails;
     // record 5
     $oDate->addSpan($oSpanDay);
     $oAudit->updated = $oDate->getDate();
     $oAudit->username = '******';
     $aDetails['status'] = OA_ENTITY_STATUS_EXPIRED;
     $oAudit->details = serialize($aDetails);
     $idAudit = $oAudit->insert();
     $aExpect[$idAudit] = $oAudit->toArray();
     $aExpect[$idAudit]['details'] = $aDetails;
     // record 6
     $oDate->addSpan($oSpanDay);
     $oAudit->account_id = 2;
     $oAudit->contextid = 3;
     $oAudit->username = '******';
     $oAudit->updated = $oDate->getDate();
     $aDetails['campaignname'] = 'Campaign 3';
     $aDetails['status'] = OA_ENTITY_STATUS_RUNNING;
     $oAudit->details = serialize($aDetails);
     $idAudit = $oAudit->insert();
     $aExpect[$idAudit] = $oAudit->toArray();
     $aExpect[$idAudit]['details'] = $aDetails;
     // record 7 - is a maintenance audit rec so should not be returned
     $oDate->addSpan($oSpanDay);
     $oAudit->username = '******';
     $oAudit->contextid = 1;
     $oAudit->updated = $oDate->getDate();
     $aDetails['campaignname'] = 'Campaign 1';
     $aDetails['status'] = OA_ENTITY_STATUS_RUNNING;
     $oAudit->details = serialize($aDetails);
     $oAudit->insert();
     $aParams = array();
     $aResults = $dllAuditPartialMock->getAuditLogForAuditWidget($aParams);
     $this->assertIsA($aResults, 'array');
     $this->assertEqual(count($aResults), 5);
     foreach ($aResults as $i => $aResRow) {
         $aExpRow = $aExpect[$aResRow['auditid']];
         $this->assertEqual($aResRow['auditid'], $aExpRow['auditid']);
         $this->assertEqual($aResRow['actionid'], $aExpRow['actionid']);
         $this->assertEqual($aResRow['context'], $dllAuditPartialMock->getContextDescription($aExpRow['context']));
         $this->assertEqual($aResRow['contextid'], $aExpRow['contextid']);
         $this->assertEqual($aResRow['parentid'], $aExpRow['parentid']);
         $this->assertEqual($aResRow['username'], $aExpRow['username']);
         $this->assertEqual($aResRow['details']['campaignname'], $aExpRow['details']['campaignname']);
         $this->assertEqual($aResRow['details']['status'], $aExpRow['details']['status']);
         $oDate = new Date($aResRow['updated']);
         $oDate->toUTC();
         $this->assertEqual($oDate->getDate(), $aExpRow['updated']);
     }
     // Check that the account_id filter is working
     $aParams = array('account_id' => 2);
     $aResults = $dllAuditPartialMock->getAuditLogForAuditWidget($aParams);
     $this->assertIsA($aResults, 'array');
     $this->assertEqual(count($aResults), 1);
 }
Ejemplo n.º 17
0
 /**
  * Build the internal arrays that contain data about the calculated holidays
  *
  * @access   protected
  * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  * @throws   object PEAR_ErrorStack
  */
 function _buildHolidays()
 {
     parent::_buildHolidays();
     $easterDate = $this->getHolidayDate('easter');
     $ashWednesdayDate = $this->getHolidayDate('ashWednesday');
     $ascensionDayDate = $this->getHolidayDate('ascensionDay');
     $advent1Date = $this->getHolidayDate('advent1');
     /**
      * New Year's Day
      */
     $this->_addHoliday('newYearsDay', $this->_year . '-01-01', 'New Year\'s Day');
     /**
      * Valentine's Day
      */
     $this->_addHoliday('valentinesDay', $this->_year . '-02-14', 'Valentine\'s Day');
     /**
      * "Weiberfastnacht"
      */
     $wFasnetDate = new Date($ashWednesdayDate);
     $wFasnetDate->subtractSpan(new Date_Span('6, 0, 0, 0'));
     $this->_addHoliday('womenFasnet', $wFasnetDate, 'Carnival');
     /**
      * Carnival / "Fastnacht"
      */
     $fasnetDate = new Date($easterDate);
     $fasnetDate->subtractSpan(new Date_Span('47, 0, 0, 0'));
     $this->_addHoliday('fasnet', $fasnetDate, 'Carnival');
     /**
      * Rose Monday
      */
     $roseMondayDate = new Date($easterDate);
     $roseMondayDate->subtractSpan(new Date_Span('48, 0, 0, 0'));
     $this->_addHoliday('roseMonday', $roseMondayDate, 'Rose Monday');
     /**
      * International Women's Day
      */
     $this->_addHoliday('womensDay', $this->_year . '-03-08', 'International Women\'s Day');
     /**
      * April 1st
      */
     $this->_addHoliday('april1st', $this->_year . '-04-01', 'April 1st');
     /**
      * Girls' Day (fourth Thursday in April)
      */
     $girlsDayDate = new Date($this->_year . '-04-01');
     $dayOfWeek = $girlsDayDate->getDayOfWeek();
     switch ($dayOfWeek) {
         case 0:
         case 1:
         case 2:
         case 3:
             $span = new Date_Span(sprintf('%d, 0, 0, 0', 4 - $dayOfWeek + 21));
             break;
         case 4:
             $span = new Date_Span('21, 0, 0, 0');
             break;
         case 5:
         case 6:
             $span = new Date_Span(sprintf('%d, 0, 0, 0', -1 * $dayOfWeek + 11 + 21));
             break;
     }
     $girlsDayDate->addSpan($span);
     $this->_addHoliday('girlsDay', $girlsDayDate, 'Girls\' Day');
     /**
      * International Earth' Day
      */
     $this->_addHoliday('earthDay', $this->_year . '-04-22', 'International Earth\' Day');
     /**
      * German Beer's Day
      */
     $this->_addHoliday('beersDay', $this->_year . '-04-23', 'German Beer\'s Day');
     /**
      * Walpurgis Night
      */
     $this->_addHoliday('walpurgisNight', $this->_year . '-04-30', 'Walpurgis Night');
     /**
      * Day of Work
      */
     $this->_addHoliday('dayOfWork', $this->_year . '-05-01', 'Day of Work');
     /**
      * World's Laughing Day
      */
     $laughingDayDate = new Date($this->_year . '-05-01');
     while ($laughingDayDate->getDayOfWeek() != 0) {
         $laughingDayDate = $laughingDayDate->getNextDay();
     }
     $this->_addHoliday('laughingDay', $laughingDayDate, 'World\'s Laughing Day');
     /**
      * Europe Day
      */
     $this->_addHoliday('europeDay', $this->_year . '-05-05', 'Europe Day');
     /**
      * Mothers' Day
      */
     $mothersDay = new Date($laughingDayDate);
     $mothersDay->addSpan(new Date_Span('7, 0, 0, 0'));
     $this->_addHoliday('mothersDay', $mothersDay, 'Mothers\' Day');
     /**
      * End of World War 2 in Germany
      */
     $this->_addHoliday('endOfWWar2', $this->_year . '-05-08', 'End of World War 2 in Germany');
     /**
      * Fathers' Day
      */
     $this->_addHoliday('fathersDay', $ascensionDayDate, 'Fathers\' Day');
     /**
      * Amnesty International Day
      */
     $this->_addHoliday('aiDay', $this->_year . '-05-28', 'Amnesty International Day');
     /**
      * International Children' Day
      */
     $this->_addHoliday('intChildrenDay', $this->_year . '-06-01', 'International Children\'s Day');
     /**
      * Day of organ donation
      */
     $organDonationDate = new Date($this->_year . '-06-01');
     while ($organDonationDate->getDayOfWeek() != 6) {
         $organDonationDate = $organDonationDate->getNextDay();
     }
     $this->_addHoliday('organDonationDay', $organDonationDate, 'Day of organ donation');
     /**
      * Dormouse' Day
      */
     $this->_addHoliday('dormouseDay', $this->_year . '-06-27', 'Dormouse\' Day');
     /**
      * Christopher Street Day
      */
     $this->_addHoliday('christopherStreetDay', $this->_year . '-06-27', 'Christopher Street Day');
     /**
      * Hiroshima Commemoration Day
      */
     $this->_addHoliday('hiroshimaCommemorationDay', $this->_year . '-08-06', 'Hiroshima Commemoration Day');
     /**
      * Augsburg peace celebration
      */
     $this->_addHoliday('augsburgPeaceCelebration', $this->_year . '-08-08', 'Augsburg peace celebration');
     /**
      * International left-handeds' Day
      */
     $this->_addHoliday('leftHandedDay', $this->_year . '-08-13', 'International left-handeds\' Day');
     /**
      * Anti-War Day
      */
     $this->_addHoliday('antiWarDay', $this->_year . '-09-01', 'Anti-War Day');
     /**
      * Day of German Language
      */
     $germanLangDayDate = new Date($this->_year . '-09-01');
     while ($germanLangDayDate->getDayOfWeek() != 6) {
         $germanLangDayDate = $germanLangDayDate->getNextDay();
     }
     $germanLangDayDate->addSpan(new Date_Span('7, 0, 0, 0'));
     $this->_addHoliday('germanLanguageDay', $germanLangDayDate, 'Day of German Language');
     /**
      * International diabetes day
      */
     $this->_addHoliday('diabetesDay', $this->_year . '-11-14', 'International diabetes day');
     /**
      * German Unification Day
      */
     $this->_addHoliday('germanUnificationDay', $this->_year . '-10-03', 'German Unification Day');
     /**
      * Libraries' Day
      */
     $this->_addHoliday('librariesDay', $this->_year . '-10-24', 'Libraries\' Day');
     /**
      * World's Savings Day
      */
     $this->_addHoliday('savingsDay', $this->_year . '-10-30', 'World\'s Savings Day');
     /**
      * Halloween
      */
     $this->_addHoliday('halloween', $this->_year . '-10-31', 'Halloween');
     /**
      * Stamp's Day
      * 
      * year <= 1948: 7th of January
      * year > 1948: last Sunday in October
      */
     $stampsDayDate = null;
     if ($this->_year <= 1948) {
         $stampsDayDate = new Date($this->_year . '-01-07');
         while ($stampsDayDate->getDayOfWeek() != 0) {
             $stampsDayDate = $stampsDayDate->getNextDay();
         }
     } else {
         $stampsDayDate = new Date($this->_year . '-10-31');
         while ($stampsDayDate->getDayOfWeek() != 0) {
             $stampsDayDate = $stampsDayDate->getPrevDay();
         }
     }
     $this->_addHoliday('stampsDay', $stampsDayDate, 'Stamp\'s Day');
     /**
      * International Men's Day
      */
     $this->_addHoliday('mensDay', $this->_year . '-11-03', 'International Men\'s Day');
     /**
      * Fall of the Wall of Berlin
      */
     $this->_addHoliday('wallOfBerlin', $this->_year . '-11-09', 'Fall of the Wall of Berlin 1989');
     /**
      * Beginning of the Carnival
      */
     $this->_addHoliday('carnivalBeginning', $this->_year . '-11-11', 'Beginning of the Carnival');
     /**
      * People's Day of Mourning
      */
     $dayOfMourning = $advent1Date;
     $dayOfMourning->subtractSpan(new Date_Span('14, 0, 0, 0'));
     $this->_addHoliday('dayOfMourning', $dayOfMourning, 'People\'s Day of Mourning');
     if (Date_Holidays::errorsOccurred()) {
         return Date_Holidays::getErrorStack();
     }
     return true;
 }
Ejemplo n.º 18
0
 /**
  * Build the internal arrays that contain data about the calculated holidays
  *
  * @access   protected
  * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  * @throws   object PEAR_ErrorStack
  */
 function _buildHolidays()
 {
     /**
      * Circumcision of Jesus
      */
     $this->_addHoliday('jesusCircumcision', $this->_year . '-01-01', 'Circumcision of Jesus');
     /**
      * Epiphanias
      */
     $this->_addHoliday('epiphany', $this->_year . '-01-06', 'Epiphany');
     /**
      * Cleaning of Mariä 
      */
     $this->_addHoliday('mariaCleaning', $this->_year . '-02-02', 'Cleaning of Maria');
     /**
      * Josef's Day
      */
     $this->_addHoliday('josefsDay', $this->_year . '-03-19', 'Josef\'s Day');
     /**
      * Maria Announcement
      */
     $this->_addHoliday('mariaAnnouncement', $this->_year . '-03-25', 'Maria Announcement');
     /**
      * Easter Sunday
      */
     $easterDate = Date_Holidays_Driver_Christian::calcEaster($this->_year);
     $this->_addHoliday('easter', $easterDate, 'Easter Sunday');
     /**
      * Palm Sunday
      */
     $palmSundayDate = new Date($easterDate);
     $palmSundayDate->subtractSpan(new Date_Span('7, 0, 0, 0'));
     $this->_addHoliday('palmSunday', $palmSundayDate, 'Palm Sunday');
     /**
      * Passion Sunday
      */
     $passionSundayDate = new Date($palmSundayDate);
     $passionSundayDate->subtractSpan(new Date_Span('7, 0, 0, 0'));
     $this->_addHoliday('passionSunday', $passionSundayDate, 'Passion Sunday');
     /**
      * Painful Friday
      */
     $painfulFridayDate = new Date($palmSundayDate);
     $painfulFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0'));
     $this->_addHoliday('painfulFriday', $painfulFridayDate, 'Painful Friday');
     /**
      * White Sunday
      */
     $whiteSundayDate = new Date($easterDate);
     $whiteSundayDate->addSpan(new Date_Span('7, 0, 0, 0'));
     $this->_addHoliday('whiteSunday', $whiteSundayDate, 'White Sunday');
     /**
      * Ash Wednesday
      */
     $ashWednesdayDate = new Date($easterDate);
     $ashWednesdayDate->subtractSpan(new Date_Span('46, 0, 0, 0'));
     $this->_addHoliday('ashWednesday', $ashWednesdayDate, 'Ash Wednesday');
     /**
      * Good Friday / Black Friday
      */
     $goodFridayDate = new Date($easterDate);
     $goodFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0'));
     $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday');
     /**
      * Green Thursday
      */
     $this->_addHoliday('greenThursday', $goodFridayDate->getPrevDay(), 'Green Thursday');
     /**
      * Easter Monday
      */
     $this->_addHoliday('easterMonday', $easterDate->getNextDay(), 'Easter Monday');
     /**
      * Whitsun (determines Whit Monday, Ascension Day and Feast of Corpus Christi)
      */
     $whitsunDate = new Date($easterDate);
     $whitsunDate->addSpan(new Date_Span('49, 0, 0, 0'));
     $this->_addHoliday('whitsun', $whitsunDate, 'Whitsun');
     /**
      * Request Sunday
      */
     $requestSunday = new Date($whitsunDate);
     $requestSunday->subtractSpan(new Date_Span('14, 0, 0, 0'));
     $this->_addHoliday('requestSunday', $requestSunday, 'Request Sunday');
     /**
      * Ascension Day
      */
     $ascensionDayDate = new Date($whitsunDate);
     $ascensionDayDate->subtractSpan(new Date_Span('10, 0, 0, 0'));
     $this->_addHoliday('ascensionDay', $ascensionDayDate, 'Ascension Day');
     /**
      * Whit Monday
      */
     $this->_addHoliday('whitMonday', $whitsunDate->getNextDay(), 'Whit Monday');
     /**
      * Haunting of Mariä 
      */
     $this->_addHoliday('mariaHaunting', $this->_year . '-05-31', 'Haunting of Maria');
     /**
      * Trinitatis
      */
     $trinitatisDate = new Date($whitsunDate);
     $trinitatisDate->addSpan(new Date_Span('7, 0, 0, 0'));
     $this->_addHoliday('trinitatis', $trinitatisDate, 'Trinitatis');
     /**
      * Feast of Corpus Christi
      */
     $corpusChristiDate = new Date($whitsunDate);
     $corpusChristiDate->addSpan(new Date_Span('11, 0, 0, 0'));
     $this->_addHoliday('corpusChristi', $corpusChristiDate, 'Feast of Corpus Christi');
     /**
      * Heart of Jesus 
      *
      * Friday of the 3rd week past Whitsun
      */
     $heartJesusDate = new Date($whitsunDate);
     $heartJesusDate->addSpan(new Date_Span('19, 0, 0, 0'));
     $this->_addHoliday('heartJesus', $heartJesusDate, 'Heart of Jesus celebration');
     /**
      * Johannis celebration
      */
     $this->_addHoliday('johannisCelebration', $this->_year . '-06-24', 'Johannis celebration');
     /**
      * Petrus and Paulus
      */
     $this->_addHoliday('petrusAndPaulus', $this->_year . '-06-29', 'Petrus and Paulus');
     /**
      * Ascension of Maria
      */
     $this->_addHoliday('mariaAscension', $this->_year . '-08-15', 'Ascension of Maria');
     /**
      * Celebration of raising the Cross
      */
     $this->_addHoliday('crossRaising', $this->_year . '-09-14', 'Celebration of raising the Cross');
     /**
      * Thanks Giving
      * 
      * Sunday past Michaelis (29. September)
      */
     $michaelisDate = new Date($this->_year . '-09-29');
     $dayOfWeek = $michaelisDate->getDayOfWeek();
     $michaelisDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0', 7 - $dayOfWeek)));
     $thanksGivingDate = $michaelisDate;
     $this->_addHoliday('thanksGiving', $thanksGivingDate, 'Thanks Giving');
     /**
      * Kermis
      *
      * 3rd Sunday in October
      */
     $kermisDate = new Date($this->_year . '-10-01');
     $dayOfWeek = $kermisDate->getDayOfWeek();
     if ($dayOfWeek != 0) {
         $kermisDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0', 7 - $dayOfWeek)));
     }
     $kermisDate->addSpan(new Date_Span('14, 0, 0, 0'));
     $this->_addHoliday('kermis', $kermisDate, 'Kermis');
     /**
      * Reformation Day
      */
     $this->_addHoliday('reformationDay', $this->_year . '-10-31', 'Reformation Day');
     /**
      * All Saints' Day
      */
     $this->_addHoliday('allSaintsDay', $this->_year . '-11-01', 'All Saints\' Day');
     /**
      * All Souls' Day
      */
     $this->_addHoliday('allSoulsDay', $this->_year . '-11-02', 'All Souls\' Day');
     /**
      * Martin's Day
      */
     $this->_addHoliday('martinsDay', $this->_year . '-11-11', 'Martin\'s Day');
     /**
      * 4th Advent
      */
     $Advent4Date = new Date($this->_year . '-12-24');
     $dayOfWeek = $Advent4Date->getDayOfWeek();
     if ($dayOfWeek == 0) {
         $dayOfWeek = 7;
     }
     $Advent4Date->subtractSpan(new Date_Span(sprintf('%d, 0, 0, 0', $dayOfWeek)));
     $this->_addHoliday('advent4', $Advent4Date, '4th Advent');
     /**
      * 1st Advent
      */
     $Advent1Date = new Date($Advent4Date);
     $Advent1Date->subtractSpan(new Date_Span('21, 0, 0, 0'));
     $this->_addHoliday('advent1', $Advent1Date, '1st Advent');
     /**
      * 2nd Advent
      */
     $Advent2Date = new Date($Advent4Date);
     $Advent2Date->subtractSpan(new Date_Span('14, 0, 0, 0'));
     $this->_addHoliday('advent2', $Advent2Date, '2nd Advent');
     /**
      * 3rd Advent
      */
     $Advent3Date = new Date($Advent4Date);
     $Advent3Date->subtractSpan(new Date_Span('7, 0, 0, 0'));
     $this->_addHoliday('advent3', $Advent3Date, '3rd Advent');
     /**
      * Death' Sunday
      */
     $deathSundayDate = new Date($Advent1Date);
     $deathSundayDate->subtractSpan(new Date_Span('7, 0, 0, 0'));
     $this->_addHoliday('deathSunday', $deathSundayDate, 'Death\' Sunday');
     /**
      * Day of Repentance
      */
     $dayOfRepentance = new Date($deathSundayDate);
     $dayOfRepentance->subtractSpan(new Date_Span('4, 0, 0, 0'));
     $this->_addHoliday('dayOfRepentance', $dayOfRepentance, 'Day of Repentance');
     /**
      * St. Nicholas' Day
      */
     $this->_addHoliday('stNicholasDay', $this->_year . '-12-06', 'St. Nicholas\' Day');
     /**
      * Maria' conception
      */
     $this->_addHoliday('mariaConception', $this->_year . '-12-08', 'Conception of Maria');
     /**
      * Christmas Eve
      */
     $this->_addHoliday('xmasEve', $this->_year . '-12-24', 'Christmas Eve');
     /**
      * Christmas day
      */
     $this->_addHoliday('xmasDay', $this->_year . '-12-25', 'Christmas Day');
     /**
      * Boxing day
      */
     $this->_addHoliday('boxingDay', $this->_year . '-12-26', 'Boxing Day');
     /**
      * New Year's Eve
      */
     $this->_addHoliday('newYearsEve', $this->_year . '-12-31', 'New Year\'s Eve');
     if (Date_Holidays::errorsOccurred()) {
         return Date_Holidays::getErrorStack();
     }
     return true;
 }
Ejemplo n.º 19
0
 /**
  * requires permission checks
  *
  * @param array $aParam
  * @return array
  */
 function getAuditLogForAuditWidget($aParam = array())
 {
     $oAudit = OA_Dal::factoryDO('audit');
     // Apply account level filters
     if (!empty($aParam['account_id'])) {
         $oAudit->account_id = $aParam['account_id'];
     }
     if (!empty($aParam['advertiser_account_id'])) {
         $oAudit->advertiser_account_id = $aParam['advertiser_account_id'];
     }
     if (!empty($aParam['website_account_id'])) {
         $oAudit->website_account_id = $aParam['website_account_id'];
     }
     $oDate = new Date();
     $oDate->toUTC();
     $oDate->subtractSpan(new Date_Span('7-0-0-0'));
     $oAudit->whereAdd("username <> 'Maintenance'");
     $oAudit->whereAdd('parentid IS NULL');
     $oAudit->whereAdd("updated >= " . DBC::makeLiteral($oDate->format('%Y-%m-%d %H:%M:%S')));
     $oAudit->orderBy('auditid DESC');
     $oAudit->limit(0, 5);
     $numRows = $oAudit->find();
     $oNow = new Date();
     $aResult = array();
     while ($oAudit->fetch()) {
         $aAudit = $oAudit->toArray();
         $oDate = new Date($aAudit['updated']);
         $oDate->setTZbyID('UTC');
         $oDate->convertTZ($oNow->tz);
         $aAudit['updated'] = $oDate->format('%Y-%m-%d %H:%M:%S');
         $aAudit['details'] = unserialize($aAudit['details']);
         $aAudit['context'] = $this->getContextDescription($aAudit['context']);
         $aResult[] = $aAudit;
     }
     return $aResult;
 }