You are here

class ContentService in Content Planner 8

Class UserProfileImage.

Hierarchy

Expanded class hierarchy of ContentService

1 file declares its use of ContentService
RecentCalendarPublicationsBlock.php in modules/content_calendar/src/Plugin/DashboardBlock/RecentCalendarPublicationsBlock.php

File

modules/content_calendar/src/ContentService.php, line 11

Namespace

Drupal\content_calendar
View source
class ContentService {
  private $contentTypeConfig;

  /**
   * ContentService constructor.
   */
  public function __construct() {
    $this->contentTypeConfig = ContentTypeConfig::loadMultiple();
  }

  /**
   * @return \Drupal\Core\Entity\EntityInterface[]|static[]
   */
  public function getContentTypeConfig() {
    return $this->contentTypeConfig;
  }

  /**
   *
   */
  public function getRecentContent($limit) {
    $configs = $this
      ->getContentTypeConfig();
    $types = [];
    if (is_array($configs)) {
      foreach ($configs as $config) {
        $types[] = $config
          ->getOriginalId();
      }
    }
    if (empty($types)) {
      return [];
    }
    $ids = \Drupal::entityQuery('node')
      ->condition('status', 1)
      ->condition('type', $types, 'IN')
      ->sort('created', 'DESC')
      ->range(0, $limit)
      ->execute();
    return $nodes = Node::loadMultiple($ids);
  }

  /**
   *
   */
  public function getFollowingContent($limit) {
    $configs = $this
      ->getContentTypeConfig();
    $types = [];
    if (is_array($configs)) {
      foreach ($configs as $config) {
        $types[] = $config
          ->getOriginalId();
      }
    }
    if (empty($types)) {
      return [];
    }
    $ids = \Drupal::entityQuery('node')
      ->condition('status', 0)
      ->condition('type', $types, 'IN')
      ->condition('publish_on', NULL, 'IS NOT NULL')
      ->sort('publish_on', 'ASC')
      ->range(0, $limit)
      ->execute();
    return $nodes = Node::loadMultiple($ids);
  }

}

Members