Ejemplo n.º 1
0
 public function updatePowerStatus()
 {
     // get all power equipments of this station
     $powerEquips = PowerStatus::findAll(['station_id' => $this->request['id']]);
     if (!empty($powerEquips)) {
         $i = 0;
         foreach ($powerEquips as $equip) {
             $value = $this->request['power'][$i];
             Yii::$app->db->createCommand()->update('power_status', ['status' => $value], ['id' => $equip['id']])->execute();
             $i++;
         }
     }
 }
Ejemplo n.º 2
0
 public function getPowerStatuses()
 {
     return $this->hasMany(PowerStatus::className(), ['item_id' => 'id']);
 }
Ejemplo n.º 3
0
 private function setPowerEquipment($ids, $model)
 {
     if (!empty($ids) && $model->id > 0) {
         // delete excess equipment
         $excessIds = array_diff($model->power_equipment, $ids);
         if (!empty($excessIds)) {
             foreach ($excessIds as $excessId) {
                 PowerStatus::deleteAll(['item_id' => $excessId, 'station_id' => $model->id]);
             }
         }
         // add new equipment
         $newIds = array_diff($ids, $model->power_equipment);
         if (!empty($newIds)) {
             foreach ($newIds as $newId) {
                 $data[] = [$newId, $model->id];
             }
             Yii::$app->db->createCommand()->batchInsert('power_status', ['item_id', 'station_id'], $data)->execute();
         }
     }
 }