Пример #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();
 }
Пример #2
0
 /**
  * Throws if the current user is not allowed to create annotations for a site.
  *
  * @param int $idSite The site ID.
  * @throws Exception if the current user is anonymous or does not have view access
  *                   for site w/ id=$idSite.
  */
 private static function checkUserCanAddNotesFor($idSite)
 {
     if (!AnnotationList::canUserAddNotesFor($idSite)) {
         throw new Exception("The current user is not allowed to add notes for site #{$idSite}.");
     }
 }