コード例 #1
0
	/**
	 * Sets general variables to the view that are used by various templates and Javascript.
	 * If any error happens, displays the login screen
	 * @param Piwik_View $view
	 * @return void
	 */
	protected function setGeneralVariablesView($view)
	{
		$view->date = $this->strDate;
		
		try {
			$view->idSite = $this->idSite;
			if(empty($this->site) || empty($this->idSite))
			{
				throw new Exception("The requested website idSite is not found in the request, or is invalid.
				Please check that you are logged in Piwik and have permission to access the specified website.");
			}
			$this->setPeriodVariablesView($view);
			
			$rawDate = Piwik_Common::getRequestVar('date');
			$periodStr = Piwik_Common::getRequestVar('period');
			if($periodStr != 'range')
			{
				$date = Piwik_Date::factory($this->strDate);
				$period = Piwik_Period::factory($periodStr, $date);
			}
			else
			{
				$period = new Piwik_Period_Range($periodStr, $rawDate, $this->site->getTimezone());
			}
			$view->rawDate = $rawDate;
			$view->prettyDate = $period->getPrettyString();
			$view->siteName = $this->site->getName();
			$view->siteMainUrl = $this->site->getMainUrl();
			
			$datetimeMinDate = $this->site->getCreationDate()->getDatetime();
			$minDate = Piwik_Date::factory($datetimeMinDate, $this->site->getTimezone());
			$this->setMinDateView($minDate, $view);

			$maxDate = Piwik_Date::factory('now', $this->site->getTimezone());
			$this->setMaxDateView($maxDate, $view);
			
			// Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected 
			$dateStart = $period->getDateStart();
			if($dateStart->isEarlier($minDate)) { $dateStart = $minDate; } 
			$dateEnd = $period->getDateEnd();
			if($dateEnd->isLater($maxDate)) { $dateEnd = $maxDate; }
			
			$view->startDate = $dateStart;
			$view->endDate = $dateEnd;
			
			$this->setBasicVariablesView($view);
		} catch(Exception $e) {
			Piwik_ExitWithMessage($e->getMessage());
		}
	}
コード例 #2
0
ファイル: RangeTest.php プロジェクト: nnnnathann/piwik
 /**
  * @group Core
  * @group Period
  * @group Period_Range
  */
 public function testGetPrettyString()
 {
     Piwik_Translate::getInstance()->loadEnglishTranslation();
     $month = new Piwik_Period_Range('range', '2007-02-09,2007-03-15');
     $shouldBe = 'From 2007-02-09 to 2007-03-15';
     $this->assertEquals($shouldBe, $month->getPrettyString());
 }
コード例 #3
0
ファイル: Range.test.php プロジェクト: nnnnathann/piwik
 function test_CustomRange_beforeIsAfter_yeahRight()
 {
     $range = new Piwik_Period_Range('range', '2007-02-09,2007-02-01');
     $this->assertEqual($range->getNumberOfSubperiods(), 0);
     $this->assertEqual($range->toString(), array());
     try {
         $range->getPrettyString();
         $this->fail();
     } catch (Exception $e) {
         $this->pass();
     }
 }