Source of file AuthorHelper.php
Size: 2,423 Bytes - Last Modified: 2021-12-24T06:47:36+00:00
/var/www/docs.ssmods.com/process/src/code/objects/helpers/AuthorHelper.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | <?php /** * Collect the authors for author-specific pages. * NOT needed for users to edit, thus NOT in the admin. * * @package News/blog module * @author Simon 'Sphere' Erkelens * * StartGeneratedWithDataObjectAnnotator * @property string OriginalName * @property string URLSegment * @method DataList|News[] NewsItems * @mixin GoogleSitemapExtension * EndGeneratedWithDataObjectAnnotator */ class AuthorHelper extends DataObject { private static $db = array( 'OriginalName' => 'Varchar(255)', 'URLSegment' => 'Varchar(255)', ); private static $has_many = array( 'NewsItems' => 'News', ); private static $indexes = array( 'URLSegment' => true, ); public function onBeforeWrite() { parent::onBeforeWrite(); $nameParts = explode(' ', $this->OriginalName); foreach ($nameParts as $key => $namePart) { if ($namePart == '') { unset($nameParts[$key]); } } $this->OriginalName = implode(' ', $nameParts); if (!$this->URLSegment && !AuthorHelper::get()->filter(array('OriginalName' => $this->OriginalName))->Count()) { $this->URLSegment = singleton('SiteTree')->generateURLSegment($this->OriginalName); } } /** * Free guess on what this button does. * * @param string $action * * @return string Link to this object. */ public function Link($action = 'author/') { if ($siteConfigAction = SiteConfig::current_site_config()->AuthorAction) { $action = $siteConfigAction . '/'; } /** @var NewsHolderPage $Page */ if ($Page = NewsHolderPage::get()->first()) { return ($Page->Link($action . $this->URLSegment)); } return false; } /** * This is quite handy, for meta-tags and such. * * @param string $action The added URLSegment, the actual function that'll return the news. * * @return string Link. To the item. (Yeah, I'm super cereal here) */ public function AbsoluteLink($action = 'author/') { if ($Page = $this->Link($action)) { return Director::absoluteURL($Page); } } /** * @inheritdoc * * @param null $member * * @return bool */ public function canView($member = null) { return true; } } |