Beispiel #1
0
 /**
  * @return string|Response
  * @throws DbException
  */
 public function actionAsk()
 {
     $model = new Question();
     $userModel = new QaUser();
     if ($model->load($_POST) && $userModel->load($_POST)) {
         $valid = $model->validate();
         $valid = $userModel->validate() && $valid;
         if (!$valid) {
             return $this->render('ask', compact(['model', 'userModel']));
         }
         if (!$model->save()) {
             throw new DbException(Module::t('main', 'Error create question'));
         }
         if (!$userModel->save()) {
             throw new DbException(Module::t('main', 'Error save username'));
         }
         $model->user_id = $userModel->id;
         if (!$model->save()) {
             throw new DbException(Module::t('main', 'Error saving user id'));
         }
         Yii::$app->session->setFlash('questionFormSubmitted');
         return $this->redirect(Url::to(['view', 'id' => $model->id, 'alias' => $model->alias]));
     } else {
         return $this->render('ask', compact(['model', 'userModel']));
     }
 }
Beispiel #2
0
 /**
  * @return string
  * @throws Exception
  */
 public function run()
 {
     /** @var Question $model */
     $model = $this->getModel();
     if ($model->load($_POST)) {
         if ($model->haveDraft($_POST)) {
             $model->status = QuestionInterface::STATUS_DRAFT;
         }
         if (!$model->save()) {
             throw new Exception(Module::t('main', 'Error create question'));
         }
         $this->trigger(self::EVENT_SUBMITTED);
         return $this->controller->redirect([$this->viewRoute, 'id' => $model->id]);
     } else {
         return $this->render(compact('model'));
     }
 }
Beispiel #3
0
 /**
  * @param $id
  * @throws ForbiddenHttpException
  * @throws Exception
  * @throws NotFoundHttpException
  * @return string
  */
 public function run($id)
 {
     /** @var Question $model */
     $model = $this->findModel($this->modelClass, $id);
     if ($model->isAuthor()) {
         if ($model->load($_POST)) {
             if ($model->haveDraft($_POST)) {
                 $model->status = QuestionInterface::STATUS_DRAFT;
             } else {
                 $model->status = QuestionInterface::STATUS_PUBLISHED;
             }
             if (!$model->save()) {
                 throw new Exception(Module::t('main', 'Error save question'));
             }
             $this->trigger(self::EVENT_SUBMITTED);
             return $this->controller->redirect([$this->viewRoute, 'id' => $model->id]);
         }
         return $this->render(compact('model'));
     }
     return $this->forbiddenException();
 }
Beispiel #4
0
    ?>
            <?php 
    foreach ($models as $model) {
        ?>
                <li class="list-group-item">
                    <a href="<?php 
        echo Module::url(['/qa/default/view', 'id' => $model->question->id, 'alias' => $model->question->alias]);
        ?>
">
                        <?php 
        echo Html::encode($model->question->title);
        ?>
                    </a>
                </li>
            <?php 
    }
    ?>
        <?php 
} else {
    ?>
            <li class="list-group-item"><?php 
    echo Module::t('main', 'No favorite questions');
    ?>
</li>
        <?php 
}
?>
    </ul>
</div>

Beispiel #5
0
<?php

use artkost\qa\Module;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$action = isset($action) ? $action : '';
/** @var ActiveForm $form */
$form = ActiveForm::begin(['id' => 'answer-form', 'action' => $action]);
?>

<?php 
echo $form->errorSummary($model);
?>

<?php 
echo $form->field($model, 'content')->textarea(['rows' => 6])->hint(Module::t('main', 'Markdown powered content'))->label('');
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Module::t('main', 'Answer') : Module::t('main', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

<?php 
ActiveForm::end();
Beispiel #6
0
 /**
  * Formatted user
  * @return int
  */
 public function getUserName()
 {
     return $this->user ? Module::getInstance()->getUserName($this->user, 'id') : $this->user_id;
 }
Beispiel #7
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return ['id' => Module::t('model', 'ID'), 'user_id' => Module::t('model', 'User ID'), 'question_id' => Module::t('model', 'Question ID'), 'created_at' => Module::t('model', 'Created At'), 'created_ip' => Module::t('model', 'Created Ip')];
 }
Beispiel #8
0
 /**
  * @return null
  * @throws ForbiddenHttpException
  */
 protected function forbiddenException()
 {
     throw new ForbiddenHttpException(Module::t('main', 'You are not allowed to perform this action.'));
 }
