<?php
class WizardHelper
{
    public static function checkIfWizardWasAlreadyFinished() {
        if (cfg('systemInitialized') == '1' && !Yii::app()->params->devMode) {
            throw new CHttpException(404, 'Wizard already finished');
        }
    }

    public static function isSystemInitialized()
    {
        $model = User::model()->findByAttributes(array('isSystemAdmin' => '1'));
        if ($model == null) {
            return false;
        }

        return true;
    }

    public static function initializeSystem()
    {
        $initializer = new PhonalisaInitializer();
        return $initializer->runInit();
    }

    public static function getWizardModel()
    {
        $wizardModels = Wizard::model()->findAll();
        if (empty($wizardModels)) {
            $wizardModels[] = new Wizard();
        }

        if (count($wizardModels) != 1) {
            throw new CHttpException(500, 'Internal Wizard Error wizardModel Count failed!');
        }

        return $wizardModels[0];
    }
}