Foros de discusión

[Resolved] Getting a user phone number given its id

Bob Master Flash, modificado hace 17 años.

[Resolved] Getting a user phone number given its id

New Member Mensajes: 2 Fecha de incorporación: 13/03/07 Mensajes recientes
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, modificado hace 17 años.

RE: Getting a user phone number given its id

New Member Mensajes: 16 Fecha de incorporación: 19/10/06 Mensajes recientes
I'm having the exact same problem.

Any advice would be appreciated.
Nathan McMinn, modificado hace 17 años.

RE: Getting a user phone number given its id

Junior Member Mensajes: 61 Fecha de incorporación: 14/10/05 Mensajes recientes
Check out PhoneLocalServiceUtil. You should be able to call:

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 emoticon
Bob Master Flash, modificado hace 17 años.

RE: Getting a user phone number given its id

New Member Mensajes: 2 Fecha de incorporación: 13/03/07 Mensajes recientes
Your solution is working fine.

Thanks a lot
thumbnail
delang j, modificado hace 15 años.

RE: Getting a user phone number given its id

Expert Mensajes: 252 Fecha de incorporación: 14/07/08 Mensajes recientes
List 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
thumbnail
Amos Fong, modificado hace 15 años.

RE: Getting a user phone number given its id

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
I think it should be:

List<phone> phones = PhoneLocalServiceUtil.getPhones(companyId, className, classPK);</phone>
thumbnail
delang j, modificado hace 15 años.

RE: Getting a user phone number given its id

Expert Mensajes: 252 Fecha de incorporación: 14/07/08 Mensajes recientes
hi amos, what about the second line, is it correct?
please guide me

thanks
thumbnail
Amos Fong, modificado hace 15 años.

RE: Getting a user phone number given its id

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
If you look at say, pollsdisplay/view.jsp, you can iterate through the List like:

for (Phone phone : phones) {
phone.getNumber();
}
thumbnail
delang j, modificado hace 15 años.

RE: Getting a user phone number given its id

Expert Mensajes: 252 Fecha de incorporación: 14/07/08 Mensajes recientes
hi amos,
would you explain more details? newbie like me couldnt get it

thanks.
thumbnail
Amos Fong, modificado hace 15 años.

RE: Getting a user phone number given its id

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
The directory already shows phone numbers...if you look at phone_numbers.jsp:

if (classPK &gt; 0) {
	personalPhones = PhoneServiceUtil.getPhones(className, classPK);
}

........


<ul class="property-list">

&lt;%
for (Phone phone: personalPhones) {
%&gt;

	<li class="<%= phone.isPrimary() ? " primary" : "" %>"&gt;
		&lt;%= PhoneNumberUtil.format(phone.getNumber()) %&gt; &lt;%= phone.getExtension() %&gt; &lt;%= LanguageUtil.get(pageContext, phone.getType().getName()) %&gt;
	</li>

&lt;%
}
%&gt;

</ul>
thumbnail
delang j, modificado hace 15 años.

RE: Getting a user phone number given its id

Expert Mensajes: 252 Fecha de incorporación: 14/07/08 Mensajes recientes
thanks amos for the reply but i already done with different way. here the codes, somehow one of my friend give me help.
		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 &lt; 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?
thumbnail
Amos Fong, modificado hace 15 años.

RE: Getting a user phone number given its id

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
great!

phone_numbers.jsp is located in portal-web/docroot/html/portlet/directory/user
thumbnail
Udaya Ramakrishnan, modificado hace 12 años.

RE: Getting a user phone number given its id

Junior Member Mensajes: 67 Fecha de incorporación: 7/09/11 Mensajes recientes
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:
 [b]&lt;%
      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();
        }
      }

    %&gt;
<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