コード例 #1
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->title = ucfirst($this->title);
     $user_interest = new UsersInterests();
     $user_interest->user_id = Yii::$app->user->id;
     if (!($interest = Interests::findOne([Interests::FIELD_TITLE => $this->title]))) {
         $interest = new Interests();
         $interest->title = $this->title;
         $interest->save();
     }
     $user_interest->interest_id = $interest->interest_id;
     $user_interest->save();
     return true;
 }
コード例 #2
0
 public function actionDeleteUserInterest($interest_id)
 {
     UsersInterests::deleteAll([UsersInterests::FIELD_INTEREST_ID => $interest_id, UsersInterests::FIELD_USER_ID => Yii::$app->user->id]);
     //        If interest don't assign to another user, remove it
     if (!UsersInterests::findAll([UsersInterests::FIELD_INTEREST_ID => $interest_id])) {
         Interests::deleteAll([Interests::FIELD_INTEREST_ID => $interest_id]);
     }
     Yii::$app->session->setFlash('success', 'Interest deleted successfully');
     return $this->redirect('personal-details');
 }
コード例 #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('interests')->delete();
     Interests::create(['name' => 'Музыка']);
     Interests::create(['name' => 'Кино']);
     Interests::create(['name' => 'Спорт']);
     Interests::create(['name' => 'Литература']);
     Interests::create(['name' => 'Компьютерные игры']);
     Interests::create(['name' => 'Дизайн']);
     Interests::create(['name' => 'Фотография']);
     Interests::create(['name' => 'Танцы']);
     Interests::create(['name' => 'Моделирование']);
     Interests::create(['name' => 'Туризм']);
     Interests::create(['name' => 'Техника']);
 }
コード例 #4
0
 public function search($input)
 {
     $query = Interests::query();
     $columns = Schema::getColumnListing('interests');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
コード例 #5
0
ファイル: Functions.php プロジェクト: nilamdoc/OxOPDF
 public function sumInterest($user_id)
 {
     $mongodb = Connections::get('default')->connection;
     $interest = Interests::connection()->connection->command(array('aggregate' => 'interests', 'pipeline' => array(array('$project' => array('_id' => 0, 'interest' => '$interest', 'user_id' => '$user_id', 'username' => '$username')), array('$match' => array('user_id' => $user_id)), array('$group' => array('_id' => array('user_id' => '$user_id', 'username' => '$username'), 'interest' => array('$sum' => '$interest'))))));
     return compact('interest');
 }
コード例 #6
0
 public function getInterest()
 {
     return $this->hasOne(Interests::className(), [Interests::FIELD_INTEREST_ID => self::FIELD_INTEREST_ID]);
 }
コード例 #7
0
        <?php 
echo Html::ul($interests, ['class' => 'list-inline', 'item' => function ($item, $index) {
    /* @var $item UsersInterests */
    $delete_link = Html::a(FA::icon('times'), ['delete-user-interest', UsersInterests::FIELD_INTEREST_ID => $item->interest_id], ['data-confirm' => Yii::t('yii', 'Are you sure you want to delete "' . $item->interest->title . '" interest?')]);
    return Html::tag('li', '<div class="well well-sm">' . $item->interest->title . '&nbsp&nbsp' . $delete_link . '</div>');
}]);
?>
    </div>
</div>
<div class="row">
    <div class="col-sm-12 text-right">
        <?php 
$form_interest = ActiveForm::begin(['id' => 'interests-form', 'options' => ['class' => 'form-inline'], 'fieldConfig' => ['template' => "{input}"]]);
?>
            <?php 
echo $form_interest->field($interests_model, UsersInterestsForm::FIELD_TITLE)->widget(Typeahead::className(), ['dataset' => [['local' => ArrayHelper::getColumn(Interests::find()->all(), Interests::FIELD_TITLE), 'limit' => 10]], 'pluginOptions' => ['highlight' => true]]);
?>
            <?php 
echo Html::submitButton('Add', ['class' => 'btn btn-success', 'form' => 'interests-form']);
?>
        <?php 
ActiveForm::end();
?>
    </div>
</div>
<hr>
<div class="row">
    <div class="col-sm-6 text-left">
        <?php 
echo Html::a('Home', '/site/index', ['class' => 'btn btn-default']);
?>