<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | 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$
*
*/
public $_activityId;
/**
- * store activity ids when multiple activities are created
+ * Store activity ids when multiple activities are created.
*
* @var int
*/
public $_activityIds = array();
/**
- * The id of activity type
+ * The id of activity type.
*
* @var int
*/
public $_activityTypeId;
/**
- * The name of activity type
+ * The name of activity type.
*
* @var string
*/
public $_activityTypeName;
/**
- * The id of currently viewed contact
+ * The id of currently viewed contact.
*
* @var int
*/
public $_currentlyViewedContactId;
/**
- * The id of source contact and target contact
+ * The id of source contact and target contact.
*
* @var int
*/
public $_currentUserId;
/**
- * The array of form field attributes
+ * The array of form field attributes.
*
* @var array
*/
*/
protected $_crmDir = 'Activity';
- /*
- * Survey activity
- *
- * @var boolean
- */
-
+ /**
+ * Survey activity.
+ *
+ * @var boolean
+ */
protected $_isSurveyActivity;
protected $_values = array();
protected $unsavedWarn = TRUE;
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Activity';
+ }
+
/**
* The _fields var can be used by sub class to set/unset/edit the
* form fields based on their requirement
- *
*/
- function setFields() {
+ public function setFields() {
$this->_fields = array(
'subject' => array(
'type' => 'text',
'location' => array(
'type' => 'text',
'label' => ts('Location'),
- 'attributes' =>
- CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity',
- 'location'
- ),
- 'required' => FALSE
+ 'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'location'),
+ 'required' => FALSE,
),
'details' => array(
'type' => 'wysiwyg',
'label' => ts('Details'),
// forces a smaller edit window
'attributes' => array('rows' => 4, 'cols' => 60),
- 'required' => FALSE
+ 'required' => FALSE,
),
'status_id' => array(
'type' => 'select',
'source_contact_id' => array(
'type' => 'entityRef',
'label' => ts('Added By'),
- 'required' => FALSE
+ 'required' => FALSE,
),
'target_contact_id' => array(
'type' => 'entityRef',
'label' => ts('With Contact'),
- 'attributes' => array('multiple' => TRUE, 'create' => TRUE)
+ 'attributes' => array('multiple' => TRUE, 'create' => TRUE),
),
'assignee_contact_id' => array(
'type' => 'entityRef',
- 'label' => ts('Assigned To'),
- 'attributes' => array('multiple' => TRUE, 'create' => TRUE, 'api' => array('params' => array('is_deceased' => 0))),
+ 'label' => ts('Assigned to'),
+ 'attributes' => array(
+ 'multiple' => TRUE,
+ 'create' => TRUE,
+ 'api' => array('params' => array('is_deceased' => 0)),
+ ),
),
'followup_assignee_contact_id' => array(
'type' => 'entityRef',
- 'label' => ts('Assigned To'),
- 'attributes' => array('multiple' => TRUE, 'create' => TRUE, 'api' => array('params' => array('is_deceased' => 0))),
+ 'label' => ts('Assigned to'),
+ 'attributes' => array(
+ 'multiple' => TRUE,
+ 'create' => TRUE,
+ 'api' => array('params' => array('is_deceased' => 0)),
+ ),
),
'followup_activity_type_id' => array(
'type' => 'select',
'label' => ts('Subject'),
'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity',
'subject'
- )
- )
+ ),
+ ),
);
if (($this->_context == 'standalone') &&
}
/**
- * Function to build the form
+ * Build the form object.
*
* @return void
- * @access public
*/
- function preProcess() {
+ public function preProcess() {
$this->_cdType = CRM_Utils_Array::value('type', $_GET);
$this->assign('cdType', FALSE);
if ($this->_cdType) {
$this->assign('cdType', TRUE);
return CRM_Custom_Form_CustomData::preProcess($this);
}
-
+ CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
$this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET);
$this->assign('atypefile', FALSE);
if ($this->_atypefile) {
if ($this->_action & CRM_Core_Action::DELETE) {
if (!CRM_Core_Permission::check('delete activities')) {
- CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
+ CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
}
if ($this->_activityId &&
in_array($this->_action, array(
CRM_Core_Action::UPDATE,
- CRM_Core_Action::VIEW
+ CRM_Core_Action::VIEW,
)) &&
!CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)
) {
// Set title
if (isset($activityTName)) {
$activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName);
- $this->assign('pageTitle', ts('%1 Activity', array( 1 => $activityName)));
+ $this->assign('pageTitle', ts('%1 Activity', array(1 => $activityName)));
if ($this->_currentlyViewedContactId) {
$displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId);
CRM_Utils_System::setTitle($displayName . ' - ' . $activityName);
}
else {
- CRM_Utils_System::setTitle(ts('%1 Activity', array( 1 => $activityName)));
+ CRM_Utils_System::setTitle(ts('%1 Activity', array(1 => $activityName)));
}
}
'standalone',
'home',
'dashlet',
- 'dashletFullscreen'
+ 'dashletFullscreen',
))
) {
$urlParams = 'reset=1';
$urlParams .= "&qfKey=$qfKey";
}
$path = CRM_Utils_System::currentPath();
- if ($this->_compContext == 'advanced' ) {
+ if ($this->_compContext == 'advanced') {
$urlString = 'civicrm/contact/search/advanced';
}
- elseif ($path == 'civicrm/contact/search'
+ elseif ($path == 'civicrm/group/search'
+ || $path == 'civicrm/contact/search'
|| $path == 'civicrm/contact/search/advanced'
|| $path == 'civicrm/contact/search/custom'
- || $path == 'civicrm/group/search') {
+ || $path == 'civicrm/group/search'
+ ) {
$urlString = $path;
}
else {
// figure out the file name for activity type, if any
if ($this->_activityTypeId &&
- $this->_activityTypeFile =
- CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir)
+ $this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir)
) {
$this->assign('activityTypeFile', $this->_activityTypeFile);
$this->assign('crmDir', $this->_crmDir);
}
$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
+ * Set default values for the form. For edit/view mode
* the default values are retrieved from the database
*
- * @access public
*
* @return void
*/
- function setDefaultValues() {
+ public function setDefaultValues() {
if ($this->_cdType) {
return CRM_Custom_Form_CustomData::setDefaultValues($this);
}
- $defaults = $this->_values;
+ $defaults = $this->_values + CRM_Core_Form_RecurringEntity::setDefaultValues();
// if we're editing...
if (isset($this->_activityId)) {
if (empty($defaults['activity_date_time'])) {
list($defaults['activity_date_time'],
$defaults['activity_date_time_time']
) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime');
+ list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime');
}
if ($this->_context != 'standalone') {
$defaults['source_contact_id'] = $this->_sourceContactId;
$defaults['target_contact_id'] = $this->_targetContactId;
- list($defaults['activity_date_time'], $defaults['activity_date_time_time']) =
- CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
+ list($defaults['activity_date_time'], $defaults['activity_date_time_time'])
+ = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
}
if ($this->_activityTypeId) {
'type' => 'next',
'name' => $button,
'spacing' => ' ',
- 'isDefault' => TRUE
+ 'isDefault' => TRUE,
),
array(
'type' => 'cancel',
- 'name' => ts('Cancel')
- )
+ 'name' => ts('Cancel'),
+ ),
));
return;
}
//enable form element (ActivityLinks sets this true)
$this->assign('suppressForm', FALSE);
- $element = & $this->add('select', 'activity_type_id', ts('Activity Type'),
- $this->_fields['followup_activity_type_id']['attributes'],
+ $element = &$this->add('select', 'activity_type_id', ts('Activity Type'),
+ array('' => '- ' . ts('select') . ' -') + $this->_fields['followup_activity_type_id']['attributes'],
FALSE, array(
'onchange' => "CRM.buildCustomData( 'Activity', this.value );",
- 'class' => 'crm-select2',
+ 'class' => 'crm-select2 required',
)
);
$element->freeze();
}
+ //Call to RecurringEntity buildQuickForm for add/update mode
+ if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
+ CRM_Core_Form_RecurringEntity::buildQuickForm($this);
+ }
+
foreach ($this->_fields as $field => $values) {
if (!empty($this->_fields[$field])) {
$attribute = CRM_Utils_Array::value('attributes', $values);
CRM_Campaign_BAO_Campaign::accessCampaign()
) {
$buildEngagementLevel = TRUE;
- $this->addSelect('engagement_level',array('entity' => 'activity'));
+ $this->addSelect('engagement_level', array('entity' => 'activity'));
$this->addRule('engagement_level',
ts('Please enter the engagement index as a number (integers only).'),
'positiveInteger'
$this->assign('customDataSubType', $this->_activityTypeId);
$this->assign('entityID', $this->_activityId);
- $tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
+ CRM_Core_BAO_Tag::getTags('civicrm_activity', $tags, NULL,
+ ' ', TRUE);
if (!empty($tags)) {
$this->add('select', 'tag', ts('Tags'), $tags, FALSE,
$buttons = array();
$buttons[] = array(
'type' => 'cancel',
- 'name' => ts('Done')
+ 'name' => ts('Done'),
);
$this->addButtons($buttons);
}
'type' => 'upload',
'name' => ts('Save'),
'js' => $js,
- 'isDefault' => TRUE
+ 'isDefault' => TRUE,
),
array(
'type' => 'cancel',
- 'name' => ts('Cancel')
- )
+ 'name' => ts('Cancel'),
+ ),
)
);
}
}
/**
- * global form rule
+ * Global form rule.
*
- * @param array $fields the input form values
- * @param array $files the uploaded files if any
+ * @param array $fields
+ * The input form values.
+ * @param array $files
+ * The uploaded files if any.
* @param $self
*
- * @internal param array $options additional user data
- *
- * @return true if no errors, else array of errors
- * @access public
- * @static
+ * @return bool|array
+ * true if no errors, else array of errors
*/
- static function formRule($fields, $files, $self) {
+ public static function formRule($fields, $files, $self) {
// skip form rule if deleting
if (CRM_Utils_Array::value('_qf_Activity_next_', $fields) == 'Delete') {
return TRUE;
}
$errors = array();
- if (!$self->_single && !$fields['activity_type_id']) {
+ if ((array_key_exists('activity_type_id', $fields) || !$self->_single) && empty($fields['activity_type_id'])) {
$errors['activity_type_id'] = ts('Activity Type is a required field');
}
- //Activity type is mandatory if creating new activity, CRM-4515
- if (array_key_exists('activity_type_id', $fields) && empty($fields['activity_type_id'])) {
- $errors['activity_type_id'] = ts('Activity Type is required field.');
- }
-
if (CRM_Utils_Array::value('activity_type_id', $fields) == 3 &&
CRM_Utils_Array::value('status_id', $fields) == 1
) {
}
/**
- * Function to process the form
+ * Process the form submission.
*
- * @access public
*
- * @param null $params
- * @return void
+ * @param array $params
+ * @return array|null
*/
public function postProcess($params = NULL) {
if ($this->_action & CRM_Core_Action::DELETE) {
// delete tags for the entity
$tagParams = array(
'entity_table' => 'civicrm_activity',
- 'entity_id' => $this->_activityId
+ 'entity_id' => $this->_activityId,
);
CRM_Core_BAO_EntityTag::del($tagParams);
CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully."), ts('Record Deleted'), 'success');
- return;
+ return NULL;
}
// store the submitted values in an array
$activity = $this->processActivity($params);
}
+ $activityIds = empty($this->_activityIds) ? array($this->_activityId) : $this->_activityIds;
+ foreach ($activityIds as $activityId) {
+ // set params for repeat configuration in create mode
+ $params['entity_id'] = $activityId;
+ $params['entity_table'] = 'civicrm_activity';
+ if (!empty($params['entity_id']) && !empty($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']);
+ }
+ else {
+ $params['parent_entity_id'] = $params['entity_id'];
+ $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($params['entity_id'], $params['entity_table']);
+ }
+ if (property_exists($scheduleReminderDetails, 'id')) {
+ $params['schedule_reminder_id'] = $scheduleReminderDetails->id;
+ }
+ }
+ $params['dateColumns'] = array('activity_date_time');
+
+ // Set default repetition start if it was not provided.
+ if (empty($params['repetition_start_date'])) {
+ $params['repetition_start_date'] = $params['activity_date_time'];
+ }
+
+ // unset activity id
+ unset($params['id']);
+ $linkedEntities = array(
+ array(
+ 'table' => 'civicrm_activity_contact',
+ 'findCriteria' => array(
+ 'activity_id' => $activityId,
+ ),
+ 'linkedColumns' => array('activity_id'),
+ 'isRecurringEntityRecord' => FALSE,
+ ),
+ );
+ CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_activity', $linkedEntities);
+ }
+
return array('activity' => $activity);
}
/**
- * Process activity creation
+ * Process activity creation.
*
- * @param array $params associated array of submitted values
+ * @param array $params
+ * Associated array of submitted values.
*
- * @return $this|null|object
- * @access protected
+ * @return self|null|object
*/
protected function processActivity(&$params) {
$activityAssigned = array();
$mailStatus = '';
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
- 'activity_assignee_notification')) {
+ 'activity_assignee_notification')
+ ) {
$activityIDs = array($activity->id);
if ($followupActivity) {
$activityIDs = array_merge($activityIDs, array($followupActivity->id));
array(
1 => $subject,
2 => $followupStatus,
- 3 => $mailStatus
+ 3 => $mailStatus,
)
), ts('Saved'), 'success');
/**
* Shorthand for getting id by display name (makes code more readable)
- *
- * @access protected
+ * @param $displayName
+ * @return null|string
*/
protected function _getIdByDisplayName($displayName) {
return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
/**
* Shorthand for getting display name by id (makes code more readable)
- *
- * @access protected
+ * @param $id
+ * @return null|string
*/
protected function _getDisplayNameById($id) {
return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
}
/**
- * Function to let injecting activity type file do any processing
+ * Let injecting activity type file do any processing.
* needed, before the activity is added/updated
*
+ * @param array $params
*/
- function beginPostProcess(&$params) {
+ public function beginPostProcess(&$params) {
if ($this->_activityTypeFile) {
$className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
$className::beginPostProcess($this, $params);
}
/**
- * Function to let injecting activity type file do any processing
+ * Let injecting activity type file do any processing
* needed, after the activity has been added/updated
*
+ * @param array $params
+ * @param $activity
*/
- function endPostProcess(&$params, &$activity) {
+ public function endPostProcess(&$params, &$activity) {
if ($this->_activityTypeFile) {
$className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
- $className::endPostProcess($this, $params, $activity );
+ $className::endPostProcess($this, $params, $activity);
}
}
-}
+}