_filter, 'associateCategoryId'); if ($categoryId) { $select->where('EXISTS ' . Model::getAssociateCategoryFilter([$categoryId])); } return $this; } protected function _prepareList(&$list) { parent::_prepareList($list); $this->_addPersonnel($list); return $this; } protected function _addPersonnel(&$list) { if (empty($list)) { return $this; } $ids = Qs_Array::fetchCol($list, 'id'); $select = $this->_db->select(); $select->from($this->_getPair('User'), ['companyId', 'name' => UserModel::getFullNameWithNicknameExpr()]); $select->join($this->_getPair('CompanyUtilityStaff', 'cus'), '`cus`.`userId` = `User`.`id`', ['sorter']); $select->join($this->_getPair('PersonnelPosition', 'p'), '`p`.`id` = `cus`.`positionId`', ['position' => 'title']); $select->where('`cus`.`companyId` IN (?)', $ids, Qs_Db::INT_TYPE); $select->where('`User`.`status` = ?', UserEntity::STATUS_ACTIVE); $select->order('cus.sorter'); $personnel = $this->_db->fetchAll($select, [], Qs_Db::FETCH_GROUP); foreach ($list as &$item) { $item['personnel'] = (array_key_exists($item['id'], $personnel)) ? $personnel[$item['id']] : []; } return $this; } }