Streams Class
Static methods for the Streams models.
Item Index
Methods
- actionUrl static
- calculateAccess static
- close static
- create static
- displayName static
- experience static
- fetch static
- fetchOne static
- forUser static
- getRelations
- interests static
- invite static
- isAuthorizedToCreate static
- join static
- leave static
- lookup static
- my static
- participating static
- register static
- relate static
- related static
- relatedFromTotals static
- relatedToTotals static
- request static
- requestedField static
- requestedFields static
- requestedMessageType static
- requestedName static
- requestedPublisherId static
- requestedType static
- splitFullName static
- subscribe static
- take static
- unrelate static
- unsubscribe static
Properties
- $ACCESS_SOURCES
- $ACCESS_SOURCES['contact']
- $ACCESS_SOURCES['direct']
- $ACCESS_SOURCES['inherited_contact']
- $ACCESS_SOURCES['inherited_direct']
- $ACCESS_SOURCES['inherited_public']
- $ACCESS_SOURCES['public']
- $ADMIN_LEVEL
- $ADMIN_LEVEL['invite']
- $ADMIN_LEVEL['manage']
- $ADMIN_LEVEL['max']
- $ADMIN_LEVEL['none']
- $ADMIN_LEVEL['own']
- $ADMIN_LEVEL['tell']
- $cache static
- $dontCache static
- $fetch static
- $followedInvite
- $READ_LEVEL
- $READ_LEVEL['content']
- $READ_LEVEL['max']
- $READ_LEVEL['messages']
- $READ_LEVEL['none']
- $READ_LEVEL['participants']
- $READ_LEVEL['relations']
- $READ_LEVEL['see']
- $requestedName_override static
- $requestedPublisherId_override static
- $WRITE_LEVEL
- $WRITE_LEVEL['close']
- $WRITE_LEVEL['closePending']
- $WRITE_LEVEL['edit']
- $WRITE_LEVEL['join']
- $WRITE_LEVEL['max']
- $WRITE_LEVEL['none']
- $WRITE_LEVEL['post']
- $WRITE_LEVEL['postPending']
- $WRITE_LEVEL['suggest']
- WRITE_LEVEL['relate']
- WRITE_LEVEL['relations']
- WRITE_LEVEL['vote']
Events
- Streams/fetch/$streamType
- Streams/invite
- Streams/register
- Streams/register
- Streams/relateFrom/$streamType
- Streams/relateFrom/$streamType
- Streams/relateTo/$categoryType
- Streams/relateTo/$categoryType
- Streams/request
- Streams/request
- Streams/unrelateFrom/$streamType
- Streams/unrelateFrom/$streamType
- Streams/unrelateTo/$categoryType
- Streams/unrelateTo/$streamType
- Streams/updateRelation/$categoryType
- Streams/updateRelation/$streamType
Methods
actionUrl
-
$publisherId
-
$name
-
$what
A convenience method to get the URL of the streams-related action
Parameters:
-
$publisherId
StringThe name of the publisher
-
$name
StringThe name of the stream
-
$what
StringDefaults to 'stream'. Can also be 'message', 'relation', etc.
Returns:
The corresponding URL
calculateAccess
-
$asUserId
-
$publisherId
-
$streams
-
[$recalculate=false]
-
[$actualPublisherId=null]
-
[$inheritAccess=true]
Calculates the access for one or more streams by querying the database Modifies the objects in the $streams array, setting their access levels. After the function returns, you will be able to call the methods testReadLevel(), testWriteLevel() and testAdminLevel() on these streams before using them on the user's behalf.
Parameters:
-
$asUserId
StringSet this to the user relative to whom access is calculated. If this matches the publisherId, just sets full access and calls publishedByFetcher(true). If this is '', only returns the streams anybody can see. If this is null, the logged-in user's id is used, or '' if no one is logged in
-
$publisherId
StringThe id of the user publishing these streams
-
$streams
ArrayAn array of streams, obtained for example by Streams::fetch
-
[$recalculate=false]
Boolean optionalPass true here to force recalculating access to streams for which access was already calculated
-
[$actualPublisherId=null]
String optionalFor internal use only. Used by Streams::isAuthorizedToCreate function.
-
[$inheritAccess=true]
String optionalSet to false to skip inheriting access from other streams, even if specified
Returns:
The number of streams that were recalculated
close
-
$asUserId
-
$publisherId
-
$streamName
-
[$options=array()]
Closes a stream, which prevents anyone from posting messages to it unless they have WRITE_LEVEL >= "close", as well as attempting to remove all relations to other streams. A "cron job" can later go and delete closed streams. The reason you should avoid deleting streams right away is that other subscribers may still want to receive the last messages posted to the stream.
Parameters:
-
$asUserId
StringThe id of the user who would be closing the stream
-
$publisherId
StringThe id of the user publishing the stream
-
$streamName
StringThe name of the stream
-
[$options=array()]
Array optionalCan include "skipAccess"
create
-
$asUserId
-
$publisherId
-
[$type=null]
-
[$fields=array()]
-
[$relate=array()]
-
[&$result=null]
Creates a new stream in the system
Parameters:
-
$asUserId
StringThe user who is attempting to create the stream.
-
$publisherId
StringThe id of the user to publish the stream.
-
[$type=null]
String | Array optionalThe type of the stream to create. Required unless you specify the name of the stream in the options, and you've specified its type in a config file listed under a config named "Streams/userStreams/$module".
-
[$fields=array()]
Array optionalUse this to set additional fields for the stream:
-
[title=null]
String optionalYou can set the stream's title
-
[icon=null]
String optionalYou can set the stream's icon
-
[title=null]
String optionalYou can set the stream's content
-
[attributes=null]
String | Array optionalYou can set the stream's attributes directly as a JSON string
-
[readLevel=null]
String | Integer optionalYou can set the stream's read access level, see Streams::$READ_LEVEL
-
[writeLevel=null]
String | Integer optionalYou can set the stream's write access level, see Streams::$WRITE_LEVEL
-
[adminLevel=null]
String | Integer optionalYou can set the stream's admin access level, see Streams::$ADMIN_LEVEL
-
[name=null]
String optionalHere you can specify an exact name for the stream to be created. Otherwise a unique one is generated automatically.
-
[skipAccess=false]
Boolean optionalSkip all access checks when creating and relating the stream.
-
-
[$relate=array()]
Array optionalFill this out in order to relate the newly created stream to a category stream, and also inheritAccess from it. When using this option, a user may be authorized to create a stream they would otherwise not be authorized to create. This happens when the asUserId user has a writeLevel of at least "relate" in the existing category stream, and the publisherId user has a template for this stream type that is related to either the category stream, or a template for the category stream's type.
-
[publisherId]
String optionalThe id of the user publishing the category stream, defaults to $publisherId
-
[streamName]
String optionalThe name of the category stream
-
[type]
String optionalThe type of relation, defaults to ""
-
[weight]
String optionalTo set the weight for the relation. You can pass a numeric value here, or something like "max+1" to make the weight 1 greater than the current MAX(weight)
-
-
[&$result=null]
Array optionalOptionally pass a reference here to hold the result of calling Streams::relate().
Returns:
Returns the stream that was created.
displayName
-
$userId
-
$streams=null
-
$options=array()
-
[$options.short]
-
[$options.show]
-
[$options.html]
-
[$options.escape]
-
[$options.asUserId=Users::loggedInUser()]
-
[$options.fullAccess=false]
-
[$fallback='Someone']
-
[$fallback='Someone']
Produce user's display name
Parameters:
-
$userId
String | Users_UserCan be Users_User object or a string containing a user id
-
$streams=null
ArrayAn array of streams fetched for this user. If it is null, we fetch them as the logged-in user.
-
$options=array()
Array -
[$options.short]
Boolean optionalShow one part of the name only
-
[$options.show]
Boolean optionalThe parts of the name to show. Can have the letters "f", "l", "u" in any order.
-
[$options.html]
Boolean optionalIf true, encloses the first name, last name, username in span tags. If an array, then it will be used as the attributes of the html.
-
[$options.escape]
Boolean optionalIf true, does HTML escaping of the retrieved field
-
[$options.asUserId=Users::loggedInUser()]
String optionalOptionally override which user to get the display name as
-
[$options.fullAccess=false]
String optionalif true, sets the $asUserId = $userId
-
[$fallback='Someone']
String optionalHTML to return if there is no info to get displayName from.
-
[$fallback='Someone']
String | Null optionalWhat to return if there is no info to get displayName from.
Returns:
experience
-
[$experienceId='main']
Get a stream of type "Streams/experience" published by the community
Parameters:
-
[$experienceId='main']
String optional
Returns:
fetch
-
$asUserId
-
$publisherId
-
$name
-
[$fields='*']
-
[$options=array()]
Fetches streams from the database.
Parameters:
-
$asUserId
StringSet this to the user for which you are fetching the streams. If this matches the publisherId, just returns the streams. If this is '', only returns the streams anybody can see. Otherwise, return the streams joined with the calculated access settings. If you pass null here, then either the logged-in user's id or '' will be used.
-
$publisherId
StringThe id of the user publishing these streams
-
$name
String | Array | Db_RangeThe name of the stream to fetch. Can end in "/" for template streams. Also it can be an array of stream names, or a custom Db_Range for stream names
-
[$fields='*']
String optionalComma delimited list of fields to retrieve in the stream. Must include at least "publisherId" and "name". since make up the primary key of the stream table.
-
[$options=array()]
Array optionalProvide additional query options like 'limit', 'offset', 'orderBy', 'where' etc. See Db_Query_Mysql::options().
-
[refetch]
Boolean optionalIgnore cache of previous calls to fetch, and save a new cache if necessary.
-
[dontCache]
Boolean optionalDo not cache the results of fetching the streams
-
[withParticipant=false]
Boolean optionalAdditionally call ->set('participant', $p) on the stream objects, with the participant object corresponding to $asUserId, if any.
-
[withMessageTotals]
Array optionalPass an array of ($streamName => $messageTypes) here to additionally call ->set('messageTotals', $t) on the stream objects.
-
[withRelatedToTotals]
Array optionalpass array('withRelatedFromTotals' => array($streamName => true)) for all rows pass array('withRelatedFromTotals' => array($streamName => array($relationType$, ...))) for particular rows to additionally call ->set('relatedToTotals', $t) on the stream objects.
-
[withRelatedFromTotals]
Array optionalpass array('withRelatedFromTotals' => array($streamName => true)) for all rows pass array('withRelatedFromTotals' => array($streamName => array('relationType', ...))) for particular rows to additionally call ->set('relatedFromTotals', $t) on the stream objects.
-
Returns:
Returns an array of Streams_Stream objects with access info calculated specifically for $asUserId . Make sure to call the methods testReadLevel(), testWriteLevel() and testAdminLevel() on these streams before using them on the user's behalf.
fetchOne
-
$asUserId
-
$publisherId
-
$name
-
$fields='*'
-
$options=array()
-
[$options.refetch]
-
[$options.dontCache]
-
[$options.withParticipant]
-
[$options.withMessageTotals]
-
[$options.withRelatedToTotals]
-
[$options.withRelatedFromTotals]
Fetches one stream from the database.
Parameters:
-
$asUserId
StringSet this to the user for which you are fetching the streams. If this matches the publisherId, just returns the streams. If this is '', only returns the streams anybody can see. Otherwise, return the streams joined with the calculated access settings. If you pass null here, then either the logged-in user's id or '' will be used.
-
$publisherId
StringThe id of the user publishing these streams
-
$name
String | Array | Db_RangeThe name of the stream to fetch. Can end in "/" for template streams. Also it can be an array of stream names, or a custom Db_Range for stream names
-
$fields='*'
String | BooleanMust include "publisherId" and "name" fields, since they make up the primary key of the stream table. Pass true here to throw an exception if the stream is missing.
-
$options=array()
ArrayProvide additional query options like 'limit', 'offset', 'orderBy', 'where' etc. See Db_Query_Mysql::options().
-
[$options.refetch]
Boolean optionalIgnore cache of previous calls to fetch, and save a new cache if necessary.
-
[$options.dontCache]
Boolean optionalDo not cache the results of fetching the streams
-
[$options.withParticipant]
Boolean optionalAdditionally call ->set('participant', $p) on the stream object, with the participant object corresponding to $asUserId, if any.
-
[$options.withMessageTotals]
Array optionalPass an array of arrays ($streamName => $messageTypes) here to additionally call ->set('messageTotals', $t) on the stream objects.
-
[$options.withRelatedToTotals]
Array optionalpass array('withRelatedToTotals' => array('streamName' => true)) for all rows pass array('withRelatedToTotals' => array('streamName' => array('relationType', ...))) for particular rows to additionally call ->set('relatedToTotals', $t) on the stream objects.
-
[$options.withRelatedFromTotals]
Array optionalpass array('withRelatedFromTotals' => array('streamName' => true)) for all rows pass array('withRelatedFromTotals' => array('streamName' => array('relationType', ...))) for particular rows to additionally call ->set('relatedFromTotals', $t) on the stream objects.
Returns:
Returns a Streams_Stream object with access info calculated specifically for $asUserId . Make sure to call the methods testReadLevel(), testWriteLevel() and testAdminLevel() on these streams before using them on the user's behalf.
forUser
-
$asUserId
-
$publisherId
Get all the streams starting with "Streams/user/" for a particular user. This is cached via Streams:;fetch, so you can call it repeatedly.
Parameters:
-
$asUserId
StringThe id of the user who's supposed to be accessing the stream.
-
$publisherId
StringThe id of the user who is publishing the streams.
Returns:
getRelations
-
$asUserId
-
$toPublisherId
-
$toStreamName
-
$type
-
$fromPublisherId
-
$fromStreamName
-
$relatedTo
-
$relatedFrom
-
$categories
-
$streams
-
$options=array()
-
[$options.skipAccess=false]
Gets relations. At most one of toStreamName, toStreamName can be an array.
Parameters:
-
$asUserId
StringThe user who is fetching
-
$toPublisherId
StringThe publisher of the category
-
$toStreamName
String | ArrayThe name of the category. May be turned into an array.
-
$type
StringThe type of the relation.
-
$fromPublisherId
StringThe publisher of the member stream(s)
-
$fromStreamName
String | ArrayThe name of the member stream(s). May be turned into an array.
-
$relatedTo
Arrayreference to array of Streams_RelatedTo to fill
-
$relatedFrom
Arrayreference to array of Streams_RelatedFrom to fill
-
$categories
Arrayreference to array of Streams_Stream to fill with categories
-
$streams
Arrayreference to array of Streams_Stream to fill with streams
-
$options=array()
ArrayAn array of options that can include:
-
[$options.skipAccess=false]
Boolean optionalIf true, skips the access checks and just relates the stream to the category
interests
-
[$communityId=Users::communityId()]
Get a structured, sorted array with all the interests in a community
Parameters:
-
[$communityId=Users::communityId()]
String optionalthe id of the community
Returns:
an array of $category => ($subcategory =>) $interest
invite
-
$publisherId
-
$streamName
-
$who
-
[$options=array()]
Invites a user (or a future user) to a stream .
Parameters:
-
$publisherId
StringThe id of the stream publisher
-
$streamName
StringThe name of the stream the user will be invited to
-
$who
ArrayArray that can contain the following keys:
-
[userId]
String | Array optionaluser id or an array of user ids
-
[platform]
String optionalplatform for which uids are passed
-
[uid]
String | Array optionalplatform uid or array of uids
-
[label]
String | Array optionallabel or an array of labels, or tab-delimited string
-
[identifier]
String | Array optionalidentifier such as an email or mobile number, or an array of identifiers, or tab-delimited string
-
[newFutureUsers]
Integer optionalthe number of new Users_User objects to create via Users::futureUser in order to invite them to this stream. This typically is used in conjunction with passing the "html" option to this function.
-
[token=false]
Boolean optionalpass true here to save a Streams_Invite row with empty userId, which is used whenever someone shows up with the token and presents it via "Q.Streams.token" querystring parameter. See the Streams/before/Q_objects.php hook for more information.
-
-
[$options=array()]
Array optional-
[addLabel]
String | Array optionallabel or an array of ($label => array($title, $icon)) for adding publisher's contacts
-
[addMyLabel]
String | Array optionallabel or an array of ($label => array($title, $icon)) for adding asUserId's contacts
-
[readLevel]
String | Integer optionalthe read level to grant those who are invited
-
[writeLevel]
String | Integer optionalthe write level to grant those who are invited
-
[adminLevel]
String | Integer optionalthe admin level to grant those who are invited
-
[permissions]
Array optionalarray of additional permissions to grant
-
[displayName]
String optionalthe display name to use to represent the inviting user
-
[appUrl]
String optionalCan be used to override the URL to which the invited user will be redirected and receive "Q.Streams.token" in the querystring.
-
[html]
Array optionalan array of ($template, $batchName) such as ("MyApp/foo.handlebars", "foo") for generating html snippets which can then be viewed from and printed via the action Streams/invitations?batchName=$batchName&invitingUserId=$asUserId&limit=$limit&offset=$offset
-
[asUserId=Users::loggedInUser(true)->id]
String optionalInvite as this user id, defaults to logged-in user
-
[skipAccess]
Boolean optionalwhether to skip access checks when adding labels and contacts
-
Returns:
Returns array with keys "success", "userIds", "statuses", "identifierTypes", "alreadyParticipating". The userIds array contains userIds from "userId" first, then "identifiers", "uids", "label", then "newFutureUsers". The statuses is an array of the same size and in the same order. The identifierTypes array is in the same order as well. If the "token" option was set to true, the array also contains the "invite" key pointing to a Streams_Invite object that was saved in the database (whose userId field is empty because anyone with the token may accept this invite).
isAuthorizedToCreate
-
$userId
-
$publisherId
-
$streamType
-
[$relate=array()]
Calculates whether a given user is authorized by a specific publisher to create a particular type of stream.
Parameters:
-
$userId
StringThe user who would be creating the stream.
-
$publisherId
StringThe id of the user who would be publishing the stream.
-
$streamType
StringThe type of the stream that would be created
-
[$relate=array()]
Array optionalThe user would also be authorized if the stream would be related to an existing category stream, in which the user has a writeLevel of at least "relate", and the user that would be publishing this new stream has a template for this stream type that is related to either the category stream or a template matching the category stream. To test for this, pass an array with the following keys:
-
publisherId
StringThe id of the user publishing that stream, defaults to $publisherId
-
streamName
StringThe name of the stream to which the new stream would be related
-
type
StringThe type of relation, defaults to ""
-
Returns:
Returns a stream template the user must use, otherwise a boolean true/false to indicate a yes or no regardless of template.
join
-
$asUserId
-
$publisherId
-
$streams
-
[$options=array()]
If the user is not participating in the stream yet, inserts a participant record and posts a "Streams/join" or "Streams/visit" type message to the stream, depending on whether the user is already participating in the stream. Otherwise updates the participant record's timestamp and other things. Also relates every stream joined to streams named under the config field "Streams"/"types"/$streamType/"participating"
Parameters:
-
$asUserId
StringThe id of the user that is joining. Pass null here to use the logged-in user's id.
-
$publisherId
StringThe id of the user publishing all the streams
-
$streams
ArrayAn array of Streams_Stream objects or stream names
-
[$options=array()]
Array optionalAn associative array of options.
-
[subscribed]
Boolean optionalIf true, the user is set as subscribed
-
[posted]
Boolean optionalIf true, the user is set as subscribed
-
[extra]
Array optionalAny extra information to tree-merge for the participants
-
[noVisit]
Boolean optionalIf user is already participating, don't post a "Streams/visited" message
-
[skipAccess]
Boolean optionalIf true, skip access check for whether user can join
-
[skipRelationMessages=true]
Boolean optionalif true, skip posting messages on the stream about being related to the Streams/participating streams of the joining user with id asUserId's
-
Returns:
Returns an array of (streamName => Streams_Participant) pairs. The newly inserted rows will have wasInserted() return true.
leave
-
$asUserId
-
$publisherId
-
$streams
-
[$options=array()]
If the user is participating in (some of) the streams, sets state of participant row as "left" and posts a "Streams/leave" type message to the streams. Also unrelates every stream left to streams named under the config field "Streams"/"types"/$streamType/"participating"
Parameters:
-
$asUserId
StringThe id of the user that is joining. Pass null here to use the logged-in user's id.
-
$publisherId
StringThe id of the user publishing all the streams
-
$streams
ArrayAn array of Streams_Stream objects or stream names
-
[$options=array()]
Array optionalAn associative array of options.
-
[extra]
Array optionalAny extra information to tree-merge for the participants
-
[skipAccess]
Boolean optionalIf true, skip access check for whether user can join
-
[skipRelationMessages=true]
Boolean optionalif true, skip posting messages on the stream about being unrelated to the joining asUserId's Streams/participating streams.
-
Returns:
Returns an array of (streamName => Streams_Participant) pairs
lookup
-
$publisherId
-
$types
-
$title
Look up stream by types and title filter
Parameters:
-
$publisherId
StringThe id of the publisher whose streams to look through
-
$types
String | ArrayThe possible stream type, or an array of types
-
$title
StringA string to compare titles by using SQL's "LIKE" statement
my
-
$field='content'
-
[$escape=false]
A shorthand to get a stream whose name starts with "Streams/user/".
Parameters:
-
$field='content'
String | ArrayOptional. Defaults to "content". Can be an array of fields, in which case the function returns an array.
-
[$escape=false]
Boolean optionalIf true, escapes as HTML
Returns:
Returns the value of the field, or an array of values, depending on whether $field is an array or a string
participating
-
[$options.type]
-
[$options=array()]
Gets the streams related by relation of type "Streams/participating" to the given category stream. Typically, these relations are added and removed when the user joins or leaves the related streams, which is done automatically by the Streams plugin with the streams named in under the config field "Streams"/"types"/$streamType/"participating", which is an array of stream names.
Parameters:
-
[$options.type]
String | Array | Db_Range optionalFilter the type(s) of the streams to return, that the user is participating in.
-
[$options=array()]
Array optionaloptions you can pass to Streams::relate() method
-
[publisherId=Users::loggedInUser(true)->id]
String optionalthe publisher of the category stream
-
[categoryName='Streams/participating']
String optionalthe name of the category stream
-
[asUserId=Users::loggedInUser(true)->id]
String optionalthe user to fetch as
-
Returns:
Returns array($relations, $relatedStreams, $stream). However, if $streamName wasn't a string or ended in "/" then the third parameter is an array of streams. Also, if $options['streamsOnly'] or $options['relationsOnly'] is set, then returns only $relatedStreams or $relations.
register
-
$fullName
-
$identifier
-
[$icon=true]
-
[$options=array()]
Registers a user. Can be hooked to 'Users/register' before event so it can override standard functionality. Method ensures user registration based on full name and also handles registration of invited user
Parameters:
-
$fullName
Array | StringA string, or an array with keys
-
first
StringThe first name
-
last
StringThe last name
-
-
$identifier
String | ArrayCan be an email address or mobile number. Or it could be an array of $type => $info
-
[identifier]
String optionalan email address or phone number
-
[device]
Array optionalan array with keys "deviceId", "platform", "appId", "version", "formFactor" to store in the Users_Device table for sending notifications
-
[app]
Array optionalan array with "platform" key, and optional "appId"
-
-
[$icon=true]
Array | String | True optionalBy default, the user icon is "default". But you can pass here an array of filename => url pairs, or a gravatar url to download the various sizes from gravatar. Finally, you can pass true to generate an icon instead of using the default icon. If $identifier['app']['platform'] is specified, and $icon==true, then an attempt will be made to download the icon from the user's account on the platform.
-
[$options=array()]
Array optionalAn array of options that could include:
-
[activation]
String optionalThe key under "Users"/"transactional" config to use for sending an activation message. Set to false to skip sending the activation message for some reason.
-
Returns:
relate
-
$asUserId
-
$toPublisherId
-
$toStreamName
-
$type
-
$fromPublisherId
-
$fromStreamName
-
$options=array()
-
[$options.skipAccess=false]
-
[$options.skipMessageTo=false]
-
[$options.skipMessageFrom=false]
-
[$options.weight]
-
[$options.extra]
Make the stream a member of category or other aggregating stream, First parameter set - where to add, Second parameter set - what to add NOTE: this currently only works when fromPublisherId and toPublisherId are on same Q cluster
Parameters:
-
$asUserId
StringThe user who is making aggreagtor operation on the stream (add stream to category)
-
$toPublisherId
StringThe user who has published the category stream
-
$toStreamName
String | ArrayThe name of the category stream. Pass an array of strings to relate a single stream to multiple categories, but in that case make sure fromStreamName is a string.
-
$type
StringThe type of the relation
-
$fromPublisherId
StringThe user who has published the related stream
-
$fromStreamName
StringThe name of the related stream. Pass an array of strings to relate multiple streams to a single category, but in that case make sure toStreamName is a string.
-
$options=array()
ArrayAn array of options that can include:
-
[$options.skipAccess=false]
Boolean optionalIf true, skips the access checks and just relates the stream to the category
-
[$options.skipMessageTo=false]
Boolean optionalIf true, skips posting the Streams/relatedFrom message to the "to" streams
-
[$options.skipMessageFrom=false]
Boolean optionalIf true, skips posting the Streams/relatedFrom message to the "from" streams
-
[$options.weight]
Double | String optionalPass a numeric value here, or something like "max+1" to make the weight 1 greater than the current MAX(weight)
-
[$options.extra]
Array optionalCan be array of ($streamName => $extra) info to save in the "extra" field.
Returns:
Returns false if the operation was canceled by a hook Returns true if relation was already there Otherwise returns array with keys "messagesFrom" and "messageTo" and values of type Streams_Message
request
-
$publisherId
-
$streamName
-
[$options=array()]
Each user is allowed at most one request per stream. If a request already exists, then this function returns it, even if it has different parameters. Otherwise, it inserts a request for upgrading access to a stream, and schedules actions to be taken automatically if the request is granted. It also posts a "Streams/request" message to the stream, so that someone with the adminLevel >= invite and adequate readLevel, writeLevel and permissions can grant the request.
Parameters:
-
$publisherId
StringThe id of the stream publisher
-
$streamName
StringThe name of the stream the request is about
-
[$options=array()]
Array optionalAll of these are optional
-
[userId=Users::loggedInUser()->id]
String optionalThe id of the user requesting the upgraded access.
-
[readLevel]
String | Integer optionalupgrade to read level being requested
-
[writeLevel]
String | Integer optionalupgrade to write level being requested
-
[adminLevel]
String | Integer optionalupgrade to admin level being requested
-
[permissions]
Array optionalarray of additional permissions to request
-
[actions]
Array optionalarray of actions to take automatically right after a request is granted, e.g. "Streams/join" or "Streams/subscribe". These can be interpreted in the "after" hook for "Streams/request" event.
-
Returns:
The request row that has been inserted into the database
requestedField
-
$field
-
$throwIfMissing=false
-
$default=null
Get the stream field from the request, if it can't be deduced throws error
Parameters:
-
$field
StringThe fiels name
-
$throwIfMissing=false
BooleanOptional. If true, throws an exception if the stream field cannot be deduced
-
$default=null
MixedIs returned if field is not set
Returns:
The value of the field
requestedFields
()
Array | String
static
Get the fields that have been requested in the request, otherwise '*'
Returns:
An array or string of fields to select
requestedMessageType
-
$throwIfMissing=false
Get the message type from the request, if it can be deduced
Parameters:
-
$throwIfMissing=false
BooleanOptional. If true, throws an exception if the message type cannot be deduced
Returns:
The type of the message
requestedName
-
$throwIfMissing=false
-
[$returnAs='string']
-
[$uri=Q_Dispatcher::uri()]
Get the stream name from the request, if it can be deduced. Checks $_REQUEST['streamName'], then tries $_REQUEST['name']. If both are empty, tries Q_Dispatcher::uri() and returns "{$uri->name_prefix}{$uri->name}", which is useful when the URL contains just the last part of a stream's name.
Parameters:
-
$throwIfMissing=false
BooleanOptional. If true, throws an exception if the stream name cannot be deduced
-
[$returnAs='string']
String optionalCan be "array" or "string".
-
[$uri=Q_Dispatcher::uri()]
Array | String optionalAn array or string representing a uri to use instead of the Q_Dispatcher::uri()
Returns:
The name of the stream
requestedPublisherId
-
$throwIfMissing=false
-
[$uri=Q_Dispatcher::uri()]
Get the publisher id from the request, if it can be deduced
Parameters:
-
$throwIfMissing=false
BooleanOptional. If true, throws an exception if the publisher id cannot be deduced
-
[$uri=Q_Dispatcher::uri()]
Array | String optionalAn array or string representing a uri to use instead of the Q_Dispatcher::uri()
Returns:
The id of the publisher user
requestedType
-
$throwIfMissing=false
Get the stream type from the request, if it can be deduced
Parameters:
-
$throwIfMissing=false
BooleanOptional. If true, throws an exception if the stream type cannot be deduced
Returns:
The type of the stream
splitFullName
-
$fullName
Get first and last name out of full name
Parameters:
-
$fullName
StringThe string representing full name
Returns:
array containing 'first' and 'last' properties
subscribe
-
$asUserId
-
$publisherId
-
$streams
-
[$options=array()]
Subscribe to one or more streams, to start receiving notifications. Posts "Streams/subscribe" message to the streams. Also posts "Streams/subscribed" messages to user's "Streams/participating" stream. If options are not given check the subscription templates:
1. generic publisher id and generic user
2. exact publisher id and generic user
3. generic publisher id and exact user
default is to subscribe to ALL messages.
If options are supplied - skip templates and use options.
Using subscribe if subscription is already active will modify existing subscription - change type(s) or modify notifications
Parameters:
-
$asUserId
StringThe id of the user that is joining. Pass null here to use the logged-in user's id.
-
$publisherId
StringThe id of the user publishing all the streams
-
$streams
ArrayAn array of Streams_Stream objects or stream names
-
[$options=array()]
Array optionalOptions for the subscribe() and join() methods
-
[filter]
Array optionaloptional array with two keys
-
[types]
Array optionalarray of message types, if this is empty then subscribes to all types -
[notifications=0]
Array optionallimit number of notifications, 0 means no limit
-
-
[untilTime=null]
Datetime optionaltime limit, if any for subscription
-
[rule=array()]
Array optionaloptionally override the rule for new subscriptions
-
[deliver=array('to']
Array optionalunder "to" key, named the field under Streams/rules/deliver config, which will contain the names of destinations, which can include "email", "mobile", "email+pending", "mobile+pending" -
[readyTime]
Datetime optionaltime from which user is ready to receive notifications again -
[filter]
Array optionaloptionally set a filter for the rules to add
-
-
[skipRules=false]
Boolean optionalif true, do not attempt to create rules for new subscriptions
-
[skipAccess=false]
Boolean optionalif true, skip access check for whether user can join and subscribe
-
[skipMessage=false]
Boolean optionalif true, skip posting the "Streams/subscribe" message to the stream
-
Returns:
An array of Streams_Participant rows from the database.
take
-
$streams
-
$name
-
$readLevel
-
$field='content'
-
[$escape=false]
Takes some information out of an existing set of streams
Parameters:
-
$streams
Array -
$name
String -
$readLevel
StringTest each stream for at least this read level. If the test fails, return null in its stead.
-
$field='content'
String | ArrayOptional. Defaults to "content". Can be an array of fields, in which case the function returns an array.
-
[$escape=false]
Boolean optionalDefaults to false. If true, escapes the values as HTML
Returns:
Returns the value of the field, or an array of values, depending on whether $field is an array or a string
unrelate
-
$asUserId
-
$toPublisherId
-
$toStreamName
-
$type
-
$fromPublisherId
-
$fromStreamName
-
$options=array()
-
[$options.skipAccess=false]
-
[$options.skipMessageTo=false]
-
[$options.skipMessageFrom=false]
-
[$options.adjustWeights=false]
Remove a relation where a member stream is related to a category stream. Can only remove one relation at a time. Adjusts weights after removal.
Parameters:
-
$asUserId
StringThe user who is making unrelate operation on the stream (remove stream from category)
-
$toPublisherId
StringThe user who has published the category stream
-
$toStreamName
String | ArrayThe name of the category stream. Pass an array of strings to relate a single stream to multiple categories, but in that case make sure fromStreamName is a string.
-
$type
StringThe type of the relation
-
$fromPublisherId
StringThe user who has publishes the related stream
-
$fromStreamName
StringThe name of the related stream. Pass an array of strings to relate multiple streams to a single category, but in that case make sure toStreamName is a string.
-
$options=array()
ArrayAn array of options that can include:
-
[$options.skipAccess=false]
Boolean optionalIf true, skips the access checks and just unrelates the stream from the category
-
[$options.skipMessageTo=false]
Boolean optionalIf true, skips posting the Streams/unrelatedTo message to the "to" streams
-
[$options.skipMessageFrom=false]
Boolean optionalIf true, skips posting the Streams/unrelatedFrom message to the "from" streams
-
[$options.adjustWeights=false]
Boolean optionalIf true, also decrements all following relations' weights by one.
Returns:
Whether the relation was removed
unsubscribe
-
$asUserId
-
$publisherId
-
$streams
-
[$options=array()]
Unsubscribe from one or more streams, to stop receiving notifications. Pooststs "Streams/unsubscribe" message to the streams. Also posts "Streams/unsubscribed" messages to user's "Streams/participating" stream. Does not change the actual subscription, but only the participant row. (When subscribing again, the existing subscription will be used.)
Parameters:
-
$asUserId
StringThe id of the user that is joining. Pass null here to use the logged-in user's id.
-
$publisherId
StringThe id of the user publishing all the streams
-
$streams
ArrayAn array of Streams_Stream objects or stream names
-
[$options=array()]
Array optional-
[leave=false]
Boolean optionalset to true to also leave the streams
-
[skipAccess=false]
Boolean optionalif true, skip access check for whether user can join and subscribe
-
[skipMessage=false]
Boolean optionalif true, skip posting the "Streams/unsubscribe" message to the stream
-
Returns:
Returns an array of Streams_Participant rows, if any were in the database.
Properties
$ACCESS_SOURCES
Array
Access sources
$ACCESS_SOURCES['contact']
Integer
final
From contact
Default: 1
$ACCESS_SOURCES['direct']
Integer
final
Direct access
Default: 2
$ACCESS_SOURCES['inherited_contact']
Integer
final
Inherited from contact
Default: 4
$ACCESS_SOURCES['inherited_direct']
Integer
final
Inherited direct access
Default: 5
$ACCESS_SOURCES['inherited_public']
Integer
final
Inherited public access
Default: 3
$ACCESS_SOURCES['public']
Integer
final
Public access
Default: 0
$ADMIN_LEVEL
Array
Admin levels
$ADMIN_LEVEL['invite']
Integer
final
Able to create invitations for others, granting access and permissions up to what they themselves have
Default: 20
$ADMIN_LEVEL['manage']
Integer
final
Can approve posts, and give people any adminLevel < 'manage'
Default: 30
$ADMIN_LEVEL['max']
Integer
final
Max admin level
Default: 40
$ADMIN_LEVEL['none']
Integer
final
Cannot do anything related to admin / users
Default: 0
$ADMIN_LEVEL['own']
Integer
final
Can give people any adminLevel <= 'own'
Default: 40
$ADMIN_LEVEL['tell']
Integer
final
Can prove things about the stream's content or participants
Default: 10
$cache
Array
static
$dontCache
String
static
You can set this to true to prevent caching for a while, e.g. during installer scripts, but make sure to set it back to false when done.
$fetch
Array
protected
static
$READ_LEVEL
Array
Read levels
$READ_LEVEL['content']
Integer
final
Can see the stream's content
Default: 20
$READ_LEVEL['max']
Integer
final
Max read level
Default: 40
$READ_LEVEL['messages']
Integer
final
Can play stream in a player
Default: 40
$READ_LEVEL['none']
Integer
final
Can't see the stream
Default: 0
$READ_LEVEL['participants']
Integer
final
Can see participants in the stream
Default: 30
$READ_LEVEL['relations']
Integer
final
Can see relations to other streams
Default: 25
$READ_LEVEL['see']
Integer
final
Can see icon and title
Default: 10
$requestedName_override
String
static
$requestedPublisherId_override
String
static
$WRITE_LEVEL
Array
Write levels
$WRITE_LEVEL['close']
Integer
final
Don't delete, just prevent any new changes to stream however, joining and leaving is still ok
Default: 40
$WRITE_LEVEL['closePending']
Integer
final
Can post a message requesting to close the stream
Default: 35
$WRITE_LEVEL['edit']
Integer
final
Can post messages to edit stream content immediately
Default: 30
$WRITE_LEVEL['join']
Integer
final
Can become a participant, chat, and leave
Default: 10
$WRITE_LEVEL['max']
Integer
final
Max write level
Default: 40
$WRITE_LEVEL['none']
Integer
final
Cannot affect stream or participants list
Default: 0
$WRITE_LEVEL['post']
Integer
final
Can post messages which appear immediately
Default: 20
$WRITE_LEVEL['postPending']
Integer
final
Can post messages, but manager must approve
Default: 15
$WRITE_LEVEL['suggest']
Integer
final
Can post messages requesting edits of stream
Default: 28
WRITE_LEVEL['relate']
Integer
final
Can post messages relating other streams to this one
Default: 23
WRITE_LEVEL['relations']
Integer
final
Can update properties of relations directly
Default: 25
WRITE_LEVEL['vote']
Integer
final
Can vote for a relation message posted to the stream.
Default: 13
Events
Streams/fetch/$streamType
After
Event Payload:
-
streams
&array -
asUserId
String -
publisherId
String -
name
String -
criteria
Array -
fields
String -
options
Array
Streams/invite
After
Event Payload:
-
success
String -
userIds
Array -
identifiers
Array -
identifierTypes
Array -
alreadyParticipating
Array -
invite
Streams_Invite
Streams/register
Before
Event Payload:
-
username
String -
identifier
String | Array -
icon
String
Streams/register
After
Event Payload:
-
username
String -
identifier
String | Array -
icon
String -
'user'
Users_User
Streams/relateFrom/$streamType
Before
Event Payload:
-
relatedTo
Array -
relatedFrom
Array -
asUserId
String -
category
Streams_Stream -
stream
Streams_Stream
Streams/relateFrom/$streamType
After
Event Payload:
-
relatedTo
String -
relatedFrom
String -
asUserId
String -
extra
Array -
category
Streams_Stream -
stream
Streams_Stream
Streams/relateTo/$categoryType
After
Event Payload:
-
relatedTo
String -
relatedFrom
String -
asUserId
String -
category
Streams_Stream -
stream
Streams_Stream
Streams/relateTo/$categoryType
Before
Event Payload:
-
relatedTo
Array -
relatedFrom
Array -
asUserId
String -
category
Streams_Stream -
stream
Streams_Stream
Streams/unrelateFrom/$streamType
Before
Event Payload:
-
relatedTo
String -
relatedFrom
String -
asUserId
String
Streams/unrelateFrom/$streamType
After
Event Payload:
-
relatedTo
String -
relatedFrom
String -
asUserId
String
Streams/unrelateTo/$categoryType
After
Event Payload:
-
relatedTo
String -
relatedFrom
String -
asUserId
String
Streams/unrelateTo/$streamType
Before
Event Payload:
-
relatedTo
String -
relatedFrom
String -
asUserId
String
Streams/updateRelation/$categoryType
After
Event Payload:
-
relatedTo
String -
relatedFrom
String -
asUserId
String -
weight
Double -
previousWeight
Double
Streams/updateRelation/$streamType
Before
Event Payload:
-
relatedTo
String -
relatedFrom
String -
asUserId
String -
weight
Double -
previousWeight
Double