1

I'm new to Bolt CMS, but it looks good so far. My goal for now is to create rating for articles. For that, I created ratings content type, and there I placed article_id, user_id and rating fields. Now how can I set those fields to create relations between themselves?

Since Bolt is biult on Symfony, I'd expect it to use Doctrine and its tools.

My current contenttype for ratings is very poor:

ratings:
    name: Ratings
    slug: ratings
    singular_name: Rating
    singular_slug: rating
    fields:
        article_id:
            type: integer
        user_id:
            type: integer
        rating:
            type: integer
Tomek Buszewski
  • 7,659
  • 14
  • 67
  • 112

2 Answers2

0

What exactly should the rating do? Do visitors have to be able to rate articles? In that case you might look at the rateit extension http://extensions.bolt.cm/view/5d137130-4ab8-4e75-9d58-43f3f99c5a5a

jadwigo
  • 339
  • 1
  • 9
  • It's actually a little more complex - I plan to have something like "best articles" with highest rated ones etc. I would prefer to do this _my way_ that to rely on plugins. – Tomek Buszewski Sep 29 '15 at 11:48
  • You can use relations in bolt contenttypes, see https://docs.bolt.cm/relationships .. so you might have a content type articles and a content type ratings, where a rating is related to an article but the interface will get very convoluted – jadwigo Sep 30 '15 at 12:09
  • I have both `article` and `rating` contenttype, but I don't know how to join them the way I want. I need automatic binding, not something picked from the CMS' panel by hand. – Tomek Buszewski Oct 01 '15 at 09:46
  • you could add a choice field called `rating` with 1-5 stars to your content type, and then use `{% setcontent topten = 'article' limit 10 orderby '-rating' %}` to get the ten highest rated articles https://docs.bolt.cm/content-fetching – jadwigo Oct 03 '15 at 12:36
0

If I understood your question, what you want is to have, ratings and articles relationship. Here is the code for that. Articles has many Ratings.

ratings:
    name: Ratings
    singular_name: Rating
    fields:
        name:
            label: Name
            type: text
            group: General
        email:
            label: Email
            type: text
            group: General

articles:
    name: Articles
    singular_name: Article
    fields:
        name:
            label: Name
            type: text
            group: General
    relations:
        ratings:
            multiple: true
            label: "Choose ratings"

It´s important to understand that BOLT CMS is built on Shoulders of Symphony and Silex. But for getting content, you don´t have to use Doctrine Query. I recommend taking a look at the Backend folder that has Records.php if you are on BOLT 3.* or Backend.php if you are on older versions. Check the editContent action. And if you want on the Frontend.php it's easy to follow the code.

Hope this helps !!!

Simon Berton
  • 468
  • 5
  • 13