sudo docker run --privileged-d-p 389:389 rroemhild/test-openldap;exit 0
clear-db:
pkill --signal SIGTSTP -f"$(DOLOMON)" &
sudo su postgres -c"echo \"SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname IN ('dolomon_test_db', 'dolomon_minion_test_db') AND pid <> pg_backend_pid();\" | psql"
return$c->app->pg->db->query('SELECT u.id, u.login, u.first_name, u.last_name, u.mail, EXTRACT(\'epoch\' FROM u.last_login) AS last_login, u.confirmed, count(d.id) AS dolos_nb FROM users u JOIN categories c ON c.user_id = u.id LEFT JOIN dolos d ON d.category_id = c.id WHERE u.login LIKE ? OR u.mail LIKE ? GROUP BY u.id ORDER BY '.$sort.''.$dir,'%'.$search.'%','%'.$search.'%')->hashes;
return$c->app->pg->db->query('SELECT u.id, u.login, u.first_name, u.last_name, u.mail, EXTRACT(\'epoch\' FROM u.last_login) AS last_login, u.confirmed, count(d.id) AS dolos_nb FROM users u JOIN categories c ON c.user_id = u.id LEFT JOIN dolos d ON d.category_id = c.id WHERE u.login LIKE ? OR u.mail LIKE ? GROUP BY u.id ORDER BY '.$sort.''.$dir.', id ASC','%'.$search.'%','%'.$search.'%')->hashes;
}
=head2 get_users
Get paginated array of users
=cut
sub get_users{
my$c=shift;
my$page=shift;
...
...
@@ -27,9 +39,14 @@ sub get_users {
$dir='DESC'unless$direq'ASC';
return$c->app->pg->db->query('SELECT u.id, u.login, u.first_name, u.last_name, u.mail, EXTRACT(\'epoch\' FROM u.last_login) AS last_login, u.confirmed, count(d.id) AS dolos_nb FROM users u JOIN categories c ON c.user_id = u.id LEFT JOIN dolos d ON d.category_id = c.id GROUP BY u.id ORDER BY '.$sort.''.$dir.' LIMIT ? OFFSET ?',$nb,$page)->hashes;
return$c->app->pg->db->query('SELECT u.id, u.login, u.first_name, u.last_name, u.mail, EXTRACT(\'epoch\' FROM u.last_login) AS last_login, u.confirmed, count(d.id) AS dolos_nb FROM users u JOIN categories c ON c.user_id = u.id LEFT JOIN dolos d ON d.category_id = c.id GROUP BY u.id ORDER BY '.$sort.''.$dir.', id ASC LIMIT ? OFFSET ?',$nb,$page)->hashes;
If the id is provided, fetch the informations from the database and fill the C<dolos> attribute
with a L<Mojo::Collection> of L<Dolomon::Dolo> belonging to the category.
=cut
sub new{
my$c=shift;
...
...
@@ -71,42 +81,77 @@ sub new {
return$c;
}
=head2 evacuate_to
Changes the C<category_id> of all the L<Dolomon::Dolo> belonging to the current category.
=cut
sub evacuate_to{
my$c=shift;
my$new_cat_id=shift;
$c->app->pg->db->query('UPDATE dolos SET category_id = ? WHERE category_id = ?',($new_cat_id,$c->id));
}
=head2 count
Returns the number of L<Dolomon::Dolo> belonging to the current category.
=cut
sub count{
my$c=shift;
return$c->app->pg->db->query('SELECT SUM(count) FROM dolos WHERE category_id = ?',$c->id)->array->[0];
}
=head2 get_raw_dys
Returns a L<Mojo::Collection> of hash tables representing the yearly stats of the dolos belonging to the current category.
=cut
sub get_raw_dys{
my$c=shift;
return$c->app->pg->db->query('SELECT y.year, SUM(y.count) AS count FROM dolos_year y JOIN dolos d ON y.dolo_id = d.id WHERE d.category_id = ? GROUP BY y.year ORDER BY y.year ASC',$c->id)->hashes;
}
=head2 get_raw_dms
Returns a L<Mojo::Collection> of hash tables representing the monthly stats of the dolos belonging to the current category.
=cut
sub get_raw_dms{
my$c=shift;
return$c->app->pg->db->query('SELECT m.year, m.month, SUM(m.count) AS count FROM dolos_month m JOIN dolos d ON m.dolo_id = d.id WHERE d.category_id = ? GROUP BY m.year, m.month ORDER BY m.year, m.month ASC',$c->id)->hashes;
}
=head2 get_raw_dws
Returns a L<Mojo::Collection> of hash tables representing the weekly stats of the dolos belonging to the current category.
=cut
sub get_raw_dws{
my$c=shift;
return$c->app->pg->db->query('SELECT w.year, w.week, SUM(w.count) AS count FROM dolos_week w JOIN dolos d ON w.dolo_id = d.id WHERE d.category_id = ? GROUP BY w.year, w.week ORDER BY w.year, w.week ASC',$c->id)->hashes;
}
=head2 get_raw_dds
Returns a L<Mojo::Collection> of hash tables representing the dayly stats of the dolos belonging to the current category.
=cut
sub get_raw_dds{
my$c=shift;
return$c->app->pg->db->query('SELECT a.year, a.month, a.day, SUM(a.count) AS count FROM dolos_day a JOIN dolos d ON a.dolo_id = d.id WHERE d.category_id = ? GROUP BY a.year, a.month, a.day ORDER BY a.year, a.month, a.day ASC',$c->id)->hashes;
}
=head2 get_raw_dhs
Returns a L<Mojo::Collection> of hash tables representing the hits’ stats of the dolos belonging to the current category.