+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | 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$
*
*/
require_once 'packages/When/When.php';
+/**
+ * Class CRM_Core_BAO_RecurringEntity
+ */
class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
const RUNNING = 1;
public static $status = NULL;
- static $_recurringEntityHelper =
- array(
+ static $_recurringEntityHelper
+ = array(
'civicrm_event' => array(
'helper_class' => 'CRM_Event_DAO_Event',
'delete_func' => 'delete',
- 'pre_delete_func' => 'CRM_Event_Form_ManageEvent_Repeat::checkRegistrationForEvents'
+ 'pre_delete_func' => 'CRM_Event_Form_ManageEvent_Repeat::checkRegistrationForEvents',
),
'civicrm_activity' => array(
'helper_class' => 'CRM_Activity_DAO_Activity',
'delete_func' => 'delete',
- 'pre_delete_func' => ''
- )
+ 'pre_delete_func' => '',
+ ),
);
- static $_dateColumns =
- array(
+ static $_dateColumns
+ = array(
'civicrm_event' => array(
'dateColumns' => array('start_date'),
'excludeDateRangeColumns' => array('start_date', 'end_date'),
- 'intervalDateColumns' => array('end_date')
+ 'intervalDateColumns' => array('end_date'),
),
'civicrm_activity' => array(
'dateColumns' => array('activity_date_time'),
- )
+ ),
);
- static $_tableDAOMapper =
- array(
- 'civicrm_event' => 'CRM_Event_DAO_Event',
+ static $_tableDAOMapper
+ = array(
+ 'civicrm_event' => 'CRM_Event_DAO_Event',
'civicrm_price_set_entity' => 'CRM_Price_DAO_PriceSetEntity',
- 'civicrm_uf_join' => 'CRM_Core_DAO_UFJoin',
+ 'civicrm_uf_join' => 'CRM_Core_DAO_UFJoin',
'civicrm_tell_friend' => 'CRM_Friend_DAO_Friend',
- 'civicrm_pcp_block' => 'CRM_PCP_DAO_PCPBlock',
- 'civicrm_activity' => 'CRM_Activity_DAO_Activity',
- 'civicrm_activity_contact' => 'CRM_Activity_DAO_ActivityContact',
+ 'civicrm_pcp_block' => 'CRM_PCP_DAO_PCPBlock',
+ 'civicrm_activity' => 'CRM_Activity_DAO_Activity',
+ 'civicrm_activity_contact' => 'CRM_Activity_DAO_ActivityContact',
);
- static $_updateSkipFields =
- array(
- 'civicrm_event' => array('start_date', 'end_date'),
+ static $_updateSkipFields
+ = array(
+ 'civicrm_event' => array('start_date', 'end_date'),
'civicrm_tell_friend' => array('entity_id'),
- 'civicrm_pcp_block' => array('entity_id'),
- 'civicrm_activity' => array('activity_date_time'),
+ 'civicrm_pcp_block' => array('entity_id'),
+ 'civicrm_activity' => array('activity_date_time'),
);
- static $_linkedEntitiesInfo =
- array(
+ static $_linkedEntitiesInfo
+ = array(
'civicrm_tell_friend' => array(
- 'entity_id_col' => 'entity_id',
- 'entity_table_col' => 'entity_table'
+ '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,
+ '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,
+ 'is_multirecord' => TRUE,
),
'civicrm_pcp_block' => array(
- 'entity_id_col' => 'entity_id',
- 'entity_table_col' => 'entity_table'
+ 'entity_id_col' => 'entity_id',
+ 'entity_table_col' => 'entity_table',
),
);
+ /**
+ * Getter for status.
+ *
+ * @return string
+ */
public static function getStatus() {
return self::$status;
}
+ /**
+ * Setter for status.
+ *
+ * @param string $status
+ */
public static function setStatus($status) {
self::$status = $status;
}
+
/**
- * Save records in civicrm_recujrring_entity table
+ * Save records in civicrm_recurring_entity table.
*
* @param array $params
- * Reference array contains the values submitted by the form .
- *
- * @static
+ * Reference array contains the values submitted by the form.
*
* @return object
*/
public static function add(&$params) {
- if (CRM_Utils_Array::value('id', $params)) {
+ if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'RecurringEntity', $params['id'], $params);
}
else {
$daoRecurringEntity->find(TRUE);
$result = $daoRecurringEntity->save();
- if (CRM_Utils_Array::value('id', $params)) {
+ if (!empty($params['id'])) {
CRM_Utils_Hook::post('edit', 'RecurringEntity', $daoRecurringEntity->id, $daoRecurringEntity);
}
else {
* @param string $entityTable
* Name of the entity table .
*
- * @static
*
* @return object
*/
public static function quickAdd($parentId, $entityId, $entityTable) {
- $params =
- array(
- 'parent_id' => $parentId,
- 'entity_id' => $entityId,
- 'entity_table' => $entityTable
+ $params
+ = array(
+ 'parent_id' => $parentId,
+ 'entity_id' => $entityId,
+ 'entity_table' => $entityTable,
);
return self::add($params);
}
/**
- * This function updates the mode column in the civicrm_recurring_entity table
+ * This function updates the mode column in the civicrm_recurring_entity table.
*
* @param int $mode
* Mode of the entity to cascade changes across parent/child relations eg 1 - only this entity, 2 - this and the following entities, 3 - All the entity .
}
/**
- * This function generates all new entities based on object vars
+ * This function generates all new entities based on object vars.
*
* @return array
*/
/**
* This function builds a "When" object based on schedule/reminder params
*
- * @return object When object
+ * @return object
+ * When object
*/
public function generateRecursion() {
// return if already generated
}
/**
- * Generate new DAOs and along with entries in civicrm_recurring_entity table
+ * Generate new DAOs and along with entries in civicrm_recurring_entity table.
*
* @return array
*/
public function generateEntities() {
self::setStatus(self::RUNNING);
- $newEntities = array();
+ $newEntities = array();
$findCriteria = array();
if (!empty($this->recursionDates)) {
if ($this->entity_id) {
* This function iterates through when object criterias and
* generates recursive dates based on that
*
- * @return array array of dates
+ * @return array
+ * array of dates
*/
public function generateRecursiveDates() {
$this->generateRecursion();
$exRangeStart = $exRangeEnd = NULL;
if (!empty($this->excludeDateRangeColumns)) {
$exRangeStart = $this->excludeDateRangeColumns[0];
- $exRangeEnd = $this->excludeDateRangeColumns[1];
+ $exRangeEnd = $this->excludeDateRangeColumns[1];
}
$count = 1;
$recursionDates[$count][$col] = CRM_Utils_Date::processDate($newDate->format('Y-m-d H:i:s'));
}
if ($exRangeStart) {
- $exRangeStartDate = CRM_Utils_Date::processDate($recursionDates[$count][$exRangeStart], NULL, FALSE, 'Ymd');
- $exRangeEndDate = CRM_Utils_Date::processDate($recursionDates[$count][$exRangeEnd], NULL, FALSE, 'Ymd');
+ $exRangeStartDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value($exRangeStart, $recursionDates[$count]), NULL, FALSE, 'Ymd');
+ $exRangeEndDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value($exRangeEnd, $recursionDates[$count]), NULL, FALSE, 'Ymd');
}
foreach ($this->excludeDates as $exDate) {
}
/**
- * This function gets all the children for a particular parent entity
+ * This function gets all the children for a particular parent entity.
*
* @param int $parentId
* Parent entity id .
* @param int $initiatorId
* The instance where this function is invoked from .
*
- * @static
*
- * @return array an array of child ids
+ * @return array
+ * an array of child ids
*/
static public function getEntitiesForParent($parentId, $entityTable, $includeParent = TRUE, $mode = 3, $initiatorId = NULL) {
$entities = array();
}
$queryParams = array(
- 1 => array($parentId, 'Integer'),
+ 1 => array($parentId, 'Integer'),
2 => array($entityTable, 'String'),
3 => array($initiatorId, 'Integer'),
);
$query .= " AND entity_id != " . ($initiatorId ? "%3" : "%1");
}
- if ($mode == '1') { // MODE = SINGLE
+ // MODE = SINGLE
+ if ($mode == '1') {
$query .= " AND entity_id = %3";
}
- elseif ($mode == '2') { // MODE = FUTURE
+ // MODE = FUTURE
+ elseif ($mode == '2') {
$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";
* @param int $mode
* 1. retrieve only one entity. 2. retrieve all future entities in the repeating set. 3. all entities in the repeating set. .
*
- * @static
*
- * @return array array of connected ids
+ * @return array
+ * array of connected ids
*/
static public function getEntitiesFor($entityId, $entityTable, $includeParent = TRUE, $mode = 3) {
$parentId = self::getParentFor($entityId, $entityTable);
}
/**
- * This function gets the parent for the entity id passed to it
+ * This function gets the parent for the entity id passed to it.
*
* @param int $entityId
* Entity ID .
* @param bool $includeParent
* Include parent in result set .
*
- * @static
*
- * @return int unsigned $parentId Parent ID
+ * @return int
+ * unsigned $parentId Parent ID
*/
static public function getParentFor($entityId, $entityTable, $includeParent = TRUE) {
if (empty($entityId) || empty($entityTable)) {
if (!$includeParent) {
$query .= " AND parent_id != %1";
}
- $parentId =
- CRM_Core_DAO::singleValueQuery($query,
+ $parentId
+ = CRM_Core_DAO::singleValueQuery($query,
array(
1 => array($entityId, 'Integer'),
2 => array($entityTable, 'String'),
}
/**
- * This function copies the information from parent entity and creates other entities with same information
+ * This function copies the information from parent entity and creates other entities with same information.
*
* @param string $entityTable
* Entity table name .
* @param bool $createRecurringEntity
* If to create a record in recurring_entity table .
*
- * @static
*
* @return object
*/
$newObject = CRM_Core_DAO::copyGeneric($daoName, $fromCriteria, $newParams);
if (is_a($newObject, 'CRM_Core_DAO') && $newObject->id && $createRecurringEntity) {
- $object = new $daoName( );
+ $object = new $daoName();
foreach ($fromCriteria as $key => $value) {
$object->$key = $value;
}
* @param object $event
* An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just updated .
*
- * @static
*
* @return void
*/
$processedEntities[$key] = 1;
if (array_key_exists($entityTable, self::$_tableDAOMapper)) {
- $daoName = self::$_tableDAOMapper[$entityTable];
+ $daoName = self::$_tableDAOMapper[$entityTable];
$skipData = array();
if (array_key_exists($entityTable, self::$_updateSkipFields)) {
* @param object $event
* An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just inserted .
*
- * @static
*
* @return void
*/
if (empty($hasaRecurringRecord)) {
// check if its a linked entity
if (array_key_exists($obj->__table, self::$_linkedEntitiesInfo) &&
- !CRM_Utils_Array::value('is_multirecord', self::$_linkedEntitiesInfo[$obj->__table])) {
+ !CRM_Utils_Array::value('is_multirecord', self::$_linkedEntitiesInfo[$obj->__table])
+ ) {
$linkedDAO = new self::$_tableDAOMapper[$obj->__table]();
$linkedDAO->id = $obj->id;
if ($linkedDAO->find(TRUE)) {
$idCol = self::$_linkedEntitiesInfo[$obj->__table]['entity_id_col'];
$tableCol = self::$_linkedEntitiesInfo[$obj->__table]['entity_table_col'];
- $pEntityID = $linkedDAO->$idCol;
+ $pEntityID = $linkedDAO->$idCol;
$pEntityTable = $linkedDAO->$tableCol;
// find all parent recurring entity set
else {
// linked entity doesn't exist. lets create them
$newCriteria = array(
- $idCol => $val['id'],
- $tableCol => $val['table']
+ $idCol => $val['id'],
+ $tableCol => $val['table'],
);
$linkedObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($obj->__table,
array('id' => $obj->id),
* @param object $event
* An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just deleted .
*
- * @static
*
* @return void
*/
* This function deletes main entity and related linked entities from recurring-entity table
*
* @param int $entityId
- * Entity id .
+ * Entity id
* @param string $entityTable
- * Name of the entity table .
+ * Name of the entity table
*
- * @static
*
- * @return boolean|object Returns either boolean value or CRM_Core_DAO_RecurringEntity object
+ * @return bool|CRM_Core_DAO_RecurringEntity
*/
static public function delEntity($entityId, $entityTable, $isDelLinkedEntities = FALSE) {
if (empty($entityId) || empty($entityTable)) {
}
/**
- * This function maps values posted from form to civicrm_action_schedule columns
+ * This function maps values posted from form to civicrm_action_schedule columns.
*
* @param array $formParams
* And array of form values posted .
*/
public function mapFormValuesToDB($formParams = array()) {
$dbParams = array();
- if (CRM_Utils_Array::value('used_for', $formParams)) {
+ if (!empty($formParams['used_for'])) {
$dbParams['used_for'] = $formParams['used_for'];
}
- if (CRM_Utils_Array::value('entity_id', $formParams)) {
+ if (!empty($formParams['entity_id'])) {
$dbParams['entity_value'] = $formParams['entity_id'];
}
- if (CRM_Utils_Array::value('repetition_start_date', $formParams)) {
- if (CRM_Utils_Array::value('repetition_start_date_display', $formParams)) {
+ if (!empty($formParams['repetition_start_date'])) {
+ if (!empty($formParams['repetition_start_date_display'])) {
$repetitionStartDate = $formParams['repetition_start_date_display'];
}
else {
$repetitionStartDate = $formParams['repetition_start_date'];
}
- if (CRM_Utils_Array::value('repetition_start_date_time', $formParams)) {
+ if (!empty($formParams['repetition_start_date_time'])) {
$repetitionStartDate = $repetitionStartDate . " " . $formParams['repetition_start_date_time'];
}
$repetition_start_date = new DateTime($repetitionStartDate);
$dbParams['start_action_date'] = CRM_Utils_Date::processDate($repetition_start_date->format('Y-m-d H:i:s'));
}
- if (CRM_Utils_Array::value('repetition_frequency_unit', $formParams)) {
+ if (!empty($formParams['repetition_frequency_unit'])) {
$dbParams['repetition_frequency_unit'] = $formParams['repetition_frequency_unit'];
}
- if (CRM_Utils_Array::value('repetition_frequency_interval', $formParams)) {
+ if (!empty($formParams['repetition_frequency_interval'])) {
$dbParams['repetition_frequency_interval'] = $formParams['repetition_frequency_interval'];
}
//For Repeats on:(weekly case)
if ($formParams['repetition_frequency_unit'] == 'week') {
- if (CRM_Utils_Array::value('start_action_condition', $formParams)) {
+ if (!empty($formParams['start_action_condition'])) {
$repeats_on = CRM_Utils_Array::value('start_action_condition', $formParams);
$dbParams['start_action_condition'] = implode(",", array_keys($repeats_on));
}
//For Repeats By:(monthly case)
if ($formParams['repetition_frequency_unit'] == 'month') {
if ($formParams['repeats_by'] == 1) {
- if (CRM_Utils_Array::value('limit_to', $formParams)) {
+ if (!empty($formParams['limit_to'])) {
$dbParams['limit_to'] = $formParams['limit_to'];
}
}
if ($formParams['repeats_by'] == 2) {
if (CRM_Utils_Array::value('entity_status_1', $formParams) && CRM_Utils_Array::value('entity_status_2', $formParams)) {
- $dbParams['entity_status'] = $formParams['entity_status_1']." ".$formParams['entity_status_2'];
+ $dbParams['entity_status'] = $formParams['entity_status_1'] . " " . $formParams['entity_status_2'];
}
}
}
//For "Ends" - After:
if ($formParams['ends'] == 1) {
- if (CRM_Utils_Array::value('start_action_offset', $formParams)) {
+ if (!empty($formParams['start_action_offset'])) {
$dbParams['start_action_offset'] = $formParams['start_action_offset'];
}
}
//For "Ends" - On:
if ($formParams['ends'] == 2) {
- if (CRM_Utils_Array::value('repeat_absolute_date', $formParams)) {
+ if (!empty($formParams['repeat_absolute_date'])) {
$dbParams['absolute_date'] = CRM_Utils_Date::processDate($formParams['repeat_absolute_date']);
}
}
* @param int $scheduleReminderId
* Primary key of civicrm_action_schedule table .
*
- * @static
*
* @return object
*/
}
$dao = CRM_Core_DAO::executeQuery($query,
array(
- 1 => array($scheduleReminderId, 'Integer')
+ 1 => array($scheduleReminderId, 'Integer'),
)
);
$dao->fetch();
}
/**
- * This function is a wrapper of getScheduleReminderDetailsById function
+ * wrapper of getScheduleReminderDetailsById function.
*
* @param int $scheduleReminderId
* Primary key of civicrm_action_schedule table .
* @param array $scheduleReminderDetails
* Array of repeat criterias saved in civicrm_action_schedule table .
*
- * @return object When object
+ * @return object
+ * When object
*/
public function getRecursionFromSchedule($scheduleReminderDetails = array()) {
$r = new When();
if ($repetition_frequency_unit == "day") {
$repetition_frequency_unit = "dai";
}
- $repetition_frequency_unit = $repetition_frequency_unit.'ly';
+ $repetition_frequency_unit = $repetition_frequency_unit . 'ly';
$r->recur($start, $repetition_frequency_unit);
}
if ($scheduleReminderDetails['entity_status']) {
$startActionDate = explode(" ", $scheduleReminderDetails['entity_status']);
switch ($startActionDate[0]) {
- case 'first':
- $startActionDate1 = 1;
- break;
- case 'second':
- $startActionDate1 = 2;
- break;
- case 'third':
- $startActionDate1 = 3;
- break;
- case 'fourth':
- $startActionDate1 = 4;
- break;
- case 'last':
- $startActionDate1 = -1;
- break;
+ case 'first':
+ $startActionDate1 = 1;
+ break;
+
+ case 'second':
+ $startActionDate1 = 2;
+ break;
+
+ case 'third':
+ $startActionDate1 = 3;
+ break;
+
+ case 'fourth':
+ $startActionDate1 = 4;
+ break;
+
+ case 'last':
+ $startActionDate1 = -1;
+ break;
}
- $concatStartActionDateBits = $startActionDate1.strtoupper(substr($startActionDate[1], 0, 2));
+ $concatStartActionDateBits = $startActionDate1 . strtoupper(substr($startActionDate[1], 0, 2));
$r->byday(array($concatStartActionDateBits));
}
elseif ($scheduleReminderDetails['limit_to']) {
$r->count($scheduleReminderDetails['start_action_offset']);
}
- if (CRM_Utils_Array::value('absolute_date', $scheduleReminderDetails)) {
+ if (!empty($scheduleReminderDetails['absolute_date'])) {
$absoluteDate = CRM_Utils_Date::setDateDefaults($scheduleReminderDetails['absolute_date']);
- $endDate = new DateTime($absoluteDate[0].' '.$absoluteDate[1]);
+ $endDate = new DateTime($absoluteDate[0] . ' ' . $absoluteDate[1]);
$endDate->modify('+1 day');
$r->until($endDate);
}
/**
- * This function gets time difference between the two datetime object
+ * This function gets time difference between the two datetime object.
*
* @param DateTime $startDate
* Start Date .
* @param DateTime $endDate
* End Date .
*
- * @static
*
- * @return object DateTime object which contain time difference
+ * @return object
+ * DateTime object which contain time difference
*/
static public function getInterval($startDate, $endDate) {
if ($startDate && $endDate) {
$startDate = new DateTime($startDate);
- $endDate = new DateTime($endDate);
+ $endDate = new DateTime($endDate);
return $startDate->diff($endDate);
}
}
/**
- * This function gets all columns from civicrm_action_schedule on the basis of event id
+ * 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 .
*
- * @static
*
* @return object
*/
}
$params = array(
1 => array($entityId, 'Integer'),
- 2 => array($used_for, 'String')
+ 2 => array($used_for, 'String'),
);
$dao = CRM_Core_DAO::executeQuery($query, $params);
$dao->fetch();
}
/**
- * Update mode column in civicrm_recurring_entity table for event related tabs
+ * Update mode column in civicrm_recurring_entity table for event related tabs.
*
* @param int $entityId
* Event id .
*/
public static function updateModeLinkedEntity($entityId, $linkedEntityTable, $mainEntityTable) {
$result = array();
- if ( $entityId && $linkedEntityTable && $mainEntityTable ) {
+ if ($entityId && $linkedEntityTable && $mainEntityTable) {
if (CRM_Utils_Array::value($linkedEntityTable, self::$_tableDAOMapper)) {
$dao = self::$_tableDAOMapper[$linkedEntityTable];
}
else {
CRM_Core_Session::setStatus('Could not update mode for linked entities');
- return;
+ return NULL;
}
$entityTable = $linkedEntityTable;
$params = array(
- 'entity_id' => $entityId,
- 'entity_table' => $mainEntityTable
- );
+ 'entity_id' => $entityId,
+ 'entity_table' => $mainEntityTable,
+ );
$defaults = array();
CRM_Core_DAO::commonRetrieve($dao, $params, $defaults);
- if (CRM_Utils_Array::value('id', $defaults)) {
+ if (!empty($defaults['id'])) {
$result['entityId'] = $defaults['id'];
$result['entityTable'] = $entityTable;
}
}
return $result;
}
+
}