Beispiel #9
0
<?php

/**
 * @var \app\modules\qa\models\Answer $model
 * @var \app\modules\qa\models\QaUser $userModel
 * @var \app\modules\qa\models\Question $question
 */
use artkost\qa\Module;
use yii\helpers\Url;
$this->title = Module::t('main', 'Answer to {title}', ['title' => $question->title]);
$this->params['breadcrumbs'][] = ['label' => Module::t('main', 'Questions'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $question->title, 'url' => ['view', 'id' => $question->id, 'alias' => $question->alias]];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
    <div class="col-lg-12">
        <h1><?php 
echo $this->title;
?>
</h1>
        <div class="qa-view-answer-form">
            <?php 
echo $this->render(Url::to('/default/parts/form-answer'), ['model' => $model, 'userModel' => $userModel, 'action' => Module::url(['answer', 'id' => $model->question->id])]);
?>
        </div>
    </div>
</div>

Beispiel #10
0
?>
</span>
    <?php 
if (Vote::isUserCan($model, $userId)) {
    ?>
        <a class="qa-vote-down js-vote-down"
           href="<?php 
    echo Module::url([$route, 'id' => $model->id, 'vote' => 'down']);
    ?>
"
           title="<?php 
    echo Module::t('main', 'Vote down');
    ?>
">
            <span class="glyphicon glyphicon-chevron-down"></span>
        </a>
    <?php 
} else {
    ?>
        <span class="qa-vote-down qa-vote-down-disabled js-vote-down"
              title="<?php 
    echo Module::t('main', 'Vote down');
    ?>
">
            <span class="glyphicon glyphicon-chevron-down"></span>
        </span>
    <?php 
}
?>
</div>
Beispiel #11
0
    echo Module::url($editRoute);
    ?>
" title="<?php 
    echo Module::t('main', 'Edit');
    ?>
"
       class="label label-success"><span
            class="glyphicon glyphicon-pencil"></span></a>

    <?php 
    if ($model instanceof Question) {
        ?>
        <a href="<?php 
        echo Module::url($deleteRoute);
        ?>
" title="<?php 
        echo Module::t('main', 'Delete');
        ?>
"
           class="label label-danger"
           data-confirm="<?php 
        echo Module::t('main', 'Sure?');
        ?>
" data-method="post" data-pjax="0"><span
                class="glyphicon glyphicon-remove"></span></a>
    <?php 
    }
    ?>
    </span>
<?php 
}
Beispiel #12
0
?>
"><?php 
echo 'Все';
?>
</a></li>

        <li <?php 
echo $route == 'unanswered' ? 'class="active"' : '';
?>
><a
                href="<?php 
echo url::to(['unanswered']);
?>
"><?php 
echo 'Неосвещенные';
?>
</a></li>

        <li <?php 
echo $route == 'answered' ? 'class="active"' : '';
?>
><a
                href="<?php 
echo Module::url(['answered']);
?>
"><?php 
echo 'Отвеченные';
?>
</a></li>
    </ul>
</div>
Beispiel #13
0
            ?>
                        <small><span class="label label-default"><?php 
            echo Module::t('main', 'Draft');
            ?>
</span></small>
                    <?php 
        }
        ?>
                </h4>
                <div class="question-tags">
                    <?php 
        echo $this->render('tags-list', ['model' => $model]);
        ?>
                </div>
            </div>
        </div>
    <?php 
    }
} else {
    ?>
        <div class="list-group-item qa-item-not-found">
            <h4 class="list-group-item-heading question-heading"><?php 
    echo Module::t('main', 'No questions yet');
    ?>
</h4>
        </div>
    <?php 
}
?>
</div>
Beispiel #14
0
    ?>
" class="btn <?php 
    echo $answer->isCorrect() ? 'btn-warning' : 'btn-default';
    ?>
 btn-sm qa-answer-correct-link js-answer-correct-link"
           href="<?php 
    echo Module::url(['answer-correct', 'id' => $answer->id, 'questionId' => $question->id]);
    ?>
