namespace Friendica\Model;
use Friendica\BaseModule;
+use Friendica\Content\Widget;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
*
* Count unread items of each circle of the local user
*
+ * @param int $uid
* @return array
* 'id' => circle id
* 'name' => circle name
* 'count' => counted unseen circle items
* @throws \Exception
*/
- public static function countUnseen()
+ public static function countUnseen(int $uid)
{
$stmt = DBA::p("SELECT `circle`.`id`, `circle`.`name`,
(SELECT COUNT(*) FROM `post-user`
) AS `count`
FROM `group` AS `circle`
WHERE `circle`.`uid` = ?;",
- DI::userSession()->getLocalUserId(),
- DI::userSession()->getLocalUserId()
+ $uid,
+ $uid
);
return DBA::toArray($stmt);
* Returns a templated circle selection list
*
* @param int $uid User id
- * @param int $gid An optional pre-selected circle
- * @param string $label An optional label of the list
+ * @param int $gid A pre-selected circle
+ * @param string $id The id of the option group
+ * @param string $label The label of the option group
* @return string
* @throws \Exception
*/
- public static function getSelectorHTML(int $uid, int $gid = 0, string $label = ''): string
+ public static function getSelectorHTML(int $uid, int $gid, string $id, string $label): string
{
$display_circles = [
[
Logger::info('Got circles', $display_circles);
- if ($label == '') {
- $label = DI::l10n()->t('Default privacy circle for new contacts');
- }
-
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('circle_selection.tpl'), [
+ '$id' => $id,
'$label' => $label,
'$circles' => $display_circles
]);
}
if ($each == 'circle') {
- $count = DBA::count('group_member', ['gid' => $circle['id']]);
+ $networks = Widget::unavailableNetworks();
+ $sql_values = array_merge([$circle['id']], $networks);
+ $condition = ["`circle-id` = ? AND NOT `contact-network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")"];
+ $condition = array_merge($condition, $sql_values);
+
+ $count = DBA::count('circle-member-view', $condition);
$circle_name = sprintf('%s (%d)', $circle['name'], $count);
} else {
$circle_name = $circle['name'];
* @param integer $id Contact ID
* @return integer Circle ID
*/
- public static function getIdForForum(int $id): int
+ public static function getIdForGroup(int $id): int
{
- Logger::info('Get id for forum id', ['id' => $id]);
+ Logger::info('Get id for group id', ['id' => $id]);
$contact = Contact::getById($id, ['uid', 'name', 'contact-type', 'manually-approve']);
if (empty($contact) || ($contact['contact-type'] != Contact::TYPE_COMMUNITY) || !$contact['manually-approve']) {
return 0;
* @param integer $id Contact ID
* @return void
*/
- public static function updateMembersForForum(int $id)
+ public static function updateMembersForGroup(int $id)
{
- Logger::info('Update forum members', ['id' => $id]);
+ Logger::info('Update group members', ['id' => $id]);
$contact = Contact::getById($id, ['uid', 'url']);
if (empty($contact)) {
return;
}
- $gid = self::getIdForForum($id);
+ $gid = self::getIdForGroup($id);
if (empty($gid)) {
return;
}
}
DBA::delete('group_member', ['gid' => $gid, 'contact-id' => $current]);
- Logger::info('Updated forum members', ['id' => $id, 'count' => DBA::count('group_member', ['gid' => $gid])]);
+ Logger::info('Updated group members', ['id' => $id, 'count' => DBA::count('group_member', ['gid' => $gid])]);
}
}