CRM-13244 - RecipientBuilder - Move entity-specific bits to ActionMappings
[civicrm-core.git] / CRM / Event / Page / ManageEvent.php
index 4f81772dceaa5e9fdd46005c3092b96780728d38..8ddbc0288bb66017c5328bc5745ce3dc197fb4ac 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -39,7 +39,7 @@
 class CRM_Event_Page_ManageEvent extends CRM_Core_Page {
 
   /**
-   * The action links that we need to display for the browse screen
+   * The action links that we need to display for the browse screen.
    *
    * @var array
    */
@@ -56,7 +56,7 @@ class CRM_Event_Page_ManageEvent extends CRM_Core_Page {
   protected $_isTemplate = FALSE;
 
   /**
-   * Get action Links
+   * Get action Links.
    *
    * @return array
    *   (reference) of action links
@@ -98,7 +98,7 @@ class CRM_Event_Page_ManageEvent extends CRM_Core_Page {
   }
 
   /**
-   * Get tab  Links for events
+   * Get tab  Links for events.
    *
    * @param $enableCart
    *
@@ -137,7 +137,7 @@ class CRM_Event_Page_ManageEvent extends CRM_Core_Page {
           'field' => 'is_online_registration',
         );
 
-      if (CRM_Core_Permission::check('administer CiviCRM')) {
+      if (CRM_Core_Permission::check('administer CiviCRM') || CRM_Event_BAO_Event::checkPermission(NULL, CRM_Core_Permission::EDIT)) {
         self::$_tabLinks[$cacheKey]['reminder']
           = array(
             'title' => ts('Schedule Reminders'),
@@ -243,12 +243,11 @@ class CRM_Event_Page_ManageEvent extends CRM_Core_Page {
   }
 
   /**
-   * Browse all events
+   * Browse all events.
    *
    * @return void
    */
   public function browse() {
-    $this->assign('includeWysiwygEditor', TRUE);
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter',
       'String',
       $this
@@ -314,20 +313,17 @@ ORDER BY start_date desc
       'enable_cart'
     );
     $this->assign('eventCartEnabled', $enableCart);
-    $mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', 'civicrm_event', 'id', 'entity_value');
+    $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array(
+      'id' => CRM_Core_ActionScheduleTmp::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();
-        $isRecurringEvent = CRM_Core_BAO_RecurringEntity::getParentFor($dao->id, 'civicrm_event');
+        $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($dao->id, 'civicrm_event');
         $manageEvent[$dao->id]['repeat'] = '';
-        if ($isRecurringEvent) {
-          if ($dao->id == $isRecurringEvent) {
-            $manageEvent[$dao->id]['repeat'] = 'Recurring Event - (Parent)';
-          }
-          else {
-            $manageEvent[$dao->id]['repeat'] = 'Recurring Event - (Child)';
-          }
+        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]);
 
@@ -377,7 +373,7 @@ ORDER BY start_date desc
 
         //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, $mappingID);
+        $manageEvent[$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mapping->id);
         $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');
@@ -461,15 +457,9 @@ ORDER BY start_date desc
     }
 
     $value = $this->get('event_type_id');
-    $val = array();
     if ($value) {
       if (is_array($value)) {
-        foreach ($value as $k => $v) {
-          if ($v) {
-            $val[$k] = $k;
-          }
-        }
-        $type = implode(',', $val);
+        $type = implode(',', $value);
       }
       $clauses[] = "event_type_id IN ({$type})";
     }