Example #1
0
 /**
  * Function to get events Summary
  *
  * @static
  *
  * @return array Array of event summary values
  */
 static function getEventSummary()
 {
     $eventSummary = $eventIds = array();
     $config = CRM_Core_Config::singleton();
     // get permission and include them here
     // does not scale, but rearranging code for now
     // FIXME in a future release
     $permissions = CRM_Event_BAO_Event::checkPermission();
     $validEventIDs = '';
     if (empty($permissions[CRM_Core_Permission::VIEW])) {
         $eventSummary['total_events'] = 0;
         return $eventSummary;
     } else {
         $validEventIDs = " AND civicrm_event.id IN ( " . implode(',', array_values($permissions[CRM_Core_Permission::VIEW])) . " ) ";
     }
     // We're fetching recent and upcoming events (where start date is 7 days ago OR later)
     $query = "\nSELECT     count(id) as total_events\nFROM       civicrm_event\nWHERE      civicrm_event.is_active = 1 AND\n           ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND\n           civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )\n           {$validEventIDs}";
     $dao = CRM_Core_DAO::executeQuery($query);
     if ($dao->fetch()) {
         $eventSummary['total_events'] = $dao->total_events;
     }
     if (empty($eventSummary) || $dao->total_events == 0) {
         return $eventSummary;
     }
     //get the participant status type values.
     $cpstObject = new CRM_Event_DAO_ParticipantStatusType();
     $cpst = $cpstObject->getTableName();
     $query = "SELECT id, name, label, class FROM {$cpst}";
     $status = CRM_Core_DAO::executeQuery($query);
     $statusValues = array();
     while ($status->fetch()) {
         $statusValues[$status->id]['id'] = $status->id;
         $statusValues[$status->id]['name'] = $status->name;
         $statusValues[$status->id]['label'] = $status->label;
         $statusValues[$status->id]['class'] = $status->class;
     }
     // Get the Id of Option Group for Event Types
     $optionGroupDAO = new CRM_Core_DAO_OptionGroup();
     $optionGroupDAO->name = 'event_type';
     $optionGroupId = NULL;
     if ($optionGroupDAO->find(TRUE)) {
         $optionGroupId = $optionGroupDAO->id;
     }
     // Get the event summary display preferences
     $show_max_events = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'show_events');
     // default to 10 if no option is set
     if (is_null($show_max_events)) {
         $show_max_events = 10;
     }
     // show all events if show_events is set to a negative value
     if ($show_max_events >= 0) {
         $event_summary_limit = "LIMIT      0, {$show_max_events}";
     } else {
         $event_summary_limit = "";
     }
     $query = "\nSELECT     civicrm_event.id as id, civicrm_event.title as event_title, civicrm_event.is_public as is_public,\n           civicrm_event.max_participants as max_participants, civicrm_event.start_date as start_date,\n           civicrm_event.end_date as end_date, civicrm_event.is_online_registration, civicrm_event.is_monetary, civicrm_event.is_show_location,civicrm_event.is_map as is_map, civicrm_option_value.label as event_type, civicrm_tell_friend.is_active as is_friend_active,\n           civicrm_event.slot_label_id,\n           civicrm_event.summary as summary,\n           civicrm_pcp_block.id as is_pcp_enabled\nFROM       civicrm_event\nLEFT JOIN  civicrm_option_value ON (\n           civicrm_event.event_type_id = civicrm_option_value.value AND\n           civicrm_option_value.option_group_id = %1 )\nLEFT JOIN  civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_event.id  AND civicrm_tell_friend.entity_table = 'civicrm_event' )\nLEFT JOIN  civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_event.id AND civicrm_pcp_block.entity_table = 'civicrm_event')\nWHERE      civicrm_event.is_active = 1 AND\n           ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND\n           civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )\n           {$validEventIDs}\nGROUP BY   civicrm_event.id\nORDER BY   civicrm_event.start_date ASC\n{$event_summary_limit}\n";
     $eventParticipant = array();
     $properties = array('id' => 'id', 'eventTitle' => 'event_title', 'isPublic' => 'is_public', 'maxParticipants' => 'max_participants', 'startDate' => 'start_date', 'endDate' => 'end_date', 'eventType' => 'event_type', 'isMap' => 'is_map', 'participants' => 'participants', 'notCountedDueToRole' => 'notCountedDueToRole', 'notCountedDueToStatus' => 'notCountedDueToStatus', 'notCountedParticipants' => 'notCountedParticipants');
     $params = array(1 => array($optionGroupId, 'Integer'));
     $mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', 'civicrm_event', 'id', 'entity_value');
     $dao = CRM_Core_DAO::executeQuery($query, $params);
     while ($dao->fetch()) {
         foreach ($properties as $property => $name) {
             $set = NULL;
             switch ($name) {
                 case 'is_public':
                     if ($dao->{$name}) {
                         $set = 'Yes';
                     } else {
                         $set = 'No';
                     }
                     $eventSummary['events'][$dao->id][$property] = $set;
                     break;
                 case 'is_map':
                     if ($dao->{$name} && $config->mapAPIKey) {
                         $values = array();
                         $ids = array();
                         $params = array('entity_id' => $dao->id, 'entity_table' => 'civicrm_event');
                         $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
                         if (is_numeric(CRM_Utils_Array::value('geo_code_1', $values['location']['address'][1])) || $config->mapGeoCoding && !empty($values['location']['address'][1]['city']) && !empty($values['location']['address'][1]['state_province_id'])) {
                             $set = CRM_Utils_System::url('civicrm/contact/map/event', "reset=1&eid={$dao->id}");
                         }
                     }
                     $eventSummary['events'][$dao->id][$property] = $set;
                     if (in_array($dao->id, $permissions[CRM_Core_Permission::EDIT])) {
                         $eventSummary['events'][$dao->id]['configure'] = CRM_Utils_System::url('civicrm/admin/event', "action=update&id={$dao->id}&reset=1");
                     }
                     break;
                 case 'end_date':
                 case 'start_date':
                     $eventSummary['events'][$dao->id][$property] = CRM_Utils_Date::customFormat($dao->{$name}, NULL, array('d'));
                     break;
                 case 'participants':
                 case 'notCountedDueToRole':
                 case 'notCountedDueToStatus':
                 case 'notCountedParticipants':
                     $set = NULL;
                     $propertyCnt = 0;
                     if ($name == 'participants') {
                         $propertyCnt = self::getParticipantCount($dao->id);
                         if ($propertyCnt) {
                             $set = CRM_Utils_System::url('civicrm/event/search', "reset=1&force=1&event={$dao->id}&status=true&role=true");
                         }
                     } elseif ($name == 'notCountedParticipants') {
                         $propertyCnt = self::getParticipantCount($dao->id, TRUE, FALSE, TRUE, FALSE);
                         if ($propertyCnt) {
                             // FIXME : selector fail to search w/ OR operator.
                             // $set = CRM_Utils_System::url( 'civicrm/event/search',
                             // "reset=1&force=1&event=$dao->id&status=false&role=false" );
                         }
                     } elseif ($name == 'notCountedDueToStatus') {
                         $propertyCnt = self::getParticipantCount($dao->id, TRUE, FALSE, FALSE, FALSE);
                         if ($propertyCnt) {
                             $set = CRM_Utils_System::url('civicrm/event/search', "reset=1&force=1&event={$dao->id}&status=false");
                         }
                     } else {
                         $propertyCnt = self::getParticipantCount($dao->id, FALSE, FALSE, TRUE, FALSE);
                         if ($propertyCnt) {
                             $set = CRM_Utils_System::url('civicrm/event/search', "reset=1&force=1&event={$dao->id}&role=false");
                         }
                     }
                     $eventSummary['events'][$dao->id][$property] = $propertyCnt;
                     $eventSummary['events'][$dao->id][$name . '_url'] = $set;
                     break;
                 default:
                     $eventSummary['events'][$dao->id][$property] = $dao->{$name};
                     break;
             }
         }
         // prepare the area for per-status participant counts
         $statusClasses = array('Positive', 'Pending', 'Waiting', 'Negative');
         $eventSummary['events'][$dao->id]['statuses'] = array_fill_keys($statusClasses, array());
         $eventSummary['events'][$dao->id]['friend'] = $dao->is_friend_active;
         $eventSummary['events'][$dao->id]['is_monetary'] = $dao->is_monetary;
         $eventSummary['events'][$dao->id]['is_online_registration'] = $dao->is_online_registration;
         $eventSummary['events'][$dao->id]['is_show_location'] = $dao->is_show_location;
         $eventSummary['events'][$dao->id]['is_subevent'] = $dao->slot_label_id;
         $eventSummary['events'][$dao->id]['is_pcp_enabled'] = $dao->is_pcp_enabled;
         $eventSummary['events'][$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mappingID);
         $statusTypes = CRM_Event_PseudoConstant::participantStatus();
         foreach ($statusValues as $statusId => $statusValue) {
             if (!array_key_exists($statusId, $statusTypes)) {
                 continue;
             }
             $class = $statusValue['class'];
             $statusCount = self::eventTotalSeats($dao->id, "( participant.status_id = {$statusId} )");
             if ($statusCount) {
                 $urlString = "reset=1&force=1&event={$dao->id}&status={$statusId}";
                 $statusInfo = array('url' => CRM_Utils_System::url('civicrm/event/search', $urlString), 'name' => $statusValue['name'], 'label' => $statusValue['label'], 'count' => $statusCount);
                 $eventSummary['events'][$dao->id]['statuses'][$class][] = $statusInfo;
             }
         }
     }
     $countedRoles = CRM_Event_PseudoConstant::participantRole(NULL, 'filter = 1');
     $nonCountedRoles = CRM_Event_PseudoConstant::participantRole(NULL, '( filter = 0 OR filter IS NULL )');
     $countedStatus = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
     $nonCountedStatus = CRM_Event_PseudoConstant::participantStatus(NULL, '( is_counted = 0 OR is_counted IS NULL )');
     $countedStatusANDRoles = array_merge($countedStatus, $countedRoles);
     $nonCountedStatusANDRoles = array_merge($nonCountedStatus, $nonCountedRoles);
     $eventSummary['nonCountedRoles'] = implode('/', array_values($nonCountedRoles));
     $eventSummary['nonCountedStatus'] = implode('/', array_values($nonCountedStatus));
     $eventSummary['countedStatusANDRoles'] = implode('/', array_values($countedStatusANDRoles));
     $eventSummary['nonCountedStatusANDRoles'] = implode('/', array_values($nonCountedStatusANDRoles));
     return $eventSummary;
 }
