public function findAllCoworkers() { $k = ''; foreach (array_keys(ModelUser::newInstance()->getPersistentData()) as $v) { $k .= "`user1`.`{$v}` `a__{$v}`, `user2`.`{$v}` `b__{$v}`,"; } $sth = ServiceDb::getInstance()->prepare(' select `user_has_user`.*, ' . $k . ' `user1`.`id` `a__id`, `user2`.`id` `b__id` from `user_has_user` left join `user` `user1` on `user1`.`id`=`user_has_user`.`user_id1` left join `user` `user2` on `user2`.`id`=`user_has_user`.`user_id2` where (`user_has_user`.`type` & ' . ModelUser_has_user::WORK . ' ) and exists ( select 1 from `user_has_user` `foo` where `user_has_user`.`user_id2`=`foo`.`user_id1` and (`foo`.`type` & ' . ModelUser_has_user::WORK . ' ) )'); $sth->execute(); $pairs = array(); $arr = array(); foreach ($sth->fetchAll() as $data) { $datax = array(); // FIXME : find another way to avoir doublons if (in_array($data['a__id'] . '.' . $data['b__id'], $pairs) || in_array($data['b__id'] . '.' . $data['a__id'], $pairs)) { continue; } $pairs[] = $data['a__id'] . '.' . $data['b__id']; $a = ModelUser_has_user::newInstance()->hydrate($data); foreach ($data as $k => $v) { if (strpos($k, 'a__') === 0) { $datax[str_replace('a__', '', $k)] = $v; } } $a->setUser1(ModelUser::newInstance()->hydrate($datax)); foreach ($data as $k => $v) { if (strpos($k, 'b__') === 0) { $datax[str_replace('b__', '', $k)] = $v; } } $a->setUser2(ModelUser::newInstance()->hydrate($datax)); $arr[] = $a; } return $arr; }
public function delUser_has_user(ModelUser_has_user $relation) { unset($this->user_has_user[$relation->getUser_id2()]); return $this; }