comparison check_sections.php @ 1:1f9d2bfe1d13

handle new section created by user, update sections_index table
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 19 Mar 2015 18:36:21 +0100
parents 723a162b6627
children 373c8ecad8b4
comparison
equal deleted inserted replaced
0:723a162b6627 1:1f9d2bfe1d13
54 echo ("Failed during updating books table."); 54 echo ("Failed during updating books table.");
55 } 55 }
56 } 56 }
57 57
58 function checkSections($count){ 58 function checkSections($count){
59 59 /*
60 /* $query="SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count 60 $query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
61 FROM sections 61 FROM sections
62 JOIN books ON sections.books_id = books.id 62 JOIN books ON sections.books_id = books.id
63 WHERE NOT EXISTS 63 WHERE NOT EXISTS
64 (SELECT 1 FROM sections_versions WHERE books_id=sections.books_id) 64 (SELECT 1 FROM sections_versions WHERE books_id=sections.books_id)
65 GROUP BY books_id, start_page, end_page 65 GROUP BY books_id, start_page, end_page
66 HAVING COUNT( * ) >=".$count." 66 HAVING COUNT( * ) >=".$count.")
67 ORDER BY COUNT( * ) DESC ";*/ 67 UNION
68 (SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count
69 FROM sections_revisions
70 JOIN books ON sections_revisions.books_id = books.id
71 JOIN (
72 SELECT sections_versions.id
73 FROM sections_versions WHERE sections_versions.version=(SELECT MAX(version) FROM sections_versions)
74 GROUP BY books_id
75 ) AS t ON t.id=sections_revisions.versions_id
76 WHERE deleted=0
77 GROUP BY books_id, versions_id,start_page, end_page
78 HAVING COUNT( * ) >=".$count.")
79 ORDER BY count DESC ";
80 */
68 $query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count 81 $query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
69 FROM sections 82 FROM sections_index
70 JOIN books ON sections.books_id = books.id 83 JOIN books ON sections_index.books_id = books.id
71 WHERE NOT EXISTS 84 WHERE NOT EXISTS
72 (SELECT 1 FROM sections_versions WHERE books_id=sections.books_id) 85 (SELECT 1 FROM sections_versions WHERE books_id=sections_index.books_id)
73 GROUP BY books_id, start_page, end_page 86 GROUP BY books_id, start_page, end_page
74 HAVING COUNT( * ) >=".$count.") 87 HAVING COUNT( * ) >=".$count.")
75 UNION 88 UNION
76 (SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count 89 (SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count
77 FROM sections_revisions 90 FROM sections_revisions