require('./connect.db.inc.php');
-$date = date('Y-m-d', time() + 7 * 24*60*60);
-$stamp = date('Ymd000000');
-$like = date('%-m-d', time() + 7 * 24*60*60);
-
-XDB::execute("DELETE FROM watch_ops
- WHERE cid = 4 AND date < CURDATE()");
-
-XDB::execute("INSERT INTO watch_ops (uid, cid, known, date)
- SELECT user_id, 4, $stamp, '$date'
- FROM auth_user_md5
- WHERE naissance LIKE '$like' AND deces=0");
-
+$it = 0;
+do {
+ XDB::execute('UPDATE profiles
+ SET next_birthday = DATE_ADD(next_birthday, INTERVAL 1 YEAR)
+ WHERE (next_birthday != 0 AND next_birthday IS NOT NULL AND next_birthday < CURDATE())
+ AND deathdate IS NULL');
+ ++$it;
+ $affected = XDB::affectedRows();
+ echo "Iteration $it => $affected changes\n";
+} while ($affected > 0);
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>
}
}
+class UFC_ProfileUpdated implements UserFilterCondition
+{
+ private $comparison;
+ private $date;
+
+ public function __construct($comparison = null, $date = null)
+ {
+ $this->comparison = $comparison;
+ $this->date = $date;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ return 'p.last_change ' . $this->comparison . XDB::format(' {?}', date('Y-m-d H:i:s', $this->date));
+ }
+}
+
+class UFC_Birthday implements UserFilterCondition
+{
+ private $comparison;
+ private $date;
+
+ public function __construct($comparison = null, $date = null)
+ {
+ $this->comparison = $comparison;
+ $this->date = $date;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ return 'p.next_birthday ' . $this->comparison . XDB::format(' {?}', date('Y-m-d', $this->date));
+ }
+}
+
class UFC_Sex implements UserFilterCondition
{
private $sex;
public function buildCondition(UserFilter &$uf)
{
$sub = $uf->addWatchRegistrationFilter($this->uid);
- return 'wn' . $sub . '.uid IS NOT NULL';
+ $su = $uf->addWatchFilter($this->uid);
+ return 'FIND_IN_SET(\'registration\', w' . $su . '.flags) OR wn' . $sub . '.uid IS NOT NULL';
}
}
public function buildCondition(UserFilter &$uf)
{
$sub = $uf->addWatchFilter($this->uid);
- return 'FIND_IN_SET(\'contacts\' w' . $sub . '.flags) AND ' . parent::buildCondition($uf);
+ return 'FIND_IN_SET(\'contacts\', w' . $sub . '.flags) AND ' . parent::buildCondition($uf);
}
}
+
/******************
* ORDERS
******************/
{
if (is_null($this->lastcount)) {
$this->buildQuery();
- return (int)XDB::fetchOneCell('SELECT COUNT(*)
- ' . $this->query . '
- GROUP BY a.uid');
+ return (int)XDB::fetchOneCell('SELECT COUNT(DISTINCT a.uid)
+ ' . $this->query);
} else {
return $this->lastcount;
}
$res = XDB::query("SELECT a.uid, a.hruid, a.display_name, a.full_name,
a.sex = 'female' AS femme, a.email_format,
a.token, FIND_IN_SET('watch', a.flags) AS watch_account,
- UNIX_TIMESTAMP(fp.last_seen) AS banana_last, w.last AS watch_last,
+ UNIX_TIMESTAMP(fp.last_seen) AS banana_last, UNIX_TIMESTAMP(w.last) AS watch_last,
a.last_version, g.g_account_name IS NOT NULL AS googleapps,
UNIX_TIMESTAMP(s.start) AS lastlogin, s.host,
a.is_admin, at.perms
$profile->id(), $field);
}
- public static function getCondition(PlUser &$user)
+ public function getCondition(PlUser &$user)
{
- return new UFC_And(new UFC_ProfileUpdated('>=', $user->watch_last),
+ return new UFC_And(new UFC_ProfileUpdated('>', $user->watch_last),
new UFC_WatchContacts($user->id()));
}
}
{
const ID = 2;
- public static function getCondition(PlUser &$user)
+ public function getCondition(PlUser &$user)
{
- return new UFC_And(new UFC_Registered(false, '>=', $user->watch_last),
- new UFC_WatchRegistration($user->id()));
+ return new UFC_And(new UFC_Registered(false, '>', $user->watch_last),
+ new UFC_Or(new UFC_WatchContacts($user->id()),
+ new UFC_WatchPromo($user->id()),
+ new UFC_WatchRegistration($user->id())));
}
}
{
const ID = 3;
- public static function getCondition(PlUser &$user)
+ public function getCondition(PlUser &$user)
{
- return new UFC_And(new UFC_Dead('>=', $user->watch_last, true),
+ return new UFC_And(new UFC_Dead('>', $user->watch_last, true),
new UFC_Or(new UFC_WatchPromo($user->id()),
new UFC_WatchContacts($user->id())));
}
{
const ID = 4;
- public static function getCondition(PlUser &$user)
+ public function getCondition(PlUser &$user)
{
- return new UFC_And(new UFC_Birthday(),
+ return new UFC_And(new UFC_OR(new UFC_Birthday('=', time()),
+ new UFC_And(new UFC_Birthday('<=', time() + 864000),
+ new UFC_Birthday('>', $user->watch_last + 864000))),
new UFC_Or(new UFC_WatchPromo($user->id()),
new UFC_WatchContacts($user->id())));
}
}
+class Watch
+{
+ private static $classes = array('WatchRegistration',
+ 'WatchProfileUpdate',
+ 'WatchDeath',
+ 'WatchBirthday');
+
+ private static function fetchCount(PlUser &$user, $class)
+ {
+ $obj = new $class();
+ $uf = new UserFilter($obj->getCondition($user));
+ return $uf->getTotalCount();
+ }
+
+ public static function getCount(PlUser &$user)
+ {
+ $count = 0;
+ foreach (self::$classes as $class) {
+ $count += self::fetchCount($user, $class);
+ }
+ return $count;
+ }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>
S::assert_xsrf_token();
XDB::execute('UPDATE watch
SET ' . XDB::changeFlag('flags', 'contacts', Env::b('contacts')) . '
- WHERE uid = {?}', S::i('uid'));
+ WHERE uid = {?}', S::i('uid'));
}
if (Env::has('flags_mail')) {
S::assert_xsrf_token();
XDB::execute('UPDATE watch
SET ' . XDB::changeFlag('flags', 'mail', Env::b('mail')) . '
- WHERE uid = {?}', S::i('uid'));
+ WHERE uid = {?}', S::i('uid'));
}
$user = S::user();
pl_redirect('events#newsid'.$eid);
}
+ require_once 'notifs.inc.php';
+ echo Watch::getCount(S::user());
+
function next_event(PlIterator &$it)
{
$user = S::user();
# birthdate and birthdate given by reference directory (library, school...)
birthdate date default null,
birthdate_ref date default null,
+ next_birthday date default null,
deathdate date default null,
deathdate_rec date default null,
insert into profiles
select u.user_id AS pid, u.hruid AS hrpid, u.matricule AS xorg_id,
u.matricule_ax AS ax_id, u.naissance AS birthdate, u.naissance_ini AS birthdate_ref,
+ u.naissance AS next_birthday,
IF(u.deces = 0, NULL, u.deces) AS deathdate,
IF(u.deces = 0, NULL, u.deces) AS deathdate_rec,
IF(FIND_IN_SET('femme', flags), 'female', 'male') AS sex,
--- /dev/null
+../../bin/cron/notifs.birthday.php
\ No newline at end of file
--- /dev/null
+../../bin/connect.db.inc.php
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+echo "Upgrading database"
+mysql x4dat < *.sql
+
+echo "Updating birthday date"
+php birthday.php