コード例 #1
0
 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);
     }
 }
コード例 #2
0
 public function getCurrentAuthor()
 {
     $id = $this->getRequest()->param('ID');
     return AuthorHelper::get()->filter(array('URLSegment' => $id))->first();
 }
コード例 #3
0
 /**
  * Create the author if non-existing yet, and set his/her ID to this item.
  */
 private function setAuthorData()
 {
     $this->Author = trim($this->Author);
     $nameParts = explode(' ', $this->Author);
     foreach ($nameParts as $key => $namePart) {
         if ($namePart == '') {
             unset($nameParts[$key]);
         }
     }
     $this->Author = implode(' ', $nameParts);
     $author = AuthorHelper::get()->filter('OriginalName', trim($this->Author))->first();
     if (!$author->exists()) {
         $author = AuthorHelper::create();
         $author->OriginalName = trim($this->Author);
         $author->write();
     }
     $this->AuthorHelperID = $author->ID;
 }