8 – Store data per user in the field and extract using SQL in the view ordering plugin

TL; DR: This is less a question about how to write a view ordering complement, and more if I can serialize key / value pairs and selectively order one of them using SQL functions.

I have a content type with a comment field.

There is a corresponding view with An exposed filter where a user can select. From a drop-down

I wrote a field controller that analyzes the comments (remember: a comments field only contains settings and statistics, comments are their own entities, so you must load them separately) to see if the selected user has left a comment on each node .

This generates a & # 39; discussed? & # 39; Column for sight: Yes / No, no. of comments etc.

At present, the result is not stored in the database, it is executed every time.

The challenge is to make the column classifiable, since the results are different for each user that you can select.


I guess the only practical way to do it would be to store the result in the database (which will be updated after creating / deleting the comments), so I can use $ this-> query-> addOrderBy () in SortPluginBase.

It would have to be scalable, that is, a single field with all values, not one field per person.

If I serialized the value (for example, the uid / key / value pairs) and stored it in a field, it would be fairly easy to rewrite my field controller to show the correct result in an unclassified view.

But for the classification, is there any SQL that I can use to extract the value of the correct key? (This would also have to deal with situations in which a new user has been added, but no data will be stored for them in the legacy comments, for example, a default / reservation value if the key is not found).

Or would someone recommend a completely different approach? (There are HOOK_views_pre_render (), but to go through the results seems to be a bit ugly …)