Jump to content

Group awards by type [SOLVED]


Imanol

Recommended Posts

Hello,

 

I would like to create two type of awards: Medals, given to pilots when they reach a certain number of flight hours and PIREPs, and events awards, manually given to pilots when they participate in a event. I need to show up theses awards in pilot profile divided into to groups: Medals and Events.

 

Is there any piece of code I could use to do it? Thanks in advance.

Edited by Imanol
Topic solved
Link to comment
Share on other sites

10 hours ago, Imanol said:

Hello,

 

I would like to create two type of awards: Medals, given to pilots when they reach a certain number of flight hours and PIREPs, and events awards, manually given to pilots when they participate in a event. I need to show up theses awards in pilot profile divided into to groups: Medals and Events.

 

Is there any piece of code I could use to do it? Thanks in advance.

 

https://github.com/nabeelio/phpvms/blob/dev/modules/Awards/Awards/PilotFlightAwards.php

 

You can check the default award classes to have a better understanding how it works, and then you can create your own classes as you wish.

 

For displaying them separately in pilot profile you need to edit the blade file(s) of your theme as you wish. You can use some filtering within the loops or anything else matching your needs.

 

https://github.com/nabeelio/phpvms/blob/dev/resources/views/layouts/default/profile/index.blade.php

 

Good luck

Link to comment
Share on other sites

Hi @DisposableHero! I understand how award classes works but I don't know how to set them to be shown up in these two groups. I've edited the default skin but awards are show all together. This is the code of my profile/index.blade.php

 


<h3 class="titles">Premios</h3>
<hr> 
@if($user->awards)
  <div class="row row-cols-2 row-cols-md-4 row-cols-lg-6">
    @foreach($user->awards as $award)
      <div class="col">
        <div class="card mb-2">
          <img class="img-mh150" src="{{ $award->image_url }}" alt="{{ $award->name }}" title="{{ $award->description }}">
        </div>
      </div>
    @endforeach
  </div>
@endif


<br><br>

@endsection

 

Link to comment
Share on other sites

You can use two different loops to display different awards according to your setup @Imanol

 

@foreach($user->awards->whereIn('id', [1,2,4,5,7,90]) as $awards)

 

https://laravel.com/docs/10.x/collections#available-methods may help

 

Or you can use some basic php functions to check the name, like if it contains some specific words to separate then

 

@if(str_contains($award->description, 'Medal'))

 

 

Good luck

Link to comment
Share on other sites

Hi @DisposableHero,

 

I really apreaciate your help. I could split awards into groups using this code:

 

@if(str_contains($award->ref_model, 'Modules\Awards\Awards\PilotHoursAwards'))

 

Thus I just have to change the award type in order to show all the awards which belong to the same category.

 

Kind regards!

  • Like 1
Link to comment
Share on other sites

  • Imanol changed the title to Group awards by type [SOLVED]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...