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($subscriptions, $charasteristicsIndex)
 {
     $subscription = new SubscriptionData();
     $subscriptionCount = 0;
     $subscriptionModels = array();
     foreach ($subscriptions as $subscriptiondata) {
         if ($subscriptionDataModel = \app\models\SubscriptionData::find()->where(array('charasteristic' => $charasteristicsIndex, 'datetime' => $subscriptiondata['datetime'], 'value' => $subscriptiondata['value']))->one()) {
             $subscriptiondata = array_merge($subscriptiondata, array('charasteristic' => $charasteristicsIndex));
             //die(print_r($subscriptiondata,true));
             $subscriptionDataModel->setattributes($subscriptiondata);
             $subscriptionModels[] = $subscriptionDataModel;
             //if ($subscriptionDataModel->save()) {
             //++$subscriptionCount;
             //}
             /* else {
                return $subscriptionDataModel->getErrors();
                } */
         }
     }
     $subscription->saveAll($subscriptionModels);
     return sizeof($subscriptions);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSubscriptionDatas()
 {
     return $this->hasMany(SubscriptionData::className(), ['charasteristic' => 'id']);
 }