Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Analyze - třída pro výběr sanktorálu a temporálu z databáze a jejich analýzu
- *
- * Vybere z databáze za pomocí dibi všechny události, seřadí je a vrátí DibiObject k dalšímu porovnání
- * záznamů a jejich filtraci.
- *
- * @author Honza Kafka <akfak.naj@gmail.com>
- * @licence CC BY-NC-SA
- * @link http://kalendar.farnostnm.cz/wiki/
- * @version 1.1.0
- * @date 2014-11-11 19:09 Červený Kostelec (rev.)
- * @date 2013-07-19 15:34 Červený Kostelec
- */
- class Analyze extends Nette\Object {
- public $connection;
- private $analyzeLiturgicYear;
- private $analyzeDay;
- private $date;
- /** konkrétní data vytažená z databáze */
- private $data;
- /** ID záznamů, které se budou zobrazovat */
- private $resultData;
- /**
- * Spustí výběr temporálu / sanktorálu z databáze, zanalyzuje přednosti slavení
- * Temporál potřebuje proměnné: $week, $season, $sundayCycle, $yearCycle, $weekday
- * Sanktorál potřebuje proměnné: $day, $month
- * Proměnné události potřebují jako kód pro vyhledávání konstantu třídy Enum (uloženo v AnalyzeDay::eventName::private)
- */
- public function __construct(Nette\Database\Context $connection){
- $this->connection = $connection;
- $this->resultData = array();
- }
- /**
- * Nastaví do proměnné analýzu liturgického roku
- */
- public function setAnalyzeLiturgicYear(AnalyzeLiturgicYear $analyzeLiturgicYear){
- $this->analyzeLiturgicYear = $analyzeLiturgicYear;
- return $this;
- }
- /**
- * Nastaví do proměnné analýzu konkrétního dne + totéž pro datum konkrétního dne
- */
- public function setAnalyzeDay(AnalyzeDay $analyzeDay){
- $this->analyzeDay = $analyzeDay;
- $this->date = $this->analyzeDay->getDate();
- return $this;
- }
- /**
- * Získání temporálu a sanktorálu z databáze.
- * ------------------------------------------
- * Dotaz je podmíněný existencí názvu liturgické slavnosti (nevím, jak jednodušejc to napsat v nette, proto je to
- * přes podmínku. Určitě by šla nějaká podmínka v SQL, ale do toho se fakt nechci pouštět).
- */
- public function getEvents(){
- if($this->analyzeDay->getEventName()){
- return $this->connection->table("liturgical_celebration")
- ->where('(week = ? AND season = ? AND (cycle = ? OR cycle = ? OR cycle IS NULL) AND weekday = ?)
- OR
- (month = ? AND day = ? AND (season = ? OR season IS NULL))
- OR
- ( (cycle = ? OR cycle = ? OR cycle IS NULL) AND (pattern = ? OR title LIKE ?) )',
- $this->analyzeDay->getWeek(),
- $this->analyzeDay->getSeason(),
- $this->analyzeLiturgicYear->getSundayCycle(),
- $this->analyzeLiturgicYear->getYearCycle(),
- $this->analyzeDay->getWeekday(),
- $this->analyzeDay->getMonth(),
- $this->analyzeDay->getDay(),
- $this->analyzeDay->getSeason(),
- $this->analyzeLiturgicYear->getSundayCycle(),
- $this->analyzeLiturgicYear->getYearCycle(),
- $this->analyzeDay->getEventName(),
- constant("Enum::".$this->analyzeDay->getEventName())
- )
- ->order('generic_number DESC, sequence_number DESC, weekday');
- }else{
- return $this->connection->table("liturgical_celebration")
- ->where('(week = ? AND season = ? AND (cycle = ? OR cycle = ? OR cycle IS NULL) AND weekday = ?)
- OR
- (month = ? AND day = ? AND (season = ? OR season IS NULL))',
- $this->analyzeDay->getWeek(),
- $this->analyzeDay->getSeason(),
- $this->analyzeLiturgicYear->getSundayCycle(),
- $this->analyzeLiturgicYear->getYearCycle(),
- $this->analyzeDay->getWeekday(),
- $this->analyzeDay->getMonth(),
- $this->analyzeDay->getDay(),
- $this->analyzeDay->getSeason()
- )
- ->order('generic_number DESC, sequence_number DESC, weekday');
- }
- }
- /**
- * Porovná výsledky temporálu a sanktorálu z databáze
- * --------------------------------------------------
- * Do této funkce doporučuji nehrabat, dalo to příšerně moc práce to vymyslet!!!
- */
- public function compare(){
- $this->data = $this->getEvents()->fetchAll(); // výsledky z databáze převede do pole
- $generic_number = 0; // nula je kvůli prvnímu průchodu, aby šel správně
- foreach($this->data as $item){
- if($item['generic_number'] > $generic_number){
- if(isset($this->resultData)){
- unset($this->resultData); // vyprázdní paměť výsledků
- }
- $generic_number = $item['generic_number'];
- }
- $this->resultData[] = $item['id'];
- }
- }
- /*
- public function compare(){
- $this->data = $this->getEvents()->fetchAll(); // výsledky z databáze převede do pole
- // hodnoty slavení (bloky důležitosti)
- $type = array(Enum::COMMON_TIME => 1, Enum::OPTIONAL_MEMORY => 1, Enum::MEMORY => 2, Enum::FEAST => 3, Enum::SUNDAY => 4, Enum::CELEBRATION => 5);
- $max = 1;
- //for($i = 0; $i < count($this->data); $i++){
- foreach($this->data as $item){
- //$item = $this->data[$i];
- if( ($type[$item['type']] >= $max) or (isset($item['type_diocese']) or isset($item['type_cathedral']) or isset($item['type_area'])) ){
- // NEchceme zobrazit ferii doby adventní po 17. prosinci
- if($this->date->format("d") < 17 or $this->date->format("m") <> 12 or $item['season'] <> Enum::ADVENT or $item['type'] <> Enum::COMMON_TIME or $item['month'] <> null or $item['day'] <> null){
- // NEzobrazit ani nezávazné památky a památky v době postní
- if( ($item['season'] == Enum::LENT or $this->analyzeDay->getSeason() == Enum::LENT) and ($item['type'] == Enum::MEMORY or $item['type'] == Enum::OPTIONAL_MEMORY)){
- }else{
- $this->resultData[] = $item['id'];
- }
- // slavení týkající se území, diecéze nebo katedrály považujeme jako ferii, abychom mohli zobrazovat další záznamy
- if(isset($item['type_diocese']) or isset($item['type_cathedral']) or isset($item['type_area'])){
- $max = 1;
- }else{
- $max = $type[$item['type']];
- }
- }
- }
- }
- }
- */
- /**
- * Zapíše výslednou analýzu dne do databáze
- */
- public function insertResults(){
- if(count($this->resultData) >= 1){
- foreach($this->resultData as $value){
- $insert[] = array(
- 'year' => $this->date->format("Y"),
- 'month' => $this->date->format("m"),
- 'day' => $this->date->format("d"),
- 'liturgical_celebration_id' => $value
- );
- }
- $this->connection->table("generated_days")->insert($insert);
- $this->resultData = array();
- }
- }
- /**
- * Vrátí hotové výsledky pro další použí (např. zapsání do databáze)
- * @return array
- */
- public function getResults(){
- return $this->resultData;
- }
- /*
- id
- cyklus cycle
- tyden week
- mesic month
- den day
- mesic_den month_day
- obdobi season
- den_v_tydnu weekday
- zobrazit_od display_from
- zobrazit_do display_to
- zaltar psalter
- barva color
- 1_cteni 1_reading
- 1_cteni_text 1_reading_text
- zalm psalm
- zalm_antifona psalm_antiphon
- zalm_text psalm_text
- 2_cteni 2_reading
- 2_cteni_text
- 2_cteni_zalm
- 2_cteni_zalm_antifona
- 2_cteni_zalm_text
- 3_cteni
- 3_cteni_text
- 3_cteni_zalm
- 3_cteni_zalm_antifona
- 3_cteni_zalm_text
- 4_cteni
- 4_cteni_text
- 4_cteni_zalm
- 4_cteni_zalm_antifona
- 4_cteni_zalm_text
- 5_cteni
- 5_cteni_text
- 5_cteni_zalm
- 5_cteni_zalm_antifona
- 5_cteni_zalm_text
- 6_cteni
- 6_cteni_text
- 6_cteni_zalm
- 6_cteni_zalm_antifona
- 6_cteni_zalm_text
- 7_cteni
- 7_cteni_text
- 7_cteni_zalm
- 7_cteni_zalm_antifona
- 7_cteni_zalm_text
- 8_cteni
- 8_cteni_text
- 8_cteni_zalm
- 8_cteni_zalm_antifona
- 8_cteni_zalm_text
- evangelium gospel
- evangelium_text gospel_text
- nazev title
- cast part
- typ type
- typ_dieceze type_diocese
- typ_katedrala type_cathedral
- typ_oblast type_area
- druhove_cislo generic_number
- poradove_cislo sequence_number
- vzorec pattern
- update update
- opraveno revision
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement