function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->IP) {
         $this->IP = $this->getIPAddress();
     }
     if (!$this->Code) {
         $this->Code = substr(hash("md5", uniqid()), 0, 7);
     }
     if ($this->Title) {
         $filter = URLSegmentFilter::create();
         $this->URLSegment = $filter->filter($this->Title);
         // Fallback to generic page name if path is empty (= no valid, convertable characters)
         if (!$this->URLSegment || $this->URLSegment == '-' || $this->URLSegment == '-1') {
             $this->URLSegment = $this->Code;
         }
         $originalURLSegment = $this->URLSegment;
         $originalTitle = $this->Title;
         $id = intval($this->ID) - 0;
         for ($i = 2; $i < 9999; $i++) {
             $count = EVCDataSet::get()->filter(array("URLSegment" => $this->URLSegment))->exclude(array("ID" => $id))->Count();
             if ($count) {
                 $this->URLSegment = $originalURLSegment . "-" . $i;
                 $this->Title = $originalTitle . " #" . $i;
             } else {
                 $i = 9999999;
             }
         }
     }
 }
コード例 #2
0
 function previous($request)
 {
     $this->previousCalculations = PaginatedList::create(EVCDataSet::get()->filter(array("Locked" => 1))->where("Title IS NOT NULL AND Title <> ''"));
     $this->previousCalculations->setPageLength(100);
     return array();
 }