public function findByWithUser($names, $ids) { if (!is_array($ids)) { $ids = array($ids); } if (!is_array($names)) { $names = array($names); } $c = static::getModelName(); $sth = ServiceDb::getInstance()->prepare(' select `' . static::getTableName() . '`.*, `user`.* from `' . static::getTableName() . '` left join `user` on `user`.`id`=`' . static::getTableName() . '`.`user_id` where `' . implode('`=? and `', $names) . '`=?'); $sth->execute($ids); $arr = array(); foreach ($sth->fetchAll() as $data) { if ($data['id'] == ServiceAuth::getInstance()->getUser()->getId()) { continue; } $a = new ModelUser(); $a->hydrate($data); $b = new $c(); $b->hydrate($data); $a->setProfile($b); $arr[] = $a; } return $arr; }
public function findAllWithReputation() { $sth = ServiceDb::getInstance()->prepare(' select `user`.*, (`inBounds`/(`inBounds`+`outBounds`)) `reputation` from `user` order by `reputation` desc, `inBounds` desc'); $sth->execute(); $arr = array(); foreach ($sth->fetchAll() as $data) { $a = new ModelUser(); $a->hydrate($data); $arr[] = $a; } return $arr; }
public function countDesc() { $sth = ServiceDb::getInstance()->prepare(' select `action`.* ,`user`.* ,count(*) as `nb` from `action` left join `user` on `user`.`id`=`action`.`user_id` group by `action`.`user_id` order by `nb` desc'); $sth->execute(); $arr = array(); foreach ($sth->fetchAll() as $data) { $a = new ModelUser(); $a->hydrate($data); $b = new ModelAction(); $b->hydrate($data); $b->setUser($a); $arr[] = array($b, $data['nb']); } return $arr; }