src/Database/SkeModel.php
protected function validateEvent(SkeVent &$skeVent)
    {
        $bValid = true;
        $skeVent->resetErrors();
        $aData = $skeVent->toArray();

        // Check required fields && valid options
        foreach (Sked::form()->getFieldDefinitions() as $strKey => $aDefinition) {

            // Required
            if (!isset($aData[$strKey]) && ($aDefinition['required'] ?? false) && !isset($aData['id'])) {
                $bValid = false;
                $skeVent->addError(
                    $strKey,
                    'The "' . $aDefinition['attribs']['label'] . '" field is required.'
                );

            // Valid option
            } elseif (!$this->validateOption($aData[$strKey] ?? null, $aDefinition['options'] ?? null)) {
                $bValid = false;
                $skeVent->addError(
                    $strKey,
                    'An invalid ' . $strKey . ' option was given.'
                );
            }
        }

        // Check reminder fields - should both be present, or neither
        if (isset($aData['lead_time_num']) || isset($aData['lead_time_unit'])) { // one is set
            if (!isset($aData['lead_time_num']) || !isset($aData['lead_time_unit'])) { // but not both
                $bValid = false;
                $skeVent->addError(
                    isset($aData['lead_time_num']) ? 'lead_time_unit' : 'lead_time_num',
                    'Both Reminder fields should be filled out (or clear them both).'
                );
            }
        }

        // Check recurring-event fields
        if (isset($aData['ends_at'])) {
            if (!isset($aData['frequency'])) {
                $bValid = false;
                $skeVent->addError(
                    'frequency',
                    'A frequency is required for recurring events.'
                );
            }
            if (!isset($aData['interval']) || SkeVent::INTERVAL_ONCE === $aData['interval']) {
                $bValid = false;
                $skeVent->addError(
                    'interval',
                    'An interval (daily, weekly, etc.) is required for recurring events.'
                );
            }
        }
        if (isset($aData['frequency']) && !isset($aData['interval'])) {
            $bValid = false;
            $skeVent->addError(
                'interval',
                'An interval (daily, weekly, etc.) is required when a frequency is selected.'
            );
        }
        if (isset($aData['interval'])) {
            if (SkeVent::INTERVAL_DAILY === $aData['interval'] && isset($aData['weekdays'])) {
                $bValid = false;
                $skeVent->addError(
                    'weekdays',
                    'A day of the week cannot be selected for daily events.'
                );
            }
        }

        return $bValid;
    }
protected function validateEvent(SkeVent &$skeVent)
    {
        $bValid = true;
        $skeVent->resetErrors();
        $aData = $skeVent->toArray();

        // Check required fields && valid options
        foreach (Sked::form()->getFieldDefinitions() as $strKey => $aDefinition) {

            // Required
            if (!isset($aData[$strKey]) && ($aDefinition['required'] ?? false) && !isset($aData['id'])) {
                $bValid = false;
                $skeVent->addError(
                    $strKey,
                    'The "' . $aDefinition['attribs']['label'] . '" field is required.'
                );

            // Valid option
            } elseif (!$this->validateOption($aData[$strKey] ?? null, $aDefinition['options'] ?? null)) {
                $bValid = false;
                $skeVent->addError(
                    $strKey,
                    'An invalid ' . $strKey . ' option was given.'
                );
            }
        }

        // Check reminder fields - should both be present, or neither
        if (isset($aData['lead_time_num']) || isset($aData['lead_time_unit'])) { // one is set
            if (!isset($aData['lead_time_num']) || !isset($aData['lead_time_unit'])) { // but not both
                $bValid = false;
                $skeVent->addError(
                    isset($aData['lead_time_num']) ? 'lead_time_unit' : 'lead_time_num',
                    'Both Reminder fields should be filled out (or clear them both).'
                );
            }
        }

        // Check recurring-event fields
        if (isset($aData['ends_at'])) {
            if (!isset($aData['frequency'])) {
                $bValid = false;
                $skeVent->addError(
                    'frequency',
                    'A frequency is required for recurring events.'
                );
            }
            if (!isset($aData['interval']) || SkeVent::INTERVAL_ONCE === $aData['interval']) {
                $bValid = false;
                $skeVent->addError(
                    'interval',
                    'An interval (daily, weekly, etc.) is required for recurring events.'
                );
            }
        }
        if (isset($aData['frequency']) && !isset($aData['interval'])) {
            $bValid = false;
            $skeVent->addError(
                'interval',
                'An interval (daily, weekly, etc.) is required when a frequency is selected.'
            );
        }
        if (isset($aData['interval'])) {
            if (SkeVent::INTERVAL_DAILY === $aData['interval'] && isset($aData['weekdays'])) {
                $bValid = false;
                $skeVent->addError(
                    'weekdays',
                    'A day of the week cannot be selected for daily events.'
                );
            }
        }

        return $bValid;
    }
