Exemplo n.º 1
0
 /**
  * onLoad
  *
  * @param count integer
  */
 public function onLoad()
 {
     parent::onLoad();
     $count = $this->args->get('count', 8);
     $now = new DateTime('NOW', $this->registry['core.default_timezone']);
     $past = new DateTime('NOW', $this->registry['core.default_timezone']);
     $past->sub(new DateInterval('P' . $count . 'D'));
     $act = array();
     // condition
     $con = new Condition();
     $con->add('scope', '=', 0);
     $con->add('date', '>=', $past->format(DateTime::SQL));
     // get activities
     $handler = $this->hm->getHandler('AmunService\\User\\Activity');
     $result = $handler->getAll(array('id', 'scope', 'summary', 'date', 'authorId', 'authorName', 'authorThumbnailUrl'), 0, 64, 'date', Sql::SORT_ASC, $con);
     foreach ($result as $row) {
         $date = new DateTime($row['date'], $this->registry['core.default_timezone']);
         $interval = $date->diff($now);
         $key = $interval->format('%d');
         if (!isset($act[$key])) {
             $act[$key] = 1;
         } else {
             $act[$key]++;
         }
     }
     // build params
     $chd = array();
     $labels = array();
     $max = 0;
     $days = 0;
     for ($i = $count - 1; $i >= 0; $i--) {
         if (isset($act[$i])) {
             if ($act[$i] > $max) {
                 $max = $act[$i];
             }
             $chd[$i] = $act[$i];
         } else {
             $chd[$i] = 0;
         }
         $labels[] = date('d M', time() - $i * 3600 * 24);
         $days++;
     }
     $params = array('cht' => 'ls', 'chd' => 't:' . implode(',', $chd), 'chs' => '320x100', 'chco' => '0077CC', 'chds' => '0,' . $max, 'chxt' => 'x', 'chxl' => '0:|' . implode('|', $labels), 'chxr' => '0,1,' . $days . ',1');
     $this->display($params);
 }
Exemplo n.º 2
0
 private function display(array $result)
 {
     $now = new DateTime('NOW', $this->registry['core.default_timezone']);
     echo '<ul>';
     foreach ($result as $row) {
         $date = new DateTime($row['date'], $this->registry['core.default_timezone']);
         $interval = $now->diff($date);
         if ($interval->format('%d') == 0) {
             if ($interval->format('%h') == 0) {
                 $ago = 'ago ' . $interval->format('%i minutes');
             } else {
                 $ago = 'ago ' . $interval->format('%h hours');
             }
         } else {
             $ago = 'on ' . $date->format($this->registry['core.format_datetime']);
         }
         echo '<li>' . $row['summary'] . '<p class="muted">' . $ago . '</p></li>';
     }
     echo '</ul>';
     echo '<div class="clearfix"></div>';
 }