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));
 }
 /**
  * @inheritdoc
  */
 public function disable()
 {
     foreach (DropboxPost::find()->all() as $post) {
         $post->delete();
     }
     parent::disable();
 }
 public function actionEdit()
 {
     $id = Yii::$app->request->get('id');
     $dropboxPost = DropboxPost::findOne(['id' => $id]);
     $form = new \humhub\modules\dropbox\models\CreateDropboxPostForm();
     $form->message = $dropboxPost->message;
     $fileIds = "";
     foreach ($dropboxPost->files as $file) {
         $fileIds .= $file->id . ",";
     }
     $form->dropboxFileId = $fileIds;
     if (!$dropboxPost->content->canWrite()) {
         throw new HttpException(403, Yii::t('DropboxModule.controllers_DropboxController', 'Access denied!'));
     }
     if ($form->load(Yii::$app->request->post()) && $form->validate()) {
         $dropboxPost->message = $form->message;
         $dropboxPost->save();
         $dropboxPost = DropboxPost::findOne(['id' => $id]);
         $dropboxFileIds = explode(",", $form->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 $dropboxPost->getWallOut();
     }
     return $this->renderAjax('edit', array('model' => $form, 'dropboxPost' => $dropboxPost, 'id' => $dropboxPost->id));
 }
 public function up()
 {
     $this->renameClass('DropboxPost', DropboxPost::className());
     $this->update('dropbox_file', ['object_model' => DropboxPost::className()]);
     foreach (\humhub\modules\activity\models\Activity::findAll(['module' => 'dropbox']) as $activity) {
         $activity->delete();
     }
 }
 public function getFiles()
 {
     return $this->hasMany(DropboxFile::className(), ['object_id' => 'id'])->andWhere(['dropbox_file.object_model' => DropboxPost::className()]);
 }