/** * Returns an array of users that will receive the activity notification * @param $userpath is used to identify how to retrieve a user who is getting the notification * @param $arguments are passed from the activity to help gather the information needed * @return array|string array of user names * @throws Exception if user not found */ function getUsers($userpath, $arguments) { $userarr = explode(":", $userpath); switch ($userarr[0]) { case "argument": break; case "object": $users[] = $arguments['object']; break; case "user": $users[] = $arguments['user']; break; case "parent_comment_user": $users[] = $arguments['parent_comment_user']; break; case "trackeritem": $lib = TikiLib::lib('trk'); //get tracker id $io = $lib->get_item_info($arguments['object']); $tracker_id = $io["trackerId"]; //get the second parameter in the user path and set as field $field_id = $lib->get_field_id($tracker_id, $userarr[1]); $result = $lib->get_tracker_item((string) $arguments['object']); $users[] = $result[$field_id]; break; case "groupmember": $userlib = TikiLib::lib('user'); $users = $userlib->get_members($arguments['groupname']); break; case "groupmanagers": $api = new TikiAddons_Api_Group(); $group = $arguments['groupname']; if ($api->isOrganicGroup($group)) { $users = $api->getOrganicGroupLeaders($group); } break; default: TikiLib::lib('errorreport')->report(tr('Problem finding the associated user. %0 is not recognized. See EventNotify.php', $userarr[0])); break; } return $users; }
function getDocument($objectId, Search_Type_Factory_Interface $typeFactory) { $row = $this->db->table('users_groups')->fetchRow(['groupDesc'], array('groupName' => $objectId)); if (!$row) { return false; } $api = new TikiAddons_Api_Group(); $groupName = $objectId; $addongroup = false; $addonpendinggroup = false; $addonleadergroup = false; if ($ret = $api->getOrganicGroupName($objectId)) { $groupName = $ret; $addongroup = $api->isOrganicGroup($objectId); if ($addongroup == true && $api->getOrganicGroupPendingToken($objectId) == $objectId) { $addonpendinggroup = true; } if ($addongroup == true && $api->getOrganicGroupLeaderToken($objectId) == $objectId) { $addonleadergroup = true; } } $data = array('title' => $typeFactory->sortable($groupName), 'description' => $typeFactory->plaintext($row['groupDesc']), 'searchable' => $typeFactory->identifier('n'), 'view_permission' => $typeFactory->identifier('tiki_p_group_view'), 'addongroup' => $addongroup ? $typeFactory->identifier('y') : $typeFactory->identifier('n'), 'addonleadergroup' => $addonleadergroup ? $typeFactory->identifier('y') : $typeFactory->identifier('n'), 'addonpendinggroup' => $addonpendinggroup ? $typeFactory->identifier('y') : $typeFactory->identifier('n')); return $data; }
function assign_user_to_group($user, $group, $bulk = false) { if (!$this->group_exists($group)) { throw new Exception(tr('Cannot add user %0 to nonexistent group %1', $user, $group)); } if (!$this->user_exists($user)) { throw new Exception(tr('Cannot add nonexistent user %0 to group %1', $user, $group)); } global $prefs, $tiki_p_admin, $page; $cachelib = TikiLib::lib('cache'); $tikilib = TikiLib::lib('tiki'); $access = TikiLib::lib('access'); if ($this->is_user_banned_from_group($user, $group)) { $msg = tr('User "%0" is banned from the group "%1".', $user, $group); if ($tiki_p_admin === 'y') { $access->check_authenticity($msg . ' ' . tra('Do you want to unban them and continue?')); $this->unban_user_from_group($user, $group); } else { $access->display_error($page, $msg); } } $cachelib->invalidate('user_details_' . $user); $tikilib->invalidate_usergroups_cache($user); $this->invalidate_usergroups_cache($user); // this is needed as cache is present in this instance too $group_ret = false; $userid = $this->get_user_id($user); if ($userid > 0) { $query = "insert ignore into `users_usergroups`(`userId`,`groupName`, `created`) values(?,?,?)"; $result = $this->query($query, array($userid, $group, $tikilib->now), -1, -1, false); $group_ret = true; } $this->update_group_expiries(); if ($prefs['feature_community_send_mail_join'] == 'y') { $api = new TikiAddons_Api_Group(); if ($api->isOrganicGroup($group)) { $groupleaders = $api->getOrganicGroupLeaders($group); $groupleaders = array_combine($groupleaders, $groupleaders); unset($groupleaders[$user]); if (isset($groupleaders[$_SESSION['u_info']['login']])) { unset($groupleaders[$_SESSION['u_info']['login']]); } if (!empty($groupleaders)) { $par_data['gname'] = $group; $par_data['user'] = $user; if (strpos($group, 'pending')) { $mail_temp = 'user_joins_group_notification_to_leads_need_app.tpl'; } else { $mail_temp = 'user_joins_group_notification_to_leads.tpl'; } require_once "lib/notifications/notificationemaillib.php"; sendEmailNotification($groupleaders, 'group_lead_mail', 'user_joins_group_notification_to_leads_subject.tpl', $par_data, $mail_temp); } } } if ($group_ret) { $watches = $tikilib->get_event_watches('user_joins_group', $group); if (count($watches)) { require_once "lib/notifications/notificationemaillib.php"; $smarty = TikiLib::lib('smarty'); $smarty->assign('mail_user', $user); $smarty->assign('mail_group', $group); sendEmailNotification($watches, null, 'user_joins_group_notification_subject.tpl', null, 'user_joins_group_notification.tpl'); } $api = new TikiAddons_Api_Group(); TikiLib::events()->trigger('tiki.user.groupjoin', array('type' => 'user', 'object' => $user, 'group' => $group, 'addongroup' => $api->getOrganicGroupName($group), 'is_organic' => $api->isOrganicGroup($group) ? 1 : 0, 'is_private' => $api->organicGroupIsPrivate($group) ? 1 : 0, 'addongroupid' => $api->getItemIdFromToken($group), 'bulk_import' => $bulk)); } return $group_ret; }