/** * Returns versions by an entry ID. * * @param int $entryId The entry ID to search for. * @param string $localeId The locale ID to search for. * @param int|null $limit The limit on the number of versions to retrieve. * @param bool $includeCurrent Whether to include the current "top" version of the entry. * * @return array */ public function getVersionsByEntryId($entryId, $localeId, $limit = null, $includeCurrent = false) { if (!$localeId) { $localeId = craft()->i18n->getPrimarySiteLocale(); } $versions = array(); $query = craft()->db->createCommand()->select('*')->from('entryversions')->where(array('and', 'entryId = :entryId', 'locale = :locale'), array(':entryId' => $entryId, ':locale' => $localeId))->order('dateCreated desc')->limit($limit); if (!$includeCurrent) { $query->offset(1); } $results = $query->queryAll(); foreach ($results as $result) { $result['data'] = JsonHelper::decode($result['data']); // Don't initialize the content unset($result['data']['fields']); $versions[] = EntryVersionModel::populateModel($result); } return $versions; }
/** * Returns a version by its offset. * * @param int $entryId * @param int $offset * @return EntryVersionModel|null */ public function getVersionByOffset($entryId, $offset = 0) { $versionRecord = EntryVersionRecord::model()->findByAttributes(array('entryId' => $entryId, 'locale' => craft()->i18n->getPrimarySiteLocale())); if ($versionRecord) { return EntryVersionModel::populateModel($versionRecord); } }