Forums

Home » Liferay Portal » English » Liferay Legacy

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Bob Master Flash
[Resolved] Getting a user phone number given its id
March 26, 2007 6:10 AM
Answer

Bob Master Flash

Rank: New Member

Posts: 2

Join Date: March 13, 2007

Recent Posts

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
Shane W
RE: Getting a user phone number given its id
March 15, 2007 11:58 PM
Answer

Shane W

Rank: New Member

Posts: 16

Join Date: October 19, 2006

Recent Posts

I'm having the exact same problem.

Any advice would be appreciated.
Nathan McMinn
RE: Getting a user phone number given its id
March 16, 2007 11:54 AM
Answer

Nathan McMinn

Rank: Junior Member

Posts: 62

Join Date: October 13, 2005

Recent Posts

Check out PhoneLocalServiceUtil. You should be able to call:

1getPhones(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 emoticon
Bob Master Flash
RE: Getting a user phone number given its id
March 26, 2007 6:11 AM
Answer

Bob Master Flash

Rank: New Member

Posts: 2

Join Date: March 13, 2007

Recent Posts

Your solution is working fine.

Thanks a lot
delang j
RE: Getting a user phone number given its id
February 11, 2009 1:53 AM
Answer

delang j

Rank: Regular Member

Posts: 235

Join Date: July 13, 2008

Recent Posts

1List phone = PhoneLocalServiceUtil.getPhones(companyId, className, classPK);
2        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
RE: Getting a user phone number given its id
February 11, 2009 9:42 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

I think it should be:

1List<Phone> phones = PhoneLocalServiceUtil.getPhones(companyId, className, classPK);
delang j
RE: Getting a user phone number given its id
February 12, 2009 9:13 AM
Answer

delang j

Rank: Regular Member

Posts: 235

Join Date: July 13, 2008

Recent Posts

hi amos, what about the second line, is it correct?
please guide me

thanks
Amos Fong
RE: Getting a user phone number given its id
February 12, 2009 12:18 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

If you look at say, pollsdisplay/view.jsp, you can iterate through the List like:

1for (Phone phone : phones) {
2phone.getNumber();
3}
delang j
RE: Getting a user phone number given its id
February 14, 2009 3:04 AM
Answer

delang j

Rank: Regular Member

Posts: 235

Join Date: July 13, 2008

Recent Posts

hi amos,
would you explain more details? newbie like me couldnt get it

thanks.
Amos Fong
RE: Getting a user phone number given its id
February 17, 2009 10:12 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

The directory already shows phone numbers...if you look at phone_numbers.jsp:

 1if (classPK > 0) {
 2    personalPhones = PhoneServiceUtil.getPhones(className, classPK);
 3}
 4
 5........
 6
 7
 8<ul class="property-list">
 9
10<%
11for (Phone phone: personalPhones) {
12%>
13
14    <li class="<%= phone.isPrimary() ? "primary" : "" %>">
15        <%= PhoneNumberUtil.format(phone.getNumber()) %> <%= phone.getExtension() %> <%= LanguageUtil.get(pageContext, phone.getType().getName()) %>
16    </li>
17
18<%
19}
20%>
21
22</ul>
delang j
RE: Getting a user phone number given its id
February 18, 2009 1:32 AM
Answer

delang j

Rank: Regular Member

Posts: 235

Join Date: July 13, 2008

Recent Posts

thanks amos for the reply but i already done with different way. here the codes, somehow one of my friend give me help.
 1        String phoneType = LanguageUtil.get(pageContext, "none");
 2
 3        String mobileNo = LanguageUtil.get(pageContext, "none");
 4
 5        String officeNo = LanguageUtil.get(pageContext, "none");
 6
 7        List resultsPhone = new ArrayList();
 8
 9        resultsPhone.addAll(PhoneLocalServiceUtil.getPhones(user2.getCompanyId(), Contact.class.getName(), contact2.getContactId()));
10
11        for (int p = 0; p < resultsPhone.size(); p++) {
12
13            Phone phone = (Phone)resultsPhone.get(p);
14
15            phoneType = phone.getType().getName();
16            if (phoneType.equals("Mobile")) mobileNo = phone.getNumber();
17
18            if (phoneType.equals("Business")) officeNo = phone.getNumber() + "<br>Ext: " + phone.getExtension();
19        }


btw where is the phone_number.jsp file?
Amos Fong
RE: Getting a user phone number given its id
February 18, 2009 10:13 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

great!

phone_numbers.jsp is located in portal-web/docroot/html/portlet/directory/user
Udaya Ramakrishnan
RE: Getting a user phone number given its id
October 11, 2011 6:38 AM
Answer

Udaya Ramakrishnan

Rank: Junior Member

Posts: 67

Join Date: September 6, 2011

Recent Posts

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:
 1 [b]<%
 2      ExpandoBridge eb = user.getExpandoBridge();
 3      List<Phone> phones = PhoneLocalServiceUtil.getPhones(user2.getCompanyId(), Contact.class.getName(), user2.getContactId());
 4      String mobileNo = "";
 5      String phoneNo = "";
 6      for (Phone phone : phones) {
 7        String phoneType = phone.getType().getName();
 8
 9        if ("Business".equals(phoneType)) {
10          phoneNo = phone.getNumber();
11        } else if ("Mobile".equals(phoneType)) {
12          mobileNo = phone.getNumber();
13        }
14      }
15
16    %>
17<liferay-ui:search-container-column-text
18         href="<%= rowURL %>"
19         name="Phone"
20         orderable="<%= true %>"
21         value='<%= phoneNo %>' />
22 [/b]


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
Attachment

Attachments: Phone in directory list.png (13.9k)