Esempio n. 1
0
 /**
  * Increment or decrement votes of model by given type
  * @param ActiveRecord $model
  * @param string $type can be 'up' or 'down'
  * @param string $partial template name
  * @param string $format
  * @return Response
  */
 protected function entityVote($model, $type, $partial = 'parts/vote', $format = 'json')
 {
     $data = ['status' => false];
     if ($model && Vote::isUserCan($model, Yii::$app->user->id)) {
         $data = ['status' => true, 'html' => $this->controller->renderPartial($partial, ['model' => Vote::process($model, $type)])];
     }
     if (Yii::$app->request->isAjax) {
         return new Response(['data' => $data, 'format' => $format]);
     }
     return $this->controller->redirect([$this->viewRoute, 'id' => $model['id']]);
 }
Esempio n. 2
0
 /**
  * This is invoked after the record is deleted.
  */
 public function afterDelete()
 {
     parent::afterDelete();
     Question::decrementAnswers($this->question_id);
     Vote::removeRelation($this);
 }
Esempio n. 3
0
 /**
  * This is invoked after the record is deleted.
  */
 public function afterDelete()
 {
     parent::afterDelete();
     Tag::updateFrequency($this->tags, '');
     Vote::removeRelation($this);
     Answer::removeRelation($this->id);
 }
Esempio n. 4
0
File: like.php Progetto: faninv/gtqa
<?php

/**
 * @var \yii\db\ActiveRecord $model
 * @var string $route
 */
use artkost\qa\models\Vote;
use artkost\qa\Module;
$userId = Yii::$app->user->id;
?>
<span class="qa-like js-vote">
    <?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 
 public function down()
 {
     $this->dropTable(Vote::tableName());
 }