protected function preSave()
 {
     if ($this->ko_benutzer == 0) {
         $this->ko_benutzer = Security::getUserId();
         $this->ko_datum = new \DateTime();
     }
 }
 /**
  * Gibt den Text mit den ersetzten Links zurück
  * @return string
  */
 public function getText()
 {
     $this->text = html_entity_decode($this->text);
     $matches = [];
     // Suchen nach allem, dass in [[ ]] eingeschlossen ist
     preg_match_all('/\\[\\[([\\w\\.\\säöüÄÖÜß]+)\\]\\]/', $this->text, $matches);
     Logging::debug(print_r($matches, true));
     foreach ($matches[1] as $match) {
         $artikel = CmsArtikel::loadByBezeichnung($match, $this->kategorieId);
         if ($artikel == null) {
             Logging::info('Lege Artikel neu an: ' . $match);
             $artikel = new CmsArtikel();
             $artikel->ca_kategorie = $this->kategorieId;
             $artikel->ca_bezeichnung = $match;
             $artikel->ca_aktiv = 1;
             $artikel->ca_autor = Security::getUserId();
             $artikel->save();
             $titel = Text::get($artikel->getElementId() . '.titel');
             $titel->te_text = $match;
             $titel->save();
         }
         $link = EntityLinks::show($artikel);
         $tag = "<a href=\"{$link}\">{$match}</a>";
         $this->text = str_replace('[[' . $match . ']]', $tag, $this->text);
     }
     return $this->text;
 }
 /**
  * @param $user
  * @param $pass
  * @param $token
  * @return array
  */
 private function loginUser($user, $pass, &$token)
 {
     if (Security::login($user, $pass)) {
         $token = md5(Security::getUserId() . date('dmyHis'));
         $user = new User(Security::getUserId());
         $user->us_hash = $token;
         $user->save();
         return true;
     }
     return false;
 }
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     // TODO: Refactor!
     if (isset(Application::getCurrentRequest()->target) && Application::getCurrentRequest()->target != '') {
         $name = Application::getCurrentRequest()->target;
     }
     $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
     if (empty($file->error) && $this->kollektionId > 0) {
         $medium = new Medien();
         $medium->me_kollektion = $this->kollektionId;
         $medium->me_titel = $file->name;
         $medium->me_dateiname = $file->name;
         $medium->me_erweiterung = strtolower(substr(strrchr($name, '.'), 1));
         $medium->me_groesse = $file->size;
         $medium->me_upload_am = date('d.m.Y');
         $medium->me_upload_von = Security::getUserId();
         if (isset(Application::getCurrentRequest()->token) && Application::getCurrentRequest()->token != '') {
             $medium->me_token = Application::getCurrentRequest()->token;
         }
         $medium->save();
         $file->id = $medium->id;
     }
     return $file;
 }