protected function validateEvent ( SkeVent & $ skeVent ) { $ bValid = true ; $ skeVent -> resetErrors ( ) ; $ aData = $ skeVent -> toArray ( ) ; // Check required fields && valid options foreach ( Sked :: form ( ) -> getFieldDefinitions ( ) as $ strKey => $ aDefinition ) { // Required if ( ! isset ( $ aData [ $ strKey ] ) && ( $ aDefinition [ 'required' ] ?? false ) && ! isset ( $ aData [ 'id' ] ) ) { $ bValid = false ; $ skeVent -> addError ( $ strKey , 'The "' . $ aDefinition [ 'attribs' ] [ 'label' ] . '" field is required.' ) ; // Valid option } elseif ( ! $ this -> validateOption ( $ aData [ $ strKey ] ?? null , $ aDefinition [ 'options' ] ?? null ) ) { $ bValid = false ; $ skeVent -> addError ( $ strKey , 'An invalid ' . $ strKey . ' option was given.' ) ; } } // Check reminder fields - should both be present, or neither if ( isset ( $ aData [ 'lead_time_num' ] ) || isset ( $ aData [ 'lead_time_unit' ] ) ) { // one is set if ( ! isset ( $ aData [ 'lead_time_num' ] ) || ! isset ( $ aData [ 'lead_time_unit' ] ) ) { // but not both $ bValid = false ; $ skeVent -> addError ( isset ( $ aData [ 'lead_time_num' ] ) ? 'lead_time_unit' : 'lead_time_num' , 'Both Reminder fields should be filled out (or clear them both).' ) ; } } // Check recurring-event fields if ( isset ( $ aData [ 'ends_at' ] ) ) { if ( ! isset ( $ aData [ 'frequency' ] ) ) { $ bValid = false ; $ skeVent -> addError ( 'frequency' , 'A frequency is required for recurring events.' ) ; } if ( ! isset ( $ aData [ 'interval' ] ) || SkeVent :: INTERVAL_ONCE === $ aData [ 'interval' ] ) { $ bValid = false ; $ skeVent -> addError ( 'interval' , 'An interval (daily, weekly, etc.) is required for recurring events.' ) ; } } if ( isset ( $ aData [ 'frequency' ] ) && ! isset ( $ aData [ 'interval' ] ) ) { $ bValid = false ; $ skeVent -> addError ( 'interval' , 'An interval (daily, weekly, etc.) is required when a frequency is selected.' ) ; } if ( isset ( $ aData [ 'interval' ] ) ) { if ( SkeVent :: INTERVAL_DAILY === $ aData [ 'interval' ] && isset ( $ aData [ 'weekdays' ] ) ) { $ bValid = false ; $ skeVent -> addError ( 'weekdays' , 'A day of the week cannot be selected for daily events.' ) ; } } return $ bValid ; }
Validate the event data.

If errors are found, adds them to the SkeVent object.

@param CampusUnion\Sked\SkeVent $skeVent Passed by reference.
@return bool Valid/invalid.
Validate the event data .