/** * Gets a previous slug from the entry log * @param \ride\library\orm\OrmManager $orm * @param \ride\library\reflection\ReflectionHelper $reflectionHelper * @param \ride\web\cms\orm\ContentProperties $contentProperties * @param string $locale Code of the locale * @param string $id Requested slug * @return string|null Current slug of the entry, null if no change found */ protected function getIdFromLog(OrmManager $orm, ReflectionHelper $reflectionHelper, ContentProperties $contentProperties, $locale, $id) { $entryLogChangeModel = $orm->getEntryLogChangeModel(); $meta = $this->model->getMeta(); $isLocalized = $meta->isLocalized(); if ($isLocalized) { $model = $orm->getModel($meta->getLocalizedModelName()); } else { $model = $this->model; } $idField = $contentProperties->getIdField(); // look in the log for the requested id $query = $entryLogChangeModel->createQuery($locale); $query->addCondition('{entryLog.model} = %1%', $model->getName()); $query->addCondition('{fieldName} = %1%', $idField); $query->addCondition('{oldValue} = %1%', $id); $query->addOrderBy('{id} DESC'); $entryLogChange = $query->queryFirst(); if (!$entryLogChange) { // no history of the provided id return null; } $entryLog = $entryLogChange->getEntryLog(); $entryId = $entryLog->getEntry(); // get the original entry $entry = $model->getById($entryId, $this->locale); if (!$entry) { return null; } // retrieve and return the id value from the entry return $reflectionHelper->getProperty($entry, $idField); }
/** * Loads the properties of the detail widget for the provided site and locale * @param string $index The key to store the values * @param string $site Id of the site * @param string $locale Code of the current locale * @return null */ protected function parseArguments($index, $site, $locale) { $properties = new ContentProperties(); $properties->getFromWidgetProperties($this->properties, $locale); $this->reflectionHelper = $this->model->getReflectionHelper(); $this->arguments[$index] = array(ContentProperties::PROPERTY_RECURSIVE_DEPTH => $properties->getRecursiveDepth(), ContentProperties::PROPERTY_INCLUDE_UNLOCALIZED => $properties->getIncludeUnlocalized(), ContentProperties::PROPERTY_ID_FIELD => $properties->getIdField(), ContentProperties::PROPERTY_FORMAT_TITLE => $properties->getContentTitleFormat(), ContentProperties::PROPERTY_FORMAT_TEASER => $properties->getContentTeaserFormat(), ContentProperties::PROPERTY_FORMAT_IMAGE => $properties->getContentImageFormat(), ContentProperties::PROPERTY_FORMAT_DATE => $properties->getContentDateFormat(), self::PROPERTY_URL => rtrim($this->routerService->getUrl($this->baseScript, 'cms.front.' . $site . '.' . $this->node->getId() . '.' . $locale), '/') . '/'); }