_getSchoolReportContacts($schoolIds); foreach ($list as $idx => $row) { $list[$idx]['contacts'] = empty($schoolUsers[$row['id']]) ? null : $schoolUsers[$row['id']]; } } return parent::_prepareList($list); } /** * @param array $schoolIds * * @return $this|array [schoolId => [['id' => , 'name' =>], ...], ...] */ protected function _getSchoolReportContacts(array $schoolIds) { if (empty($schoolIds)) { return $this; } $select = $this->_db->select(); $select->from($this->_getPair('User'), array('key' => 'idSchool', 'id', 'name')); $select->where('User.idSchool IN(?)', $schoolIds, Qs_Db::INT_TYPE); $select->where('User.reportContact = "y"'); $select->where('User.system = "n"'); return $this->_db->fetchAll($select, null, Qs_Db::FETCH_GROUP); } public function insert($data = null) { throw new Exception('Method "' . __METHOD__ . '" is no supported'); } public function update($data = null) { throw new Exception('Method "' . __METHOD__ . '" is no supported'); } public function link($userId) { return $this->_getTable('User')->update( array('reportContact' => 'y'), array('idSchool = ?' => $this->getPrimaryKey(), 'id = ?' => $userId) ); } public function unlink($userId) { return $this->_getTable('User')->update( array('reportContact' => 'n'), array('idSchool = ?' => $this->getPrimaryKey(), 'id = ?' => $userId) ); } public function getSchool4Select() { return $this->_get4Select('School', array('id', 'name'), null, null, 'name'); } public function getNonContactUserList($schoolId) { $select = $this->_db->select(); $select->from($this->_getPair('User'), array('id', 'name')); $select->where('idSchool = ?', (int) $schoolId); $select->where('reportContact = "n"'); $select->where('system = "n"'); $select->order('name'); return $this->_db->fetchAll($select); } public function getNonContactUser4Select() { $result = array(); $list = $this->getNonContactUserList($this->getPrimaryKey()); foreach ($list as $row) { $result[$row['id']] = $row['name']; } return $result; } }