Beispiel #1
0
 /**
  * @param \User\Model\User $item
  */
 public function suggest($item)
 {
     $item->prepairSuggest();
     $select = $this->getDbSql()->select(array('u' => self::TABLE_NAME), array('id', 'username', 'fullName', 'email', 'role'));
     $select->columns(['id', 'username', 'fullName', 'email', 'role']);
     $select->where(['(u.username LIKE ? OR u.fullName LIKE ? OR u.email LIKE ?)' => ['%' . $item->getUsername() . '%', '%' . $item->getUsername() . '%', '%' . $item->getUsername() . '%']]);
     $select->where(['role  != ?' => User::ROLE_MENTOR]);
     //        $select->where(['role  != ?'=> User::ROLE_SUPERADMIN]);
     if ($item->getOption('ids')) {
         $select->where(['u.id' => $item->getOption('ids')]);
     }
     if ($item->getRole()) {
         $select->where(['u.role' => $item->getRole()]);
     }
     $select->limit(20);
     $query = $this->getDbSql()->buildSqlString($select);
     $rows = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE);
     $result = [];
     $userIds = [];
     if ($rows->count()) {
         foreach ($rows as $row) {
             $row = (array) $row;
             $row['label'] = $row['username'] . ' - ' . ($row['fullName'] ?: $row['email']);
             $result[] = $row;
             $userIds[$row['id']] = $row['id'];
         }
     }
     return $result;
 }