You are here

public function Feed::orderByDate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/Writer/Feed.php \Zend\Feed\Writer\Feed::orderByDate()

Orders all indexed entries by date, thus offering date ordered readable content where a parser (or Homo Sapien) ignores the generic rule that XML element order is irrelevant and has no intrinsic meaning.

Using this method will alter the original indexation.

Return value

Feed

File

vendor/zendframework/zend-feed/src/Writer/Feed.php, line 134

Class

Feed

Namespace

Zend\Feed\Writer

Code

public function orderByDate() {

  /**
   * Could do with some improvement for performance perhaps
   */
  $timestamp = time();
  $entries = [];
  foreach ($this->entries as $entry) {
    if ($entry
      ->getDateModified()) {
      $timestamp = (int) $entry
        ->getDateModified()
        ->getTimestamp();
    }
    elseif ($entry
      ->getDateCreated()) {
      $timestamp = (int) $entry
        ->getDateCreated()
        ->getTimestamp();
    }
    $entries[$timestamp] = $entry;
  }
  krsort($entries, SORT_NUMERIC);
  $this->entries = array_values($entries);
  return $this;
}