public function import($charasteristicsArray, $serviceIndex) { $subscriptionCount = 0; foreach ($charasteristicsArray as $charasteristics) { if (isset($charasteristics['charasteristicUuid']) && is_array($charasteristics['charasteristicUuid'])) { $charasteristics['charasteristicUuid'] = $charasteristics['charasteristicUuid'][0]; } if (!($charasteristicsModel = Charasteristic::find()->where(array('service' => $serviceIndex, 'charasteristicUuid' => $charasteristics['charasteristicUuid']))->one())) { $charasteristicsModel = new Charasteristic(); } $charasteristics = array_merge($charasteristics, array('service' => $serviceIndex)); $charasteristicsModel->setattributes($charasteristics); if ($charasteristicsModel->save()) { $charasteristicsIndex = $charasteristicsModel->getPrimaryKey(); //return $charasteristicsIndex; //die(print_r($charasteristics,true)); if (isset($charasteristics['subscriptionData'])) { $subscriptionCount += \app\models\SubscriptionData::import($charasteristics['subscriptionData'], $charasteristicsIndex); } } else { die(print_r($charasteristicsModel->getErrors(), true)); } } return $subscriptionCount; }
public function import($services, $deviceIndex) { $subscriptionCount = 0; foreach ($services as $service) { if (isset($service['serviceUuid']) && is_array($service['serviceUuid'])) { $service['serviceUuid'] = $service['serviceUuid'][0]; } if (!($serviceModel = Service::find()->where(array('device' => $deviceIndex, 'serviceUuid' => $service['serviceUuid']))->one())) { $serviceModel = new Service(); } $service = array_merge($service, array('device' => $deviceIndex)); $serviceModel->setAttributes($service); if ($serviceModel->save()) { $serviceIndex = $serviceModel->getPrimaryKey(); if (isset($service['charasteristics'])) { $subscriptionCount += \app\models\Charasteristic::import($service['charasteristics'], $serviceIndex); } } //else { //die(print_r( $serviceModel->getErrors(),true)); //} } return $subscriptionCount; }
/** * @return \yii\db\ActiveQuery */ public function getCharasteristics() { return $this->hasMany(Charasteristic::className(), ['service' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getCharasteristic0() { return $this->hasOne(Charasteristic::className(), ['id' => 'charasteristic']); }