">
            <span class="glyphicon glyphicon-ok"></span>
        </a>
    <?php 
} else {
    ?>
        <?php 
    if ($answer->isCorrect()) {
        ?>
            <span title="<?php 
        echo Module::t('main', 'Answer is correct');
        ?>
" class="btn btn-warning btn-sm qa-answer-correct-button">
                <span class="glyphicon glyphicon-ok"></span>
            </span>
        <?php 
    }
    ?>
    <?php 
}
?>
</span>
Beispiel #15
0
</a></li>
        <?php 
if (!Yii::$app->user->isGuest) {
    ?>
            <li <?php 
    echo $route == 'my' ? 'class="active"' : '';
    ?>
><a
                    href="<?php 
    echo Module::url(['my']);
    ?>
"><?php 
    echo Module::t('main', 'My');
    ?>
</a></li>
            <li <?php 
    echo $route == 'favorite' ? 'class="active"' : '';
    ?>
><a
                    href="<?php 
    echo Module::url(['favorite']);
    ?>
"><?php 
    echo Module::t('main', 'Favorite');
    ?>
</a></li>
        <?php 
}
?>
    </ul>
</div>
Beispiel #16
0
<?php

use artkost\qa\Module;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$action = isset($action) ? $action : '';
/** @var ActiveForm $form */
$form = ActiveForm::begin(['id' => 'answer-form', 'action' => $action, 'enableClientValidation' => true]);
?>

<?php 
echo $form->errorSummary([$model, $userModel]);
?>

<?php 
echo $form->field($userModel, 'username')->textInput();
?>

<?php 
echo $form->field($model, 'content')->textarea(['rows' => 6])->hint(Module::t('main', 'Markdown powered content'));
?>

    <div class="form-group">
        <?php 
echo Html::submitButton(Module::t('main', 'Answer'), ['class' => 'btn btn-success']);
?>
    </div>

<?php 
ActiveForm::end();
Beispiel #17
0
echo $form->field($model, 'tags')->autoComplete($autocompleteRoute)->textInput()->hint(Module::t('main', 'Comma separated list of tags'));
?>

    <div class="form-group">
        <div class="btn-group btn-group-lg">
            <button type="submit" name="draft" class="btn"><?php 
echo Module::t('main', 'Draft');
?>
</button>
            <?php 
if ($model->isNewRecord) {
    ?>
                <button type="submit" name="submit" class="btn btn-primary"><?php 
    echo Module::t('main', 'Publish');
    ?>
</button>
            <?php 
} else {
    ?>
                <button type="submit" name="update" class="btn btn-success"><?php 
    echo Module::t('main', 'Update');
    ?>
</button>
            <?php 
}
?>
        </div>
    </div>

<?php 
ActiveForm::end();
Beispiel #18
0
    <?php 
if (Vote::isUserCan($model, $userId)) {
    ?>
        <a class="btn btn-success btn-sm js-vote-up"
           href="<?php 
    echo Module::url([$route, 'id' => $model->id, 'vote' => 'up']);
    ?>
"
           title="<?php 
    echo Module::t('main', 'Like');
    ?>
">
            <span class="glyphicon glyphicon-heart"></span> <?php 
    echo $model->votes;
    ?>
        </a>
    <?php 
} else {
    ?>
        <span class="btn btn-success btn-sm disabled js-vote-up" title="<?php 
    echo Module::t('main', 'Like');
    ?>
">
            <span class="glyphicon glyphicon-heart"></span> <?php 
    echo $model->votes;
    ?>
        </span>
    <?php 
}
?>
</span>
Beispiel #19
0
<?php

/**
 * @var \artkost\qa\models\Question $model
 * @var string $route
 */
use artkost\qa\Module;
?>
<div class="qa-favorite js-favorite <?php 
echo $model->isFavorite() ? 'qa-favorite-active' : '';
?>
">
    <a title="<?php 
echo Module::t('main', 'Add to favorite');
?>
" class="qa-favorite-link js-favorite-link"
       href="<?php 
echo Module::url(['question-favorite', 'id' => $model->id]);
?>
">
        <span class="glyphicon <?php 
echo $model->isFavorite() ? 'glyphicon-star' : 'glyphicon-star-empty';
?>
"></span>
    </a>
</div>
Beispiel #20
0
use artkost\qa\Module;
use yii\helpers\Html;
?>

<div class="panel panel-default">
    <div class="panel-heading"><?php 
echo Module::t('main', 'Popular tags');
?>
</div>
    <div class="panel-body">
        <span class="qa-tags">
            <?php 
