Skip to content

Commit

Permalink
2018
Browse files Browse the repository at this point in the history
  • Loading branch information
cuileon committed Apr 25, 2018
1 parent 4c94733 commit bb5a4b5
Show file tree
Hide file tree
Showing 100 changed files with 1,707 additions and 3,540 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ phpunit.phar

# vagrant runtime
/.vagrant

# views and widgets
/frontend/views
/frontend/widgets
16 changes: 8 additions & 8 deletions backend/controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public function behaviors()
* Lists all Post models.
* @return mixed
*/
public function actionIndex($node_id)
public function actionIndex($id)
{
$searchModel = new PostSearch();
$queryParams = Yii::$app->request->queryParams;
$queryParams['PostSearch']['node_id'] = $node_id;
$queryParams['PostSearch']['pubport_id'] = $id;
$dataProvider = $searchModel->search($queryParams);

return $this->render('index', [
'node_id' => $node_id,
'id' => $id,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
Expand All @@ -74,18 +74,18 @@ public function actionView($id)
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($node_id)
public function actionCreate($id)
{
$post = new Post();
$post->loadDefaultValues();
$post->node_id = $node_id;
$model = new $post->node->typeClass;
$post->pubport_id = $id;
$model = new $post->pubport->node->typeClass;

if ($post->load(Yii::$app->request->post()) && $model->load(Yii::$app->request->post())) {
Yii::$app->db->transaction(function() use($post, $model) {
$post->save() && $post->link($post->node->typeName, $model);
$post->save() && $post->link($post->pubport->node->typeName, $model);
});
return $this->redirect(['index', 'node_id' => $node_id]);
return $this->redirect(['index', 'id' => $id]);
} else {
return $this->render('create', [
'post' => $post,
Expand Down
124 changes: 124 additions & 0 deletions backend/controllers/PubportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace backend\controllers;

use Yii;
use common\models\Pubport;
use backend\models\PubportSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;

/**
* NodeConfigController implements the CRUD actions for NodeConfig model.
*/
class PubportController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}

/**
* Lists all Node models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new PubportSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}

/**
* Creates a new NodeConfig model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Pubport();
$model->loadDefaultValues();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}

/**
* Updates an existing Node model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', Yii::t('app', 'Operation success.'));
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}

/**
* Deletes an existing Node model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();

return $this->redirect(['index']);
}

/**
* Finds the Node model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Node the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Pubport::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
6 changes: 4 additions & 2 deletions backend/controllers/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function actionCreate()
$model = new Template();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
file_put_contents(Yii::getAlias('@frontend/views/' . $model->key) . '.php', $model->content);
return $this->redirect(['update', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
Expand All @@ -95,7 +96,8 @@ public function actionUpdate($id)
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
file_put_contents(Yii::getAlias('@frontend/views/' . $model->key) . '.php', $model->content);
return $this->redirect(['update', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

namespace app\modules\user\controllers;
namespace backend\controllers;

use Yii;
use common\models\Message;
use common\models\User;
use yii\data\ActiveDataProvider;
use common\models\Widget;
use backend\models\WidgetSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;

/**
* MessageController implements the CRUD actions for Message model.
* WidgetController implements the CRUD actions for Widget model.
*/
class MessageController extends Controller
class WidgetController extends Controller
{
/**
* @inheritdoc
Expand All @@ -27,92 +26,87 @@ public function behaviors()
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
'delete' => ['POST'],
],
],
];
}

/**
* Lists all Message models.
* Lists all Widget models.
* @return mixed
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => Message::find()->where(['to_id' => Yii::$app->user->id])->orWhere(['from_id' => Yii::$app->user->id])->andWhere(['parent_id' => 0])->orderBy('id DESC'),
]);
$searchModel = new WidgetSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}

/**
* Displays a single Message model.
* Displays a single Widget model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$model = $this->findModel($id);

if($model->from_id != Yii::$app->user->id && $model->to_id != Yii::$app->user->id) {
throw new NotFoundHttpException('The requested page does not exist.');
}
$message = new Message;
$to_id = Yii::$app->user->id == $model->from_id ? $model->to_id : $model->from_id;
$to = User::findOne($to_id);
$message->to_id = $to->username;
$message->parent_id = $id;

$dataProvider = new ActiveDataProvider([
'query' => Message::find()->where(['id' => $id])->orWhere(['parent_id' => $id]),
]);

if ($message->load(Yii::$app->request->post()) && $message->save()) {
return $this->refresh();
}

return $this->render('view', [
'message' => $message,
'model' => $model,
'dataProvider' => $dataProvider,
'model' => $this->findModel($id),
]);
}

/**
* Creates a new Message model.
* Creates a new Widget model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($id = null)
public function actionCreate()
{
$model = new Message();
$model = new Widget();

if(!empty($id)) {
$user = User::find()->where(['id' => $id])->one();
$model->to_id = $user->username;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
file_put_contents(Yii::getAlias('@frontend/widgets/' . $model->name) . '.php', $model->content);
return $this->redirect(['update', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}

/**
* Updates an existing Widget model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
file_put_contents(Yii::getAlias('@frontend/widgets/' . $model->name) . '.php', $model->content);
return $this->redirect(['update', 'id' => $model->id]);
} else {
return $this->render('create', [
return $this->render('update', [
'model' => $model,
]);
}
}

/**
* Deletes an existing Message model.
* Deletes an existing Widget model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
Expand All @@ -125,15 +119,15 @@ public function actionDelete($id)
}

/**
* Finds the Message model based on its primary key value.
* Finds the Widget model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Message the loaded model
* @return Widget the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Message::findOne($id)) !== null) {
if (($model = Widget::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
Expand Down
4 changes: 2 additions & 2 deletions backend/models/PostSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PostSearch extends Post
public function rules()
{
return [
[['id', 'node_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['id', 'pubport_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['user_id'], 'safe'],
];
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public function search($params)
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'node_id' => $this->node_id,
'pubport_id' => $this->pubport_id,
'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
Expand Down
Loading

0 comments on commit bb5a4b5

Please sign in to comment.