Skip to content
Snippets Groups Projects
ConfigurationModel.php 1.37 KiB
Newer Older
  • Learn to ignore specific revisions
  • Damien's avatar
    Damien committed
    <?php
    
    /**
    * Copyright Maarch since 2008 under licence GPLv3.
    * See LICENCE.txt file at the root folder for more details.
    * This file is part of Maarch software.
    *
    */
    
    /**
    * @brief Configuration Model
    * @author dev@maarch.org
    */
    
    namespace Configuration\models;
    
    use SrcCore\models\DatabaseModel;
    use SrcCore\models\ValidatorModel;
    
    class ConfigurationModel
    {
    
        public static function getByService(array $aArgs)
        {
            ValidatorModel::notEmpty($aArgs, ['service']);
            ValidatorModel::stringType($aArgs, ['service']);
    
    Damien's avatar
    Damien committed
            ValidatorModel::arrayType($aArgs, ['select']);
    
            $configuration = DatabaseModel::select([
                'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
    
                'table'     => ['configurations'],
                'where'     => ['service = ?'],
                'data'      => [$aArgs['service']],
    
    Damien's avatar
    Damien committed
            ]);
    
            if (empty($configuration[0])) {
                return [];
            }
    
            return $configuration[0];
        }
    
        public static function update(array $aArgs)
        {
            ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']);
            ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']);
    
            DatabaseModel::update([
    
                'table' => 'configurations',
    
    Damien's avatar
    Damien committed
                'set'   => $aArgs['set'],
                'where' => $aArgs['where'],
                'data'  => $aArgs['data']
            ]);
    
            return true;
        }
    }