foreach ($models as $tag) {
    ?>
                <a href="<?php 
    echo Module::url(['/qa/default/tags', 'tags' => $tag['name']]);
    ?>
"
                   class="label label-primary"
                   title="<?php 
    echo Html::encode($tag['name']);
    ?>
"
                   rel="tag"><?php 
    echo Html::encode($tag['name']);
    ?>
</a>
            <?php 
}
?>
        </span>
Beispiel #21
0
/* @var $model app\modules\qa\models\Question */
/* @var $form ActiveForm */
$form = ActiveForm::begin(['id' => 'question-form', 'enableClientValidation' => true]);
?>

<?php 
echo $form->errorSummary([$model, $userModel]);
?>

<?php 
echo $form->field($model, 'title')->textInput()->hint(Module::t('main', "What's your question? Be specific."));
?>

<?php 
echo $form->field($userModel, 'username')->textInput();
?>

<?php 
echo $form->field($model, 'content')->textarea(['rows' => 5])->hint(Module::t('main', 'Markdown powered content'));
?>

    <div class="form-group">
        <div class="btn-group ">
            <?php 
echo Html::submitButton(Module::t('main', 'Publish'), ['class' => 'btn btn-primary']);
?>
        </div>
    </div>

<?php 
ActiveForm::end();
Beispiel #22
0
                <li class="list-group-item">
                    <a href="<?php 
        echo Module::url(['/qa/default/view', 'id' => $model->id, 'alias' => $model->alias]);
        ?>
"
                       title="<?php 
        echo Html::encode($model->title);
        ?>
">
                        <?php 
        echo Html::encode($model->title);
        ?>
                    </a>
                </li>
            <?php 
    }
    ?>
        <?php 
} else {
    ?>
            <li class="list-group-item"><?php 
    echo Module::t('main', 'No popular questions');
    ?>
</li>
        <?php 
}
?>
    </ul>
</div>

Beispiel #23
0
<?php

use artkost\qa\Module;
$this->title = Module::t('main', 'Edit {title}', ['title' => $model->title]);
$this->params['breadcrumbs'][] = ['label' => Module::t('main', 'Questions'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="row">
    <div class="col-lg-12">
        <h1><?php 
echo $this->title;
?>
</h1>
        <?php 
echo $this->render('parts/form-question', ['model' => $model]);
?>
    </div>
</div>
Beispiel #24
0
<?php

/**
 * @var \artkost\qa\models\Question[] $models
 * @var \yii\data\ActiveDataProvider $dataProvider
 */
use artkost\qa\Module;
$this->title = Module::t('main', 'Questions');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="qa-index">
    <div class="row">
        <div class="col-md-12">
            <?php 
echo $this->render('_tabs', ['route' => $this->context->action->id]);
?>
            <?php 
echo $this->render('parts/list', ['models' => $models]);
?>
        </div>
    </div>
    <?php 
echo $dataProvider ? $this->render('parts/pager', ['dataProvider' => $dataProvider]) : false;
?>
</div>


Beispiel #25
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return ['id' => Module::t('model', 'ID'), 'name' => Module::t('model', 'Name'), 'frequency' => Module::t('model', 'Frequency')];
 }
Beispiel #26
0
    ?>
 col-md-10">
                    <section class="panel-body">
                        <div class="qa-view-text">
                            <?php 
    echo $row->body;
    ?>
                        </div>
                    </section>
                </section>
            </article>

        <?php 
}
?>
        </div>

        <div class="qa-view-answer-pager">
            <?php 
echo $this->render('parts/pager', ['dataProvider' => $answerDataProvider]);
?>
        </div>

        <div class="qa-view-answer-form">
            <?php 
echo $this->render('parts/form-answer', ['model' => $answer, 'action' => Module::url(['answer', 'id' => $model->id])]);
?>
        </div>
    </div>
</section>
Beispiel #27
0
<?php

/**
 * @var \artkost\qa\models\Question $model
 */
use artkost\qa\Module;
use yii\helpers\Html;
?>

<span class="qa-tags">
    <?php 
foreach ($model->tagsList as $tag) {
    ?>
        <a href="<?php 
    echo Module::url(['tags', 'tags' => $tag]);
    ?>
" class="label label-primary" title="<?php 
    echo Html::encode($tag);
    ?>
"
           rel="tag"><?php 
    echo Html::encode($tag);
    ?>
</a>
    <?php 
}
?>
</span>