Funktion wird nicht aufgerufen

Kalito

Erfahrenes Mitglied
Hallo, ich arbeite gerade mit dem Framework cakephp und komme an einer Stelle gerade nicht weiter.

PHP:
public function verhaltensregeln(){
        $this->set('title_for_layout', 'Verhaltenskodex');
        if($this->request->is('post')){ 
            //Wenn die Funktion aufgerufen wird, wird der Post von anmelden übernommen. Dies wird mit der Funktion abgefangen
            if(array_key_exists('Registration', $this->request->data))
                $this->redirect(array('controller'=>'registrations','action'=>'verhaltensregeln'));
            
            //Akzeptieren der Regel
            $this->Rule->query('INSERT INTO rules_users (created, modified, day_id, rule_id, user_id) VALUES (NOW(), NOW(), '.$this->Session->read('day_id').','.$this->request->data['RulesUser']['rule_id'].','.$this->Auth->user('id').') ');
            $this->redirect(array('controller'=>'registrations','action'=>'verhaltensregeln'));
        }
        else{
           $regel = array(); 
           $regel = $this->Rule->query('SELECT * FROM `rules` WHERE id NOT IN (SELECT rule_id FROM rules_users WHERE day_id='.$this->Session->read('day_id').' AND user_id='.$this->Auth->user('id').') LIMIT 0,1'); 
           
           (count($regel) != 0) ? $this->set('regel',$regel): $this->warteliste();  
        }
    }

Kurz zur Funktion. Ein Benutzer muss X Regeln akzeptieren, bevor er in den nächsten Schritt darf. Und genau da liegt das Problem. Wenn bei
PHP:
(count($regel) != 0) ? $this->set('regel',$regel): $this->warteliste();
$regel == 0 ist, dann geht er in den richtigen Zweig (getestet durch eine echo Ausgabe), jedoch ruft er wieder die Funktion verhaltensregeln auf. Die Funktion warteliste ist privat und besitzt keine View-Datei. Wo könnte mein Fehler liegen?

Danke und Gruß
 
PHP:
private function warteliste(){
        $this->request->data = $this->Session->read('this->request->data');
        
        //User meldet sich an
        if(!$this->request->data['Registration']['angemeldet']){
            //Aktuelle Anzahl der belegten Plätze der option und dessen maximal mögliche Anzahl
            $aktuelleAnzahl = $this->Registration->find('count', array('conditions'=>array('Registration.day_option_id' => $this->request->data['Registration']['day_option_id'],'abgelehnt'=>0),'group'=>array('day_option_id')));
            $AnzahlPlaetze = $this->Registration->DayOption->find('first', array('fields'=>'plaetze','conditions'=>array('DayOption.id'=>$this->request->data['Registration']['day_option_id'])));
            $this->Registration->save($this->request->data);
            
            //E-Mails und Definierung der Warteschlangen-Flag
            if($aktuelleAnzahl <= $AnzahlPlaetze['DayOption']['plaetze']){
                $this->istAngemeldet($this->Auth->user('email_jcn'),$this->Auth->user('firstname'),$this->Auth->user('username'));
            }
            else{
                $this->Mail->versenden("warteliste",array('empfaenger'=>$this->Auth->user('email_jcn'), 'inhalt'=>array('firstname'=>$this->Auth->user('firstname')))); 
                $this->request->data['Registration']['warteliste'] = 1;   
            }
            $this->Registration->save($this->request->data);    
            $this->Session->setFlash('Deine Anmelduzng wurde erfolgreich gespeichert', 'flash_success');
            $this->redirect(array('controller'=>'days','action' => 'show'));
        }
        //Benutzer ändert seine Optionen
        else{
            //Holen der alten DayOptions und Registrationsdaten
            $this->Registration->id = $this->request->data['Registration']['angemeldet'];
            $oldDayOption = $this->Registration->find('first', array('conditions'=>array('Registration.id'=>$this->Registration->id),'recursive'=>-1,'fields'=>array('modified','day_option_id', 'bezahlt')));
            
            //Modifieddatum soll sich nur bei Änderung der day_option_id ändern
            if($oldDayOption['Registration']['day_option_id'] == $this->request->data['Registration']['day_option_id']) 
                $this->request->data['Registration']['modified'] = $oldDayOption['Registration']['modified']; 
            //Option wird geändert
            else{
                $this->Registration->save($this->request->data);
                
                //Beim Wechsel wird geprüft, ob es bei der alten Option eine Warteliste gibt
                $countOldDayOption = $this->Registration->find('count',array('conditions'=>array('day_option_id'=>$oldDayOption['Registration']['day_option_id'],'abgelehnt'=>0),'group'=>array('day_option_id')));
                $maxCountOldDayOption = $this->Registration->DayOption->find('first', array('fields'=>'plaetze','conditions'=>array('DayOption.id'=>$oldDayOption['Registration']['day_option_id'])));
                
                //Wenn es eine Warteschlange gibt, dann ist der erste auf dieser eine Mail über die Aufnahme zu senden sowie den Flag der Warteschlage auf 0 zu setzen
                if($countOldDayOption >= $maxCountOldDayOption['DayOption']['plaetze']){
                    $neuerUser = $this->Registration->query("SELECT username, email_jcn, firstname, id 
                                                            FROM users AS User 
                                                            WHERE User.id =
                                                                (SELECT user_id FROM registrations 
                                                                WHERE day_option_id=".$this->Session->read('day_id')." AND abgelehnt=0 
                                                                ORDER BY id ASC 
                                                                LIMIT ".$oldDayOption['Registration']['day_option_id'].",1)");   
                    $this->Registration->id = $neuerUser['Registration']['id'];
                    $neu['Registration']['warteliste'] = 0;
                    $this->Registration->save($neu);
                    $this->istAngemeldet($neuerUser['Registration']['email_jcn'], $neuerUser['Registration']['firstname'], $neuerUser['Registration']['username']);    
                }
                
                //Prüfung ob bei der neuen Option eine Warteschlange existiert
                $countDayOption = $this->Registration->find('count',array('conditions'=>array('day_option_id'=>$this->request->data['Registration']['day_option_id'], 'abgelehnt'=>0),'group'=>array('day_option_id')));
                $maxCountDayOption = $this->Registration->DayOption->find('first', array('fields'=>'plaetze','conditions'=>array('DayOption.id'=>$this->request->data['Registration']['day_option_id'])));
                
                //E-Mails und Definierung der Warteschlangen-Flag
                if($countDayOption <= $maxCountDayOption['DayOption']['plaetze']){
                    $this->istAngemeldet($this->Auth->user('email_jcn'),$this->Auth->user('firstname'),$this->Auth->user('username'));
                }
                else{
                    $this->Mail->versenden("warteliste",array('empfaenger'=>$this->Auth->user('email_jcn'), 'inhalt'=>array('firstname'=>$this->Auth->user('firstname')))); 
                    $this->request->data['Registration']['warteliste'] = 1;   
                }
                
                $this->Registration->save($this->request->data);
                $this->Session->setFlash('Deine Anmeldung wurde erfolgreich gespeichert', 'flash_success');
                $this->redirect(array('controller'=>'days','action' => 'show'));
            }
        }       
    }
 

Neue Beiträge

Zurück