/** 
  * Private method that handles assinging
  * karma to a user
  * @param string $karma_name
  * @param int $user_id
  * @return bool
  */
 public function addKarma($karma_name, $user_id)
 {
     // First find the karma record
     $karma = Karma::findOne(['name' => $karma_name]);
     if ($karma) {
         KarmaUser::attachKarma($user_id, $karma->id);
         return true;
     } else {
         return false;
     }
 }
 public function search($params)
 {
     $query = KarmaUser::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // load the search form data and validate
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     // adjust the query by adding the filters
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['user_id' => $this->user_id]);
     $query->andFilterWhere(['karma_id' => $this->karma_id]);
     return $dataProvider;
 }
Exemple #3
0
?>
">
                <span class="pull-left profile-size-sm">
                    <img class="media-object img-rounded profile-size-sm"
                     src="<?php 
echo $user->getProfileImage()->getUrl();
?>
"
                     height="32" width="32" alt="32x32" data-src="holder.js/32x32"/>
                    <div class="profile-overlay-img profile-overlay-img-sm"></div>
                </span>
            </a>
            <div class="user-title pull-left">
                <strong>
                    <?php 
echo Html::encode($user->displayName);
?>
                    <?php 
if (isset(Yii::$app->modules['karma'])) {
    echo "(" . KarmaUser::score($user->id) . ")";
}
?>
                </strong><br/><span class="truncate"><?php 
echo Html::encode($user->profile->title);
?>
</span>
            </div>
        </div>
    </div>
    
</div>
<?php

/**
 * Connected Communities Initiative
 * Copyright (C) 2016 Queensland University of Technology
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
use humhub\modules\karma\models\KarmaUser;
?>
<div class="pull-left entry">
    <span class="count"><?php 
echo KarmaUser::score($user->id);
?>
</span><br>
    <span class="title">Karma Score</span>
</div>
 /** 
  * Attaches karam to a user
  * @param int $user_id
  * @param int $karma_id
  * @return bool
  */
 public static function attachKarma($user_id, $karma_id)
 {
     $karma = new KarmaUser();
     $karma->user_id = $user_id;
     $karma->karma_id = $karma_id;
     if ($karma->validate()) {
         $karma->save();
         return true;
     } else {
         return false;
     }
 }