DeviceStats.php 1.53 KB
<?php

namespace domain\device;

use Yii;
use domain\device\models\DeviceStats as DeviceStatsModel;

class DeviceStats
{
    /**
     * @param $item
     * @return null
     */
    static function create($item)
    {
        $createModel = Yii::createObject([
            'class'             => DeviceStatsModel::className(),
            'barcode'           => $item['barcode'],
            'device_id'         => $item['device_id'],
            'manufacture_id'    => $item['manufacture_id'],
            'project_id'        => $item['project_id'],
            'model_id'          => $item['model_id'],
            'software_version'  => $item['software_version'],
            'hardware_version'  => $item['hardware_version'],
            'timestamp'         => $item['timestamp'],
            'city'              => $item['city'],
            'ip'                => $item['ip']
        ]);
        if ($createModel->save()) {
            return $createModel;
        } else {
            return null;
        }
    }

    /**
     * @param $id
     * @return bool|false|int
     * @throws \Exception
     * @throws \Throwable
     */
    static function delete($id)
    {
        $deviceStats = DeviceStatsModel::findOne($id);
        if (empty($deviceStats)) {
            return false;
        }
        return $deviceStats->delete();
    }

    /**
     * @return bool|int
     */
    static function deleteAll($condition)
    {
        if (empty($condition)) {
            return false;
        }

        return DeviceStatsModel::deleteAll($condition);
    }
}