public function main() { $data = ['pageName' => 'main']; $data['novelCnt'] = Novel::where('state', '=', 'detect')->count(); $data['chapterCnt'] = Chapter::where('state', '=', 'detected')->count(); $data['mailCnt'] = Mail::where('state', '=', 'ready')->count(); return view('index', $data); }
public function getNextDownloadChapter() { $chapters = Chapter::where('novel_id', '=', $this->id)->where('state', '=', 'detected')->where('index', '>', $this->latestChapter)->orderBy('index')->take(1)->get(); if ($chapters->count() == 0) { return null; } else { return $chapters[0]; } }
public function fetchChapter() { $dom = Utils::getDom($this->novel->url); $dds = $dom->find('dl', 0)->find('dd'); $end = count($dds); $chapterIndex = $end + 1; $newed = false; foreach (range($end, 3, -3) as $i) { foreach (range(2, 0) as $j) { $chapterIndex--; $index = $i - $j - 1; $a = $dds[$index]->find('a', 0); if ($a == null) { continue; } if (Chapter::where('index', '=', $chapterIndex)->count() != 0) { $newed = true; break; } $name = $a->text(); $url = $this->novel->url . $a->getAttribute('href'); $chapter = new Chapter(); $chapter->name = $name; $chapter->index = $chapterIndex; $chapter->state = 'detected'; $chapter->url = $url; $chapter->novel_id = $this->novel->id; $chapter->save(); } if ($newed) { break; } } $this->novel->lastDetect = Carbon::now()->toDateTimeString(); $this->novel->save(); }
public function deleteAllWithBookID($id) { // Checking if chapter exists $chapters = Chapter::where('book_id', $id)->get(); // If chapters exists if (sizeof($chapters) > 0) { // Delete related chapters foreach ($chapters as $chapter) { // Finding related pages $pages = $this->pagesService->deleteAllWithChapter($chapter->id); } Chapter::where('book_id', $id)->delete(); // Returning success message return $this->responseService->returnSuccess(); } else { // Chapter not found // Returning error message return $this->responseService->errorMessage('Chapter was not Found.'); } }