Description:
This simple module stores visits of user's profile. The visit is stored in
database table with indication when it was made and if the user, which profile
was visIted, saw it.
Every unique visit is stored for 1 month. If there are more visits in 1 month
time from the current user, they won't be recoreded.
Module was tuned up for performance. It uses Drupal built-in cache system
and cron jobs to clean old data.
Module has integration with views.
Currently there is limited functionality of the module, there is no admin panel,
But if the module will be approved and there will be request for more
functionality I'm willing to extend it.

Dependencies:
Views (required)

Installation:
Install the module through the admin panel.
For this module to work properly cron jobs must run on the site.

Usage:
To see a visits you will have to create your own view (through views module).
The simple view can be created this way:
- Add new view of type "User"
- Under Advanced -> Relationships you have two fields:
"Users visits: Uid of the host"
"Users visits: Uid of the visitor"
Add any of this realtionships and add fields based on the selected relationship
(like user's name, picture, etc..).
You can insert the link to the view in your's template file using the function:
profile_visits_title_callback($uid_host);
This function will return unread user's visits in singular/plural form.

Sandbox project link:
http://drupal.org/sandbox/zpieslak/1489652

Git clone:
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/zpieslak/1489652.git profile_visits

Comments

patrickd’s picture

Welcome!

You could make your project page look more structures by some html tags ;)
Also have a look at how to make your project page follow tips for a great project page.

Does it really make sense to put this module into the Profile visits package ?

Great to see that you've already cleaned up the code with drupalcs :)

We do really need more hands in the application queue and highly recommend to get a review bonus so we will(/can) come back to your application sooner.

regards

zpieslak’s picture

Hi patrickd,

Thank you for your feedback. I removed the "package" from info file. I also changed the project page to look more clean. Let me know if there is anything more to fix.

chertzog’s picture

At first glance, the code looks good! (And its a little longer than your Invite Link module...though not by much).

Here are some suggestions:

  1. Maybe add a menu tab to the users profile that has the profile visit history on it. This would serve two fold:
    • It would remove the dependancy on Views, and
    • Provide defaultfunctionality out of the box.
  2. Consider making the visit expiration admin configurable.
  3. Add another table to store total visits:
    • This would keep a running history for the life of the account, of how many visits the profile has gotten. That way you wouldnt lose the history when the visits expire.
  4. What about a block that shows the total number of visits (see previous comment), and the number of new visits (Think the "Your Posts" block on your d.o dashboard). -- It would be a pretty small block though.

Instead of waiting to add functionality until the module is approved, add it during the process. I just had my first project application approved a week or so ago. And if you look at the code from the first commit to the code when it was approved, it went through a number of evolutions. Adding any one of these items would help demonstrate your ability to write well formed code.

zpieslak’s picture

Hi chertzog,

Thank you for your suggestions. I think all the issues can be done via views module (except admin configuration). But despite that
I'm willing to do them, but first let me know if this module is enough to get this issue closed. So I can move on.

chertzog’s picture

I agree that they all can be done via the views module, but thats not the point. The point of this is process is to see whether or not you can write well formed code. By adding some of those features yourself (instead of relying on the views module) you accomplish 3 things:

  1. You remove a dependency. Yes views is a popular module and is installed on most project, but still, it relies on views for something that could easily be accomplished by something like this:
    $visits = db_query('SELECT * FROM {user_visits} ...')->fetchAll; 
    foreach ($visits as $vist) {
    $rows[] = array(
      $visit-> uid,
      $visit ->  visited_at,
    );
    }
    
    $table = array(
      'headers => array(t('header1'), t('header2')),
      'rows' => $rows,
    );
    $output = theme('table', $table);
    return $output;
    

    Obviously this is just an example, but you could probably provide some default page showing a table of visits in about 20-30 lines of code.

  2. Out of the box features. Provide a tab on the users profile by default, then let users override it with a more detailed view.
  3. You provide more code for reviewers to look at and better get a sense of your coding abilities.
zpieslak’s picture

Hi,

Thank you for your suggestions. So what is now is not enough to close this issue?

chertzog’s picture

That's not up to me. Again its not just on quantity, but quality. Show the reviewers that you understand how to write code for drupal.

My suggestion is this:

While waiting for a more in depth review, why not start adding some of the new features. It will probably help get you approved faster.

zpieslak’s picture

Hi,

Ok, I added some features:
- Currently there is default view provided with the module, so there is no need to initial configuration
- I added user tab as you proposed
- I added special permission which is required to view own visits

Let me know what you think.

MrMaksimize’s picture

Hi zpieslak

Ran this through ventral
There are some minor errors it found
http://ventral.org/pareview/httpgitdrupalorgsandboxzpieslak1489652git

don't use $GLOBALS - use global $user here
Also try to make this function more readable. Really tough to find out what it does.
Drupal coding standards recommend line length at 80 http://drupal.org/coding-standards#linelength

Also wrap the stuff after the || in parentheses as well :)

 function profile_visits_access($uid_host) {
  return ((($GLOBALS['user']->uid == $uid_host) && user_access('access own visits')) || user_access('administer users')) && $uid_host > 0;
 }

other than that, code looks clean.

The only suggestion I have is to make the module a bit more user friendly. Add some functionality as mentioned above, maybe a theme, maybe rules integration.

