/** * Draws the Upload Button output. */ public function run() { $objectModel = ""; $objectId = ""; if ($this->object !== null) { $objectModel = $this->object->className(); $objectId = $this->object->getPrimaryKey(); } return $this->render('embeddedMediaUploadButton', array('fileListFieldName' => $this->fileListFieldName, 'uploaderId' => $this->uploaderId, 'objectModel' => $objectModel, 'objectId' => $objectId)); }
/** * Attaches a given list of files to an record (HActiveRecord). * This is used when uploading files before the record is created yet. * * @param HActiveRecord $object is a HActiveRecord * @param string $files is a comma seperated list of newly uploaded file guids */ public static function attachPrecreated($object, $files) { if (!$object instanceof \yii\db\ActiveRecord) { throw new Exception("Invalid object given - require instance of HActiveRecord!"); } // Attach Files foreach (explode(",", $files) as $fileGuid) { $file = self::findOne(['guid' => trim($fileGuid)]); if ($file != null && $file->object_model == "") { $file->object_model = $object->className(); $file->object_id = $object->getPrimaryKey(); if (!$file->save()) { throw new Exception("Could not save precreated file!"); } } } }