DeviceRepository.php 969 Bytes
<?php

namespace domain;

use domain\models\Device as DeviceModel;

class DeviceRepository
{
    /**
     * @param $where
     * @return array|\yii\db\ActiveRecord[]
     */
    static function getList($where, $limit = 0, $offset = 0)
    {
        $deviceFind = DeviceModel::find();
        $deviceFind->where($where);
        $deviceFind->asArray();
        if ($offset) {
            $deviceFind->offset($offset);
        }
        if ($limit) {
            $deviceFind->limit($limit);
        }
        $all = $deviceFind->all();

        return $all;
    }

    /**
     * @param $where
     * @return int|string
     */
    static function getListCount($where)
    {
        $deviceFind = DeviceModel::find();
        $deviceFind->where($where);
        $all = $deviceFind->count();

        return $all;
    }

    /**
     * @param $id
     * @return null|static
     */
    static function selectOne($id)
    {
        return DeviceModel::findOne($id);
    }
}