public function actionIndex()
 {
     if (!Setting::Get('apiKey', 'dropbox')) {
         return $this->render('errorMissingKey', array());
     }
     $model = new CreateDropboxPostForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $dropboxPost = new DropboxPost();
         $dropboxPost->message = $model->message;
         $dropboxPost->content->container = $this->contentContainer;
         $dropboxPost->content->visibility = $this->contentContainer->visibility;
         $dropboxPost->save();
         $dropboxFileIds = explode(",", $model->dropboxFileId);
         foreach ($dropboxFileIds as $dropboxFileId) {
             if ($dropboxFileId != null) {
                 $dropboxFile = DropboxFile::findOne(['id' => $dropboxFileId]);
                 if ($dropboxFile->object_model != DropboxPost::className() || $dropboxFile->object_id != $dropboxPost->id) {
                     $dropboxFile->object_model = DropboxPost::className();
                     $dropboxFile->object_id = $dropboxPost->id;
                     $dropboxFile->save();
                 }
             }
         }
         return $this->htmlRedirect($this->contentContainer->createUrl());
     }
     return $this->render('index', array('model' => $model));
 }
 /**
  * This validator function checks the dropboxFileId.
  *
  * @param type $attribute
  * @param type $params
  */
 public function checkDropboxFileId($attribute, $params)
 {
     if ($this->dropboxFileId != "") {
         foreach (explode(',', $this->dropboxFileId) as $fileId) {
             if ($fileId != "") {
                 $dropboxFile = DropboxFile::findOne(array('id' => $fileId));
                 if ($dropboxFile == null) {
                     $this->addError($attribute, Yii::t('DropboxModule.forms_CreateDropboxPostForm', "Invalid file"));
                 }
             }
         }
     }
 }
 public function actionDeleteFile()
 {
     Yii::$app->response->format = 'json';
     $this->forcePostRequest();
     $dropboxFile = DropboxFile::findOne(['id' => Yii::$app->request->post('id')]);
     // Json Array
     $json = array();
     $json['success'] = false;
     if ($dropboxFile && $dropboxFile->canDelete() && $dropboxFile->delete()) {
         $json['success'] = true;
     }
     return $json;
 }
 public function getFiles()
 {
     return $this->hasMany(DropboxFile::className(), ['object_id' => 'id'])->andWhere(['dropbox_file.object_model' => DropboxPost::className()]);
 }
$this->registerJsVar('warning_on_posting_modal_message', Yii::t('DropboxModule.widgets_DropboxFileListerWidget', 'The files you want to share are private. In order to share files in your space we have generated a shared link. Everyone with the link can see the file.<br/>Are you sure you want to share?'));
$this->registerJsVar('unset_warning_on_posting_checkbox_label', Yii::t('DropboxModule.widgets_DropboxFileListerWidget', 'Do not show this warning in future'));
$this->registerJsVar('warning_on_posting_modal_confirm', Yii::t('DropboxModule.widgets_DropboxFileListerWidget', "Yes, I\\'m sure"));
$this->registerJsVar('warning_on_posting_modal_cancel', Yii::t('DropboxModule.widgets_DropboxFileListerWidget', 'Cancel'));
?>
<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="<?php 
echo Setting::Get('apiKey', 'dropbox');
?>
"></script>

<script type="text/javascript">
    $(document).ready(function () {
        init();
<?php 
foreach (explode(",", $currentValue) as $id) {
    $dropboxFile = DropboxFile::findOne(['dropbox_file.id' => trim($id)]);
    if ($dropboxFile != null) {
        ?>
                addToFileList("<?php 
        echo $dropboxFile->id;
        ?>
", "<?php 
        echo $dropboxFile->name;
        ?>
");
        <?php 
    }
}
?>
    });
</script>
 /**
  * Returns all files belongs to a given HActiveRecord Object.
  * 
  * @param HActiveRecord $object
  * @return Array of DropboxImage instances
  */
 public static function getFilesOfObject(HActiveRecord $object)
 {
     return DropboxFile::findAll(array('object_id' => $object->getPrimaryKey(), 'object_model' => get_class($object)));
 }