/**
  * A method to test the set/get methods:
  *  - setSpanDays()
  *  - getStartDate()
  *  - getEndDate()
  *  - getStartDateString()
  *  - getEndDateString()
  */
 function testSetAndGet()
 {
     $oDaySpan = new OA_Admin_DaySpan();
     $oTestStartDate = new Date('1987-04-12 15:10:11');
     $oTestEndDate = new Date('2004-10-12 23:59:58');
     $oDaySpan->setSpanDays($oTestStartDate, $oTestEndDate);
     // Dates should not be equal, as span dates will be "rounded"
     $this->assertNotEqual($oDaySpan->getStartDate(), $oTestStartDate);
     $this->assertNotEqual($oDaySpan->getEndDate(), $oTestEndDate);
     // Round the test dates, and ensure they match!
     $oTestStartDate->setHour(0);
     $oTestStartDate->setMinute(0);
     $oTestStartDate->setSecond(0);
     $oTestEndDate->setHour(23);
     $oTestEndDate->setMinute(59);
     $oTestEndDate->setSecond(59);
     $this->assertEqual($oDaySpan->getStartDate(), $oTestStartDate);
     $this->assertEqual($oDaySpan->getEndDate(), $oTestEndDate);
     // Test the default format for the string methods
     $this->assertEqual($oDaySpan->getStartDateString(), '1987-04-12');
     $this->assertEqual($oDaySpan->getEndDateString(), '2004-10-12');
     // Test custom formats for the string methods
     $this->assertEqual($oDaySpan->getStartDateString('%d-%m-%Y'), '12-04-1987');
     $this->assertEqual($oDaySpan->getEndDateString('%d-%m-%y'), '12-10-04');
 }
 /**
  * A method that echos the HTML for this field.
  */
 function display()
 {
     $oStartDate = $this->getStartDate();
     $startDateStr = is_null($oStartDate) ? '' : $oStartDate->format('%Y-%m-%d');
     $oEndDate = $this->getEndDate();
     $endDateStr = is_null($oEndDate) ? '' : $oEndDate->format('%Y-%m-%d');
     echo "\n        <select name='{$this->_name}_preset' id='{$this->_name}_preset' onchange='{$this->_name}FormChange(" . ($this->_autoSubmit ? 1 : 0) . ")' tabindex='" . $this->_tabIndex++ . "'>";
     foreach ($this->_fieldSelectionNames as $v => $n) {
         $selected = $v == $this->_fieldSelectionValue ? " selected='selected'" : '';
         echo "\n            <option value='{$v}'{$selected}>{$n}</option>";
     }
     echo "\n        </select>\n        <label for='{$this->_name}_start' style='margin-left: 1em'> " . $this->oTrans->translate('From') . "</label>\n        <input class='date' name='{$this->_name}_start' id='{$this->_name}_start' type='text' value='{$startDateStr}' tabindex='" . $this->_tabIndex++ . "' />\n        <input type='image' src='" . OX::assetPath() . "/images/icon-calendar.gif' id='{$this->_name}_start_button' align='absmiddle' border='0' tabindex='" . $this->_tabIndex++ . "' />\n        <label for='{$this->_name}_end' style='margin-left: 1em'> " . $this->oTrans->translate('To') . "</label>\n        <input class='date' name='{$this->_name}_end' id='{$this->_name}_end' type='text' value='{$endDateStr}' tabindex='" . $this->_tabIndex++ . "' />\n        <input type='image' src='" . OX::assetPath() . "/images/icon-calendar.gif' id='{$this->_name}_end_button' align='absmiddle' border='0' tabindex='" . $this->_tabIndex++ . "' />\n        <script type='text/javascript'>\n        <!--\n        Calendar.setup({\n            inputField : '{$this->_name}_start',\n            ifFormat   : '%Y-%m-%d',\n            button     : '{$this->_name}_start_button',\n            align      : 'Bl',\n            weekNumbers: false,\n            firstDay   : " . ($GLOBALS['pref']['ui_week_start_day'] ? 1 : 0) . ",\n            electric   : false\n        })\n        Calendar.setup({\n            inputField : '{$this->_name}_end',\n            ifFormat   : '%Y-%m-%d',\n            button     : '{$this->_name}_end_button',\n            align      : 'Bl',\n            weekNumbers: false,\n            firstDay   : " . ($GLOBALS['pref']['ui_week_start_day'] ? 1 : 0) . ",\n            electric   : false\n        })\n        // Tabindex handling\n        {$this->_name}TabIndex = " . ($this->_tabIndex - 4) . ";\n        // Functions\n        function {$this->_name}Reset()\n        {\n            document.getElementById('{$this->_name}_start').value = '{$startDateStr}';\n            document.getElementById('{$this->_name}_start').value = '{$endDateStr}';\n            document.getElementById('{$this->_name}_preset').value = '{$this->_fieldSelectionValue}';\n        }\n        function {$this->_name}FormSubmit() {\n            submitForm();\n            return false;\n        }\n        function {$this->_name}FormChange(bAutoSubmit)\n        {\n            var o = document.getElementById('{$this->_name}_preset');\n            var {$this->_name}SelectName = o.options[o.selectedIndex].value;\n            var specific = {$this->_name}SelectName == 'specific';";
     $oTmpDaySpan = new OA_Admin_DaySpan();
     foreach ($this->_fieldSelectionNames as $v => $n) {
         if ($v != 'specific') {
             if ($v != 'all_events') {
                 $oTmpDaySpan->setSpanPresetValue($v);
                 $oTmpStartDate = $oTmpDaySpan->getStartDate();
                 $sTmpStartDate = $oTmpStartDate->format('%Y-%m-%d');
                 $oTmpEndDate = $oTmpDaySpan->getEndDate();
                 $sTmpEndDate = $oTmpEndDate->format('%Y-%m-%d');
             } else {
                 $sTmpStartDate = '';
                 $sTmpEndDate = '';
             }
             echo "\n            if ({$this->_name}SelectName == '{$v}') {\n                document.getElementById('{$this->_name}_start').value = '{$sTmpStartDate}';\n                document.getElementById('{$this->_name}_end').value = '{$sTmpEndDate}';\n            }\n                ";
         }
     }
     echo "\n\n            document.getElementById('{$this->_name}_start').readOnly = !specific;\n            document.getElementById('{$this->_name}_end').readOnly = !specific;\n\n            if (!specific) {\n                document.getElementById('{$this->_name}_start').style.backgroundColor = '#CCCCCC';\n                document.getElementById('{$this->_name}_end').style.backgroundColor = '#CCCCCC';\n                document.getElementById('{$this->_name}_start').tabIndex = null;\n                document.getElementById('{$this->_name}_start_button').tabIndex = null;\n                document.getElementById('{$this->_name}_end').tabIndex = null;\n                document.getElementById('{$this->_name}_end_button').tabIndex = null;\n            } else {\n                document.getElementById('{$this->_name}_start').style.backgroundColor = '#FFFFFF';\n                document.getElementById('{$this->_name}_end').style.backgroundColor = '#FFFFFF';\n                document.getElementById('{$this->_name}_start').tabIndex = {$this->_name}TabIndex;\n                document.getElementById('{$this->_name}_start_button').tabIndex = {$this->_name}TabIndex + 1;\n                document.getElementById('{$this->_name}_end').tabIndex = {$this->_name}TabIndex + 2;\n                document.getElementById('{$this->_name}_end_button').tabIndex = {$this->_name}TabIndex + 3;\n            }\n\n            document.getElementById('{$this->_name}_start_button').readOnly = !specific;\n            document.getElementById('{$this->_name}_end_button').readOnly = !specific;\n            document.getElementById('{$this->_name}_start_button').src = specific ? '" . OX::assetPath() . "/images/icon-calendar.gif' : '" . OX::assetPath() . "/images/icon-calendar-d.gif';\n            document.getElementById('{$this->_name}_end_button').src = specific ? '" . OX::assetPath() . "/images/icon-calendar.gif' : '" . OX::assetPath() . "/images/icon-calendar-d.gif';\n            document.getElementById('{$this->_name}_start_button').style.cursor = specific ? 'auto' : 'default';\n            document.getElementById('{$this->_name}_end_button').style.cursor = specific ? 'auto' : 'default';\n\n            if (!specific && bAutoSubmit) {\n                submitForm();\n            }\n        }\n        {$this->_name}FormChange(0);\n        //-->\n        </script>";
 }
