$patient_links = $patient_link->loadList(null, null, "{$page}, 30"); $patient_ids1 = CMbArray::pluck($patient_links, "patient_id1"); $patient_ids2 = CMbArray::pluck($patient_links, "patient_id2"); $where = array("patient_id" => CSQLDataSource::prepareIn(array_merge($patient_ids1, $patient_ids2))); $patients = $patient->loadList($where); } else { $patients = $patient->loadList($where, "nom, prenom", "{$page}, 30", null, $leftjoin); } CPatient::massLoadIPP($patients); /** @var CPatientState $patients_state */ $patients_state = CPatient::massLoadBackRefs($patients, "patient_state", "datetime DESC"); $mediusers = CPatientState::massLoadFwdRef($patients_state, "mediuser_id"); /** @var CPatientLink[] $link1 */ $link1 = CPatient::massLoadBackRefs($patients, "patient_link1"); /** @var CPatientLink[] $link2 */ $link2 = CPatient::massLoadBackRefs($patients, "patient_link2"); $patient_link1 = CPatientLink::massLoadFwdRef($link1, "patient_id2"); $patient_link2 = CPatientLink::massLoadFwdRef($link2, "patient_id1"); $patient_link = $patient_link1 + $patient_link2; CPatient::massLoadIPP($patient_link); foreach ($link1 as $_link1) { $_link1->_ref_patient_doubloon = $patient_link[$_link1->patient_id2]; } foreach ($link2 as $_link2) { $_link2->_ref_patient_doubloon = $patient_link[$_link2->patient_id1]; } foreach ($patients_state as $_patient_state) { /** @var CPatient $patient */ $patient = $patients[$_patient_state->patient_id]; $_patient_state->_ref_patient = $patient; $_patient_state->_ref_mediuser = $mediusers[$_patient_state->mediuser_id];