4848 * @method void setLocked(int $value)
4949 * @method string getDisplayName()
5050 * @method void setDisplayName(string $value)
51+ * @method string getLabel()
52+ * @method void setLabel(string $value)
5153 * @method string getMiscSettings()
5254 * @method void setMiscSettings(string $value)
5355 * @method ?int getAnonymizedVotes()
@@ -63,17 +65,17 @@ class Share extends EntityWithUser implements JsonSerializable {
6365 public const EMAIL_DISABLED = 'disabled ' ;
6466
6567 // Only authenticated access
66- public const TYPE_USER = ' user ' ;
67- public const TYPE_ADMIN = ' admin ' ;
68- public const TYPE_GROUP = ' group ' ;
68+ public const TYPE_USER = UserBase:: TYPE_USER ;
69+ public const TYPE_ADMIN = UserBase:: TYPE_ADMIN ;
70+ public const TYPE_GROUP = UserBase:: TYPE_GROUP ;
6971
7072 // Public and authenticated Access
71- public const TYPE_PUBLIC = ' public ' ;
73+ public const TYPE_PUBLIC = UserBase:: TYPE_PUBLIC ;
7274
7375 // Only public access
74- public const TYPE_EMAIL = ' email ' ;
75- public const TYPE_CONTACT = ' contact ' ;
76- public const TYPE_EXTERNAL = ' external ' ;
76+ public const TYPE_EMAIL = UserBase:: TYPE_EMAIL ;
77+ public const TYPE_CONTACT = UserBase:: TYPE_CONTACT ;
78+ public const TYPE_EXTERNAL = UserBase:: TYPE_EXTERNAL ;
7779
7880 // no direct Access
7981 public const TYPE_TEAM = 'circle ' ;
@@ -178,7 +180,7 @@ public function jsonSerialize(): array {
178180 }
179181
180182 public function resolveUser (): Ghost |Group |Team |Contact |ContactGroup |User |Email |GenericUser {
181- return UserMapper::getUserObject (
183+ return UserMapper::createUserObject (
182184 $ this ->getType (),
183185 $ this ->getUserId (),
184186 $ this ->getDisplayName (),
@@ -242,35 +244,50 @@ public function setPublicPollEmail(string $value): void {
242244 $ this ->setMiscSettingsByKey ('publicPollEmail ' , $ value );
243245 }
244246
245- /**
246- * Share label for public shares, now stored as displayName
247- * TODO: remove after migration was introduced
248- */
249- public function setLabel (string $ label ): void {
250- $ this ->setDisplayName ($ label );
251- $ this ->label = $ label ;
252- }
253-
254247 /**
255248 * Share label for public shares
256249 * TODO: remove after migrating labels to displayName
257250 */
258251 public function getLabel (): string {
259252 // In case of public poll use label as fallback for displayName
260- return $ this ->displayName ?? $ this ->label ?? '' ;
253+ return $ this ->label ?? $ this ->displayName ?? '' ;
261254 }
262255
263256 /**
264257 * Sharee's displayName. In case of public poll label is used instead
265258 * TODO: remove public poll check after migration labels to displayName
266259 */
267260 public function getDisplayName (): string {
268- if ($ this ->getType () === self ::TYPE_PUBLIC ) {
269- return $ this ->getLabel ();
270- }
271261 return $ this ->displayName ?? '' ;
272262 }
273263
264+ public function setFromUserObject (UserBase $ userGroup , string $ token , string $ purpose = 'poll ' ): void {
265+ // Contacts are converted: with email → email share, without email → external share
266+ $ type = $ userGroup ->getType ();
267+ if ($ type === self ::TYPE_CONTACT || $ type === self ::TYPE_EMAIL ) {
268+ $ type = self ::TYPE_EXTERNAL ;
269+ }
270+
271+ $ this ->setType ($ type );
272+ $ this ->setDisplayName ($ userGroup ->getDisplayName ());
273+ $ this ->setEmailAddress ($ userGroup ->getEmailAddress ());
274+
275+ // ignore if share is for poll Groups
276+ if ($ purpose === 'poll ' ) {
277+ if ($ type === self ::TYPE_PUBLIC ) {
278+ // public share to create, set token as userId
279+ $ this ->setUserId ($ token );
280+ } else {
281+ $ this ->setUserId ($ userGroup ->getShareUserId ());
282+ }
283+ if ($ type === self ::TYPE_EXTERNAL ) {
284+ $ this ->setLanguage ($ userGroup ->getLanguageCode ());
285+ $ this ->setTimeZoneName ($ userGroup ->getTimeZoneName ());
286+ }
287+ }
288+ }
289+
290+
274291 public function getTimeZoneName (): string {
275292 return $ this ->getMiscSettingsArray ()['timeZone ' ] ?? '' ;
276293 }
0 commit comments