e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
323 stars 214 forks source link

Issue: Admin UI - Custom Code #2976

Open LaocheXe opened 6 years ago

LaocheXe commented 6 years ago

I'm working on a plugin, I have a dropdown menu in the admin ui for the plugin to select a user - I went and added a custom query:

SELECT u.user_id, u.user_name FROM `#user` AS u
LEFT JOIN `#service_records_sys` AS sr ON sr.user_id = u.user_id
WHERE sr.user_id IS NULL

That filters out the users who already have a service record in the dropdown. Issue is, when going to Managed (list) user names are no longer displayed....

capture

The code used:

public function init()
{
$filterQuery = "SELECT u.user_id, u.user_name FROM `#user` AS u
LEFT JOIN `#service_records_sys` AS sr ON sr.user_id = u.user_id
WHERE sr.user_id IS NULL";
                        $sql = e107::getDB();
            if($sql->retrieve($filterQuery))
            {
                while ($row = $sql->fetch())
                {
                    $this->user_id[$row['user_id']] = $row['user_name'];
                }
            } 
            $this->fields['user_id']['writeParms'] = $this->user_id;
}

I used to have it without the LEFT JOIN which had no filter

public function init()
{
                       $sql = e107::getDB();
                       if($sql->select("user", "*", true))
            {
                while ($row = $sql->fetch())
                {
                    $this->user_id[$row['user_id']] = $row['user_name'];
                }
            } 
            $this->fields['user_id']['writeParms'] = $this->user_id;
}
LaocheXe commented 6 years ago

I could use Custom function which would be 'method' - but how would I display it as a dropdown in edit, and when listed (read) show the user names? and inline edit allow for admin to change user display name?