This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » Php variables for user_id, name and...
expandshrink

Php variables for user_id, name and last name of logged in user.

Php variables for user_id, name and last name of logged in user.

Tuesday 29 November 2011 9:44:28 pm - 6 replies

Hola a todos!
How could I get the user_id, name, lastname and login from an connected user in Ezpublish by using php?. I need to know what are the variables that handles this information. (My native language is Spanish).

Tuesday 29 November 2011 10:36:57 pm

Hello Grey,

 

You will want to use the eZUser class in most use cases.

 

So read the class api documentation please,

http://pubsvn.ez.no/doxygen/trunk/html/classeZUser.html

 

Also are you working within templates or PHP code where you have this need?

Each of these are different use cases so if your working with templates you may need to use template operators to fetch these detail in a different way than PHP.

 

I hope this helps ....

 

Cheers,

Heath

Thursday 01 December 2011 4:42:20 pm

I have read the API documentation related to the class "ezUser" (recommended for you).
I need to develop an interface where you can display the amount of times a user has connected to eZ publish and the last time you login.
I know this information exists in the database.
Table "ezuservisit"
-Field "last_visit_timestamp"
-Field "login_count"
-Field "user_id"
Table "ezuser"
-Field "login"
-Field "contentobject_id."
I have web programming skills in php and sql postgres, but I have no idea how to startdevelopment. I need more documentation to understand and initiate.
I would like a guide to begin the development of this interface.

Thursday 01 December 2011 7:19:57 pm

First, please ignore the eZ Publish database tables entirely. I know your new to eZ and know know any better but ....

You may not yet understand but when developing in eZ Publish you do not write sql or use the tables directly (in almost all use cases, 99%).

You need to focus on -only- using the eZ Publish PHP API of PHP Classes available to you. These PHP classes will grant you access to virtually everything contained within the db, most times without writing much code at all (this is key to understand).

* So dich the sql skills for a little while and focus on your PHP skills, you will need strong focus to succeed.

 

As for the functionality you desire to create ... a few issues

1) I do not believe that session information is available in the way you desire to use it (at all)

1.2) I do not believe eZ Publish tracks anything more than the ezuser.last_visit_timestamp (either on login or on each page view this unix timestamp reset I believe) so I don't think you can query eZ Publish for a list of past user sessions (or the length of each session).

1.3) Also I do not think that you can obtain (by default) an 'accumulated' session time (including passed session's lengths). You only get ezuser.last_visit_timestamp.

1.4) You can (and should) use eZUser PHP class to obtain the 'last_visit_timestamp' without writing any sql. This is a helpful starting point.

2) You say your requirement is "I need to develop an interface where you can display the amount of times a user has connected to eZ publish and the last time you login.".

2.1) Question: Where do you need to display this interface? Can you modify the templates of another existing module view interface? I would do this instead of creating another module view to display this information unless it is absolutely required, this can greatly shorten your development time.

2.2) As I said above you can easily display the date / time of the last connection to eZ Publish. You can do this today using only template code and default template fetch functions (re, 'current_user')

2.3) As I said above you can not obtain (to my knowledge) the length of time a user has been on an eZ Publish site by default (in any accurate way). Though I imagine you could invent such a solution with eZ Publish, it would prolly require custom development (and possibly module overrides depending on how / where you need to add this statistics collection and storage).

 

As for a guide, you will prolly never find such a guide as you are seeking, sorry.
I have never seen such a thing (for this topic) in 10 years of actively using eZ.

We are not much of a 'guide' / 'howto' based community. While we do have a great content available for study; few people post such guides (as you seek) online publicly in the eZ Community.

I would give up trying to find a 'guide' to tell you exactly what to do and how to do it, you won't find one.

You would be much better focusing on learning the aspects of eZ Publish you need to reach your goal.

** Ask lots of questions here in the forums, stay active in the eZ Community and you will grow more competent in time. **

 

I strongly suggest you post more complete requirements here in the forums as to what you need to build exactly. Then others in the community can more helpfully and accurately guide you in how to reach your goals best.

 

I hope this helps ...

 

Cheers,

Heath

Thursday 01 December 2011 7:38:35 pm

To get you started: tables in the db in eZ are accessed via an ORM pattern. All php classes that are subclasses of eZPersistentObject implement it.

So, if $user is an eZUser object, $user->attribute('login'); will give yout its login field.

And to retrieve a user from the db, use eZUser::fetch( $user_id ), or eZUser::fetchByName() or similar functions. All eZPersistentObject subclasses implement some FetchThis and Fetchthat functions that will generate the sql nd retrieve the data from the db for you.

php-level api documentation is btw available at http://pubsvn.ez.no

Friday 02 December 2011 6:17:23 am

Also I got to thinking later this evening
about other ideas that you might be able
 to use.

What about inventing a solution to more
accurately track user site usage statistics
(like time spent on site) with client-side javascript,
or if that is not an avenue of interest, web server
access logs (like the object view count statistics
in eZ Publish which are most commonly based
on web server access log data), though I think
javascript avenue might give more useful incentives.

 

I hope this helps ...

Cheers,

Heath

Modified on Friday 02 December 2011 6:18:11 am by // Heath

Tuesday 06 December 2011 5:08:50 pm

I have an information on a database that I want to show in eZpublish.

Question 1.
I would like to use the template "Article" to display this information.How to achieve?
This information will show using php, but this depends on the connected user (login).

Question 2. I instantiate a class to get the user using  $user->attribute('login')? I include some file to use class? would help me any example of how to show the "login".

example:
<? php
echo $user;
?>

Thank you for your help.

Modified on Tuesday 06 December 2011 5:10:21 pm by grey uzcategui

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from