Calc element in list view is "0"

Discussion in 'Community' started by varst, Aug 10, 2018.

  1. varst

    varst New Member

    Level: Community
    Hello!

    I have a Calc element and in list view the result is seen only by administrators. All other users see in the table zero. By the way access to this element is set as - Public.

    Can anybody help me?
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Standard
    Maybe an element used in your calculation is not accessible?
     
  3. varst

    varst New Member

    Level: Community
    Is accessible!

    and calc elemets code is:
    $db =& JFactory::getDBO();
    $query = "SELECT COUNT(*) FROM `Table2` WHERE `Name` = '{Table1___id}' AND `Staatus` != 'Canceled' ";
    $db->setQuery($query);
    return $db->loadResult();
     
  4. troester

    troester Well-Known Member Staff Member

    Level: Standard
    table1 is accessible for public? view list, view record, id element itself?

    BTW:"& JFactory" is deprecated
     
  5. varst

    varst New Member

    Level: Community
    Yes, all is accessible for public (view list, record and id element too).
     
  6. troester

    troester Well-Known Member Staff Member

    Level: Standard
    You can install the jDump extension to debug what '{Table1___id}' is returning for admin and for public.
     
  7. varst

    varst New Member

    Level: Community
  8. troester

    troester Well-Known Member Staff Member

    Level: Standard
    no, but the "&"
     
    varst likes this.
  9. varst

    varst New Member

    Level: Community
    But.... :confused:How it works?
     
  10. troester

    troester Well-Known Member Staff Member

    Level: Standard
  11. varst

    varst New Member

    Level: Community
  12. Sophist

    Sophist Well-Known Member

    Level: Community
    Perhaps this is a slight confusion.

    As I understand it you want the actual calc value only to be visible to administrators - and you are suggesting that for non-administrators you display zero.

    So it seems to me that you have two choices:

    1. Make the calc element visible in the list (and forms) only to administrators using Access Levels. If you still want to display zero to other users, maybe have another calc element containing zero which is only shown to non-administrators; or

    2. Add code to the calc php to check the user's admin rights and return zero if they are not administrators, and run the SQL only if they are administrators.

    If it were me, I would do 1. and simply not show the calc element unless they are administrators.
     
  13. varst

    varst New Member

    Level: Community
    Thank you for response,

    I need that all users can see the result in the list view. But now its seen only by administrators in the list view and in the record view results is seen by ALL users.
     
  14. Sophist

    Sophist Well-Known Member

    Level: Community
    I am definitely confused now. AFAIK there is no reason why non-administrators would get a different result from the calc - the php code runs on the server in the same security context regardless of the Joomla View Access Levels. I could understand that non-administrators might not see the calc element at all if you had set Access / List View to something other than Public, but I cannot understand how they would see a different value.

    What is the value of "Only Calc on Save"?

    For this type of SQL query "Only Calc on Save" will need to be set to No to run the SQL every time you display the List - and you will need to be careful about performance because it will run that SQL individually for every row in the List that is displayed which could take some time.

    (I have previously written about how to resolve these performance issues by setting Only Calc on Save = Yes and using a List PHP Event plugin and running a single Update SQL statement to update the entire table before you display the list instead of running one SQL per row.)
     
  15. varst

    varst New Member

    Level: Community
    Value of "Only Calc on Save" was "No" and "Ajax calculation" - "Yes".
    If I change "Only Calc on Save" to "Yes" then all users can see the values stored in the database.
     
  16. troester

    troester Well-Known Member Staff Member

    Level: Standard
    What are the exact "Access" settings of your table1___id element?
     
    varst likes this.
  17. Sophist

    Sophist Well-Known Member

    Level: Community
    Yes - it could be an access setting preventing the table1___id value being populated, but you also you need to make sure for table1___id that "List view settings" / "Include in list query" is set to Yes - without this, if the element is not shown in the list then the element will not be included in the Fabrik SQL statement that gets the list data and the placeholder will not be populated.
     
    varst likes this.
  18. varst

    varst New Member

    Level: Community
    THANK YOU!!!! It was: List view - Administrator
     

Share This Page