redmine

parent dd34ca79
...@@ -4,6 +4,7 @@ namespace common\modules\support\controllers; ...@@ -4,6 +4,7 @@ namespace common\modules\support\controllers;
use Yii; use Yii;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\helpers\ArrayHelper;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
...@@ -47,18 +48,16 @@ class SupportController extends Controller ...@@ -47,18 +48,16 @@ class SupportController extends Controller
public function actionIndex() public function actionIndex()
{ {
$client = new \Redmine\Client('http://help-russia.ru', Yii::$app->support->identity->redmine_key); $client = $this->getClient();
$works = $client->issue->all([ $user = $client->user->getCurrentUser();
'author_id' => 23
$models = $client->issue->all([
'author_id' => $user['user']['id'],
]); ]);
return $this->render('index', [ return $this->render('index', [
'works' => $works, 'models' => $models,
// 'ratings' => $ratings,
// 'tests' => $tests,
// 'approves' => $approves,
// 'accepteds' => $accepteds,
]); ]);
} }
...@@ -77,9 +76,13 @@ class SupportController extends Controller ...@@ -77,9 +76,13 @@ class SupportController extends Controller
public function actionView($id) public function actionView($id)
{ {
$model = $this->findModel($id); $client = $this->getClient();
$user = $client->user->getCurrentUser();
$model = $client->issue->show($id);
if($model->author_id != Yii::$app->support->identity->support_id) if(empty($model['issue']) || $model['issue']['author']['id'] != $user['user']['id'])
{ {
throw new NotFoundHttpException('Доступ запрещен!'); throw new NotFoundHttpException('Доступ запрещен!');
} }
...@@ -89,22 +92,8 @@ class SupportController extends Controller ...@@ -89,22 +92,8 @@ class SupportController extends Controller
]); ]);
} }
/** protected function getClient()
* Finds the Post model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Post the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{ {
if (($model = Issue::findOne($id)) !== null) return $client = new \Redmine\Client(Settings::getValue('redmine-url'), Yii::$app->support->identity->redmine_key);
{
return $model;
}
else
{
throw new NotFoundHttpException('The requested page does not exist.');
}
} }
} }
<?php
namespace common\modules\support\models\redmine;
use common\models\Settings;
class IssueHelper
{
public static function sort($issues)
{
$settings = [
[
'statuses' => explode(',', Settings::getValue('support-status-work')),
'title' => 'Задачи в работе',
],
[
'statuses' => explode(',', Settings::getValue('support-status-new')),
'title' => 'Задачи на оценке',
],
[
'statuses' => explode(',', Settings::getValue('support-status-test')),
'title' => 'Задачи на тестировании',
],
[
'statuses' => explode(',', Settings::getValue('support-status-approve')),
'title' => 'Задачи ожидающие проверки',
],
[
'statuses' => explode(',', Settings::getValue('support-status-accepted')),
'title' => 'Закрытые задачи',
'close' => true
],
];
foreach ($issues as $issue)
{
foreach ($settings as &$setting)
{
if(in_array($issue['status']['id'], $setting['statuses']))
{
$setting['models'][] = $issue;
}
}
}
unset($setting);
return $settings;
}
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ use yii\helpers\Html; ...@@ -4,7 +4,7 @@ use yii\helpers\Html;
?> ?>
<?php if($output['issues']) : ?> <?php if($output) : ?>
<div class="panel-group panel-group-2" id="accordion_2"> <div class="panel-group panel-group-2" id="accordion_2">
<div class="panel panel-default"> <div class="panel panel-default">
...@@ -35,7 +35,7 @@ use yii\helpers\Html; ...@@ -35,7 +35,7 @@ use yii\helpers\Html;
</div> </div>
<div id="collapse_1" class="panel-collapse collapse in"> <div id="collapse_1" class="panel-collapse collapse in">
<?php foreach ($output['issues'] as $model) : ?> <?php foreach ($output as $model) : ?>
<div class="panel-body panel-body-ex-1 color_on_cursor gray_box_2"> <div class="panel-body panel-body-ex-1 color_on_cursor gray_box_2">
<table class="w100pr"> <table class="w100pr">
<tbody> <tbody>
......
...@@ -4,6 +4,8 @@ use yii\helpers\Html; ...@@ -4,6 +4,8 @@ use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use common\modules\support\models\redmine\IssueHelper;
?> ?>
<div class="client_interface"> <div class="client_interface">
...@@ -60,14 +62,22 @@ use yii\widgets\ActiveForm; ...@@ -60,14 +62,22 @@ use yii\widgets\ActiveForm;
<table class="table"> <table class="table">
<tr> <tr>
<td class="no_pad"> <td class="no_pad">
<?=$this->render('_loop', ['output' => $ratings, 'title' => 'Задачи на оценке']);?>
<?=$this->render('_loop', ['output' => $works, 'title' => 'Задачи в работе']);?>
<?=$this->render('_loop', ['output' => $tests, 'title' => 'Задачи на тестировании']);?>
<?=$this->render('_loop', ['output' => $approves, 'title' => 'Задачи ожидающие проверки']);?> <?php
$issues = IssueHelper::sort($models['issues']);
foreach ($issues as $issue)
{
if(!isset($issue['close']))
{
echo $this->render('_loop', ['output' => $issue['models'], 'title' => $issue['title']]);
}
else
{
$accepteds = $issue['models'];
}
}
?>
</td> </td>
</tr> </tr>
...@@ -87,7 +97,7 @@ use yii\widgets\ActiveForm; ...@@ -87,7 +97,7 @@ use yii\widgets\ActiveForm;
<input type="checkbox"> <input type="checkbox">
</label> </label>
<div class="text-mes"> <div class="text-mes">
<p><?=$model->subject?></p> <p><?=$model['subject']?></p>
</div> </div>
</div> </div>
......
...@@ -14,7 +14,7 @@ class m160304_091243_fix_user_table extends Migration ...@@ -14,7 +14,7 @@ class m160304_091243_fix_user_table extends Migration
public function safeDown() public function safeDown()
{ {
$this->renameTable('users', 'redmine_key', 'support_id'); $this->renameColumn('users', 'redmine_key', 'support_id');
$this->renameColumn('users', 'support_id', Schema::TYPE_INTEGER . '(11) DEFAULT NULL'); $this->renameColumn('users', 'support_id', Schema::TYPE_INTEGER . '(11) DEFAULT NULL');
} }
} }
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160310_063328_fix_support extends Migration
{
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
$this->insert('settings', [
'module_id' => 'support',
'code' => 'redmine-key',
'name' => 'Redmine Api Key',
'value' => 'bac5a4f334595be4ce4962e6428035041f47f569',
'element' => 'text',
'hidden' => 0,
'description' => 'Redmine Api Key',
]);
$this->insert('settings', [
'module_id' => 'support',
'code' => 'redmine-url',
'name' => 'Redmine Url',
'value' => 'http://help-russia.ru',
'element' => 'text',
'hidden' => 0,
'description' => 'Redmine Url',
]);
}
public function safeDown()
{
$this->delete('settings', ['code' => 'redmine-key']);
$this->delete('settings', ['code' => 'redmine-url']);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment