当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_BAO_RecurringEntity::generate方法代码示例

本文整理汇总了PHP中CRM_Core_BAO_RecurringEntity::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_RecurringEntity::generate方法的具体用法?PHP CRM_Core_BAO_RecurringEntity::generate怎么用?PHP CRM_Core_BAO_RecurringEntity::generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Core_BAO_RecurringEntity的用法示例。


在下文中一共展示了CRM_Core_BAO_RecurringEntity::generate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postProcess


//.........这里部分代码省略.........
                 $params['parent_entity_id'] = self::$_parentEntityId;
             }
             if (!empty($params['schedule_reminder_id'])) {
                 $params['id'] = $params['schedule_reminder_id'];
             } else {
                 $params['id'] = self::$_scheduleReminderID;
             }
             //Save post params to the schedule reminder table
             $recurobj = new CRM_Core_BAO_RecurringEntity();
             $dbParams = $recurobj->mapFormValuesToDB($params);
             //Delete repeat configuration and rebuild
             if (!empty($params['id'])) {
                 CRM_Core_BAO_ActionSchedule::del($params['id']);
                 unset($params['id']);
             }
             $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
             //exclude dates
             $excludeDateList = array();
             if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
                 //Since we get comma separated values lets get them in array
                 $excludeDates = explode(",", $params['exclude_date_list']);
                 //Check if there exists any values for this option group
                 $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $type . '_repeat_exclude_dates_' . $params['parent_entity_id'], 'id', 'name');
                 if ($optionGroupIdExists) {
                     CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
                 }
                 $optionGroupParams = array('name' => $type . '_repeat_exclude_dates_' . $actionScheduleObj->entity_value, 'title' => $type . ' recursion', 'is_reserved' => 0, 'is_active' => 1);
                 $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams);
                 if ($opGroup->id) {
                     $oldWeight = 0;
                     $fieldValues = array('option_group_id' => $opGroup->id);
                     foreach ($excludeDates as $val) {
                         $optionGroupValue = array('option_group_id' => $opGroup->id, 'label' => CRM_Utils_Date::processDate($val), 'value' => CRM_Utils_Date::processDate($val), 'name' => $opGroup->name, 'description' => 'Used for recurring ' . $type, 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), 'is_active' => 1);
                         $excludeDateList[] = $optionGroupValue['value'];
                         CRM_Core_BAO_OptionValue::create($optionGroupValue);
                     }
                 }
             }
             //Set type for API
             $apiEntityType = explode("_", $type);
             if (!empty($apiEntityType[1])) {
                 $apiType = $apiEntityType[1];
             }
             //Delete relations if any from recurring entity tables before inserting new relations for this entity id
             if ($params['entity_id']) {
                 //If entity has any pre delete function, consider that first
                 if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
                     $preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id']));
                     if (!empty($preDeleteResult)) {
                         call_user_func(array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult));
                     }
                 }
                 //Ready to execute delete on entities if it has delete function set
                 if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
                     //Check if pre delete function has some ids to be deleted
                     if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) {
                         foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $eid) {
                             $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $eid));
                             if ($result['error']) {
                                 CRM_Core_Error::statusBounce('Error creating recurring list');
                             }
                         }
                     } else {
                         $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE);
                         foreach ($getRelatedEntities as $key => $value) {
                             $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $value['id']));
                             if ($result['error']) {
                                 CRM_Core_Error::statusBounce('Error creating recurring list');
                             }
                         }
                     }
                 }
                 // find all entities from the recurring set. At this point we 'll get entities which were not deleted
                 // for e.g due to participants being present. We need to delete them from recurring tables anyway.
                 $pRepeatingEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table']);
                 foreach ($pRepeatingEntities as $val) {
                     CRM_Core_BAO_RecurringEntity::delEntity($val['id'], $val['table'], TRUE);
                 }
             }
             $recursion = new CRM_Core_BAO_RecurringEntity();
             $recursion->dateColumns = $params['dateColumns'];
             $recursion->scheduleId = $actionScheduleObj->id;
             if (!empty($excludeDateList)) {
                 $recursion->excludeDates = $excludeDateList;
                 $recursion->excludeDateRangeColumns = $params['excludeDateRangeColumns'];
             }
             if (!empty($params['intervalDateColumns'])) {
                 $recursion->intervalDateColumns = $params['intervalDateColumns'];
             }
             $recursion->entity_id = $params['entity_id'];
             $recursion->entity_table = $params['entity_table'];
             if (!empty($linkedEntities)) {
                 $recursion->linkedEntities = $linkedEntities;
             }
             $recursion->generate();
             $status = ts('Repeat Configuration has been saved');
             CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
         }
     }
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:101,代码来源:RecurringEntity.php