But I think one that will hit best - is a block that's not necessarily views based. Just so people can see what the module does out of the box.

zpieslak’s picture

Hi,

Thank you for your feedback. I cleaned the code as you proposed. About this one:

don't use $GLOBALS - use global $user here
Also try to make this function more readable. Really tough to find out what it does.
Drupal coding standards recommend line length at 80 http://drupal.org/coding-standards#linelength

Also wrap the stuff after the || in parentheses as well :)

function profile_visits_access($uid_host) {
return ((($GLOBALS['user']->uid == $uid_host) && user_access('access own visits')) || user_access('administer users')) && $uid_host > 0;
}
other than that, code looks clean.

Well, I took this code form Drupal user.module. So it seems that this module is written wrong :). Here is a part I took and modfied:

/**
 * Access callback for user account editing.
 */
function user_edit_access($account) {
  return (($GLOBALS['user']->uid == $account->uid) || user_access('administer users')) && $account->uid > 0;
}
The only suggestion I have is to make the module a bit more user friendly. Add some functionality as mentioned above, maybe a theme, maybe rules integration.

But I think one that will hit best - is a block that's not necessarily views based. Just so people can see what the module does out of the box.

You can see what it does out of the box. You just have to go to user account tabs and make some visits on your account.
Besides that I will put yours ideas on the issue queue as feature requests.

MrMaksimize’s picture

Cool!

Very interesting that the user module does this... Looked around a bit more and seems that the functionality is the same. I just usually don't see it being done in that way. Cool So just let those two go then :)

zpieslak’s picture

Priority: Normal » Major
exlin’s picture

Status: Needs review » Reviewed & tested by the community

Cool that your module provides views out-of-the-box, even tho i would probably implement them using drupal cores api.

Couldn't find any issue on manual review and module works great on my localhost.

Wether or not this project is big enought to grant project promotion permissions, i will leave for someone else to evaluate.

patrickd’s picture

Is the functionality between this module and
https://drupal.org/project/user_visits
https://drupal.org/project/user_visits_adv
so different that it is necessary to make a new module out of it? (Apart from the point that this module is for d7)

zpieslak’s picture

Hi patrickd,

There are three differences:
- these modules stores all visits, my module store only one visit per one user (uid), so for example if user visits another profile in certain period of time (1 month) there will be only one visit stored (only the time of visit will be updated)
- these modules are not available for Drupal 7
- these modules don't have views support

patrickd’s picture

I'm not sure how much sense the current implementation makes regarding caching ?
As drupal has an internal page cache that won't activate the callbacks your overriding by hook_menu() and as many sites are using proxy caches like varnish (which will also not trigger your callback when a cached page is visited) - wouldn't it make more sense to use javascript here (by including it within the profile page) to call a custom callback?

I don't know how other drupal-intern statistic modules handle this (I always tend to use external tools like piwik with custom plugins), but have you thought about that case ?

zpieslak’s picture

>> I'm not sure how much sense the current implementation makes regarding caching ?

I made this module for one of my projects and there was requirement for this functionality, not the one that is present in modules you mentioned above.

>> As drupal has an internal page cache that won't activate the callbacks your overriding by hook_menu() and as many sites are using proxy caches like varnish (which will also not trigger your callback when a cached page is visited) - wouldn't it make more sense to use javascript here (by including it within the profile page) to call a custom callback?

Sorry I'm not admin expert, I don't understand? You want to tell me that hook_menu_alter won't get triggered, if some type of cache is present on the site? I didn't want to use javascript, as Drupal API provides many useful hooks and functions. I thought this will be the Drupal way to do it?

>> I don't know how other drupal-intern statistic modules handle this (I always tend to use external tools like piwik with custom plugins), but have you thought about that case ?

Hmm, by the time I was writing this module, I didn't found any proper module that suited needs of the client project I was working on. So that's why I wrote it. I thought It will be good idea to rely it on views API, as it is very flexible for admin user and any change to view output can be easily done.

klausi’s picture

Status: Reviewed & tested by the community » Fixed

Sorry for the delay, but you have not listed any reviews of other project applications in your issue summary as strongly recommended in the application documentation.

Regarding the caching: The page cache only works for anonymous users, so you should be fine.

manual review:

  1. profile_visits.module line 102: doc blocks comments should end in "*/" only, not "**/".
  2. profile_visits_cron(): I think the time span should be configurable.
  3. profile_visits_install(): why do you need to change your module's weight? If you want to make sure that any of your hooks is run before/after another hook you should use hook_module_implements_alter().

But that are just minor issues, so ...

Thanks for your contribution, zpieslak! Welcome to the community of project contributors on drupal.org.

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

As you continue to work on your module, keep in mind: Commit messages - providing history and credit and Release naming conventions.

Thanks to the dedicated reviewer(s) as well.

zpieslak’s picture

Hi,

Thank you for your time. I will surely update the module with new features. I added your ideas to issues queue.

>> profile_visits_install(): why do you need to change your module's weight? If you want to make sure that any of your hooks is run before/after another hook you should use hook_module_implements_alter().

I needed that because the module has to use hook_menu_alter after views module use it. So that I can change page title. I didn't know this hook - hook_module_implements_alter. But I will change it. It seems to be suited better for that task.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

added some new features to module