ContentService.php in Content Planner 8
File
modules/content_calendar/src/ContentService.php
View source
<?php
namespace Drupal\content_calendar;
use Drupal\content_calendar\Entity\ContentTypeConfig;
use Drupal\node\Entity\Node;
class ContentService {
private $contentTypeConfig;
public function __construct() {
$this->contentTypeConfig = ContentTypeConfig::loadMultiple();
}
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);
}
}