Exemplo n.º 1
0
 protected function displayByDateAdded(PinholeTagList $tag_list)
 {
     $now = new SwatDate();
     $now->convertTZById($this->app->config->date->time_zone);
     $store = new SwatTableStore();
     foreach ($tag_list as $tag) {
         $ds = new SwatDetailsStore();
         $ds->tag = $tag;
         $tag_date = $tag->getDataObject()->first_modified;
         $tag_date->convertTZById($this->app->config->date->time_zone);
         $days_past = $now->diff($tag_date)->days;
         if ($days_past <= 1) {
             $ds->date_part = Pinhole::_('Today');
         } elseif ($days_past <= $now->getDayOfWeek() + 1) {
             $ds->date_part = Pinhole::_('This Week');
         } elseif ($days_past <= $now->getDay()) {
             $ds->date_part = Pinhole::_('This Month');
         } elseif ($days_past <= $now->getDayOfYear()) {
             $ds->date_part = Pinhole::_('This Year');
         } else {
             $ds->date_part = sprintf(Pinhole::_('%s'), $tag_date->getYear());
         }
         $store->add($ds);
     }
     $ul_tag = new SwatHtmlTag('ul');
     $li_tag = new SwatHtmlTag('li');
     $ul_tag->open();
     $part = null;
     foreach ($store as $ds) {
         if ($part !== $ds->date_part) {
             if ($part !== null) {
                 $li_tag->close();
             }
             $li_tag->open();
             $h2_tag = new SwatHtmlTag('h2');
             $h2_tag->class = 'pinhole-tag-entity';
             $h2_tag->setContent($ds->date_part);
             $h2_tag->display();
         } elseif ($part !== null) {
             echo ', ';
         }
         $this->displayTag($ds->tag);
         $part = $ds->date_part;
     }
     $li_tag->close();
     $ul_tag->close();
 }
Exemplo n.º 2
0
 /**
  * Gets the previous tag before this tag
  *
  * @return PinholeDateTag the previous tag before this tag or null if there
  *                         is no previous tag.
  */
 public function prev()
 {
     $returned_tag = null;
     switch ($this->name) {
         case 'date':
             $date = new SwatDate($this->value);
             $date->subtractDays(1);
             $value = $date->formatLikeIntl('yyyy-MM-dd');
             break;
         case 'week':
             if (ctype_digit($this->value)) {
                 $value = $this->value > 1 ? $this->value - 1 : null;
             } else {
                 // beginning of previous week
                 $start_date = new SwatDate($this->value);
                 $start_date->subtractDays(7 + $start_date->getDayOfWeek());
                 $value = $start_date->formatLikeIntl('yyyy-MM-dd');
             }
             break;
         case 'year':
             $value = $this->value > 0 ? $this->value - 1 : null;
             break;
         case 'month':
             $value = $this->value > 1 ? $this->value - 1 : null;
             break;
         case 'day':
             $value = $this->value > 1 ? $this->value - 1 : null;
             break;
         default:
             $value = null;
             break;
     }
     if ($value !== null) {
         $string = sprintf('%s.%s=%s', self::NS, $this->name, $value);
         $tag = new PinholeDateTag();
         if ($tag->parse($string, $this->db, $this->instance) !== false) {
             $returned_tag = $tag;
         }
     }
     return $returned_tag;
 }