Foren
[Resolved] Getting a user phone number given its id
Bob Master Flash, geändert vor 17 Jahren.
[Resolved] Getting a user phone number given its id
New Member Beiträge: 2 Beitrittsdatum: 13.03.07 Neueste Beiträge
Hello
My question is simple : i would like to retrieve a user phone number list given the user id.
I can retrieve all user information (first name organization etc.) but for the phone numer list, there is no method...
I tried to retrieve it using PhoneUtil.findByUserId(userId) but i have no hibernate session...
I saw a addPhone method with a userId parameter, so i guess there is a way to have it using the api.
I cannot use the PortletRequest.USER_INFO because i want to display all portal users phone numbers.
Thanks a lot for your advice.
Me
My question is simple : i would like to retrieve a user phone number list given the user id.
I can retrieve all user information (first name organization etc.) but for the phone numer list, there is no method...
I tried to retrieve it using PhoneUtil.findByUserId(userId) but i have no hibernate session...
I saw a addPhone method with a userId parameter, so i guess there is a way to have it using the api.
I cannot use the PortletRequest.USER_INFO because i want to display all portal users phone numbers.
Thanks a lot for your advice.
Me
Shane W, geändert vor 17 Jahren.
RE: Getting a user phone number given its id
New Member Beiträge: 16 Beitrittsdatum: 19.10.06 Neueste Beiträge
I'm having the exact same problem.
Any advice would be appreciated.
Any advice would be appreciated.
Nathan McMinn, geändert vor 17 Jahren.
RE: Getting a user phone number given its id
Junior Member Beiträge: 61 Beitrittsdatum: 14.10.05 Neueste Beiträge
Check out PhoneLocalServiceUtil. You should be able to call:
Where companyId is the companyId you are using, classname is 'com.liferay.portal.model.Contact', and the classPk is the username you want.
This should return you a list of com.liferay.portal.model.Phone objects.
Let me know if it works
getPhones(String companyId, String className, String classPk)
Where companyId is the companyId you are using, classname is 'com.liferay.portal.model.Contact', and the classPk is the username you want.
This should return you a list of com.liferay.portal.model.Phone objects.
Let me know if it works
Bob Master Flash, geändert vor 17 Jahren.
RE: Getting a user phone number given its id
New Member Beiträge: 2 Beitrittsdatum: 13.03.07 Neueste Beiträge
Your solution is working fine.
Thanks a lot
Thanks a lot
delang j, geändert vor 15 Jahren.
RE: Getting a user phone number given its id
Expert Beiträge: 252 Beitrittsdatum: 14.07.08 Neueste BeiträgeList phone = PhoneLocalServiceUtil.getPhones(companyId, className, classPK);
row.addText(ListUtil.toString(phone, "number", ", "), rowURL);
this is what i've done so far but without error and output. am i miss something. Please help me, i just want to display phone number on directory portlet.
thanks
Amos Fong, geändert vor 15 Jahren.
RE: Getting a user phone number given its id
Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
I think it should be:
List<phone> phones = PhoneLocalServiceUtil.getPhones(companyId, className, classPK);</phone>
delang j, geändert vor 15 Jahren.
RE: Getting a user phone number given its id
Expert Beiträge: 252 Beitrittsdatum: 14.07.08 Neueste Beiträge
hi amos, what about the second line, is it correct?
please guide me
thanks
please guide me
thanks
Amos Fong, geändert vor 15 Jahren.
RE: Getting a user phone number given its id
Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
If you look at say, pollsdisplay/view.jsp, you can iterate through the List like:
for (Phone phone : phones) {
phone.getNumber();
}
delang j, geändert vor 15 Jahren.
RE: Getting a user phone number given its id
Expert Beiträge: 252 Beitrittsdatum: 14.07.08 Neueste Beiträge
hi amos,
would you explain more details? newbie like me couldnt get it
thanks.
would you explain more details? newbie like me couldnt get it
thanks.
Amos Fong, geändert vor 15 Jahren.
RE: Getting a user phone number given its id
Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
The directory already shows phone numbers...if you look at phone_numbers.jsp:
if (classPK > 0) {
personalPhones = PhoneServiceUtil.getPhones(className, classPK);
}
........
<ul class="property-list">
<%
for (Phone phone: personalPhones) {
%>
<li class="<%= phone.isPrimary() ? " primary" : "" %>">
<%= PhoneNumberUtil.format(phone.getNumber()) %> <%= phone.getExtension() %> <%= LanguageUtil.get(pageContext, phone.getType().getName()) %>
</li>
<%
}
%>
</ul>
delang j, geändert vor 15 Jahren.
RE: Getting a user phone number given its id
Expert Beiträge: 252 Beitrittsdatum: 14.07.08 Neueste Beiträge
thanks amos for the reply but i already done with different way. here the codes, somehow one of my friend give me help.
btw where is the phone_number.jsp file?
String phoneType = LanguageUtil.get(pageContext, "none");
String mobileNo = LanguageUtil.get(pageContext, "none");
String officeNo = LanguageUtil.get(pageContext, "none");
List resultsPhone = new ArrayList();
resultsPhone.addAll(PhoneLocalServiceUtil.getPhones(user2.getCompanyId(), Contact.class.getName(), contact2.getContactId()));
for (int p = 0; p < resultsPhone.size(); p++) {
Phone phone = (Phone)resultsPhone.get(p);
phoneType = phone.getType().getName();
if (phoneType.equals("Mobile")) mobileNo = phone.getNumber();
if (phoneType.equals("Business")) officeNo = phone.getNumber() + "<br>Ext: " + phone.getExtension();
}
btw where is the phone_number.jsp file?
Amos Fong, geändert vor 15 Jahren.
RE: Getting a user phone number given its id
Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
great!
phone_numbers.jsp is located in portal-web/docroot/html/portlet/directory/user
phone_numbers.jsp is located in portal-web/docroot/html/portlet/directory/user
Udaya Ramakrishnan, geändert vor 12 Jahren.
RE: Getting a user phone number given its id
Junior Member Beiträge: 67 Beitrittsdatum: 07.09.11 Neueste Beiträge
hi
thank u so much for ur code.
let me post my code of what i did in directory portlet to have phone number..
In \html\portlet\directory\user\search_columns.jspf i included the following lines to have phone numbers into list:
This will include phone number into the list.
Attached the screen shots also
u can use the following link as reference: http://www.abcseo.com/tech/liferay/search-container
thank u so much for ur code.
let me post my code of what i did in directory portlet to have phone number..
In \html\portlet\directory\user\search_columns.jspf i included the following lines to have phone numbers into list:
[b]<%
ExpandoBridge eb = user.getExpandoBridge();
List<phone> phones = PhoneLocalServiceUtil.getPhones(user2.getCompanyId(), Contact.class.getName(), user2.getContactId());
String mobileNo = "";
String phoneNo = "";
for (Phone phone : phones) {
String phoneType = phone.getType().getName();
if ("Business".equals(phoneType)) {
phoneNo = phone.getNumber();
} else if ("Mobile".equals(phoneType)) {
mobileNo = phone.getNumber();
}
}
%>
<liferay-ui:search-container-column-text href="<%= rowURL %>" name="Phone" orderable="<%= true %>" value="<%= phoneNo %>" />
[/b]
</phone>
This will include phone number into the list.
Attached the screen shots also
u can use the following link as reference: http://www.abcseo.com/tech/liferay/search-container
Anhänge: