示例#1
0
 /**
  * Controller action that returns HTML displaying annotations for a site and
  * specific date range.
  *
  * Query Param Input:
  *  - idSite: The ID of the site to get annotations for. Only one allowed.
  *  - date: The date to get annotations for. If lastN is not supplied, this is the start date,
  *          otherwise the start date in the last period.
  *  - period: The period type.
  *  - lastN: If supplied, the last N # of periods will be included w/ the range specified
  *           by date + period.
  *
  * Output:
  *  - HTML displaying annotations for a specific range.
  *
  * @param bool $fetch True if the annotation manager should be returned as a string,
  *                    false if it should be echo-ed.
  * @param bool|string $date Override for 'date' query parameter.
  * @param bool|string $period Override for 'period' query parameter.
  * @param bool|string $lastN Override for 'lastN' query parameter.
  * @return string|void
  */
 public function getAnnotationManager($fetch = false, $date = false, $period = false, $lastN = false)
 {
     $idSite = Common::getRequestVar('idSite');
     if ($date === false) {
         $date = Common::getRequestVar('date', false);
     }
     if ($period === false) {
         $period = Common::getRequestVar('period', 'day');
     }
     if ($lastN === false) {
         $lastN = Common::getRequestVar('lastN', false);
     }
     // create & render the view
     $view = new View('@Annotations/getAnnotationManager');
     $allAnnotations = Request::processRequest('Annotations.getAll', array('date' => $date, 'period' => $period, 'lastN' => $lastN));
     $view->annotations = empty($allAnnotations[$idSite]) ? array() : $allAnnotations[$idSite];
     $view->period = $period;
     $view->lastN = $lastN;
     list($startDate, $endDate) = API::getDateRangeForPeriod($date, $period, $lastN);
     $view->startDate = $startDate->toString();
     $view->endDate = $endDate->toString();
     if ($startDate->toString() !== $endDate->toString()) {
         $view->selectedDate = Date::today()->toString();
     } else {
         $view->selectedDate = $endDate->toString();
     }
     $dateFormat = Piwik::translate('CoreHome_ShortDateFormatWithYear');
     $view->startDatePretty = $startDate->getLocalized($dateFormat);
     $view->endDatePretty = $endDate->getLocalized($dateFormat);
     $view->canUserAddNotes = AnnotationList::canUserAddNotesFor($idSite);
     return $view->render();
 }
 private function addAnnotations()
 {
     // create fake access for fake username
     $access = new FakeAccess();
     FakeAccess::$superUser = true;
     Access::setSingletonInstance($access);
     // add two annotations per week for three months, starring every third annotation
     // first month in 2011, second two in 2012
     $count = 0;
     $dateStart = Date::factory('2011-12-01');
     $dateEnd = Date::factory('2012-03-01');
     while ($dateStart->getTimestamp() < $dateEnd->getTimestamp()) {
         $starred = $count % 3 == 0 ? 1 : 0;
         $site1Text = "{$count}: Site 1 annotation for " . $dateStart->toString();
         $site2Text = "{$count}: Site 2 annotation for " . $dateStart->toString();
         API::getInstance()->add($this->idSite1, $dateStart->toString(), $site1Text, $starred);
         API::getInstance()->add($this->idSite2, $dateStart->toString(), $site2Text, $starred);
         $nextDay = $dateStart->addDay(1);
         ++$count;
         $starred = $count % 3 == 0 ? 1 : 0;
         $site1Text = "{$count}: Site 1 annotation for " . $nextDay->toString();
         $site2Text = "{$count}: Site 2 annotation for " . $nextDay->toString();
         API::getInstance()->add($this->idSite1, $nextDay->toString(), $site1Text, $starred);
         API::getInstance()->add($this->idSite2, $nextDay->toString(), $site2Text, $starred);
         $dateStart = $dateStart->addPeriod(1, 'WEEK');
         ++$count;
     }
 }
 public function testDeleteSuccess()
 {
     API::getInstance()->delete(self::$fixture->idSite1, 1);
     try {
         API::getInstance()->get(self::$fixture->idSite1, 1);
         $this->fail("failed to delete annotation");
     } catch (Exception $ex) {
         // pass
     }
 }
 public function addAnnotations()
 {
     APIAnnotations::getInstance()->add($this->idSite, '2012-08-09', "Note 1", $starred = 1);
     APIAnnotations::getInstance()->add($this->idSite, '2012-08-08', self::makeXssContent("annotation"), $starred = 0);
     APIAnnotations::getInstance()->add($this->idSite, '2012-08-10', "Note 3", $starred = 1);
 }