From cf2a4a79eb8344ab1c3303d4bdbb80c91d94925b Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Tue, 27 Dec 2011 01:36:09 +0100 Subject: Section's Styles are nowonlyavailable by a getter. Also fixed many MySQL Queries. These SELECT ... WHERE foo = (SELECT...) have not worked as expected, so now there are many ugly joins... --- ratatoeskr/sys/models.php | 97 ++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 35 deletions(-) (limited to 'ratatoeskr/sys/models.php') diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php index c4e0991..78057c5 100644 --- a/ratatoeskr/sys/models.php +++ b/ratatoeskr/sys/models.php @@ -259,7 +259,7 @@ class User extends BySQLRowEnabled public function get_groups() { $rv = array(); - $result = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE `id` = (SELECT `group` FROM `PREFIX_group_members` WHERE `user` = %d)", $this->id); + $result = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name` FROM `PREFIX_groups` `a` INNER JOIN `PREFIX_group_members` `b` ON `a`.`id` = `b`.`group` WHERE `b`.`user` = %d", $this->id); while($sqlrow = mysql_fetch_assoc($result)) $rv[] = Group::by_sqlrow($sqlrow); return $rv; @@ -427,9 +427,11 @@ class Group extends BySQLRowEnabled public function get_members() { $rv = array(); - $result = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE `id` = (SELECT `user` FROM `PREFIX_group_members` WHERE `group` = %d)", $this->id); + $result = qdb("SELECT `a`.`id` AS `id`, `a`.`username` AS `username`, `a`.`pwhash` AS `pwhash`, `a`.`mail` AS `mail`, `a`.`fullname` AS `fullname`, `a`.`language` AS `language` +FROM `PREFIX_users` `a` INNER JOIN `PREFIX_group_members` `b` ON `a`.`id` = `b`.`user` +WHERE `b`.`group` = %d", $this->id); while($sqlrow = mysql_fetch_assoc($result)) - $rv[] = User::by_sqlrow($result); + $rv[] = User::by_sqlrow($sqlrow); return $rv; } @@ -1185,6 +1187,7 @@ class Style extends BySQLRowEnabled public function delete() { qdb("DELETE FROM `PREFIX_styles` WHERE `id` = %d", $this->id); + qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `style` = %d", $this->id); } } @@ -1391,12 +1394,10 @@ class Section extends BySQLRowEnabled * $name - The name of the section. * $title - The title of the section (a object). * $template - Name of the template. - * $styles - List of