/** * * @param type $fieldName * @return Uploads\models\UploadsCollection */ protected function getOwnersCollectionByFieldName($fieldName) { if (!isset($this->ownersCollection[$fieldName])) { $colection = new UploadsCollection(); if ($this->ownerCollectionExists($fieldName)) { $collectionId = (int) $this->behavior->owner->getOldAttribute($fieldName); $colection->setAttribute('id', $collectionId); $colection->loadDefaultValues(); $colection->isNewRecord = false; } $this->ownersCollection[$fieldName] = $colection; } return $this->ownersCollection[$fieldName]; }
public static function saveNewFilesFromCollection(UploadsCollection $collection) { $toInsert = []; $command = \yii::$app->db->createCommand(); foreach ($collection->getNewFiles() as $file) { $file->save(); $toInsert[] = [$collection->id, (string) $file]; } return $command->batchInsert(self::TABLE_NAME, ['collection_id', 'filepath'], $toInsert)->execute(); }