Yii Framework Forum: Sent emails to users who haven't check the website for a long time (using last vist...but how to write findbyAttributes command...?) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Sent emails to users who haven't check the website for a long time (using last vist...but how to write findbyAttributes command...?) using last vist...but how to write findbyAttributes command...? Rate Topic: -----

#1 User is offline   jiaming 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 262
  • Joined: 10-April 12

Posted 24 July 2012 - 02:15 AM

Dear all,

I am doing a crontab that to email the users who haven't check our website for quite a long time.

I want to emails the user, for example, haven't on board for 1-2 weeks.

I have a column called "lastvist" in my tbl_user table.

But how can I write the filter command?

something like:
$users=Users::model()->findAllByAttributes->(...2weeks off the board since last visit....)


I store the lastvist via timestamp like this: 1343043800

Now i am doing something like this but i believe it's very low efficient since findAll is very expensive.

$now=time();
$users=Users::model()->findAll();
foreach($users as $user){
$intervel=$now-$user->lastvisit;
$days=intval($intervel/86400);
if($days > 14){
//send emails
}


Any ideas would be appreciated...

Thanks so much! :D
0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 July 2012 - 05:45 AM

using that findall, compare lastvisit date with now().
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
1

#3 User is online   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,168
  • Joined: 05-January 12
  • Location:Morocco

Posted 24 July 2012 - 07:03 AM

If you want to use findAll(), you can use it with a CDbCriteria

I would, however, use a simple SQL query to select the needed rows, if my goal is simply to send emails to the records matching a condition.
0

#4 User is offline   Luiz Celso 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 13-April 12

Posted 24 July 2012 - 07:25 AM

Use CDbExpression('NOW()') to compare the current date with the 'lastvist' in tbl_user.

Happy coding.
0

#5 User is offline   jiaming 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 262
  • Joined: 10-April 12

Posted 24 July 2012 - 07:39 AM

View Postbennouna, on 24 July 2012 - 07:03 AM, said:

If you want to use findAll(), you can use it with a CDbCriteria

I would, however, use a simple SQL query to select the needed rows, if my goal is simply to send emails to the records matching a condition.


Thanks so much for your help!! Because I also need to get user's id and other information so I use findAll instead of SQL query.

I am using something like this now:

$now=time();
$value=$now-86400*12;   //12days
$criteria = new CDbCriteria();
$criteria->condition = "lastvisit >= $value";

$users=Users::model()->findAll($criteria);
foreach($users as $user){
.....
.....


What do you think about this ....(above part)....Because corncobs are not that easy to test now ...so I gotta test it tomorrow...
0

#6 User is online   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,168
  • Joined: 05-January 12
  • Location:Morocco

Posted 24 July 2012 - 08:27 AM

View Postjiaming, on 24 July 2012 - 07:39 AM, said:

$now=time();
$value=$now-86400*12;   //12days
$criteria = new CDbCriteria();
$criteria->condition = "lastvisit >= $value";

$users=Users::model()->findAll($criteria);
foreach($users as $user){
.....
.....


It looks good to me, except that you need visitors who haven't logged in the past 12 days, so you should change your condition to
$criteria->condition = "lastvisit < $value";

0

#7 User is offline   jiaming 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 262
  • Joined: 10-April 12

Posted 24 July 2012 - 11:00 AM

View Postbennouna, on 24 July 2012 - 08:27 AM, said:

It looks good to me, except that you need visitors who haven't logged in the past 12 days, so you should change your condition to
$criteria->condition = "lastvisit < $value";



Haha my bad...That is stupid... :D :D

Thanks for your help dude!

Have a good day.

Cheers
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users