示例2: testEventGeneration

 /**
  * Testing Event Generation through Entity Recursion.
  */
 public function testEventGeneration()
 {
     //Event set initial params
     $daoEvent = new CRM_Event_DAO_Event();
     $daoEvent->title = 'Test event for Recurring Entity';
     $daoEvent->event_type_id = 3;
     $daoEvent->is_public = 1;
     $daoEvent->start_date = date('YmdHis', strtotime('2014-10-26 10:30:00'));
     $daoEvent->end_date = date('YmdHis', strtotime('2014-10-28 10:30:00'));
     $daoEvent->created_date = date('YmdHis');
     $daoEvent->is_active = 1;
     $daoEvent->save();
     $this->assertDBNotNull('CRM_Event_DAO_Event', $daoEvent->id, 'id', 'id', 'Check DB if event was created');
     //Create tell a friend for event
     $daoTellAFriend = new CRM_Friend_DAO_Friend();
     $daoTellAFriend->entity_table = 'civicrm_event';
     $daoTellAFriend->entity_id = $daoEvent->id;
     // join with event
     $daoTellAFriend->title = 'Testing tell a friend';
     $daoTellAFriend->is_active = 1;
     $daoTellAFriend->save();
     $this->assertDBNotNull('CRM_Friend_DAO_Friend', $daoTellAFriend->id, 'id', 'id', 'Check DB if tell a friend was created');
     // time to use recursion
     $recursion = new CRM_Core_BAO_RecurringEntity();
     $recursion->entity_id = $daoEvent->id;
     $recursion->entity_table = 'civicrm_event';
     $recursion->dateColumns = array('start_date');
     $recursion->schedule = array('entity_value' => $daoEvent->id, 'start_action_date' => $daoEvent->start_date, 'start_action_condition' => 'monday', 'repetition_frequency_unit' => 'week', 'repetition_frequency_interval' => 1, 'start_action_offset' => 4, 'used_for' => 'event');
     $recursion->linkedEntities = array(array('table' => 'civicrm_tell_friend', 'findCriteria' => array('entity_id' => $recursion->entity_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => TRUE));
     $interval = $recursion->getInterval($daoEvent->start_date, $daoEvent->end_date);
     $recursion->intervalDateColumns = array('end_date' => $interval);
     $generatedEntities = $recursion->generate();
     $this->assertArrayHasKey('civicrm_event', $generatedEntities, 'Check if generatedEntities has civicrm_event as required key');
     $expectedDates = array('20141027103000' => '20141029103000', '20141103103000' => '20141105103000', '20141110103000' => '20141112103000', '20141117103000' => '20141119103000');
     $this->assertCount($recursion->schedule['start_action_offset'], $generatedEntities['civicrm_event'], 'Check if the number of events created are right');
     $actualDates = array();
     foreach ($generatedEntities['civicrm_event'] as $key => $val) {
         $this->assertDBNotNull('CRM_Event_DAO_Event', $val, 'id', 'id', 'Check if repeating events were created.');
         $startDate = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $val, 'start_date', 'id')));
         $endDate = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $val, 'end_date', 'id')));
         $actualDates[$startDate] = $endDate;
     }
     $resultDates = array_diff($actualDates, $expectedDates);
     $this->assertEquals(0, count($resultDates), "Check if all the value in expected array matches actual array");
     foreach ($generatedEntities['civicrm_tell_friend'] as $key => $val) {
         $this->assertDBNotNull('CRM_Friend_DAO_Friend', $val, 'id', 'id', 'Check if friends were created in loop');
         $this->assertDBCompareValue('CRM_Friend_DAO_Friend', $val, 'entity_id', 'id', $generatedEntities['civicrm_event'][$key], 'Check DB if correct FK was maintained with event for Friend');
     }
     $this->assertCount($recursion->schedule['start_action_offset'], $generatedEntities['civicrm_tell_friend'], 'Check if the number of tell a friend records are right');
     // set mode to ALL, i.e any change to changing event affects all related recurring activities
     $recursion->mode(3);
     $daoEvent->find(TRUE);
     $daoEvent->title = 'Event Changed';
     $daoEvent->save();
     // check if other events were affected
     foreach ($generatedEntities['civicrm_event'] as $entityID) {
         $this->assertDBCompareValue('CRM_Event_DAO_Event', $entityID, 'title', 'id', 'Event Changed', 'Check if title was updated');
     }
     end($generatedEntities['civicrm_event']);
     $key = key($generatedEntities['civicrm_event']);
     end($generatedEntities['civicrm_tell_friend']);
     $actKey = key($generatedEntities['civicrm_tell_friend']);
     //Check if both(event/tell a friend) keys are same
     $this->assertEquals($key, $actKey, "Check if both the keys are same");
     //Cross check event exists before we test deletion
     $searchParamsEventBeforeDelete = array('entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event');
     $expectedValuesEventBeforeDelete = array('entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event');
     $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsEventBeforeDelete, $expectedValuesEventBeforeDelete);
     //Cross check event exists before we test deletion
     $searchParamsTellAFriendBeforeDelete = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend');
     $expectedValuesTellAFriendBeforeDelete = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend');
     $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsTellAFriendBeforeDelete, $expectedValuesTellAFriendBeforeDelete);
     //Delete an event from recurring set and respective linked entity should be deleted from civicrm_recurring_entity_table
     $daoRecurEvent = new CRM_Event_DAO_Event();
     $daoRecurEvent->id = $generatedEntities['civicrm_event'][$key];
     if ($daoRecurEvent->find(TRUE)) {
         $daoRecurEvent->delete();
         $daoRecurEvent->free();
     }
     //Check if this event_id was deleted
     $this->assertDBNull('CRM_Event_DAO_Event', $generatedEntities['civicrm_event'][$key], 'id', 'id', 'Check if event was deleted');
     $searchParams = array('entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event');
     $compareParams = array();
     $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParams, $compareParams);
     //Find tell_a_friend id if that was deleted from civicrm
     $searchActParams = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend');
     $compareActParams = array();
     $this->assertDBCompareValues('CRM_Friend_DAO_Friend', $searchActParams, $compareActParams);
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:92,代码来源:RecurringEntityTest.php


注:本文中的CRM_Core_BAO_RecurringEntity::generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。