development/coursemanagement-bundle/src/Module/Frontend/InterfaceModule.php line 107

Open in your IDE?
  1. <?php
  2. namespace CityMountain\CourseManagementBundle\Module\Frontend;
  3. use CityMountain\CourseManagementBundle\Utils\OperationCM;
  4. use CityMountain\ToolBundle\Utils\OperationTool;
  5. use Contao\Input;
  6. class InterfaceModule extends \Module
  7. {
  8.     protected $strTemplate = 'fe_modInterface';
  9.     
  10.     protected $parmTest        = false;
  11.     
  12.     protected $paramUnitId;
  13.     
  14.     protected $parmId;
  15.     
  16.     protected $parmAct;
  17.     
  18.     protected $paramDayNow;
  19.     
  20.     protected $ActMod;
  21.     protected $ActAct;
  22.     
  23.     protected $paramNoPrinterIcon         = false;
  24.     protected $paramNoHorizontaleLine     = false;
  25.     protected $paramSortOut                = array();
  26.     protected $paramInterfaceConfig        = array();
  27.     protected $paramVLSGroup            = false;
  28.     
  29.     protected $ResMember = array();
  30.     
  31.     protected $tempSaveVLSKursarten = array();
  32.     protected $tempSaveMemPos        = array();
  33.     
  34.     //Datum, Zeit, Thema, Ort, Info, Veranstalter -> Sicht für Verbände
  35.     protected $field_1_1 = Array ( 'eveId'                    =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'tl_calendar_events.id AS eveId')
  36.                                   ,'fkEventType'            =>array('sql'=>1,'noout'=>0,'lang'=>'')
  37.                                   ,'fkUnit'                    =>array('sql'=>1,'noout'=>0,'lang'=>'')
  38.                                   ,'title'                    =>array('sql'=>1,'noout'=>0,'lang'=>'','link'=>1)
  39.                                   ,'cmEventCanceled'        =>array('sql'=>1,'noout'=>1,'lang'=>'')
  40.                                   ,'fkEventSector1'            =>array('sql'=>1,'noout'=>1,'lang'=>'')
  41.                                   ,'fkEventSector2'            =>array('sql'=>1,'noout'=>1,'lang'=>'')
  42.                                   ,'startDate'                =>array('sql'=>1,'noout'=>0,'lang'=>'','css'=>'style="width:55px"')
  43.                                   ,'addTime'                =>array('sql'=>1,'noout'=>1,'lang'=>'')
  44.                                   ,'startTime'                =>array('sql'=>1,'noout'=>0,'lang'=>'')
  45.                                   ,'cmLocation'                =>array('sql'=>1,'noout'=>0,'lang'=>'')
  46.                                   ,'iconInfoBlock'            =>array('sql'=>0,'noout'=>0,'lang'=>'&nbsp;')
  47.                                   ,'cmEventHybrid'            =>array('sql'=>1,'noout'=>1,'lang'=>'')
  48.                                   ,'eveType'                =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'fkEventType AS eveType')
  49.                                  );    
  50.     //Datum, Zeit, Thema, Ort, Info -> Sicht für einzelen Veranstalter
  51.     protected $field_1_2 = Array ( 'eveId'                    =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'tl_calendar_events.id AS eveId')
  52.                                   ,'fkEventType'            =>array('sql'=>1,'noout'=>0,'lang'=>'')
  53.                                   ,'title'                    =>array('sql'=>1,'noout'=>0,'lang'=>'','link'=>1)
  54.                                   ,'cmEventCanceled'        =>array('sql'=>1,'noout'=>1,'lang'=>'')
  55.                                   ,'fkEventSector1'            =>array('sql'=>1,'noout'=>1,'lang'=>'')
  56.                                   ,'fkEventSector2'            =>array('sql'=>1,'noout'=>1,'lang'=>'')
  57.                                   ,'startDate'                =>array('sql'=>1,'noout'=>0,'lang'=>'','css'=>'style="width:55px"')
  58.                                   ,'addTime'                =>array('sql'=>1,'noout'=>1,'lang'=>'')
  59.                                   ,'startTime'                =>array('sql'=>1,'noout'=>0,'lang'=>'')
  60.                                   ,'cmLocation'                =>array('sql'=>1,'noout'=>0,'lang'=>'')
  61.                                   ,'eveType'                =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'fkEventType AS eveType')
  62.                                  );    
  63.     
  64.     
  65.     //Standardfelder für die Selektion des Interface
  66.     protected $fieldK_1 = Array  ( 'eveId'                    =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'tl_calendar_events.id AS eveId')
  67.                                  
  68.                                  );
  69.     
  70.     protected $tab_header = array();
  71.     
  72.     public function generate()
  73.     {
  74.         $request = \System::getContainer()->get('request_stack')->getCurrentRequest();
  75.         if ($request && \System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
  76.         {
  77.             $objTemplate = new \BackendTemplate('be_wildcard');
  78.             $objTemplate->wildcard = '### ' . $GLOBALS['TL_LANG']['FMD']['zCMInterface'][0] . ' ###';
  79.             $objTemplate->title = $this->headline;
  80.             $objTemplate->id = $this->id;
  81.             $objTemplate->link = $this->name;
  82.             $objTemplate->href = \StringUtil::specialcharsUrl(\System::getContainer()->get('router')->generate('contao_backend', array('do'=>'themes', 'table'=>'tl_module', 'act'=>'edit', 'id'=>$this->id)));
  83.             return $objTemplate->parse();
  84.         }
  85.         
  86.         return parent::generate();
  87.     }
  88.     
  89.     protected function compile()
  90.     {
  91.         //Parameter setzen
  92.         unset($paramUnitId,$parmId,$parmAct);
  93.         $this->parmTest        = \Input::get('test');
  94.         $this->paramUnitId = \Input::get('organizerId');    
  95.         if($this->paramUnitId==''&&\Input::get('anbieter_id')<>'')$this->paramUnitId = \Input::get('anbieter_id');        
  96.         $this->parmId        = \Input::get('id');
  97.         $this->parmAct          = \Input::get('act');
  98.         $this->paramDayNow  = mktime(0, 0, 0, date("n"), date("j"), date("Y"));
  99.         
  100.         list($this->ActMod, $this->ActAct) = explode('_', $this->parmAct);            
  101.         
  102.         //Daten auslesen
  103.         if($this->paramUnitId) //Standardausgabe für einen Anbieter
  104.         {
  105.             if($this->ActMod==1) //Eventverarbeitung
  106.             {                
  107.                 $eventType = array();
  108.                 $eventSector = array(); //Sparte
  109.                 $eventSectorSub = array(); //Rubrik
  110.                 $isHierarchy = 0;
  111.                 $units = array();
  112.                 
  113.                 switch($this->ActAct)
  114.                 {
  115.                     case 1:
  116.                     case 2:
  117.                         //Kurse alle
  118.                         
  119.                         //Veranstaltungs Art
  120.                         $tmpEventType = \Input::get('eventType');    
  121.                         if($tmpEventType==''&&\Input::get('kurs_art')<>''){
  122.                             $tmpEventType = array_key_first(OperationTool::getMasterdataValues(0,"eventType",0,array("AND mvValueMapping=".\Input::get('kurs_art'))));
  123.                         }
  124.                         if($tmpEventType)
  125.                         {
  126.                             $eventType = explode(',',$tmpEventType);
  127.                         }else
  128.                         {                            
  129.                             $eventType = array_keys(OperationTool::getMasterdataValues(0,"eventType"));
  130.                         }
  131.                         
  132.                         //Spart bzw. Sector
  133.                         $tmpEventSector = \Input::get('eventSector');    
  134.                         if($tmpEventSector==''&&\Input::get('kurs_sparte')<>''){
  135.                             $tmpEventSector = array_key_first(OperationTool::getMasterdataValues(0,"eventSector",0,array("AND mvValueMapping=".\Input::get('kurs_sparte'))));
  136.                         }
  137.                         if($tmpEventSector)
  138.                         {
  139.                             $eventSector = explode(',',$tmpEventSector);
  140.                         }
  141.                         //laden der Rubrik aus dem Sektor, wenn dieser gefüllt wird
  142.                         if(count($eventSector)>0)
  143.                         {    
  144.                             foreach($eventSector as $idSector)
  145.                               {
  146.                                 $tmpEventSectorSub = array_keys(OperationTool::getMasterdataValues(0,"eventSectorSub",0,array("AND fkEventSector=".$idSector)));
  147.                                 $eventSectorSub = array_merge($eventSectorSub,$tmpEventSectorSub);
  148.                             }
  149.                         }
  150.                                                 
  151.                         //Rubrik bzw. SectorSub
  152.                         $tmpEventSectorSub = \Input::get('eventSectorSub');    
  153.                         if($tmpEventSectorSub==''&&\Input::get('kurs_rubrik')<>''){
  154.                             $tmpEventSectorSub = array_key_first(OperationTool::getMasterdataValues(0,"eventSectorSub",0,array("AND mvValueMapping=".\Input::get('kurs_rubrik'))));
  155.                         }
  156.                         if($tmpEventSectorSub)
  157.                         {
  158.                             $eventSectorSub = array_merge($eventSectorSub,explode(',', $tmpEventSectorSub));
  159.                         }else
  160.                         {
  161.                             //Wenn Rubrik leer und keine Sparte, werden alle Rubriken geladen
  162.                             if(count($eventSectorSub)==0)
  163.                             {
  164.                                 $eventSectorSub = array_key_first(OperationTool::getMasterdataValues(0,"eventSectorSub",0));
  165.                             }
  166.                         }                        
  167.                         
  168.                         //Hierarchie prüfen                    
  169.                         $isHierarchy = \Input::get('organizerH');    
  170.                         if(\Input::get('anbieter_h')<>''){
  171.                             $isHierarchy = \Input::get('anbieter_h');
  172.                         }
  173.                         
  174.                         //Units Laden
  175.                         if(strpos($this->paramUnitId,',')){//Mehrere Vereine
  176.                             $units = array($this->paramUnitId);
  177.                             if($isHierarchy)$units = array_keys(OperationTool::getUnitsHierarchy(array_flip(explode(',',$this->paramUnitId))));
  178.                         }else{//ein Verein, nur noch Prüfung
  179.                             $units = array($this->paramUnitId);
  180.                             if($isHierarchy)$units = array_keys(OperationTool::getUnitsHierarchy(array($this->paramUnitId=>$this->paramUnitId)));
  181.                         }
  182.                         
  183.                         
  184.                         if($this->ActAct==1) $locl_field = $this->field_1_1;
  185.                         if($this->ActAct==2) $locl_field = $this->field_1_2;
  186.                         
  187.                         //Selektieren der Veranstaltungen nur wenn es einen Verein hat
  188.                         if(count($units)>0){
  189.                         $objRes = $this->Database->prepare("
  190.                                 SELECT ".$this->gen_select($locl_field)." 
  191.                                  FROM tl_calendar_events
  192.                                 WHERE pid = 2
  193.                                   AND published = 1
  194.                                   AND fkEventType IN (".implode(',',$eventType).")
  195.                                   AND id IN (SELECT pid FROM tl_zEventIndex WHERE fkEventSector1 IN (".implode(',',$eventSectorSub).")
  196.                                                                                OR fkEventSector2 IN (".implode(',',$eventSectorSub).") )
  197.                                   AND fkUnit IN (".implode(',',$units).")
  198.                                   AND startDate >= ?
  199.                                 ORDER BY startDate
  200.                                             ")->execute($this->paramDayNow); 
  201.                             
  202.                         }
  203.                         $this->tab_header = $locl_field;
  204.                         break;
  205.                 }
  206.                 
  207.             
  208.             }elseif($this->ActMod==2) //Nicht ausprogrammiert
  209.             {
  210.                 //nichts
  211.             }
  212.             
  213.         }
  214. //////            
  215.         elseif($this->parmId)  //Konfigurierteausgabe
  216.         {
  217.             //nichts
  218.         }        
  219.         
  220.         
  221.         
  222.         // Prepare table
  223.         $arrTd = array();        
  224.         $start = -1;
  225.         $limit = $objRes->numRows;
  226.         
  227.         // TBODY
  228.         if($limit<>0){
  229.         while ($objRes->next())
  230.         {            
  231.             $class = 'row_' . ++$start . (($start == 0) ? ' row_first' : '') . ((($start + 1) == $limit) ? ' row_last' : '') . ((($start % 2) == 0) ? ' even' : ' odd');
  232.             if($objRes->cmEventCanceled)$class .= ' eventCanceled';
  233.             //Daten automatisch hinzufügen
  234.             foreach ($this->tab_header as $key=>$wert)
  235.             {
  236.                 if(!$wert['noout'])$arrTd[$class][$key] = $objRes->$key;
  237.                 if(!$wert['noout']&&array_key_exists('css',$wert))$arrTd[$class][$key.'_css'] = $wert['css'];
  238.                 //$arrTd[$class][$key] = $objRes->$key;
  239.             }
  240.             
  241.             //Manuelle daten hinzufügen
  242.             if(array_key_exists('startDate',$this->tab_header))$arrTd[$class]['startDate'] = date($GLOBALS['TL_CONFIG']['dateFormat'],$objRes->startDate);
  243.             if(array_key_exists('startTime',$this->tab_header))$arrTd[$class]['startTime'] = date($GLOBALS['TL_CONFIG']['timeFormat'],$objRes->startTime);
  244.             if(array_key_exists('startTime',$this->tab_header))$arrTd[$class]['startTimeStamp'] = $objRes->startTime;
  245.             if(array_key_exists('endTime',$this->tab_header))$arrTd[$class]['endTime'] = date($GLOBALS['TL_CONFIG']['timeFormat'],$objRes->endTime);            
  246.             if(array_key_exists('fkEventType',$this->tab_header)) $arrTd[$class]['fkEventType'] = \Controller::replaceInsertTags('{{CMEvent::eventType::'.$objRes->eveId.'}}');
  247.             if(array_key_exists('fkUnit',$this->tab_header))$arrTd[$class]['fkUnit'] = OperationCM::getUnitName($objRes->fkUnit);
  248.             
  249.             //Bedinungen
  250.             //Keine Zeit, wenn diese nicht ausgewählt ist
  251.             if(array_key_exists('addTime',$this->tab_header)&&!$objRes->addTime)unset($arrTd[$class]['startTime']);
  252.             //Keine Endtzeit, wenn diese gleich Startzeit ist
  253.             if(array_key_exists('endTime',$this->tab_header)&&$objRes->endTime==$objRes->startTime)unset($arrTd[$class]['endTime']);
  254.             
  255.             //storniert einfügen bei Thema
  256.             if($objRes->cmEventCanceled && array_key_exists('title',$this->tab_header))$arrTd[$class]['title'].= ' <font color="red">abgesagt</font>';
  257.             
  258.             //iconInfoBlock
  259.             if(array_key_exists('iconInfoBlock',$this->tab_header)){
  260.                 if($objRes->cmEventHybrid==1)$arrTd[$class]['iconInfoBlock'] = '<img src="bundles/citymountaincoursemanagement/icons/iconHybrid.png" title="Hybrid-Veranstaltung">';
  261.             }
  262.             
  263.             
  264.             //Zentralle verarbeitung am Schluss
  265.             foreach ($this->tab_header as $key=>$wert) // Betrifft ganze Linie
  266.             {
  267.                 $id_iframe = '';
  268.                 //Link setzen für Detailsicht
  269.                 switch ($this->ActMod){
  270.                     case 1:
  271.                         if($this->parmId)$id_iframe= '?id_iframe='.$this->parmId;
  272.                         $linkurl = \Environment::get('url').'/veranstaltungsuebersicht/'.$objRes->eveId.'.html'.$id_iframe;
  273.                         if(!$wert['noout']&&array_key_exists('link',$wert)&&$wert['link']&&$objRes->startDate>=$this->paramDayNow)$arrTd[$class][$key] = '<a href="'.$linkurl.'">'.$arrTd[$class][$key].'</a>';
  274.                         break;
  275.                 }
  276.                 
  277.                 //Sprache laden
  278.                 switch ($this->ActMod){
  279.                     case 1:
  280.                         $this->loadLanguageFile('tl_calendar_events');
  281.                         if(!$this->tab_header[$key]['lang']&& array_key_exists($key,$GLOBALS['TL_LANG']['tl_calendar_events']))$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events'][$key][0];                        
  282.                         if(!array_key_exists($key,$GLOBALS['TL_LANG']['tl_calendar_events']) && $this->tab_header[$key]['lang']=="" )$this->tab_header[$key]['lang'] = $key;
  283.                         if($key=='startDate')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['zstartDate'][0];
  284.                         if($key=='startTime')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['zstartTime'][0];
  285.                         if($key=='endTime')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['zendTime'][0];
  286.                         if($key=='title')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['ztitle'][0];
  287.                         if($key=='cmLocation')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['cmLocationShort'][0];
  288.                         break;
  289.                 }
  290.                 
  291.             }
  292.                 
  293.         }
  294.         }else{//keine Einträge
  295.             $this->Template->no_entry = 1;
  296.             $this->paramNoPrinterIcon = true;
  297.         }
  298.         
  299.         //Sortierung der Ausgabe >> wird nicht genutzt
  300.         /*if(!$this->Template->no_entry)
  301.         {
  302.             unset($arrTd2);
  303.             
  304.             $start = -1;
  305.             foreach ($arrTd as $key => $row) {
  306.                 $class = 'row_' . ++$start . (($start == 0) ? ' row_first' : '') . ((($start + 1) == $limit) ? ' row_last' : '') . ((($start % 2) == 0) ? ' even' : ' odd');
  307.                 $arrTd2[$class] = $arrTd[$key];
  308.             }
  309.             $arrTd = $arrTd2;
  310.         }*/
  311.         
  312.         $url = $this->generate_standard_link();
  313.         
  314.         //Headerverarbeiten
  315.         foreach ($this->tab_header as $key=>$wert)
  316.         {
  317.             if(!$wert['noout'])$tab_header_out[$key] = $wert;
  318.         }
  319.         $this->Template->link_popup = $url.'&pop=1';
  320.         $this->Template->tbody = $arrTd;
  321.         $this->Template->tab_header = $tab_header_out;
  322.         $this->Template->NoPrinterIcon      = $this->paramNoPrinterIcon;
  323.         
  324.         //$this->Template->calendar = $objTemplate->parse();
  325.     }
  326.     
  327.     protected function generate_standard_link()
  328.     {
  329.         //$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $_SERVER['QUERY_STRING']        
  330.         $url = "http://".$_SERVER['HTTP_HOST']."/interface.html?";
  331.         if($this->paramUnitId) $url .= 'organizerId='.$this->paramUnitId;
  332.         if(\Input::get('organizerH')) $url .= '&organizerH='.\Input::get('organizerH');
  333.         if(\Input::get('eventType')) $url .= '&eventType='.\Input::get('eventType');
  334.         if(\Input::get('eventSector')) $url .= '&eventSector='.\Input::get('eventSector');
  335.         if(\Input::get('eventSectorSub')) $url .= '&eventSectorSub='.\Input::get('eventSectorSub');
  336.         if($this->parmId)       $url .= '&id='.$this->parmId;
  337.         $url .= '&act='.$this->parmAct;
  338.         return $url;        
  339.     }
  340.     
  341.     protected function gen_select($in)
  342.     {
  343.         unset($out);
  344.         foreach($in as $key=>$wert){
  345.             if($wert['sql']) //SQL relevant
  346.             {
  347.                 if(array_key_exists('sql_spz',$wert)&&$wert['sql_spz']) //Wenn es zusatz für die SQL abfrage hat
  348.                 {
  349.                     $out[] = $wert['sql_spz'];
  350.                 }else
  351.                 {
  352.                     $out[] = $key;
  353.                 }
  354.             }
  355.         }
  356.         return implode(',', $out);
  357.     }
  358. }
  359. ?>