protected $_values = array();
protected $unsavedWarn = TRUE;
-
+
/**
* The _fields var can be used by sub class to set/unset/edit the
* form fields based on their requirement
}
$this->set('values', $this->_values);
}
-
+
if ($this->_action & CRM_Core_Action::UPDATE) {
CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
}
}
-
+
/**
* This function sets the default values for the form. For edit/view mode
* the default values are retrieved from the database
$params['entity_table'] = 'civicrm_activity';
$scheduleReminderDetails = array();
if (!empty($params['entity_id']) && !empty($params['entity_table'])) {
- $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($params['entity_id'], $params['entity_table']);
+ $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($params['entity_id'], $params['entity_table']);
if ($checkParentExistsForThisId) {
$params['parent_entity_id'] = $checkParentExistsForThisId;
$scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $params['entity_table']);
*
*/
-require_once 'packages/When/When.php';
+require_once 'packages/When/When.php';
class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
-
+
CONST RUNNING = 1;
public $schedule = array();
public $scheduleId = NULL;
public $overwriteColumns = array();
public $intervalDateColumns = array();
public $excludeDates = array();
-
+
public $linkedEntities = array();
public $isRecurringEntityRecord = TRUE;
protected $recursion = NULL;
-
+
public static $_entitiesToBeDeleted = array();
public static $status = NULL;
-
- static $_recurringEntityHelper =
+
+ static $_recurringEntityHelper =
array(
'civicrm_event' => array(
'helper_class' => 'CRM_Event_DAO_Event',
'helper_class' => 'CRM_Activity_DAO_Activity',
'delete_func' => 'delete',
'pre_delete_func' => ''
- )
- );
-
- static $_dateColumns =
+ )
+ );
+
+ static $_dateColumns =
array(
'civicrm_event' => array(
'dateColumns' => array('start_date'),
)
);
- static $_tableDAOMapper =
+ static $_tableDAOMapper =
array(
'civicrm_event' => 'CRM_Event_DAO_Event',
'civicrm_price_set_entity' => 'CRM_Price_DAO_PriceSetEntity',
'civicrm_activity_contact' => 'CRM_Activity_DAO_ActivityContact',
);
- static $_updateSkipFields =
+ static $_updateSkipFields =
array(
'civicrm_event' => array('start_date', 'end_date'),
'civicrm_tell_friend' => array('entity_id'),
'civicrm_activity' => array('activity_date_time'),
);
- static $_linkedEntitiesInfo =
+ static $_linkedEntitiesInfo =
array(
'civicrm_tell_friend' => array(
- 'entity_id_col' => 'entity_id',
+ 'entity_id_col' => 'entity_id',
'entity_table_col' => 'entity_table'
),
'civicrm_price_set_entity' => array(
- 'entity_id_col' => 'entity_id',
+ 'entity_id_col' => 'entity_id',
'entity_table_col' => 'entity_table',
'is_multirecord' => TRUE,
),
'civicrm_uf_join' => array(
- 'entity_id_col' => 'entity_id',
+ 'entity_id_col' => 'entity_id',
'entity_table_col' => 'entity_table',
'is_multirecord' => TRUE,
),
'civicrm_pcp_block' => array(
- 'entity_id_col' => 'entity_id',
+ 'entity_id_col' => 'entity_id',
'entity_table_col' => 'entity_table'
),
);
-
+
static function getStatus() {
return self::$status;
}
-
+
static function setStatus($status) {
self::$status = $status;
}
* @return object
*/
static function quickAdd($parentId, $entityId, $entityTable) {
- $params =
+ $params =
array(
'parent_id' => $parentId,
'entity_id' => $entityId,
/**
* This function generates all new entities based on object vars
- *
+ *
* @return array
*/
function generate() {
/**
* This function builds a "When" object based on schedule/reminder params
- *
+ *
* @return object When object
*/
function generateRecursion() {
// return if already generated
- if (is_a($this->recursion, 'When')) {
+ if (is_a($this->recursion, 'When')) {
return $this->recursion;
}
/**
* Generate new DAOs and along with entries in civicrm_recurring_entity table
- *
+ *
* @return array
*/
function generateEntities() {
$newCriteria[$col] = $val;
}
// create main entities
- $obj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($this->entity_table,
+ $obj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($this->entity_table,
$findCriteria,
$newCriteria,
$this->isRecurringEntityRecord
$newCriteria[$col] = $obj->id;
}
// create linked entities
- $linkedObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($linkedInfo['table'],
+ $linkedObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($linkedInfo['table'],
$linkedInfo['findCriteria'],
$newCriteria,
CRM_Utils_Array::value('isRecurringEntityRecord', $linkedInfo, TRUE)
}
/**
- * This function iterates through when object criterias and
+ * This function iterates through when object criterias and
* generates recursive dates based on that
- *
+ *
* @return array array of dates
*/
function generateRecursiveDates() {
$this->generateRecursion();
$recursionDates = array();
- if (is_a($this->recursion, 'When')) {
+ if (is_a($this->recursion, 'When')) {
$initialCount = CRM_Utils_Array::value('start_action_offset', $this->schedule);
$exRangeStart = $exRangeEnd = NULL;
/**
* This function gets all the children for a particular parent entity
- *
+ *
* @param int $parentId Parent entity id
* @param string $entityTable Name of the entity table
* @param boolean $includeParent If true parent id is included in result set and vice versa
* @param int $mode 1. retrieve only one entity. 2. retrieve all future entities in the repeating set. 3. all entities in the repeating set.
* @param int $initiatorId the instance where this function is invoked from
- *
+ *
* @access public
* @static
- *
+ *
* @return array an array of child ids
*/
static public function getEntitiesForParent($parentId, $entityTable, $includeParent = TRUE, $mode = 3, $initiatorId = NULL) {
if (!$initiatorId) {
$initiatorId = $parentId;
- }
+ }
$queryParams = array(
1 => array($parentId, 'Integer'),
$recurringEntityID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_recurring_entity WHERE entity_id = %3 AND entity_table = %2", $queryParams);
if ($recurringEntityID) {
$query .= $includeParent ? " AND id >= %4" : " AND id > %4";
- $query .= " ORDER BY id ASC"; // FIXME: change to order by dates
+ $query .= " ORDER BY id ASC"; // FIXME: change to order by dates
$queryParams[4] = array($recurringEntityID, 'Integer');
}
else {
}
/**
- * This function when passed an entity id checks if it has parent and
+ * This function when passed an entity id checks if it has parent and
* returns all other entities that are connected to same parent.
- *
+ *
* @param int $entityId entity id
* @param string $entityTable Entity table name
* @param boolean $includeParent Include parent in result set
* @param int $mode 1. retrieve only one entity. 2. retrieve all future entities in the repeating set. 3. all entities in the repeating set.
- *
+ *
* @access public
* @static
- *
+ *
* @return array array of connected ids
*/
static public function getEntitiesFor($entityId, $entityTable, $includeParent = TRUE, $mode = 3) {
/**
* This function gets the parent for the entity id passed to it
- *
+ *
* @param int $entityId entity ID
* @param string $entityTable Entity table name
* @param boolean $includeParent Include parent in result set
- *
+ *
* @access public
* @static
- *
- * @return int unsigned $parentId Parent ID
+ *
+ * @return int unsigned $parentId Parent ID
*/
static public function getParentFor($entityId, $entityTable, $includeParent = TRUE) {
$query = "
- SELECT parent_id
+ SELECT parent_id
FROM civicrm_recurring_entity
WHERE entity_id = %1 AND entity_table = %2";
if (!$includeParent) {
$query .= " AND parent_id != %1";
}
- $parentId =
+ $parentId =
CRM_Core_DAO::singleValueQuery($query,
array(
1 => array($entityId, 'Integer'),
/**
* This function copies the information from parent entity and creates other entities with same information
- *
+ *
* @param string $entityTable Entity table name
* @param array $fromCriteria array of all the fields & values on which basis to copy
* @param array $newParams array of all the fields & values to be copied besides the other fields
* @param boolean $createRecurringEntity if to create a record in recurring_entity table
- *
+ *
* @access public
* @static
- *
+ *
* @return object
*/
static public function copyCreateEntity($entityTable, $fromCriteria, $newParams, $createRecurringEntity = TRUE) {
/**
* This function acts as a listener to dao->update whenever there is an update,
* and propagates any changes to all related entities present in recurring entity table
- *
+ *
* @param object $event An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just updated
- *
+ *
* @access public
* @static
- *
+ *
* @return void
*/
static public function triggerUpdate($event) {
return FALSE;
}
$key = "{$obj->__table}_{$obj->id}";
-
+
if (array_key_exists($key, $processedEntities)) {
// already processed
return NULL;
/**
* This function acts as a listener to dao->save,
* and creates entries for linked entities in recurring entity table
- *
+ *
* @param object $event An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just inserted
- *
+ *
* @access public
* @static
- *
+ *
* @return void
*/
static public function triggerInsert($event) {
return FALSE;
}
$key = "{$obj->__table}_{$obj->id}";
-
+
if (array_key_exists($key, $processedEntities)) {
// already being processed. Exit recursive calls.
return NULL;
if (empty($hasaRecurringRecord)) {
// check if its a linked entity
- if (array_key_exists($obj->__table, self::$_linkedEntitiesInfo) &&
+ if (array_key_exists($obj->__table, self::$_linkedEntitiesInfo) &&
!CRM_Utils_Array::value('is_multirecord', self::$_linkedEntitiesInfo[$obj->__table])) {
$linkedDAO = new self::$_tableDAOMapper[$obj->__table]();
$linkedDAO->id = $obj->id;
$pEntityID = $linkedDAO->$idCol;
$pEntityTable = $linkedDAO->$tableCol;
-
+
// find all parent recurring entity set
$pRepeatingEntities = self::getEntitiesFor($pEntityID, $pEntityTable);
$idCol => $val['id'],
$tableCol => $val['table']
);
- $linkedObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($obj->__table,
+ $linkedObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($obj->__table,
array('id' => $obj->id),
$newCriteria,
TRUE
/**
* This function acts as a listener to dao->delete, and deletes an entry from recurring_entity table
- *
+ *
* @param object $event An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just deleted
*
* @access public
* @static
- *
+ *
* @return void
*/
static public function triggerDelete($event) {
/**
* This function deletes main entity and related linked entities from recurring-entity table
- *
+ *
* @param int $entityId Entity id
* @param string $entityTable Name of the entity table
- *
+ *
* @access public
* @static
- *
+ *
* @return boolean|object Returns either boolean value or CRM_Core_DAO_RecurringEntity object
*/
static public function delEntity($entityId, $entityTable, $isDelLinkedEntities = FALSE) {
/**
* This function maps values posted from form to civicrm_action_schedule columns
- *
+ *
* @param array $formParams and array of form values posted
- *
- * @return array
+ *
+ * @return array
*/
- function mapFormValuesToDB($formParams = array()) {
+ function mapFormValuesToDB($formParams = array()) {
$dbParams = array();
if (CRM_Utils_Array::value('used_for', $formParams)) {
$dbParams['used_for'] = $formParams['used_for'];
}
}
- //For "Ends" - After:
+ //For "Ends" - After:
if ($formParams['ends'] == 1) {
if (CRM_Utils_Array::value('start_action_offset', $formParams)) {
$dbParams['start_action_offset'] = $formParams['start_action_offset'];
}
}
- //For "Ends" - On:
+ //For "Ends" - On:
if ($formParams['ends'] == 2) {
if (CRM_Utils_Array::value('repeat_absolute_date', $formParams)) {
$dbParams['absolute_date'] = CRM_Utils_Date::processDate($formParams['repeat_absolute_date']);
/**
* This function gets all the columns of civicrm_action_schedule table based on id(primary key)
- *
+ *
* @param int $scheduleReminderId primary key of civicrm_action_schedule table
- *
+ *
* @access public
* @static
- *
+ *
* @return object
*/
static public function getScheduleReminderDetailsById($scheduleReminderId) {
/**
* This function is a wrapper of getScheduleReminderDetailsById function
- *
+ *
* @param int $scheduleReminderId primary key of civicrm_action_schedule table
- *
+ *
* @return array
*/
function getScheduleParams($scheduleReminderId) {
/**
* This function takes criterias saved in civicrm_action_schedule table
* and creates recursion rule
- *
+ *
* @param array $scheduleReminderDetails array of repeat criterias saved in civicrm_action_schedule table
- *
+ *
* @return object When object
*/
function getRecursionFromSchedule($scheduleReminderDetails = array()) {
}
}
- //month
+ //month
if ($scheduleReminderDetails['repetition_frequency_unit'] == 'month') {
if ($scheduleReminderDetails['entity_status']) {
$startActionDate = explode(" ", $scheduleReminderDetails['entity_status']);
return $r;
}
-
+
/**
* This function gets time difference between the two datetime object
- *
+ *
* @param DateTime $startDate Start Date
* @param DateTime $endDate End Date
- *
+ *
* @access public
* @static
- *
+ *
* @return object DateTime object which contain time difference
*/
- static public function getInterval($startDate, $endDate) {
+ static public function getInterval($startDate, $endDate) {
if ($startDate && $endDate) {
$startDate = new DateTime($startDate);
$endDate = new DateTime($endDate);
/**
* This function gets all columns from civicrm_action_schedule on the basis of event id
- *
+ *
* @param int $entityId Entity ID
* @param string $used_for Specifies for which entity type it's used for
- *
+ *
* @access public
* @static
- *
+ *
* @return object
*/
public static function getReminderDetailsByEntityId($entityId, $used_for) {
if ($entityId) {
$query = "
SELECT *
- FROM civicrm_action_schedule
+ FROM civicrm_action_schedule
WHERE entity_value = %1";
if ($used_for) {
$query .= " AND used_for = %2";
}
return $dao;
}
-
+
/**
* Update mode column in civicrm_recurring_entity table for event related tabs
- *
+ *
* @params int $entityId event id
* @params string $linkedEntityTable Linked entity table name for this event
* @return array
$result['entityId'] = $defaults['id'];
$result['entityTable'] = $entityTable;
}
- }
+ }
return $result;
- }
+ }
}
* Current entity id
*/
protected static $_entityId = NULL;
-
+
/**
* Schedule Reminder ID
*/
protected static $_scheduleReminderID = NULL;
-
+
/**
* Schedule Reminder data
*/
protected static $_scheduleReminderDetails = array();
-
+
/**
* Parent Entity ID
*/
protected static $_parentEntityId = NULL;
-
+
/**
- * Exclude date information
+ * Exclude date information
*/
public static $_excludeDateInfo = array();
-
+
/**
* Entity Table
*/
public static $_entityTable;
-
+
/**
* Checks current entityID has parent
*/
public static $_hasParent = FALSE;
-
+
static function preProcess($entityTable) {
self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive');
self::$_entityTable = $entityTable;
-
+
if (self::$_entityId && $entityTable) {
- $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, $entityTable);
+ $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, $entityTable);
if ($checkParentExistsForThisId) {
self::$_hasParent = TRUE;
self::$_parentEntityId = $checkParentExistsForThisId;
}
}
}
-
+
/**
* This function sets the default values for the form. For edit/view mode
* the default values are retrieved from the database
}
return $defaults;
}
-
+
static function buildQuickForm(&$form) {
$form->assign('currentEntityId', self::$_entityId);
$form->assign('entityTable', self::$_entityTable);
$form->assign('scheduleReminderId', self::$_scheduleReminderID);
$form->assign('hasParent', self::$_hasParent);
-
+
$form->_freqUnits = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units');
foreach ($form->_freqUnits as $val => $label) {
if ($label == "day") {
$form->addDate('exclude_date', ts('Exclude Date(s)'), FALSE);
$select = $form->add('select', 'exclude_date_list', ts(''), self::$_excludeDateInfo, FALSE, array('style' => 'width:150px;', 'size' => 4));
$select->setMultiple(TRUE);
- $form->addElement('button','add_to_exclude_list','>>','onClick="addToExcludeList(document.getElementById(\'exclude_date\').value);"');
- $form->addElement('button','remove_from_exclude_list', '<<', 'onClick="removeFromExcludeList(\'exclude_date_list\')"');
+ $form->addElement('button','add_to_exclude_list','>>','onClick="addToExcludeList(document.getElementById(\'exclude_date\').value);"');
+ $form->addElement('button','remove_from_exclude_list', '<<', 'onClick="removeFromExcludeList(\'exclude_date_list\')"');
$form->addElement('hidden', 'copyExcludeDates', '', array('id' => 'copyExcludeDates'));
$form->addElement('hidden', 'allowRepeatConfigToSubmit', '', array('id' => 'allowRepeatConfigToSubmit'));
$form->addButtons(array(
}
$actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
- //exclude dates
+ //exclude dates
$excludeDateList = array();
- if (CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
+ if (CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
//Since we get comma separated values lets get them in array
$excludeDates = array();
$excludeDates = explode(",", $params['copyExcludeDates']);
if ($optionGroupIdExists) {
CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
}
- $optionGroupParams =
+ $optionGroupParams =
array(
'name' => $type.'_repeat_exclude_dates_'.$actionScheduleObj->entity_value,
'title' => $type.' recursion',
$oldWeight= 0;
$fieldValues = array('option_group_id' => $opGroup->id);
foreach($excludeDates as $val) {
- $optionGroupValue =
+ $optionGroupValue =
array(
'option_group_id' => $opGroup->id,
'label' => CRM_Utils_Date::processDate($val),
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']])) {
call_user_func(array(
- CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'],
+ CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'],
call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id'])))
);
}
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'],
+ ucfirst(strtolower($apiType)),
+ CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'],
array(
'sequential' => 1,
'id' => $eid,
$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'],
+ ucfirst(strtolower($apiType)),
+ CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'],
array(
'sequential' => 1,
'id' => $value['id'],
$recursion->linkedEntities = $linkedEntities;
}
- $recurResult = $recursion->generate();
+ $recurResult = $recursion->generate();
$status = ts('Repeat Configuration has been saved');
CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
public function getTitle() {
return ts('Repeat Entity');
}
-
+
}
*/
class CRM_Core_Page_AJAX_RecurringEntity {
-
+
public static function updateMode() {
if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)) {
-
+
$finalResult = array();
$mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
$entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
$dao->entity_id = $entityId;
$dao->entity_table = $entityTable;
}
-
+
if ($dao->find(TRUE)) {
$dao->mode = $mode;
$dao->save();
echo json_encode($finalResult);
CRM_Utils_System::civiExit();
}
-
+
public static function generatePreview() {
$params = $formValues = $genericResult = array();
$formValues = $_REQUEST;
CRM_Utils_Array::value('entity_table', $formValues)) {
$startDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'][0];
$endDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['intervalDateColumns'][0];
-
+
$recursion = new CRM_Core_BAO_RecurringEntity();
if (CRM_Utils_Array::value('dateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) {
$recursion->dateColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'];
if (CRM_Utils_Array::value('excludeDateRangeColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) {
$recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns'];
}
-
+
if (CRM_Utils_Array::value('entity_id', $formValues)) {
$parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']);
}
}
}
- $result = $recursion->generateRecursiveDates();
+ $result = $recursion->generateRecursiveDates();
foreach ($result as $key => $value) {
if ($startDateColumnName) {
}
}
}
-
+
//Show the list of participants registered for the events if any
if ($formValues['entity_table'] == "civicrm_event") {
$getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE);
* the participant records
*/
protected $_campaignID = NULL;
-
+
/**
* Check if repeating event
*/
if (in_array('CiviEvent', $config->enableComponents)) {
$this->assign('CiviEvent', TRUE);
}
-
+
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
$this->assign('action', $this->_action);
}
$this->_templateId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this);
-
+
//Is a repeating event
if ($this->_isRepeatingEvent) {
$isRepeatingEntity = TRUE;
* @author Priyanka
*/
class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
-
+
/**
* Parent Event Start Date
*/
protected $_parentEventStartDate = NULL;
-
+
/**
* Parent Event End Date
*/
protected $_parentEventEndDate = NULL;
-
-
+
+
function preProcess() {
parent::preProcess();
CRM_Core_Form_RecurringEntity::preProcess('civicrm_event');
$this->assign('currentEventId', $this->_id);
-
- $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
+
+ $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
//If this ID has parent, send parent id
if ($checkParentExistsForThisId) {
/**
CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]);
}
}
- }
+ }
$this->assign('rows', $manageEvent);
}
}
$this->_parentEventStartDate = $parentEventAttributes->start_date;
$this->_parentEventEndDate = $parentEventAttributes->end_date;
}
-
+
/**
* This function sets the default values for the form. For edit/view mode
* the default values are retrieved from the database
*/
function setDefaultValues() {
$defaults = array();
-
+
//Always pass current event's start date by default
$currentEventStartDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'start_date', 'id');
list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($currentEventStartDate, 'activityDateTime');
$defaults = array_merge($defaults, $recurringEntityDefaults);
return $defaults;
}
-
+
public function buildQuickForm() {
CRM_Core_Form_RecurringEntity::buildQuickForm($this);
}
-
+
public function postProcess() {
if ($this->_id) {
- $params = $this->controller->exportValues($this->_name);
+ $params = $this->controller->exportValues($this->_name);
if ($this->_parentEventStartDate && $this->_parentEventEndDate) {
$interval = CRM_Core_BAO_RecurringEntity::getInterval($this->_parentEventStartDate, $this->_parentEventEndDate);
$params['intervalDateColumns'] = array('end_date' => $interval);
$url = 'civicrm/event/manage/repeat';
$urlParams = "action=update&reset=1&id={$this->_id}";
-
+
$linkedEntities = array(
array(
'table' => 'civicrm_price_set_entity',
'findCriteria' => array(
- 'entity_id' => $this->_id,
+ 'entity_id' => $this->_id,
'entity_table' => 'civicrm_event'
),
'linkedColumns' => array('entity_id'),
array(
'table' => 'civicrm_uf_join',
'findCriteria' => array(
- 'entity_id' => $this->_id,
+ 'entity_id' => $this->_id,
'entity_table' => 'civicrm_event'
),
'linkedColumns' => array('entity_id'),
array(
'table' => 'civicrm_tell_friend',
'findCriteria' => array(
- 'entity_id' => $this->_id,
+ 'entity_id' => $this->_id,
'entity_table' => 'civicrm_event'
),
'linkedColumns' => array('entity_id'),
array(
'table' => 'civicrm_pcp_block',
'findCriteria' => array(
- 'entity_id' => $this->_id,
+ 'entity_id' => $this->_id,
'entity_table' => 'civicrm_event'
),
'linkedColumns' => array('entity_id'),
}
else {
CRM_Core_Error::fatal("Could not find Event ID");
- }
+ }
}
-
+
/**
* This function gets the number of participant count for the list of related event ids
- *
+ *
* @param array $listOfRelatedEntities list of related event ids
- *
+ *
* @access public
* @static
- *
+ *
* @return array
*/
static public function getParticipantCountforEvent($listOfRelatedEntities = array()) {
return $entity['id'];
}, $listOfRelatedEntities));
if ($implodeRelatedEntities) {
- $query = "SELECT p.event_id as event_id,
- concat_ws(' ', e.title, concat_ws(' - ', DATE_FORMAT(e.start_date, '%b %d %Y %h:%i %p'), DATE_FORMAT(e.end_date, '%b %d %Y %h:%i %p'))) as event_data,
+ $query = "SELECT p.event_id as event_id,
+ concat_ws(' ', e.title, concat_ws(' - ', DATE_FORMAT(e.start_date, '%b %d %Y %h:%i %p'), DATE_FORMAT(e.end_date, '%b %d %Y %h:%i %p'))) as event_data,
count(p.id) as participant_count
- FROM civicrm_participant p, civicrm_event e
+ FROM civicrm_participant p, civicrm_event e
WHERE p.event_id = e.id AND p.event_id IN ({$implodeRelatedEntities})
GROUP BY p.event_id";
$dao = CRM_Core_DAO::executeQuery($query);
}
return $participantDetails;
}
-
+
/**
* This function checks if there was any registraion for related event ids,
* and returns array of ids with no regsitrations
</td>
</tr>
{/if}
-
+
{if $action eq 2 OR $action eq 1}
<tr class="crm-activity-form-block-recurring_activity">
<td colspan="2">
</td>
</tr>
{/if}
-
+
{if $action neq 4} {* Don't include "Schedule Follow-up" section in View mode. *}
<tr class="crm-activity-form-block-schedule_followup">
<td colspan="2">
<li>Daily: your event repeats daily or after every few days</li>
<li>Weekly: your event repeats on one or more days every week</li>
<li>Monthly: your event repeats on one or more days every month</li>
- <li>Yearly: your event repeats yearly or after every few years</li>
+ <li>Yearly: your event repeats yearly or after every few years</li>
</ul>
For eg - You would select option "monthly", if your event occurs every month.
{/ts}
</div>
</div>
<div id="preview-dialog" class="hide-block">
- <div id="generated_dates" class="show-block"></div>
+ <div id="generated_dates" class="show-block"></div>
</div>
{literal}
<script type="text/javascript">
cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
}
cj("#repeats-every-text").html(cj('#repetition_frequency_unit').val()+'(s)');
-
+
/***********On Load Set Ends Value (Edit Mode) **********/
if (cj('input:radio[name=ends]:checked').val() == 1) {
cj('#start_action_offset').removeAttr('disabled').attr('enabled','enabled');
//Just in-case block shows up, disable it
cj('#limit_to, #entity_status_1, #entity_status_2').removeAttr('enabled').attr('disabled','disabled');
}
-
+
cj('#repetition_frequency_unit').change(function () {
if (cj(this).val()==='hour') {
cj('#repeats-every-text').html(cj(this).val()+'(s)');
cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
} else if (cj(this).val()==='week') {
cj('#repeats-every-text').html(cj(this).val()+'(s)');
- //Show "Repeats On" block when week is selected
+ //Show "Repeats On" block when week is selected
cj('.crm-core-form-recurringentity-block-start_action_condition').show();
cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
} else if (cj(this).val()==='month') {
cj('#repeats-every-text').html(cj(this).val()+'(s)');
cj('.crm-core-form-recurringentity-block-start_action_condition').hide();
- //Show "Repeats By" block when month is selected
+ //Show "Repeats By" block when month is selected
cj('.crm-core-form-recurringentity-block-repeats_by td').show();
} else if (cj(this).val()==='year') {
cj('#repeats-every-text').html(cj(this).val()+'(s)');
cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
}
});
-
+
// For "Ends" block
cj('input:radio[name=ends]').click(function() {
if (cj(this).val() == 1) {
cj('#repeat_absolute_date_display').removeAttr('enabled').attr('disabled','disabled');
}
});
-
+
//For "Repeats By" block
cj('input:radio[name=repeats_by]').click(function() {
if (cj(this).val() == 1) {
cj('#entity_status_2').removeAttr('enabled').attr('disabled','disabled');
}
});
-
+
//Select all options in selectbox before submitting
cj(this).submit(function() {
cj('#exclude_date_list option').attr('selected',true);
return false;
}
}
-
+
});
-
+
//Detect changes in Repeat configuration field
var unsavedChanges = false;
cj('div.crm-core-form-recurringentity-block').on('change', function() {
unsavedChanges = true;
});
-
+
//If there are changes in repeat configuration, enable save button
//Dialog for preview repeat Configuration dates
cj('#preview-dialog').dialog({ autoOpen: false });
- function previewDialog() {
+ function previewDialog() {
cj('#exclude_date_list option').attr('selected',true);
//Copy exclude dates
var dateTxt=[];
}
html += '</table>';
var warningHtml = '';
- if (Object.keys(participantData).length > 0) {
+ if (Object.keys(participantData).length > 0) {
warningHtml += '<div class="messages status no-popup"><div class="icon inform-icon"></div> There are registrations for the repeating events already present in the set, continuing with the process would unlink them and repeating events without registration would be trashed. </div><table id="options" class="display"><thead><tr><th>Event ID</th><th>Event</th><th>Participant Count</th></tr><thead>';
for (var id in participantData) {
for(var data in participantData[id]) {
});
return false;
}
-
+
cj('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click( function () {
return previewDialog();
});
-
+
cj('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function () {
//Process this only when repeat is configured. We need to do this test here as there is a common save for activity.
var isRepeatConfigured = '{/literal}{$scheduleReminderId}{literal}';
cj.data( document.body, "preview-dialog", false );
return false;
}
- }
+ }
else {
if (unsavedChanges) {
cj('#allowRepeatConfigToSubmit').val('1');
}
}
});
-
+
//Build Summary
var finalSummary = '';
var numberText = '';
numberText = 's';
}
finalSummary = "Every " + interval + cj('#repetition_frequency_unit option:selected').val() + numberText;
-
+
//Case Week
var dayOfWeek = new Array();
if (cj('#repetition_frequency_unit option:selected').val() == "week") {
});
finalSummary += ' on ' + dayOfWeek.join();
}
-
+
//Case Monthly
if (cj('#repetition_frequency_unit option:selected').val() == "month") {
if (cj('input:radio[name=repeats_by]:checked').val() == 1) {
finalSummary += ' on ' + cj('#entity_status_1').val().substr(0, 1).toUpperCase() + cj('#entity_status_1').val().substr(1).toLowerCase() + ' ' + cj('#entity_status_2').val().substr(0, 1).toUpperCase() + cj('#entity_status_2').val().substr(1).toLowerCase();
}
}
-
+
//Case Ends
if (cj('input:radio[name=ends]:checked').val() == 1) {
var timeText = ''
var monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var date = new Date(cj('#repeat_absolute_date_display').val());
function addOrdinal(d) {
- if (d>3 && d<21) return 'th';
+ if (d>3 && d<21) return 'th';
switch (d % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
- }
+ }
var newDate = monthNames[(date.getMonth())] + ' ' + date.getDate()+ addOrdinal() + ' ' + date.getFullYear();
finalSummary += ', untill '+ newDate;
}
-
+
//Build/Attach final Summary
cj('#rec-summary').html(finalSummary);
-
+
});
-
+
//Exclude list function
function addToExcludeList(val) {
if (val !== "") {
}
}
</script>
-{/literal}
+{/literal}
{*Hide Summary*}
{if empty($scheduleReminderId)}
{literal}
{if $hasParent || $isRepeatingEntity}
{literal}
<script type="text/javascript">
- CRM.$(function($) {
+ CRM.$(function($) {
/** Add your linked entity mapper here **/
var mapper = {'CRM_Event_Form_ManageEvent_EventInfo': '',
'CRM_Event_Form_ManageEvent_Location': '',
cascadeChangesDialog();
return false;
}
- });
-
+ });
+
$("#_qf_Activity_upload-top, #_qf_Activity_upload-bottom").click(function() {
form = $(this).parents('form:first').attr('class');
if( form != "" && mapper.hasOwnProperty(form) ){
return false;
}
});
-
+
$(".only-this-event").click(function() {
updateMode(1);
});
$(".all-events").click(function() {
updateMode(3);
});
-
+
function updateMode(mode) {
var entityID = parseInt('{/literal}{$entityID}{literal}');
var entityTable = '{/literal}{$entityTable}{literal}';
}
});
}
- }
+ }
});
</script>
{/literal}
event.stopPropagation();
return false;
});
-
+
$('#crm-participant-link').click(function(event) {
$('#crm-participant-list').toggle();
$('#crm-event-links-list').hide();
protected function setUp() {
parent::setUp();
}
-
+
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
'used_for' => 'activity'
);
- $generatedEntities = $recursion->generate();
+ $generatedEntities = $recursion->generate();
$this->assertEquals(5, count($generatedEntities['civicrm_activity']), "Cehck if number of iterations are 5");
$expectedDates = array(
- '20141025103000',
- '20141227103000',
- '20150328103000',
- '20150627103000',
+ '20141025103000',
+ '20141227103000',
+ '20150328103000',
+ '20150627103000',
'20150926103000'
);
foreach ($generatedEntities['civicrm_activity'] as $entityID) {
}
$resultDates = array_diff($actualDates, $expectedDates);
$this->assertEquals(0, count($resultDates), "Check if all the value in expected array matches actual array");
-
+
}
-
+
/**
* Testing Event Generation through Entity Recursion
*/
$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';
array(
'table' => 'civicrm_tell_friend',
'findCriteria' => array(
- 'entity_id' => $recursion->entity_id,
+ '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();
+ $generatedEntities = $recursion->generate();
$this->assertArrayHasKey('civicrm_event', $generatedEntities, 'Check if generatedEntities has civicrm_event as required key');
$expectedDates = array(
'20141027103000' => '20141029103000',
'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) {
$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);
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']);
+
+ 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'
);
$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'
);
$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];
$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(