narcis VIP
Total posts: 138
02 Июль 2015 14:50

Hello there,

I enabled sql query in Select Field of Cobalt to allow user to select his name as following :

SELECT r.id, r.name AS text FROM #__users AS r WHERE r.id = [USER_ID]

And i added a link in Process into link. So when user goes in full article view, his name is displayed as link. Ok.

But i'm wondering if there is any way to display custom value instead of name of user; for example "User 01", because i don't want to display the name of user; user can view and select his name when he posts a new Cobalt article, but after saving, the name of user is replaced by my Custom value. It could be a sort of alias or mask ... i don't know.

I read this : http://stackoverflow.com/questions/4809452/sql-returning-custom-values-based-on-query-results

But i did not manage to set it up.

Help please.

Последние изменения: 13 Июль 2015


Sergey
Total posts: 13,748
07 Июль 2015 16:09

Why do you need SQL source for that? Why user have to select themeselfs? There is already user ID attached to he article. Intemplate it is in $item->user_id. Why do not you use that one?

And what alias do you mean? Username or how you create aliases?


pepperstreet VIP
Total posts: 3,837
08 Июль 2015 02:22

Hello narcis,

sorry, I don't get the SELECT field and SQL idea.
As far as I understan, you want a custom screen-name which is independent from the usual username/realname ?

  • Why not use a simple text input field? Label it "displayed screenname" or something like that. Output this field value to your liking... instead of the username/author.
  • Or do you want a pre-defined constant like User + userID#? Or maybe a random# number. Both would give a unique screen-name.

narcis VIP
Total posts: 138
08 Июль 2015 16:10

Hello there,

My project is a little complicated to explain, but Let me tell you some aspects (please just ignore my first post, i apologise for confusion in advance) :

I want to allow a Special joomla user to create an article AA that contains a unique code value as link in a Multiselect field; this link redirects people to another article BB (this code value is just retrieved from a field of Article BB). But people must not view this code value neither on article AA nor on article BB. Only Special user can see this value.

Article BB must be unique when Special user selects it on submit form, so the only way to retrieve it in sql query is to use code value that is unique.

So about sql query, i want to enable it in Article AA, so Special user could see the code value when he selects any article BB in submit form, but in full article AA, the code value should be replaced by a custom screen-name as you said, because it's just a boring and long code, i prefer put a nice label there.

Please tell me if it's not clear.

I tried the function SUBSTR() to limit chain characteres. So i set something like this in article AA :

SELECT r.id, CONCAT('custom screen-name', (SELECT SUBSTR(field_value, 0, 15) FROM #__js_res_record_values WHERE record_id = r.id AND field_id = 44) ,'') AS text FROM #__js_res_record AS r WHERE r.section_id = 3

But the sql query above hides value when Special user selects value in submit form. Actually, i expected value be visible on the submit form but hidden in full view.

I'm still working on it. Any idea will be really appreciated.

Regards.


Sergey
Total posts: 13,748
10 Июль 2015 10:25

To manage access to the value have nothing to do with SQL. There are aprameters in the field like who can submit, Who can view, ... Those are to manage access.

Subquery you use still can return multiple values. You can add LIMIT 1 at the end but that only solve an simptom but in fact it tells that you are doing something wrong. You what express mutilple select value as single value. It means there is some confision in the logic.

narcis Article BB must be unique when Special user selects it on submit form, so the only way to retrieve it in sql query is to use code value that is unique.

This is not clear. Are those AA and BB the same section and type or diferent? If you would say not just Article AA and BB but for example Car abd Manufacturer that would be much easier to understand. In your explanation very hard to understand how one article relate to each other.

For example you say it is unique. How? It is unique amoung all articles of this type or it only connects to one AA article? If so it is even more confusing because since you do not use this article anywhere elce, you can merge AA and BB togather since it is 1-to-1 relation.

But since you have different article most probably that is not the case. then what is the case? What you mean by to be unique?

And question why don't you use relate fields?


narcis VIP
Total posts: 138
13 Июль 2015 09:08

Thank you. I will try relate fields.

Работает на Cobalt