/** * Get the users who want to receive a certain alert type. * * @param MybbStuff_MyAlerts_Entity_AlertType $alertType The alert type * to check. * @param array $users An array of User * IDs to check. * @param int $findUsersBy The column to * find users by. * Should be one of * FIND_USERS_BY_UID * or * FIND_USERS_BY_USERNAME * * @return array */ public function doUsersWantAlert(MybbStuff_MyAlerts_Entity_AlertType $alertType, array $users = array(), $findUsersBy = self::FIND_USERS_BY_UID) { $usersWhoWantAlert = array(); switch ($findUsersBy) { case self::FIND_USERS_BY_USERNAME: $users = array_map(array($this->db, 'escape_string'), $users); $usernames = "'" . implode("','", $users) . "'"; $query = $this->db->simple_select('users', 'uid, myalerts_disabled_alert_types, usergroup', "username IN({$usernames})"); break; case self::FIND_USERS_BY_UID: default: $users = array_map('intval', $users); $uids = "'" . implode("','", $users) . "'"; $query = $this->db->simple_select('users', 'uid, myalerts_disabled_alert_types', "uid IN({$uids})"); break; } while ($user = $this->db->fetch_array($query)) { $disabledAlertTypes = @json_decode($user['myalerts_disabled_alert_types']); if (empty($disabledAlertTypes) || !in_array($alertType->getId(), $disabledAlertTypes) || !$alertType->getCanBeUserDisabled()) { $usersWhoWantAlert[] = $user; } } return $usersWhoWantAlert; }
/** * @param MybbStuff_MyAlerts_Entity_AlertType $type The alert type to set. * * @return MybbStuff_Myalerts_Entity_Alert $this. */ public function setType(MybbStuff_MyAlerts_Entity_AlertType $type) { $this->type = $type; $this->setTypeId($type->getId()); return $this; }