/** * Checks if the given or current user can report post with given id. * * @param * int postId */ public static function canReportPost($postId, $userId = "") { if (Yii::$app->user->isGuest) { return false; } $post = Post::findOne(['id' => $postId]); if (!$post) { return false; } if ($userId != "") { $user = User::findOne(['id' => $userId]); } else { $user = Yii::$app->user->getIdentity(); } if (!$user) { return false; } if ($user->super_admin) { return false; } if ($post->created_by == $user->id) { return false; } if ($post->content->container instanceof Space && ($post->content->getContainer()->isAdmin($user->id) || $post->content->getContainer()->isAdmin($post->created_by))) { return false; } if (ReportContent::findOne(['object_model' => Post::className(), 'object_id' => $post->id, 'created_by' => $user->id]) !== null) { return false; } if (User::findOne(['id' => $post->created_by, 'super_admin' => 1]) !== null) { return false; } return true; }
public function actionEdit() { $id = Yii::$app->request->get('id'); $edited = false; $model = Post::findOne(['id' => $id]); if (!$model->content->canWrite()) { throw new HttpException(403, Yii::t('PostModule.controllers_PostController', 'Access denied!')); } if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) { // Reload record to get populated updated_at field $model = Post::findOne(['id' => $id]); return $this->renderAjaxContent($model->getWallOut(['justEdited' => true])); } return $this->renderAjax('edit', array('post' => $model, 'edited' => $edited)); }
/** * Get the post the file is connected to. * @param File $basefile the file. */ public static function getBasePost($file = null) { if ($file === null) { return null; } $searchItem = $file; // if the item is connected to a Comment, we have to search for the corresponding Post if ($file->object_model === Comment::className()) { $searchItem = Comment::findOne(['id' => $file->object_id]); } $return = Post::findOne(['id' => $searchItem->object_id]); }