Exemplo n.º 3
0
 /**
  * A method to set the required variables used in generating historical
  * data, and to obtain a partial Admin_DA method name to use to obtain
  * this data.
  *
  * @param object $oCaller The calling object. Expected to have the
  *                        the following class variables:
  *                             $oCaller->statsBreakdown - One of "week", "month", "dow",
  *                                                        "hour", or unset, in which case
  *                                                        will be set to "day" by method
  *                             $oCaller->weekDays       - May be set by method
  *                             $oCaller->statsKey       - Will be set by method
  *                             $oCaller->averageDesc    - Will be set by method
  * @param string $type    One of "history" or "targeting".
  * @return string The partial Admin_DA method name (eg. "getDay") to be used to
  *                obtain the historical data - combined with other text to get the
  *                full method name (eg. "getDayHistory").
  */
 function setBreakdownInfo(&$oCaller, $type = 'history')
 {
     switch ($oCaller->statsBreakdown) {
         case 'week':
             $oCaller->weekDays = array();
             $oDaySpan = new OA_Admin_DaySpan('this_week');
             $oDate = $oDaySpan->getStartDate();
             for ($i = 0; $i < 7; $i++) {
                 $oCaller->weekDays[$oDate->getDayOfWeek()] = $GLOBALS['strDayShortCuts'][$oDate->getDayOfWeek()];
                 $oDate->addSpan(new Date_Span('1, 0, 0, 0'));
             }
             $oCaller->statsKey = $GLOBALS['strWeek'];
             $oCaller->averageDesc = $GLOBALS['strWeeks'];
             $method = 'getDayHistory';
             break;
         case 'month':
             $oCaller->statsKey = $GLOBALS['strSingleMonth'];
             $oCaller->averageDesc = $GLOBALS['strMonths'];
             $method = 'getMonthHistory';
             break;
         case 'dow':
             $oCaller->statsKey = $GLOBALS['strDayOfWeek'];
             $oCaller->averageDesc = $GLOBALS['strWeekDays'];
             $method = 'getDayOfWeekHistory';
             break;
         case 'hour':
             $oCaller->statsKey = $GLOBALS['strHour'];
             $oCaller->averageDesc = $GLOBALS['strHours'];
             $method = 'getHourHistory';
             break;
         default:
             $oCaller->statsBreakdown = 'day';
             $oCaller->statsKey = $GLOBALS['strDay'];
             $oCaller->averageDesc = $GLOBALS['strDays'];
             $method = 'getDayHistory';
             break;
     }
     return $method;
 }