Example #1
0
 /**
  * get station id by station code
  * @param $code
  * @return null
  */
 public function getStationID($code)
 {
     $station = Station::findOne(['code' => $code]);
     if ($station) {
         return $station['id'];
     }
     return null;
 }
Example #2
0
echo Html::encode($this->title);
?>
</h4>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'user_id', 'value' => function ($model) {
    $user = User::findOne($model->user_id);
    return $user->username;
}], ['attribute' => 'action', 'filter' => LogModel::_prepareDataSelect($actionList, 'key', 'name', false), 'value' => function ($model) {
    $actionList = Log::actions();
    foreach ($actionList as $action) {
        if ($model->action === $action['key']) {
            return $action['name'];
        }
    }
}], ['attribute' => 'station_id', 'value' => function ($model) {
    $station = Station::findOne($model->station_id);
    return $station ? $station->name : '';
}], ['attribute' => 'related_id', 'value' => function ($model) {
    $equip = Equipment::findOne($model->related_id);
    return $equip ? $equip['name'] : '';
}], ['attribute' => 'time', 'filter' => false, 'value' => function ($model) {
    return $model->time > 0 ? date('d/m/Y h:i A', $model->time) : '';
}]]]);
?>

</div>
Example #3
0
 public function getConnectInfo($id)
 {
     $station = Station::findOne($id);
     if (!$station) {
         $this->error = 'Không tìm thấy thông tin trạm';
     }
     $this->info['id'] = $id;
     $this->info['code'] = $station['code'];
     $this->info['name'] = $station['name'];
     $this->info['host'] = $station['ip'];
     $this->info['port'] = $station['port'];
     $this->info['change_status'] = $station['change_equipment_status'];
     return $station;
 }
Example #4
0
 public function findStation($id)
 {
     $station = Station::findOne($id);
     if (!$station) {
         return false;
     }
     return $station;
 }
Example #5
0
 public function sendMessage()
 {
     if (Yii::$app->request->isAjax) {
         $post = Yii::$app->request->post();
         if (isset($post['id']) && $post['id'] > 0) {
             $station = Station::findOne($post['id']);
             $ip = $station['ip'];
             $port = $station['port'];
             if ($ip != '' && $port != '') {
                 $client = new Client();
                 $init = $client->init($ip, $port);
                 if ($init) {
                     $send = $client->send($post['message']);
                     if ($send) {
                         print $client->returnMessage;
                     } else {
                         print $client->error;
                     }
                 } else {
                     print $client->error;
                 }
             }
         }
     }
     print 'failed';
 }