Example #2
0
 /**
  * Browse all events.
  *
  * @return void
  */
 public function browse()
 {
     Civi::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
     $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
     if (strtolower($this->_sortByCharacter) == 'all' || !empty($_POST)) {
         $this->_sortByCharacter = '';
         $this->set('sortByCharacter', '');
     }
     $this->_force = $this->_searchResult = NULL;
     $this->search();
     $params = array();
     $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
     $this->_searchResult = CRM_Utils_Request::retrieve('searchResult', 'Boolean', $this);
     $whereClause = $this->whereClause($params, FALSE, $this->_force);
     $this->pagerAToZ($whereClause, $params);
     $params = array();
     $whereClause = $this->whereClause($params, TRUE, $this->_force);
     // because is_template != 1 would be to simple
     $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)';
     $this->pager($whereClause, $params);
     list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
     // get all custom groups sorted by weight
     $manageEvent = array();
     $query = "\n  SELECT *\n    FROM civicrm_event\n   WHERE {$whereClause}\nORDER BY start_date desc\n   LIMIT {$offset}, {$rowCount}";
     $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event');
     $permissions = CRM_Event_BAO_Event::checkPermission();
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     // get the list of active event pcps
     $eventPCPS = array();
     $pcpDao = new CRM_PCP_DAO_PCPBlock();
     $pcpDao->entity_table = 'civicrm_event';
     $pcpDao->find();
     while ($pcpDao->fetch()) {
         $eventPCPS[$pcpDao->entity_id] = $pcpDao->entity_id;
     }
     // check if we're in shopping cart mode for events
     $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart');
     $this->assign('eventCartEnabled', $enableCart);
     $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID)));
     $eventType = CRM_Core_OptionGroup::values('event_type');
     while ($dao->fetch()) {
         if (in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])) {
             $manageEvent[$dao->id] = array();
             $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($dao->id, 'civicrm_event');
             $manageEvent[$dao->id]['repeat'] = '';
             if ($repeat) {
                 $manageEvent[$dao->id]['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1]));
             }
             CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]);
             // form all action links
             $action = array_sum(array_keys($this->links()));
             if ($dao->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
             if (!in_array($dao->id, $permissions[CRM_Core_Permission::DELETE])) {
                 $action -= CRM_Core_Action::DELETE;
             }
             if (!in_array($dao->id, $permissions[CRM_Core_Permission::EDIT])) {
                 $action -= CRM_Core_Action::UPDATE;
             }
             $manageEvent[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), TRUE, 'event.manage.list', 'Event', $dao->id);
             $params = array('entity_id' => $dao->id, 'entity_table' => 'civicrm_event', 'is_active' => 1);
             $defaults['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
             $manageEvent[$dao->id]['friend'] = CRM_Friend_BAO_Friend::getValues($params);
             if (isset($defaults['location']['address'][1]['city'])) {
                 $manageEvent[$dao->id]['city'] = $defaults['location']['address'][1]['city'];
             }
             if (isset($defaults['location']['address'][1]['state_province_id'])) {
                 $manageEvent[$dao->id]['state_province'] = CRM_Core_PseudoConstant::stateProvince($defaults['location']['address'][1]['state_province_id']);
             }
             //show campaigns on selector.
             $manageEvent[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns);
             $manageEvent[$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mapping->getId());
             $manageEvent[$dao->id]['is_pcp_enabled'] = CRM_Utils_Array::value($dao->id, $eventPCPS);
             $manageEvent[$dao->id]['event_type'] = CRM_Utils_Array::value($manageEvent[$dao->id]['event_type_id'], $eventType);
             $manageEvent[$dao->id]['is_repeating_event'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_RecurringEntity', $dao->id, 'parent_id', 'entity_id');
             // allow hooks to set 'field' value which allows configuration pop-up to show a tab as enabled/disabled
             CRM_Utils_Hook::tabset('civicrm/event/manage/rows', $manageEvent, array('event_id' => $dao->id));
         }
     }
     $manageEvent['tab'] = self::tabs($enableCart);
     $this->assign('rows', $manageEvent);
     $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
     $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0');
     $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
     $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
     $this->assign('findParticipants', $findParticipants);
 }