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;
 }
 /**
  * A method to activate/deactivate campaigns, based on the date and/or the inventory
  * requirements (impressions, clicks and/or conversions). Also sends email reports
  * for any campaigns that are activated/deactivated, as well as sending email reports
  * for any campaigns that are likely to expire in the near future.
  *
  * @param Date $oDate The current date/time.
  * @return string Report on the campaigns activated/deactivated.
  */
 function manageCampaigns($oDate)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oEmail =& $oServiceLocator->get('OA_Email');
     if ($oEmail === false) {
         $oEmail = new OA_Email();
         $oServiceLocator->register('OA_Email', $oEmail);
     }
     $report = "\n";
     // Select all campaigns in the system, where:
     //    The campaign is ACTIVE and:
     //    - The end date stored for the campaign is not null; or
     //    - The campaign has a lifetime impression, click or conversion
     //      target set.
     //
     //    That is:
     //    - It is possible for the active campaign to be automatically
     //      stopped, as it has a valid end date. (No limitations are
     //      applied to those campaigns tested, as the ME may not have
     //      run for a while, and if so, even campaigns with an end date
     //      of many, many weeks ago should be tested to ensure they are
     //      [belatedly] halted.)
     //    - It is possible for the active campaign to be automatically
     //      stopped, as it has at leaast one lifetime target that could
     //      have been reached.
     //
     //    The campaign is INACTIVE and:
     //    - The start date stored for the campaign is not null; and
     //    - The weight is greater than zero; and
     //    - The end date stored for the campaign is either null, or is
     //      greater than "today" less one day.
     //
     //    That is:
     //    - It is possible for the inactive campaign to be automatically
     //      started, as it has a valid start date. (No limitations are
     //      applied to those campaigns tested, as the ME may not have run
     //      for a while, and if so, even campaigns with an activation date
     //      of many, many weeks ago should be tested to ensure they are
     //      [belatedy] enabled.)
     //    - The campaign is not in a permanently inactive state, as a
     //      result of the weight being less then one, which means that
     //      it cannot be activated.
     //    - The test to start the campaign is unlikely to fail on account
     //      of the end date.
     $prefix = $this->getTablePrefix();
     $oNowDate = new Date($oDate);
     $oNowDate->toUTC();
     $query = "\n            SELECT\n                cl.clientid AS advertiser_id,\n                cl.account_id AS advertiser_account_id,\n                cl.agencyid AS agency_id,\n                cl.contact AS contact,\n                cl.email AS email,\n                cl.reportdeactivate AS send_activate_deactivate_email,\n                ca.campaignid AS campaign_id,\n                ca.campaignname AS campaign_name,\n                ca.views AS targetimpressions,\n                ca.clicks AS targetclicks,\n                ca.conversions AS targetconversions,\n                ca.status AS status,\n                ca.activate_time AS start,\n                ca.expire_time AS end\n            FROM\n                {$prefix}campaigns AS ca,\n                {$prefix}clients AS cl\n            WHERE\n                ca.clientid = cl.clientid\n                AND\n                ((\n                    ca.status = " . $this->oDbh->quote(OA_ENTITY_STATUS_RUNNING, 'integer') . " AND\n                    (\n                        ca.expire_time IS NOT NULL\n                        OR\n                        (\n                            ca.views > 0\n                            OR\n                            ca.clicks > 0\n                            OR\n                            ca.conversions > 0\n                        )\n                    )\n                ) OR (\n                    ca.status = " . $this->oDbh->quote(OA_ENTITY_STATUS_AWAITING, 'integer') . " AND\n                    (\n                        ca.activate_time <= " . $this->oDbh->quote($oNowDate->getDate(DATE_FORMAT_ISO), 'timestamp') . "\n                        AND\n                        (\n                            ca.weight > 0\n                            OR\n                            ca.priority > 0\n                        )\n                        AND\n                        (\n                            ca.expire_time >= " . $this->oDbh->quote($oNowDate->getDate(DATE_FORMAT_ISO), 'timestamp') . "\n                            OR\n                            ca.expire_time IS NULL\n                        )\n                    )\n                ))\n            ORDER BY\n                advertiser_id";
     OA::debug('- Requesting campaigns to test for activation/deactivation', PEAR_LOG_DEBUG);
     $rsResult = $this->oDbh->query($query);
     if (PEAR::isError($rsResult)) {
         return MAX::raiseError($rsResult, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
     }
     OA::debug('- Found ' . $rsResult->numRows() . ' campaigns to test for activation/deactivation', PEAR_LOG_DEBUG);
     while ($aCampaign = $rsResult->fetchRow()) {
         if ($aCampaign['status'] == OA_ENTITY_STATUS_RUNNING) {
             // The campaign is currently running, look at the campaign
             $disableReason = 0;
             $canExpireSoon = false;
             if ($aCampaign['targetimpressions'] > 0 || $aCampaign['targetclicks'] > 0 || $aCampaign['targetconversions'] > 0) {
                 OA::debug('  - Selecting impressions, clicks and conversions for this running campaign ID = ' . $aCampaign['campaign_id'], PEAR_LOG_DEBUG);
                 // The campaign has an impression, click and/or conversion target,
                 // so get the sum total statistics for the campaign
                 $query = "\n                        SELECT\n                            SUM(dia.impressions) AS impressions,\n                            SUM(dia.clicks) AS clicks,\n                            SUM(dia.conversions) AS conversions\n                        FROM\n                            " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_intermediate_ad'], true) . " AS dia,\n                            " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['banners'], true) . " AS b\n                        WHERE\n                            dia.ad_id = b.bannerid\n                            AND b.campaignid = {$aCampaign['campaign_id']}";
                 $rsResultInner = $this->oDbh->query($query);
                 $valuesRow = $rsResultInner->fetchRow();
                 if (isset($valuesRow['impressions']) || !is_null($valuesRow['clicks']) || !is_null($valuesRow['conversions'])) {
                     // There were impressions, clicks and/or conversions for this
                     // campaign, so find out if campaign targets have been passed
                     if (!isset($valuesRow['impressions'])) {
                         // No impressions
                         $valuesRow['impressions'] = 0;
                     }
                     if (!isset($valuesRow['clicks'])) {
                         // No clicks
                         $valuesRow['clicks'] = 0;
                     }
                     if (!isset($valuesRow['conversions'])) {
                         // No conversions
                         $valuesRow['conversions'] = 0;
                     }
                     if ($aCampaign['targetimpressions'] > 0) {
                         if ($aCampaign['targetimpressions'] <= $valuesRow['impressions']) {
                             // The campaign has an impressions target, and this has been
                             // passed, so update and disable the campaign
                             $disableReason |= OX_CAMPAIGN_DISABLED_IMPRESSIONS;
                         }
                     }
                     if ($aCampaign['targetclicks'] > 0) {
                         if ($aCampaign['targetclicks'] <= $valuesRow['clicks']) {
                             // The campaign has a click target, and this has been
                             // passed, so update and disable the campaign
                             $disableReason |= OX_CAMPAIGN_DISABLED_CLICKS;
                         }
                     }
                     if ($aCampaign['targetconversions'] > 0) {
                         if ($aCampaign['targetconversions'] <= $valuesRow['conversions']) {
                             // The campaign has a target limitation, and this has been
                             // passed, so update and disable the campaign
                             $disableReason |= OX_CAMPAIGN_DISABLED_CONVERSIONS;
                         }
                     }
                     if ($disableReason) {
                         // One of the campaign targets was exceeded, so disable
                         $message = '  - Exceeded a campaign quota: Deactivating campaign ID ' . "{$aCampaign['campaign_id']}: {$aCampaign['campaign_name']}";
                         OA::debug($message, PEAR_LOG_INFO);
                         $report .= $message . "\n";
                         $doCampaigns = OA_Dal::factoryDO('campaigns');
                         $doCampaigns->campaignid = $aCampaign['campaign_id'];
                         $doCampaigns->find();
                         $doCampaigns->fetch();
                         $doCampaigns->status = OA_ENTITY_STATUS_EXPIRED;
                         $result = $doCampaigns->update();
                         if ($result == false) {
                             return MAX::raiseError($rows, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
                         }
                         phpAds_userlogSetUser(phpAds_userMaintenance);
                         phpAds_userlogAdd(phpAds_actionDeactiveCampaign, $aCampaign['campaign_id']);
                     } else {
                         // The campaign didn't have a diable reason,
                         // it *might* possibly be diabled "soon"...
                         $canExpireSoon = true;
                     }
                 }
             }
             // Does the campaign need to be disabled due to the date?
             if (!empty($aCampaign['end'])) {
                 // The campaign has a valid end date, stored in in UTC
                 $oEndDate = new Date($aCampaign['end']);
                 $oEndDate->setTZByID('UTC');
                 if ($oDate->after($oEndDate)) {
                     // The end date has been passed; disable the campaign
                     $disableReason |= OX_CAMPAIGN_DISABLED_DATE;
                     $message = "  - Passed campaign end time of '" . $oEndDate->getDate() . " UTC" . "': Deactivating campaign ID {$aCampaign['campaign_id']}: {$aCampaign['campaign_name']}";
                     OA::debug($message, PEAR_LOG_INFO);
                     $report .= $message . "\n";
                     $doCampaigns = OA_Dal::factoryDO('campaigns');
                     $doCampaigns->campaignid = $aCampaign['campaign_id'];
                     $doCampaigns->find();
                     $doCampaigns->fetch();
                     $doCampaigns->status = OA_ENTITY_STATUS_EXPIRED;
                     $result = $doCampaigns->update();
                     if ($result == false) {
                         return MAX::raiseError($rows, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
                     }
                     phpAds_userlogSetUser(phpAds_userMaintenance);
                     phpAds_userlogAdd(phpAds_actionDeactiveCampaign, $aCampaign['campaign_id']);
                 } else {
                     // The campaign wasn't disabled based on the end
                     // date, to it *might* possibly be disabled "soon"...
                     $canExpireSoon = true;
                 }
             }
             if ($disableReason) {
                 // The campaign was disabled, so send the appropriate
                 // message to the campaign's contact
                 $query = "\n                        SELECT\n                            bannerid AS advertisement_id,\n                            description AS description,\n                            alt AS alt,\n                            url AS url\n                        FROM\n                            " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['banners'], true) . "\n                        WHERE\n                            campaignid = {$aCampaign['campaign_id']}";
                 OA::debug("  - Getting the advertisements for campaign ID {$aCampaign['campaign_id']}", PEAR_LOG_DEBUG);
                 $rsResultAdvertisement = $this->oDbh->query($query);
                 if (PEAR::isError($rsResultAdvertisement)) {
                     return MAX::raiseError($rsResultAdvertisement, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
                 }
                 while ($advertisementRow = $rsResultAdvertisement->fetchRow()) {
                     $advertisements[$advertisementRow['advertisement_id']] = array($advertisementRow['description'], $advertisementRow['alt'], $advertisementRow['url']);
                 }
                 if ($aCampaign['send_activate_deactivate_email'] == 't') {
                     OA::debug("  - Sending campaign deactivated email ", PEAR_LOG_DEBUG);
                     $oEmail->sendCampaignActivatedDeactivatedEmail($aCampaign['campaign_id'], $disableReason);
                     // Also send campaignDeliveryEmail for the campaign we just deactivated.
                     $doClients = OA_Dal::staticGetDO('clients', $aCampaign['advertiser_id']);
                     $aAdvertiser = $doClients->toArray();
                     OA::debug("  - Sending campaign delivery email ", PEAR_LOG_DEBUG);
                     $oStart = new Date($aAdvertiser['reportlastdate']);
                     $oEnd = new Date($oDate);
                     // Set end date to tomorrow so we get stats for today.
                     $oEnd->addSpan(new Date_Span('1-0-0-0'));
                     $oEmail->sendCampaignDeliveryEmail($aAdvertiser, $oStart, $oEnd, $aCampaign['campaign_id']);
                 }
             } else {
                 if ($canExpireSoon) {
                     // The campaign has NOT been deactivated - test to see if it will
                     // be deactivated "soon", and send email(s) warning of this as required
                     OA::debug("  - Sending campaign 'soon deactivated' email ", PEAR_LOG_DEBUG);
                     $oEmail->sendCampaignImpendingExpiryEmail($oDate, $aCampaign['campaign_id']);
                 }
             }
         } elseif (!empty($aCampaign['start'])) {
             // The campaign is awaiting activation and has a valid start date, stored in UTC
             $oStartDate = new Date($aCampaign['start']);
             $oStartDate->setTZByID('UTC');
             // Find out if there are any impression, click or conversion targets for
             // the campaign (i.e. if the target values are > 0)
             $remainingImpressions = 0;
             $remainingClicks = 0;
             $remainingConversions = 0;
             if ($aCampaign['targetimpressions'] > 0 || $aCampaign['targetclicks'] > 0 || $aCampaign['targetconversions'] > 0) {
                 OA::debug("  - The campaign ID " . $aCampaign['campaign_id'] . " has an impression, click and/or conversion target, requesting impressions so far", PEAR_LOG_DEBUG);
                 $query = "\n                        SELECT\n                            SUM(dia.impressions) AS impressions,\n                            SUM(dia.clicks) AS clicks,\n                            SUM(dia.conversions) AS conversions\n                        FROM\n                            " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_intermediate_ad'], true) . " AS dia,\n                            " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['banners'], true) . " AS b\n                        WHERE\n                            dia.ad_id = b.bannerid\n                            AND b.campaignid = {$aCampaign['campaign_id']}";
                 $rsResultInner = $this->oDbh->query($query);
                 $valuesRow = $rsResultInner->fetchRow();
                 // Set the remaining impressions, clicks and conversions for the campaign
                 $remainingImpressions = $aCampaign['targetimpressions'] - $valuesRow['impressions'];
                 $remainingClicks = $aCampaign['targetclicks'] - $valuesRow['clicks'];
                 $remainingConversions = $aCampaign['targetconversions'] - $valuesRow['conversions'];
             }
             // In order for the campaign to be activated, need to test:
             // 1) That there is no impression target (<= 0), or, if there is an impression target (> 0),
             //    then there must be remaining impressions to deliver (> 0); and
             // 2) That there is no click target (<= 0), or, if there is a click target (> 0),
             //    then there must be remaining clicks to deliver (> 0); and
             // 3) That there is no conversion target (<= 0), or, if there is a conversion target (> 0),
             //    then there must be remaining conversions to deliver (> 0)
             if (($aCampaign['targetimpressions'] <= 0 || $aCampaign['targetimpressions'] > 0 && $remainingImpressions > 0) && ($aCampaign['targetclicks'] <= 0 || $aCampaign['targetclicks'] > 0 && $remainingClicks > 0) && ($aCampaign['targetconversions'] <= 0 || $aCampaign['targetconversions'] > 0 && $remainingConversions > 0)) {
                 $message = "- Passed campaign start time of '" . $oStartDate->getDate() . " UTC" . "': Activating campaign ID {$aCampaign['campaign_id']}: {$aCampaign['campaign_name']}";
                 OA::debug($message, PEAR_LOG_INFO);
                 $report .= $message . "\n";
                 $doCampaigns = OA_Dal::factoryDO('campaigns');
                 $doCampaigns->campaignid = $aCampaign['campaign_id'];
                 $doCampaigns->find();
                 $doCampaigns->fetch();
                 $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
                 $result = $doCampaigns->update();
                 if ($result == false) {
                     return MAX::raiseError($rows, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
                 }
                 phpAds_userlogSetUser(phpAds_userMaintenance);
                 phpAds_userlogAdd(phpAds_actionActiveCampaign, $aCampaign['campaign_id']);
                 if ($aCampaign['send_activate_deactivate_email'] == 't') {
                     OA::debug("  - Sending activation email for campaign ID " . $aCampaign['campaign_id'], PEAR_LOG_DEBUG);
                     $oEmail->sendCampaignActivatedDeactivatedEmail($aCampaign['campaign_id']);
                 }
             }
         }
     }
 }
Beispiel #3
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;
 }
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'));
printf("Adding 5 seconds: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:00:20:00'));
printf("Adding 20 minutes: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:10:00:00'));
printf("Adding 10 hours: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('3:00:00:00'));
printf("Adding 3 days: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('3:10:20:05'));
printf("Adding 3 days, 10 hours, 20 minutes and 5 seconds: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
 /**
  * A method to calculate the range of dates that a statistics screen needs to display.
  *
  * Returns an array of values where:
  *
  *  - If "week" or "day" is the breakdown, array is of days, indexed by "YYYY-MM-DD",
  *    and formatted using the user's local format for days.
  *
  *  - If "month" is the breakdown, array is of months, indexed by "YYYY-MM",
  *    and formatted using the user's local format for months and days.
  *
  *  - If "dow" is the breakdown, array is of days of the week, indexed by the integers
  *    0 to 6, and formatted with the user's local weekday names.
  *
  *  - If "hour" is the breakdown, array is of hours of the day, indexed by the integers
  *    0 to 23, and formatted in the format "00:00 - 00:59", "01:00 01:59", etc.
  *
  * @param array      $aDates          An array of the start and end dates in use by the day
  *                                    span selector element, if set.
  * @param string     $breakdown       The breakdown type in use. One of "week", "day", "month",
  *                                    "dow" or "hour".
  * @param PEAR::Date $oStatsStartDate A date object representing the first day of statistics
  *                                    that are available.
  * @return array The array, as described above.
  */
 function getDatesArray($aDates, $breakdown, $oStatsStartDate)
 {
     // Does the day span selector element have dates set?
     if ($aDates['day_begin'] && $aDates['day_end'] || $aDates['period_start'] && $aDates['period_end']) {
         if ($aDates['day_begin'] && $aDates['day_end']) {
             // Use the dates given by the day span selector element
             $oStartDate = new Date($aDates['day_begin']);
             $oEndDate = new Date($aDates['day_end']);
         } else {
             // Use the dates given by the period_start and period_end
             $oStartDate = new Date($aDates['period_start']);
             $oEndDate = new Date($aDates['period_end']);
         }
         // Adjust end date to be now, if it's in the future
         if ($oEndDate->isFuture()) {
             $oEndDate = new Date();
             $aDates['day_end'] = new Date();
             $aDates['day_end'] = $aDates['day_end']->format('%Y-%m-%d');
         }
     } else {
         // Use the dates given by the statistics date limitation
         // and now
         $oStartDate = new Date();
         $oStartDate->copy($oStatsStartDate);
         $oEndDate = new Date();
     }
     // Prepare the return array
     $aDatesResult = array();
     switch ($breakdown) {
         case 'week':
         case 'day':
             $oOneDaySpan = new Date_Span('1', '%d');
             $oEndDate->addSpan($oOneDaySpan);
             $oDate = new Date();
             $oDate->copy($oStartDate);
             while ($oDate->before($oEndDate)) {
                 $aDatesResult[$oDate->format('%Y-%m-%d')] = $oDate->format($GLOBALS['date_format']);
                 $oDate->addSpan($oOneDaySpan);
             }
             break;
         case 'month':
             $oOneMonthSpan = new Date_Span((string) ($oEndDate->getDaysInMonth() - $oEndDate->getDay() + 1), '%d');
             $oEndDate->addSpan($oOneMonthSpan);
             $oDate = new Date();
             $oDate->copy($oStartDate);
             while ($oDate->before($oEndDate)) {
                 $aDatesResult[$oDate->format('%Y-%m')] = $oDate->format($GLOBALS['month_format']);
                 $oOneMonthSpan = new Date_Span((string) ($oDate->getDaysInMonth() - $oDate->getDay() + 1), '%d');
                 $oDate->addSpan($oOneMonthSpan);
             }
             break;
         case 'dow':
             for ($dow = 0; $dow < 7; $dow++) {
                 $aDatesResult[$dow] = $GLOBALS['strDayFullNames'][$dow];
             }
             break;
         case 'hour':
             for ($hour = 0; $hour < 24; $hour++) {
                 $aDatesResult[$hour] = sprintf('%02d:00 - %02d:59', $hour, $hour);
             }
             break;
     }
     return $aDatesResult;
 }
Beispiel #6
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;
 }
Beispiel #7
0
 /**
  * A private method to caclucate the number of days left until a
  * campaign expires based on the impression, click or conversion
  * delivery targets & the delivery rate of the campaign to date.
  *
  * @param array $aDeliveryData An array of two items. "delivered":
  *                             the number of impressions, clicks or
  *                             conversions delivered so far; and
  *                             "day_of_first": a string in YYYY-MM-DD
  *                             format representing the day that the
  *                             first impression, click or conversion
  *                             was delivered.
  * @param integer $target      The total number of impressions, clicks
  *                             or conversions required to be delivered
  *                             by the campaign.
  * @return array An array of three items. "daysLeft": the estimated
  *               number of days remaining until the campaign ends;
  *               "date": the estimated date of expiration; and "date_f"
  */
 function _calculateRemainingDays($aDeliveryData, $target)
 {
     global $date_format;
     $oNowDate = new Date();
     $aExpiration = array();
     // How many days since the first impression/click/conversion?
     if (!empty($aDeliveryData['day_of_first'])) {
         $oFirstDate = new Date($aDeliveryData['day_of_first']);
         $oSpan = new Date_Span();
         $oSpan->setFromDateDiff($oFirstDate, $oNowDate);
         $daysSinceFirst = ceil($oSpan->toDays());
     } else {
         $daysSinceFirst = 1;
     }
     // Have *any* impressions/clicks/conversions been delivered?
     if (!empty($aDeliveryData["delivered"]) && $aDeliveryData["delivered"] > 0) {
         $targetRemaining = $target - $aDeliveryData["delivered"];
         $deliveryRate = $aDeliveryData["delivered"] / $daysSinceFirst;
         $daysLeft = (int) round($targetRemaining / $deliveryRate);
         $oSpan = new Date_Span();
         $oSpan->setFromDays($daysLeft);
         $oEstimatedEndDate = new Date();
         $oEstimatedEndDate->addSpan($oSpan);
         if ($oEstimatedEndDate->before($oNowDate)) {
             // Ooop! Wrapped into the past - get the biggest possible date
             $oEstimatedEndDate = new Date('1960-01-01 00:00:00');
             $oEstimatedEndDate->subtractSeconds(1);
         }
         $estimatedEndDateFormat = $oEstimatedEndDate->format($date_format);
         $aExpiration = array('daysLeft' => $daysLeft, 'date_f' => $estimatedEndDateFormat, 'date' => $oEstimatedEndDate);
     }
     return $aExpiration;
 }
 /**
  * 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);
 }
Beispiel #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()
 {
     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;
 }
 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);
 }
Beispiel #11
0
 /**
  * Gets a log of audit events
  *
  * @param array $aParam An optional associative array containing various parameters to
  *                      filter the audit trail results. Possible keys / values are:
  *
  *                  - account_id                Filter the results by manager account ID.
  *                  - advertiser_account_id     Filter the results by advertiser account ID.
  *                  - website_account_id        Filter the results by website account ID.
  *
  *                  - start_date & end_date     Only display results between dates, in
  *                                              "YYYY-MM-DD" string formats.
  *
  *                  - advertiser_id             Filter the results by advertiser ID.
  *                  - campaign_id               Also filter the results by campaign ID;
  *                                              requires advertiser_id to be set.
  *
  *                  - publisher_id              Filter the results by publisher ID.
  *                  - zone_id                   Also filter the results by zone ID;
  *                                              requires publisher_id to be set.
  *
  *                      NOTE: The advertiser and publisher filtering types cannot be
  *                              combined, if they are, the advertiser filters will
  *                              be used.
  *
  *
  *
  *                  - order                     Set to "down" to have in descending order.
  *                  - listorder                 The audit trail column to order by.
  *
  *                  - startRecord               Record to begin paging?
  *                  - perPage                   Number of items displayed per page?
  *
  * @return array An associative array containing the audit events for the specified parameters
  */
 function getAuditLog($aParam = null)
 {
     // Prepare the audit trail table DB_DataObject
     $doAudit = OA_Dal::factoryDO('audit');
     // Are there any parameters?
     if (!empty($aParam) && is_array($aParam)) {
         // Check for, and apply, as required, any filters to ensure
         // that the results displayed are those that the current
         // account has access to
         if (!empty($aParam['account_id'])) {
             $where = "account_id = {}";
             $doAudit->account_id = $aParam['account_id'];
         }
         if (!empty($aParam['advertiser_account_id'])) {
             $doAudit->advertiser_account_id = $aParam['advertiser_account_id'];
         }
         if (!empty($aParam['website_account_id'])) {
             $doAudit->website_account_id = $aParam['website_account_id'];
         }
         // Check for, and apply, as required, any filters to ensure
         // that the results displayed are those in the desired date range
         if (!empty($aParam['start_date']) && !empty($aParam['end_date'])) {
             $oStartDate = new Date($aParam['start_date']);
             $oStartDate->toUTC();
             $oEndDate = new Date($aParam['end_date']);
             $oEndDate->addSpan(new Date_Span('1-0-0-0'));
             $oEndDate->toUTC();
             $doAudit->whereAdd('updated >= ' . DBC::makeLiteral($oStartDate->format('%Y-%m-%d %H:%M:%S')));
             $doAudit->whereAdd('updated < ' . DBC::makeLiteral($oEndDate->format('%Y-%m-%d %H:%M:%S')));
         }
         // Check for, and apply, as required, any filters to ensure
         // that the results displayed are those in the desired advertiser ID;
         // OR, check for, and apply, as required, and filters to ensure
         // that the results displayed are those in the desired publisher ID.
         if (!empty($aParam['advertiser_id']) && is_numeric($aParam['advertiser_id']) && $aParam['advertiser_id'] > 0) {
             $aWhere = array();
             $campaignIdSet = true;
             // Also check for, and apply, as required and filters to
             // ensure that the results displayed are ALSO for the
             // desired campaign ID
             if (empty($aParam['campaign_id']) || !is_numeric($aParam['campaign_id']) || $aParam['campaign_id'] <= 0) {
                 // The campaign ID is not set, so filtering by advertiser ID only
                 //  - Unset the fact that the campaign ID is set; and
                 //  - Add the where clause to include advertiser ID level events
                 $campaignIdSet = false;
                 $aWhere[] = "(context = 'clients' AND contextid = " . $doAudit->quote($aParam['advertiser_id']) . ")";
             }
             // Add the where clause to include campaign level events
             $aCampaignIds = array();
             // Find all campaigns in the advertiser
             $doCampaigns = OA_Dal::factoryDO('campaigns');
             $doCampaigns->clientid = $aParam['advertiser_id'];
             if ($campaignIdSet) {
                 // Also limit to the set campaign ID
                 $doCampaigns->campaignid = $aParam['campaign_id'];
             }
             $doCampaigns->find();
             if ($doCampaigns->getRowCount() > 0) {
                 while ($doCampaigns->fetch()) {
                     // Add the campaign ID to the list of campaigns in the advertiser
                     $aCampaignIds[] = $doAudit->quote($doCampaigns->campaignid);
                 }
             }
             if (!empty($aCampaignIds)) {
                 $aWhere[] = "(context = 'campaigns' AND contextid IN (" . implode(',', $aCampaignIds) . "))";
             }
             // Add the where clause to include banner level events
             $aBannerIds = array();
             // Find all banners in the advertiser's campaigns
             if (!empty($aCampaignIds)) {
                 $doBanners = OA_Dal::factoryDO('banners');
                 $doBanners->whereAdd('campaignid IN (' . implode(',', $aCampaignIds) . ')');
                 $doBanners->find();
                 if ($doBanners->getRowCount() > 0) {
                     while ($doBanners->fetch()) {
                         $aBannerIds[] = $doAudit->quote($doBanners->bannerid);
                     }
                 }
                 if (!empty($aBannerIds)) {
                     $aWhere[] = "(context = 'banners' AND contextid IN (" . implode(',', $aBannerIds) . "))";
                 }
             }
             // Combine and add above filters
             if (!empty($aWhere)) {
                 $where = '(' . implode(' OR ', $aWhere) . ')';
                 $doAudit->whereAdd($where);
             }
         } else {
             if (!empty($aParam['publisher_id']) && is_numeric($aParam['publisher_id']) && $aParam['publisher_id'] > 0) {
                 $aWhere = array();
                 $zoneIdSet = true;
                 // Also check for, and apply, as required and filters to
                 // ensure that the results displayed are ALSO for the
                 // desired zone ID
                 if (empty($aParam['zone_id']) || !is_numeric($aParam['zone_id']) || $aParam['zone_id'] <= 0) {
                     // The zone ID is not set, so filtering by publisher ID only
                     //  - Unset the fact that the zone ID is set; and
                     //  - Add the where clause to include publisher ID level events
                     $zoneIdSet = false;
                     $aWhere[] = "(context = 'affiliates' AND contextid = " . $doAudit->quote($aParam['publisher_id']) . ")";
                 }
                 // Add the where clause to include zone level events
                 $aZoneIds = array();
                 // Find all zones in the publisher
                 $doZones = OA_Dal::factoryDO('zones');
                 $doZones->affiliateid = $aParam['publisher_id'];
                 if ($zoneIdSet) {
                     // Also limit to the set zone ID
                     $doZones->zone_id = $aParam['zone_id'];
                 }
                 $doZones->find();
                 if ($doZones->getRowCount() > 0) {
                     while ($doZones->fetch()) {
                         // Add the zone ID to the list of zones in the publisher
                         $aZoneIds[] = $doAudit->quote($doZones->zoneid);
                     }
                 }
                 if (!empty($aZoneIds)) {
                     $aWhere[] = "(context = 'zones' AND contextid IN (" . implode(',', $aZoneIds) . "))";
                 }
                 // Combine and add above filters
                 if (!empty($aWhere)) {
                     $where = '(' . implode(' OR ', $aWhere) . ')';
                     $doAudit->whereAdd($where);
                 }
             }
         }
         //  Make sure that items that are children are not displayed
         $doAudit->whereAdd('parentid IS NULL');
         if ($aParam['order']) {
             if ($aParam['order'] == 'down') {
                 $doAudit->orderBy($aParam['listorder'] . ' ASC');
             } else {
                 $doAudit->orderBy($aParam['listorder'] . ' DESC');
             }
         }
         if ((!empty($aParam['startRecord']) || $aParam['startRecord'] >= 0) && $aParam['perPage']) {
             $doAudit->limit($aParam['startRecord'], $aParam['perPage']);
         } else {
             $doAudit->limit(0, 500);
             //force to a limit, to avoid unlimited querie
         }
         $numRows = $doAudit->find();
         $oNow = new Date();
         while ($doAudit->fetch()) {
             $aAudit = $doAudit->toArray();
             $aAudit['details'] = unserialize($aAudit['details']);
             //  format date
             $oDate = new Date($aAudit['updated']);
             $oDate->setTZbyID('UTC');
             $oDate->convertTZ($oNow->tz);
             $aAudit['updated'] = $oDate->format($GLOBALS['date_format'] . ', ' . $GLOBALS['time_format']);
             //  set action type
             $aAudit['action'] = $this->getActionName($aAudit['actionid']);
             $result = $this->getParentContextData($aAudit);
             $aAudit['hasChildren'] = $this->hasChildren($aAudit['auditid'], $aAudit['contextid']);
             if (empty($aAudit['username'])) {
                 $aAudit['username'] = '******';
             }
             $aAudit['contextDescription'] = $this->getContextDescription($aAudit['context']);
             $aAuditInfo[] = $aAudit;
         }
     }
     return $aAuditInfo;
 }
Beispiel #12
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;
 }
Beispiel #13
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;
 }
 /**
  * A method to test the sending of emails from the
  * manageCampaigns() method - tests the sending of
  * the "campaign deactivated" emails.
  */
 function testManageCampaignsEmailsPlacementDeactivated()
 {
     // Prepare a single placement that is active, and has a lifetime
     // impression target that has been met (so that it will need to
     // be deactivated)
     $aData = array('contact' => 'Test Placement Deactivated Contact', 'email' => '*****@*****.**', 'reportdeactivate' => 't', 'report' => 't');
     $advertiserId = $this->_insertAdvertiser($aData);
     $aAdvertiser = OA_DAL::staticGetDO('clients', $advertiserId)->toArray();
     $aData = array('status' => OA_ENTITY_STATUS_RUNNING, 'views' => '100');
     $campaignId = $this->_insertPlacement($aData);
     $aData = array('campaignid' => $campaignId);
     $adId = $this->_insertAd($aData);
     $aData = array('operation_interval_id' => 25, 'interval_start' => '2005-12-08 00:00:00', 'interval_end' => '2004-12-08 00:59:59', 'hour' => 0, 'ad_id' => 1, 'impressions' => 101);
     $this->_insertDataIntermediateAd($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}", 2));
     // This is the date that is going to be used later
     $oDate = new Date();
     $oEnd = new Date($oDate);
     $oEnd->addSpan(new Date_Span('1-0-0-0'));
     $oEmailMock->expectOnce('sendCampaignDeliveryEmail', array($aAdvertiser, new Date($aAdvertiser['reportlastdate']), $oEnd, "{$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
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatistics = $oFactory->factory();
     $report = $oDalMaintenanceStatistics->manageCampaigns($oDate);
     $oEmailMock->tally();
     // Clean up
     DataGenerator::cleanUp();
 }
	public function getExpirationDate() {
	    $startDate = new Date(isset($this->m_data['StartDate']) ? $this->m_data['StartDate'] : 0);
	    $timeSpan = new Date_Span();
	    $timeSpan->setFromDays($this->m_data['Days']);
	    $startDate->addSpan($timeSpan);
	    return $startDate->getDate();
	}
Beispiel #16
0
 function _addDays($base_date, $days)
 {
     $modified_date = new Date($base_date);
     $span = new Date_Span((string) $days, '%D');
     $modified_date->addSpan($span);
     return $modified_date;
 }
Beispiel #17
0
 function revenueInsertStats($bannerId, $aParams, $actionType)
 {
     $aZoneIds = $this->revenueGetLinkedZones($bannerId);
     $oSpan = new Date_Span('0-1-0-0');
     $oDate = new Date($aParams['start']);
     $i = 0;
     while (!$oDate->after(new Date($aParams['end']))) {
         foreach ($aZoneIds as $zoneId) {
             $doDsah = OA_Dal::factoryDO('data_summary_ad_hourly');
             $doDsah->date_time = $oDate->format('%Y-%m-%d %H:00:00');
             $doDsah->ad_id = $bannerId;
             $doDsah->zone_id = $zoneId;
             $doDsah->creative_id = 0;
             $doDsahClone = clone $doDsah;
             if (!$doDsah->count()) {
                 $doDsahClone->updated = OA::getNow();
                 if ($doDsahClone->insert()) {
                     $i++;
                 }
             }
         }
         $oDate->addSpan($oSpan);
     }
     return $i > 0;
 }