/** * unattend event * * @param int $id * @param UserTable $user */ private function unattendEvent( $id, $user ) { global $_CB_framework; $event = CBGroupJiveEvents::getEvent( (int) $id ); $returnUrl = $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $event->get( 'group' ) ) ); if ( $event->get( 'id' ) ) { if ( ! CBGroupJive::canAccessGroup( $event->group(), $user ) ) { cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) { if ( ( $event->get( 'published' ) != 1 ) && ( CBGroupJive::getGroupStatus( $user, $event->group() ) < 2 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to this event.' ), 'error' ); } elseif ( CBGroupJive::getGroupStatus( $user, $event->group() ) < 1 ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to unattend this event.' ), 'error' ); } elseif ( $event->status() == 1 ) { cbRedirect( $returnUrl, CBTxt::T( 'You can not unattend an expired event.' ), 'error' ); } } } else { cbRedirect( $returnUrl, CBTxt::T( 'Event does not exist.' ), 'error' ); } $row = new AttendanceTable(); $row->load( array( 'user_id' => (int) $user->get( 'id' ), 'event' => (int) $event->get( 'id' ) ) ); if ( ! $row->get( 'id' ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You can not unattend an event you are not attending.' ), 'error' ); } if ( ! $row->canDelete() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_EVENT_FAILED_TO_UNATTEND', 'Event failed to unattend. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } if ( ! $row->delete() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_EVENT_FAILED_TO_UNATTEND', 'Event failed to unattend. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } $extras = array( 'event_title' => htmlspecialchars( $event->get( 'title' ) ), 'event' => '<a href="' . $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $event->get( 'group' ), 'tab' => 'grouptabevents' ) ) . '">' . htmlspecialchars( CBTxt::T( $event->get( 'title' ) ) ) . '</a>' ); CBGroupJive::sendNotifications( 'event_unattend', CBTxt::T( 'User unattended your group event' ), CBTxt::T( '[user] will no longer be attending your event [event] in the group [group]!' ), $event->group(), $user, (int) $event->get( 'user_id' ), array(), 1, $extras ); cbRedirect( $returnUrl, CBTxt::T( 'Event unattended successfully!' ) ); }
/** * prepare frontend events render * * @param string $return * @param GroupTable $group * @param string $users * @param string $invites * @param array $counters * @param array $buttons * @param array $menu * @param cbTabs $tabs * @param UserTable $user * @return array|null */ public function showEvents( &$return, &$group, &$users, &$invites, &$counters, &$buttons, &$menu, &$tabs, $user ) { global $_CB_framework, $_CB_database; CBGroupJive::getTemplate( 'events', true, true, $this->element ); $canModerate = ( CBGroupJive::isModerator( $user->get( 'id' ) ) || ( CBGroupJive::getGroupStatus( $user, $group ) >= 2 ) ); $limit = (int) $this->params->get( 'groups_events_limit', 15 ); $limitstart = $_CB_framework->getUserStateFromRequest( 'gj_group_events_limitstart{com_comprofiler}', 'gj_group_events_limitstart' ); $search = $_CB_framework->getUserStateFromRequest( 'gj_group_events_search{com_comprofiler}', 'gj_group_events_search' ); $where = null; if ( $search && $this->params->get( 'groups_events_search', 1 ) ) { $where .= "\n AND ( e." . $_CB_database->NameQuote( 'title' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " OR e." . $_CB_database->NameQuote( 'event' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " OR e." . $_CB_database->NameQuote( 'address' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " OR e." . $_CB_database->NameQuote( 'location' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " )"; } $searching = ( $where ? true : false ); $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_events' ) . " AS e" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = e.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE e." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $group->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0"; if ( ! $canModerate ) { $query .= "\n AND ( e." . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . ' OR e.' . $_CB_database->NameQuote( 'published' ) . ' = 1 )'; } $query .= $where; $_CB_database->setQuery( $query ); $total = (int) $_CB_database->loadResult(); if ( ( ! $total ) && ( ! $searching ) && ( ! CBGroupJive::canCreateGroupContent( $user, $group, 'events' ) ) ) { return null; } $pageNav = new cbPageNav( $total, $limitstart, $limit ); $pageNav->setInputNamePrefix( 'gj_group_events_' ); $guests = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_events_attendance' ) . " AS ea" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS eacb" . ' ON eacb.' . $_CB_database->NameQuote( 'id' ) . ' = ea.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS eaj" . ' ON eaj.' . $_CB_database->NameQuote( 'id' ) . ' = eacb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE ea." . $_CB_database->NameQuote( 'event' ) . " = e." . $_CB_database->NameQuote( 'id' ) . "\n AND eacb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND eacb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND eaj." . $_CB_database->NameQuote( 'block' ) . " = 0"; $now = Application::Database()->getUtcDateTime(); $query = 'SELECT e.*' . ', TIMESTAMPDIFF( SECOND, ' . $_CB_database->Quote( $now ) . ',e.' . $_CB_database->NameQuote( 'start' ) . ' ) AS _start_ordering' . ', TIMESTAMPDIFF( SECOND, ' . $_CB_database->Quote( $now ) . ', e.' . $_CB_database->NameQuote( 'end' ) . ' ) AS _end_ordering' . ', a.' . $_CB_database->NameQuote( 'id' ) . ' AS _attending' . ', ( ' . $guests . ' ) AS _guests' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_events' ) . " AS e" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = e.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__groupjive_plugin_events_attendance' ) . " AS a" . ' ON a.' . $_CB_database->NameQuote( 'user_id' ) . ' = ' . (int) $user->get( 'id' ) . ' AND a.' . $_CB_database->NameQuote( 'event' ) . ' = e.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE e." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $group->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0"; if ( ! $canModerate ) { $query .= "\n AND ( e." . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . ' OR e.' . $_CB_database->NameQuote( 'published' ) . ' = 1 )'; } $query .= $where . "\n ORDER BY IF( _start_ordering < 0 AND _end_ordering > 0, 1, IF( _start_ordering > 0, 2, 3 ) ), ABS( _start_ordering )"; if ( $this->params->get( 'groups_events_paging', 1 ) ) { $_CB_database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); } else { $_CB_database->setQuery( $query ); } $rows = $_CB_database->loadObjectList( null, '\CB\Plugin\GroupJiveEvents\Table\EventTable', array( $_CB_database ) ); $input = array(); $input['search'] = '<input type="text" name="gj_group_events_search" value="' . htmlspecialchars( $search ) . '" onchange="document.gjGroupEventsForm.submit();" placeholder="' . htmlspecialchars( CBTxt::T( 'Search Events...' ) ) . '" class="form-control" />'; CBGroupJiveEvents::getEvent( $rows ); CBGroupJive::preFetchUsers( $rows ); $group->set( '_events', $pageNav->total ); return array( 'id' => 'events', 'title' => CBTxt::T( 'Events' ), 'content' => HTML_groupjiveEvents::showEvents( $rows, $pageNav, $searching, $input, $counters, $group, $user, $this ) ); }
/** * @return EventTable */ public function event() { return CBGroupJiveEvents::getEvent( (int) $this->get( 'event' ) ); }