getContent() public method

Note that this method is explicitly defined here because the magic method above cannot pass dynamic variables by reference
public getContent ( string $textquery, array $parameters = [], array &$pager = [], array $whereparameters = [] ) : Content | Content[]
$textquery string
$parameters array
$pager array
$whereparameters array
return Bolt\Legacy\Content | Bolt\Legacy\Content[]
Example #1
0
 /**
  * Get the content records, and fallback a page if none found.
  *
  * @param string         $contentTypeSlug
  * @param array          $contentParameters
  * @param ListingOptions $options
  *
  * @return Content|false
  */
 protected function getContent($contentTypeSlug, array $contentParameters, ListingOptions $options)
 {
     $records = $this->em->getContent($contentTypeSlug, $contentParameters);
     // UGLY HACK! Remove when cutting over to the new storage layer!
     $records = empty($records) ? false : $records;
     if ($records === false && $options->getPage() !== null) {
         $contentParameters['page'] = $options->getPreviousPage();
         $records = $this->em->getContent($contentTypeSlug, $contentParameters);
     }
     return $records;
 }
Example #2
0
 /**
  * Do the edit form for a record.
  *
  * @param Content $content     A content record
  * @param array   $contentType The contenttype data
  * @param boolean $duplicate   If TRUE create a duplicate record
  *
  * @return array
  */
 public function action(Content $content, array $contentType, $duplicate)
 {
     $contentTypeSlug = $contentType['slug'];
     $new = $content->getId() === null ?: false;
     $oldStatus = $content->getStatus();
     $allStatuses = ['published', 'held', 'draft', 'timed'];
     $allowedStatuses = [];
     foreach ($allStatuses as $status) {
         if ($this->users->isContentStatusTransitionAllowed($oldStatus, $status, $contentTypeSlug, $content->getId())) {
             $allowedStatuses[] = $status;
         }
     }
     // For duplicating a record, clear base field values.
     if ($duplicate) {
         $content->setId('');
         $content->setSlug('');
         $content->setDatecreated('');
         $content->setDatepublish('');
         $content->setDatedepublish(null);
         $content->setDatechanged('');
         $content->setUsername('');
         $content->setOwnerid('');
         $this->loggerFlash->info(Trans::__('contenttypes.generic.duplicated-finalize', ['%contenttype%' => $contentTypeSlug]));
     }
     // Set the users and the current owner of this content.
     if ($new || $duplicate) {
         // For brand-new and duplicated items, the creator becomes the owner.
         $contentowner = $this->users->getCurrentUser();
     } else {
         // For existing items, we'll just keep the current owner.
         $contentowner = $this->users->getUser($content->getOwnerid());
     }
     // Build list of incoming non inverted related records.
     $incomingNotInverted = [];
     foreach ($content->getRelation()->incoming($content) as $relation) {
         if ($relation->isInverted()) {
             continue;
         }
         $fromContentType = $relation->getFromContenttype();
         $record = $this->em->getContent($fromContentType . '/' . $relation->getFromId());
         if ($record) {
             $incomingNotInverted[$fromContentType][] = $record;
         }
     }
     // Test write access for uploadable fields.
     $contentType['fields'] = $this->setCanUpload($contentType['fields']);
     $templateFields = $content->getTemplatefields();
     if ($templateFields instanceof TemplateFields && ($templateFieldsData = $templateFields->getContenttype()->getFields())) {
         $templateFields->getContenttype()['fields'] = $this->setCanUpload($templateFields->getContenttype()->getFields());
     }
     // Build context for Twig.
     $contextCan = ['upload' => $this->users->isAllowed('files:uploads'), 'publish' => $this->users->isAllowed('contenttype:' . $contentTypeSlug . ':publish:' . $content->getId()), 'depublish' => $this->users->isAllowed('contenttype:' . $contentTypeSlug . ':depublish:' . $content->getId()), 'change_ownership' => $this->users->isAllowed('contenttype:' . $contentTypeSlug . ':change-ownership:' . $content->getId())];
     $contextHas = ['incoming_relations' => count($incomingNotInverted) > 0, 'relations' => isset($contentType['relations']), 'tabs' => $contentType['groups'] !== false, 'taxonomy' => isset($contentType['taxonomy']), 'templatefields' => empty($templateFieldsData) ? false : true];
     $contextValues = ['datepublish' => $this->getPublishingDate($content->getDatepublish(), true), 'datedepublish' => $this->getPublishingDate($content->getDatedepublish())];
     $context = ['incoming_not_inv' => $incomingNotInverted, 'contenttype' => $contentType, 'content' => $content, 'allowed_status' => $allowedStatuses, 'contentowner' => $contentowner, 'fields' => $this->config->fields->fields(), 'fieldtemplates' => $this->getTemplateFieldTemplates($contentType, $content), 'fieldtypes' => $this->getUsedFieldtypes($contentType, $content, $contextHas), 'groups' => $this->createGroupTabs($contentType, $contextHas), 'can' => $contextCan, 'has' => $contextHas, 'values' => $contextValues, 'relations_list' => $this->getRelationsList($contentType)];
     return $context;
 }
Example #3
0
 /**
  * Fetch a listing of ContentType records.
  *
  * @param string  $contentTypeSlug
  * @param string  $order
  * @param integer $page
  * @param array   $taxonomies
  * @param string  $filter
  */
 public function action($contentTypeSlug, $order = null, $page = null, array $taxonomies = null, $filter = null)
 {
     // Order has to be set carefully. Either set it explicitly when the user
     // sorts, or fall back to what's defined in the contenttype. Except for
     // a ContentType that has a "grouping taxonomy", as that should override
     // it. That exception state is handled by the query OrderHandler.
     $contenttype = $this->em->getContentType($contentTypeSlug);
     $contentParameters = ['paging' => true, 'hydrate' => true, 'order' => $order ?: $contenttype['sort'], 'page' => $page, 'filter' => $filter];
     // Set the amount of items to show per page
     if (!empty($contenttype['recordsperpage'])) {
         $contentParameters['limit'] = $contenttype['recordsperpage'];
     } else {
         $contentParameters['limit'] = $this->config->get('general/recordsperpage');
     }
     // Filter on taxonomies
     if ($taxonomies !== null) {
         foreach ($taxonomies as $taxonomy => $value) {
             $contentParameters[$taxonomy] = $value;
         }
     }
     return $this->em->getContent($contentTypeSlug, $contentParameters);
 }