infokani
7/21/2016 - 10:21 AM

From http://localhost/spot/members/sources

     $this->viewBuilder()->layout('trans');
        $source = $this->Sources->newEntity();
        if ($this->request->is('post')) {
            $source->path = md5(Time::now()) . '.srt';
            $file = new File($this->request->data['file']['tmp_name']);
            $file->copy(WWW_ROOT . 'files' . DS . $source->path);
            $source->title = $this->request->data['title'];
            $source->user_id = $this->Auth->user('id');
            $this->Sources->save($source);

            $f = "files" . DS . $source->path;
            $ret = SrtToArrayTool::getArrayByFile($f); // Srt to Array

            $text = '';
            foreach ($ret as $ret) {
                $text = $text . ' ' . $ret['text'];
            }
            $tok = new ClassifierBasedTokenizer(
                    new EndOfSentence(), new WhitespaceTokenizer()
            );
            $sentences = $tok->tokenize($text);

            foreach ($sentences as $sentence) {
                $DBsentence = $this->Sources->Sentences->newEntity();
                $DBsentence->source_id = $source->id;
                $DBsentence->name = $sentence;
                $this->Sources->Sentences->save($DBsentence);
            }

            $this->set('source', $source);
            return $this->redirect(['action' => 'index']);
        }
        $this->set('source', $source);
        $this->set('_serialize', ['source']);