How to show a list of registered users in Joomla? - list

I have hundreds of registered users. Those are grouped in different user groups:
See screenshot below (I changed this a little bit to protect my customers site):
Registered -> Teachers
Registered -> Students
How can I show a list of 'Teachers' online?
I want to list up all those teachers in a table or list, so that other teachers see this information.
Thank you. Any information is welcome.

You can use the following for to get the usernames from a specific user group:
$teachers = JAccess::getUsersByGroup(2); //change number in the brackets
$students = JAccess::getUsersByGroup(8); //change number in the brackets
foreach($teachers as $user_id) {
$user = JFactory::getUser($user_id);
echo $user->name;
}
foreach($students as $user_id) {
$user = JFactory::getUser($user_id);
echo $user->name;
}
Change "2" and "8" to the ID's of the Teachers and Students user groups.
Hope this helps

Personally, I think the best way to do that is to create a contact category teachers and then link each teacher to a contact record.
You can make a list of users in a group (there's even a method JAccess::getUsersByGroup() but I don't think it's that useful for this purpose. http://officialjoomlabook.com/school25/staff-directory is an example of where I did what I am suggesting.

Related

How to get Zomato restaurant ID using restaurant link?

I want to get details of a restaurant in Zomato. I have it's link as the input (https://www.zomato.com/mumbai/fantasy-the-cake-shop-kalyan?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1). By browsing the documentation of Zomato APIs, I didn't found a way to get it.
I tried searching for the restaurant using search API but it returns many results.
Any help will be appreciated
It's a two-step process:
Find out restaurant's city id, in your case, Mumbai's city id through the /cities API. It's a simple query search.
Use the city id from the above API call in the /search API, like, https://developers.zomato.com/api/v2.1/search?entity_type=city&entity_id=3&q=fantasy%20the%20cake%20shop%20kalyan
This would give all the basic information about a restaurant.
View the page's source and search for window.RES_ID
I had the same issue as you described. This Zomato's API approach is at least odd. It's almost immposible to GET any information about restaurant if you don't know res_id in advance and that's not possible to parse since Zomato will deny access.
This worked for me:
Obtain user-key from Zomato API Credentials (https://developers.zomato.com/api)
Search restaurant url via API (https://developers.zomato.com/api/v2.1/search?entity_id=84&entity_type=city&q=RESTAURANT_URL&category=7%2C9). The more specific you will be, the better results you'll get (This url is specified by city to Prague (ID = 84) and categories Daily menus (ID = 7) and Lunch (ID = 9). If there is possibility do specify city, category or cuisine, it helps, but should't be necessary. Don't forget to define GET method in headers.
Loop or filter through json results and search for the wanted url. You might need to use method valueOf() to search for the same url. Be careful, you might need to add "?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1" at the end of your wanted url so it has the same format. Check that through Zomato API Documentation page.
for (i in body.restaurants) {
var url_wanted = restaurant_url + '?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1'
var url_in_json = body.restaurants[i].restaurant.url;
if (url_wanted.valueOf() == url_in_json.valueOf()) {
var restaurant_id = body.restaurants[i].restaurant.id;
}
console.log('Voala! We have res_id:' + restaurant_id);
}
There you have it. It could be easier though.
Hope it helps!
once you have the url of the rseraunt's page you can simply look for a javascript object attribute named "window.RES_ID" and further use it in the api call.

Opencart 1.5.x (may be 2.0), how to put first/last name on any template (not registered user)

Checkout page.
Not registered user.
I need to put first/last user name on custom template (this is custom payment tpl of some small bank).
I now, how do it for registered users, it is easy:
$this->data['firstname'] = $this->customer->getFirstName();
But how to do it for not registerd user?
I can't put first/last name.
Presumably your template will only be displayed after they have placed their order but the order is still in the session?
If this is the case, you can get their details from the payment details (or shipping details depending on which one you want) in the session cookie.
So it would be something like:
$this->data['firstname'] = $this->session->data['guest']['payment']['firstname'];
This is true too:
echo ($this->data['firstname'] = $this->session->data['guest']['firstname']);
echo ($this->data['lastname'] = $this->session->data['guest']['lastname']);
echo ($this->data['email'] = $this->session->data['guest']['email']);
echo ($this->data['telephone'] = $this->session->data['guest']['telephone']);

How to get user Interests?

This is not a duplicate of How can I get the interests of my friend through facebook api?. user_interests permission (to access /me/interests) is useless (if not deprecated) Facebook feature that hardly ever returns any data.
Instead, I am referring to the data aggregated by Facebook at this page:
These are all user likes grouped into categories like "Music", "Books", "TV Shows", etc. Generally, user likes can be retrieved through /me/likes. However, the latter query returns a rather vivid array of categories.
Is there a way to get user likes categorised into the same generic categories like Facebook does?
https://developers.facebook.com/docs/reference/api/user/:
The User object has the following connections:
books: The books listed on the user's profile.
games: Games the user has added to the Arts and Entertainment section of their profile.
movies: The movies listed on the user's profile.
music: The music listed on the user's profile.
television: The television listed on the user's profile.
The fields favorite_athletes and favorite_teams are deprecated, though. Not sure, if there will be any replacement for these analog to the above connections – or if users are just supposed to normally “like” the fan pages of athletes/teams in the future.
My approach to this issue is to process the API data within my application as such:
'Books' => array('Fictional Character', 'Writer', 'Book', 'Author', 'Book Store', 'Library', 'Magazine'),
'Films' => array('Actor/Director', 'Movie', 'Producer', 'Studio', 'Movie Theater', 'TV/Movie Award', 'Fictional Character', 'Movies/Music'),
[..]
e.g., if user likes "Writer" or "Book", I assign the like to "Books" category.
However, this solution is not ideal as Facebook might change category names, add new names, etc.

Display name & picture knowing ID

I was looking to find an answer to my question, but so far I got this:
https://graph.facebook.com/the_user_id?fields=name,picture
I need to be able to display/print first,last name and picture of a set list of users for which I know their ID. What code is required to get this data and then to publish it on a php/html page? Of course, this will means that if I want to show 10 users, I will input 10 different IDs (read smtg about an array list?). Notice that I DO NOT require for this to work for the current user.
Thanks in advance for your replies.
You need to use file_get_contents ( http://uk3.php.net/file_get_contents ) or curl in php and issue a request to the url such as follows:
https://graph.facebook.com/?ids=id1,id2,id3&fields=name,picture
(replacing id1,id2 with your ids)
this will then return you a json object. You then need to decode ( http://uk3.php.net/json_decode ) and loop through this and access the information
this should get you started
// people array uses the users id as the key and the dessert as the value. The id is then used in the query to facebook to select the corresponding value from this array
$people = array("id1"=>"favourite "dessert", "id2"=>"favourite dessert", "id3"=>"apple pie");
$json = file_get_contents('https://graph.facebook.com/?ids=id1,id2,id3&fields=id,name,picture');
$json = json_decode($json);
foreach($json as $key=>$person){
echo '<p><img src="'.$person->picture.'" alt="'.$person->name.'" />';
echo $person->name.'\'s favourite dessert is '.$people[$person->id'];
echo '</p>';
}
I've batched the requests here, alternatively you could perform 10 separate queries for each user, but that would be a bit pointless and inefficient
The easiest way is with an FQL query:
SELECT first_name, last_name, pic, uid FROM user WHERE uid IN
(Known_ID_1, Known_ID_2, ... Known_ID_n)
The easiest, if you're using PHP is to install the PHP SDK, though you can also make a call directly to https://graph.facebook.com/fql?q=URL_ENCODED_QUERY

Django: structuring a complex relationship intended for use with built-in admin site

I have a fairly complex relationship that I am trying to make work with the Django admin site. I have spent quite some time trying to get this right and it just seems like I am not getting the philosophy behind the Django models.
There is a list of Groups. Each Group has multiple departments. There are also Employees. Each Employee belongs to a single group, but some employees also belong to a single Department within a Group. (Some employees might belong to only a Group but no Department, but no Employee will belong only to a Department).
Here is a simplified version of what I currently have:
class Group:
name = models.CharField(max_length=128)
class Department
group = models.ForeignKey(Group)
class Employee
department = models.ForeignKey(Department)
group = models.ForeignKey(Group)
The problem with this is that the Department select box on the Employees page must display all Departments, because a group has not yet been set. I tried to rectify this by making an EmployeeInline for the GroupAdmin page, but it is not good to have 500+ employees on a non-paginated inline. I must be able to use the models.ModelAdmin page for Employees (unless there is a way to search, sort, collapse and perform actions on inlines).
If I make EmployeeInline an inline of DepartmentAdmin (instead of having a DepartmentInline in GroupAdmin), then things are even worse, because it is not possible to have an Employee that does not belong to a Group.
Given my description of the relationships, am I missing out on some part of the Django ORM that will allow me to structure this relationship the way it 'should be' instead of hacking around and trying to make things come together?
Thanks a lot.
It sounds like what you want is for the Department options to only be those that are ForeignKey'ed to Group? The standard answer is that the admin site is only for simple CRUD operations.
But doing what you're supposed to do is boring.
You could probably overcome this limitation with some ninja javascript and JSON.
So first of all, we need an API that can let us know which departments are available for each group.
def api_departments_from_group(request, group_id):
departments = Department.objects.filter(group__id=group_id)
return json(departments) # Note: serialize, however
Once the API is in place we can add some javascript to change the <option>'s on the department select...
$(function() {
// On page load...
if ($('#id_group')) {
// Trap when the group box is changed
$('#id_group').bind('blur', function() {
$.getJSON('/api/get-departments/' + $('#id_group').val() + '/', function(data) {
// Clear existing options
$('#id_department').children().remove();
// Parse JSON and turn into <option> tags
$.each(data, function(i, item) {
$('#id_department').append('<option>' + item.name + '</option>');
});
});
});
}
});
Save that to admin-ninja.js. Then you can include it on the admin model itself...
class EmployeeAdmin(models.ModelAdmin):
# ...
class Media:
js = ('/media/admin-ninja.js',)
Yeah, so I didn't test a drop of this, but you can get some ideas hopefully. Also, I didn't get fancy with anything, for example the javascript doesn't account for an option already already being selected (and then re-select it).