Commit ff3e71e4 authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

Merge pull request #2256 from civicrm/master

merge master changes to doctrine branch
parents 2edefc5e 86d6172a
......@@ -20,7 +20,7 @@ CRM/Contact/DAO/RelationshipType.php
CRM/Contact/DAO/SavedSearch.php
CRM/Contact/DAO/SubscriptionHistory.php
CRM/Contribute/DAO
CRM/Core/BAO/AllCoreTables.php
CRM/Core/DAO/AllCoreTables.php
CRM/Core/DAO/.listAll.php
CRM/Core/DAO/listAll.php
CRM/Core/DAO/ActionLog.php
......
......@@ -192,6 +192,10 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
// CRM-8708
$activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id);
// CRM-13994 delete activity entity_tag
$query = "DELETE FROM civicrm_entity_tag WHERE entity_table = 'civicrm_activity' AND entity_id = {$activity->id}";
$dao = CRM_Core_DAO::executeQuery($query);
}
}
else {
......@@ -201,9 +205,9 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
$activity->is_deleted = 1;
$result = $activity->save();
//log activty delete.CRM-4525.
$logMsg = 'Case Activity deleted for';
$msgs = array();
// CRM-4525 log activity delete
$logMsg = 'Case Activity deleted for';
$msgs = array();
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
......
......@@ -578,6 +578,13 @@ t_act.id as case_recent_activity_id,
t_act.act_type_name as case_recent_activity_type_name,
t_act.act_type AS case_recent_activity_type ";
}
elseif ( $type == 'any' ) {
$query .= "
t_act.desired_date as case_activity_date,
t_act.id as case_activity_id,
t_act.act_type_name as case_activity_type_name,
t_act.act_type AS case_activity_type ";
}
$query .= " FROM civicrm_case
INNER JOIN civicrm_case_contact ON civicrm_case.id = civicrm_case_contact.case_id
......@@ -624,6 +631,21 @@ LEFT JOIN civicrm_option_group aog ON aog.name='activity_type'
LEFT JOIN civicrm_option_value aov ON ( aov.option_group_id = aog.id AND aov.value = act.activity_type_id )
) AS t_act ";
}
elseif ( $type == 'any' ) {
$query .= " LEFT JOIN
(
SELECT ca4.case_id, act4.id AS id, act4.activity_date_time AS desired_date, act4.activity_type_id, act4.status_id, aov.name AS act_type_name, aov.label AS act_type
FROM civicrm_activity act4
LEFT JOIN civicrm_case_activity ca4
ON ca4.activity_id = act4.id
AND act4.is_current_revision = 1
LEFT JOIN civicrm_option_group aog
ON aog.name='activity_type'
LEFT JOIN civicrm_option_value aov
ON aov.option_group_id = aog.id
AND aov.value = act4.activity_type_id
) AS t_act";
}
$query .= "
ON t_act.case_id = civicrm_case.id
......@@ -662,6 +684,9 @@ LEFT JOIN civicrm_option_group aog ON aog.name='activity_type'
elseif ($type == 'recent') {
$query .= " ORDER BY case_recent_activity_date ASC ";
}
elseif ( $type == 'any' ) {
$query .= " ORDER BY case_activity_date ASC ";
}
return $query;
}
......@@ -706,8 +731,7 @@ LEFT JOIN civicrm_option_group aog ON aog.name='activity_type'
if (!$allCases) {
$condition .= " AND case_relationship.contact_id_b = {$userID} ";
}
if ($type == 'upcoming') {
if ( $type == 'upcoming' || $type == 'any' ) {
$closedId = CRM_Core_OptionGroup::getValue('case_status', 'Closed', 'name');
$condition .= "
AND civicrm_case.status_id != $closedId";
......@@ -751,6 +775,12 @@ AND civicrm_case.status_id != $closedId";
$resultFields[] = 'case_recent_activity_type';
$resultFields[] = 'case_recent_activity_id';
}
elseif ( $type == 'any' ) {
$resultFields[] = 'case_activity_date';
$resultFields[] = 'case_activity_type_name';
$resultFields[] = 'case_activity_type';
$resultFields[] = 'case_activity_id';
}
// we're going to use the usual actions, so doesn't make sense to duplicate definitions
$actions = CRM_Case_Selector_Search::links();
......@@ -2042,7 +2072,7 @@ SELECT civicrm_contact.id as casemanager_id,
static $accessibleCaseIds;
if (!is_array($accessibleCaseIds)) {
$session = CRM_Core_Session::singleton();
$accessibleCaseIds = array_keys(self::getCases(FALSE, $session->get('userID')));
$accessibleCaseIds = array_keys(self::getCases(FALSE, $session->get('userID'), 'any'));
}
//no need of further processing.
if (empty($accessibleCaseIds)) {
......
......@@ -115,7 +115,7 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
!CRM_Core_Permission::check('access all cases and activities')
) {
$session = CRM_Core_Session::singleton();
$allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'));
$allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'), 'any');
if (!array_key_exists($this->_caseId, $allCases)) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
......
......@@ -97,7 +97,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
if (!$this->_hasAccessToAllCases) {
$this->_userCases = CRM_Case_BAO_Case::getCases(FALSE, $userID);
$this->_userCases = CRM_Case_BAO_Case::getCases(FALSE, $userID, 'any');
if (!array_key_exists($this->_caseID, $this->_userCases)) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
......
......@@ -72,7 +72,7 @@ class CRM_Case_Page_Tab extends CRM_Core_Page {
//user might have special permissions to view this case, CRM-5666
if (!CRM_Core_Permission::check('access all cases and activities')) {
$session = CRM_Core_Session::singleton();
$userCases = CRM_Case_BAO_Case::getCases(FALSE, $session->get('userID'));
$userCases = CRM_Case_BAO_Case::getCases(FALSE, $session->get('userID'), 'any');
if (!array_key_exists($this->_id, $userCases)) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
......
......@@ -174,7 +174,9 @@ class CRM_Contact_Form_Edit_CommunicationPreferences {
static function setDefaultValues(&$form, &$defaults) {
if (!empty($defaults['preferred_language'])) {
$defaults['preferred_language'] = CRM_Core_PseudoConstant::getKey('CRM_Contact_DAO_Contact', 'preferred_language', $defaults['preferred_language']);
$defaults['preferred_language'] = CRM_Utils_Array::key($defaults['preferred_language'],
CRM_Contact_BAO_Contact::buildOptions('preferred_language')
);
}
// CRM-7119: set preferred_language to default if unset
......
......@@ -357,6 +357,7 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard {
// check url is same as exiting entries, if yes just update existing
$dashlet->url = CRM_Utils_Array::value('url', $params);
$dashlet->find(TRUE);
$dashlet->name = self::getDashletName(CRM_Utils_Array::value('instanceURL', $params));
}
else {
$dashlet->id = $dashboardID;
......@@ -377,6 +378,16 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard {
return $dashlet;
}
static function getDashletName($url) {
$urlElements = explode('/', $url);
if ($urlElements[1] == 'dashlet') {
return $urlElements[2];
}
elseif ($urlElements[1] == 'report') {
return 'report/' . $urlElements[3];
}
return $url;
}
/**
* Update contact dashboard with new dashlet
*
......
......@@ -91,7 +91,7 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website {
) {
foreach ($ids as $id => $value) {
if (($value['website_type_id'] == $values['website_type_id'])
&& CRM_Utils_Array::value('url', $value)) {
&& CRM_Utils_Array::value('url', $values)) {
$values['id'] = $id;
unset($ids[$id]);
break;
......
......@@ -496,7 +496,7 @@ class CRM_Core_Session {
if (!isset(self::$_singleton->_session[self::$_singleton->_key]['status'])) {
self::$_singleton->_session[self::$_singleton->_key]['status'] = array();
}
if ($text) {
if ($text || $title) {
if ($options['unique']) {
foreach (self::$_singleton->_session[self::$_singleton->_key]['status'] as $msg) {
if ($msg['text'] == $text && $msg['title'] == $title) {
......
......@@ -61,7 +61,7 @@ function smarty_function_crmAPI($params, &$smarty) {
return;
}
if (array_key_exists('is_error', $result) && $result['is_error']) {
if (!empty($result['is_error'])) {
$smarty->trigger_error("{crmAPI} ".$result["error_message"]);
}
......
......@@ -350,7 +350,7 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form {
CRM_Event_BAO_Event::updateParticipantCampaignID($eventID, $newCampaignID);
}
}
$this->postProcessHook();
if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") {
if ($this->_isTemplate) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate',
......
......@@ -236,21 +236,22 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus {
$statusDate = CRM_Utils_Date::customFormat($statusDate, '%Y%m%d');
}
$startDate = CRM_Utils_Date::customFormat($startDate, '%Y%m%d');
$endDate = CRM_Utils_Date::customFormat($endDate, '%Y%m%d');
$joinDate = CRM_Utils_Date::customFormat($joinDate, '%Y%m%d');
$dates = array('start', 'end', 'join');
$events = array('start', 'end');
foreach ($dates as $dat) {
if (${$dat . 'Date'}) {
if (${$dat . 'Date'} && ${$dat . 'Date'} != "null") {
${$dat . 'Date'} = CRM_Utils_Date::customFormat(${$dat . 'Date'}, '%Y%m%d');
${$dat . 'Year'} = substr(${$dat . 'Date'}, 0, 4);
${$dat . 'Month'} = substr(${$dat . 'Date'}, 4, 2);
${$dat . 'Day'} = substr(${$dat . 'Date'}, 6, 2);
}
else {
${$dat . 'Date'} = '';
}
}
//fix for CRM-3570, if we have statuses with is_admin=1,
......
......@@ -552,6 +552,10 @@ GROUP BY cv.label
}
}
function groupBy(){
$this->_groupBy = "GROUP BY {$this->_aliases['civicrm_participant']}.id";
}
function postProcess() {
// get ready with post process params
......
......@@ -241,7 +241,7 @@ class CRM_Report_Form_Instance {
}
static function postProcess(&$form, $redirect = TRUE) {
$params = $form->getVar('_params');
$params = $form->getVar('_params');
$instanceID = $form->getVar('_id');
if ($isNew = $form->getVar('_createNew')) {
......@@ -254,6 +254,14 @@ class CRM_Report_Form_Instance {
if (CRM_Utils_Array::value('is_navigation', $params)) {
$params['navigation'] = $form->_navigation;
}
else {
//delete navigation if exists
$navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceID, 'navigation_id', 'id');
if ($navId) {
CRM_Core_BAO_Navigation::processDelete($navId);
CRM_Core_BAO_Navigation::resetNavigation();
}
}
// make a copy of params
$formValues = $params;
......
......@@ -214,6 +214,50 @@ VALUES {$insertStatus}";
$this->addTask('Patch word-replacement schema', 'wordReplacements_patch', $rev);
}
function upgrade_4_4_4($rev) {
// task to process sql
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.4')), 'task_4_4_x_runSql', $rev);
// Consolidate activity contacts CRM-12274.
$this->addTask('Dashboard schema', 'dashboard');
return TRUE;
}
static function dashboard(CRM_Queue_TaskContext $ctx) {
$upgrade = new CRM_Upgrade_Form();
$query = "
ALTER TABLE civicrm_dashboard
ADD name varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Internal name of dashlet.' AFTER domain_id ";
CRM_Core_DAO::executeQuery($query);
$dashboard = new CRM_Core_DAO_Dashboard();
$dashboard->find();
while ($dashboard->fetch()) {
$urlElements = explode('/', $dashboard->url);
if ($urlElements[1] == 'dashlet') {
$url = explode('&', $urlElements[2]);
$name = $url[0];
}
elseif ($urlElements[1] == 'report') {
$url = explode('&', $urlElements[3]);
$name = 'report/' .$url[0];
}
$values .= "
WHEN {$dashboard->id} THEN '{$name}'
";
}
$query = "
UPDATE civicrm_dashboard
SET name = CASE id
{$values}
END;
";
CRM_Core_DAO::executeQuery($query);
}
/**
* Update activity contacts CRM-12274
*
......
......@@ -519,7 +519,7 @@ class CRM_Utils_Array {
} else {
$keyvalue = $record->{$key};
}
if (!is_array($node[$keyvalue])) {
if (isset($node[$keyvalue]) && !is_array($node[$keyvalue])) {
$node[$keyvalue] = array();
}
$node = &$node[$keyvalue];
......
......@@ -77,7 +77,7 @@ function civicrm_api3_uf_field_create($params) {
$fieldId = CRM_Utils_Array::value('id', $params);
if (!empty($fieldId)) {
$UFField = new CRM_core_BAO_UFField();
$UFField = new CRM_Core_BAO_UFField();
$UFField->id = $fieldId;
if ($UFField->find(TRUE)) {
$ids['uf_group'] = $UFField->uf_group_id;
......
......@@ -28,7 +28,7 @@ function setting_getfields_expectedresult(){
$expectedResult = array(
'is_error' => 0,
'version' => 3,
'count' => 78,
'count' => 81,
'values' => array(
'address_standardization_provider' => array(
'group_name' => 'Address Preferences',
......@@ -513,7 +513,7 @@ function setting_getfields_expectedresult(){
'title' => 'New Version Alerts',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Displays an on-screen alert to users with "Administer CiviCRM" permissions when a new version of CiviCRM is available. This setting will only work if the "Version Check & Statistics Reporting" setting is enabled.',
'description' => 'Displays an on-screen alert to users with \"Administer CiviCRM\" permissions when a new version of CiviCRM is available. This setting will only work if the \"Version Check & Statistics Reporting\" setting is enabled.',
'help_text' => '',
),
'versionCheck' => array(
......@@ -673,7 +673,7 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Service providing CiviCRM community messages',
'help_text' => 'Use "*default*" for the system default or override with a custom URL',
'help_text' => 'Use \"*default*\" for the system default or override with a custom URL',
),
'resCacheCode' => array(
'group_name' => 'CiviCRM Preferences',
......@@ -739,7 +739,7 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl
'title' => 'Allow second-degree relationship permissions',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'If enabled, contacts with the permission to edit a related contact will inherit that contact's permission to edit other related contacts',
'description' => 'If enabled, contacts with the permission to edit a related contact will inherit that contact\'s permission to edit other related contacts',
'help_text' => '',
),
'enable_components' => array(
......@@ -769,6 +769,20 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl
'description' => '',
'help_text' => '',
),
'disable_core_css' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'disable_core_css',
'type' => 'Boolean',
'quick_form_type' => 'YesNo',
'default' => 0,
'add' => '4.4',
'title' => 'Disable CiviCRM css',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Prevent the stylesheet \"civicrm.css\" from being loaded.',
'help_text' => '',
),
'debug_enabled' => array(
'group_name' => 'Developer Preferences',
'group' => 'developer',
......@@ -782,7 +796,7 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl
'title' => 'Enable Debugging',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Set this value to Yes if you want to use one of CiviCRM's debugging tools. This feature should NOT be enabled for production sites',
'description' => 'Set this value to Yes if you want to use one of CiviCRM\'s debugging tools. This feature should NOT be enabled for production sites',
'prefetch' => 1,
'help_text' => 'Do not turn this on on production sites',
),
......@@ -800,8 +814,8 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl
'is_contact' => 0,
'description' => 'Set this value to Yes if you want CiviCRM error/debugging messages to also appear in Drupal error logs',
'prefetch' => 1,
'help_text' => 'Set this value to Yes if you want CiviCRM error/debugging messages the appear in your CMS' error log.
In the case of Drupal, this will cause all CiviCRM error messages to appear in the watchdog (assuming you have Drupal's watchdog enabled)',
'help_text' => 'Set this value to Yes if you want CiviCRM error/debugging messages the appear in your CMS\' error log.
In the case of Drupal, this will cause all CiviCRM error messages to appear in the watchdog (assuming you have Drupal\'s watchdog enabled)',
),
'backtrace' => array(
'group_name' => 'Developer Preferences',
......@@ -1046,6 +1060,26 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'description' => 'Default currency assigned to contributions and other monetary transactions.',
'help_text' => '',
),
'defaultContactCountry' => array(
'group_name' => 'Localization Preferences',
'group' => 'localization',
'name' => 'defaultContactCountry',
'prefetch' => 1,
'config_only' => 1,
'type' => 'String',
'quick_form_type' => 'Element',
'html_type' => 'text',
'html_attributes' => array(
'size' => 4,
),
'default' => '1228',
'add' => '4.4',
'title' => 'Default Country',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'This value is selected by default when adding a new contact address.',
'help_text' => '',
),
'countryLimit' => array(
'group_name' => 'Localization Preferences',
'group' => 'localization',
......@@ -1177,7 +1211,7 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'title' => 'Enable Double Opt-in for Profile Group(s) field',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'When CiviMail is enabled, users who "subscribe" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.',
'description' => 'When CiviMail is enabled, users who \"subscribe\" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.',
'help_text' => '',
),
'track_civimail_replies' => array(
......@@ -1191,7 +1225,7 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'title' => 'Enable Double Opt-in for Profile Group(s) field',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'When CiviMail is enabled, users who "subscribe" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.',
'description' => 'When CiviMail is enabled, users who \"subscribe\" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.',
'help_text' => '',
'validate_callback' => 'CRM_Core_BAO_Setting::validateBoolSetting',
),
......@@ -1206,7 +1240,7 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'title' => '',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'When CiviMail is enabled, users who "subscribe" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.',
'description' => 'When CiviMail is enabled, users who \"subscribe\" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.',
'help_text' => '',
),
'civimail_server_wide_lock' => array(
......@@ -1248,7 +1282,21 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'title' => 'Enable Double Opt-in for Profile Group(s) field',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'When CiviMail is enabled, users who "subscribe" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.',
'description' => 'When CiviMail is enabled, users who \"subscribe\" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.',
'help_text' => '',
),
'disable_mandatory_tokens_check' => array(
'group_name' => 'Mailing Preferences',
'group' => 'mailing',
'name' => 'disable_mandatory_tokens_check',
'type' => 'Integer',
'html_type' => 'checkbox',
'default' => 0,
'add' => '4.4',
'title' => 'Disable check for mandatory tokens',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Don\'t check for presence of mandatory tokens (domain address; unsubscribe/opt-out) before sending mailings. WARNING: Mandatory tokens are a safe-guard which facilitate compliance with the US CAN-SPAM Act. They should only be disabled if your organization adopts other mechanisms for compliance or if your organization is not subject to CAN-SPAM.',
'help_text' => '',
),
'default_renewal_contribution_page' => array(
......@@ -1265,7 +1313,7 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'title' => 'Default online membership renewal page',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'If you select a default online contribution page for self-service membership renewals, a "renew" link pointing to that page will be displayed on the Contact Dashboard for memberships which were entered offline. You will need to ensure that the membership block for the selected online contribution page includes any currently available memberships.',
'description' => 'If you select a default online contribution page for self-service membership renewals, a \"renew\" link pointing to that page will be displayed on the Contact Dashboard for memberships which were entered offline. You will need to ensure that the membership block for the selected online contribution page includes any currently available memberships.',
'help_text' => '',
),
'is_enabled' => array(
......@@ -1337,8 +1385,8 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'help_text' => '',
),
'userFrameworkResourceURL' => array(
'group' => 'UrlPreferences',
'group_name' => 'url',
'group' => 'url',
'group_name' => 'URL Preferences',
'name' => 'userFrameworkResourceURL',
'type' => 'String',
'default' => '',
......@@ -1351,8 +1399,8 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'validate_callback' => 'CRM_Utils_Rule::url',
),
'imageUploadURL' => array(
'group' => 'UrlPreferences',
'group_name' => 'url',
'group' => 'url',
'group_name' => 'URL Preferences',
'name' => 'imageUploadURL',
'type' => 'String',
'default' => '',
......@@ -1365,8 +1413,8 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
'validate_callback' => 'CRM_Utils_Rule::url',
),
'customCSSURL' => array(
'group' => 'UrlPreferences',
'group_name' => 'url',
'group' => 'url',
'group_name' => 'URL Preferences',
'name' => 'customCSSURL',
'type' => 'String',
'default' => '',
......@@ -1405,4 +1453,4 @@ In the case of Drupal, this will cause all CiviCRM error messages to appear in t
*
* API Standards documentation:
* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
*/
\ No newline at end of file
*/
......@@ -277,7 +277,7 @@
* });
* CRM.Backbone.extendCollection(ContactCollection);
*
* // Use class
* // Use class (with passive criteria)
* var c = new ContactCollection([], {
* crmCriteria: {contact_type: 'Organization'}
* });
......@@ -285,8 +285,21 @@
* c.get(123).set('property', 'value');
* c.get(456).setDeleted(true);
* c.save();
*
* // Use class (with active criteria)
* var criteriaModel = new SomeModel({
* contact_type: 'Organization'
* });
* var c = new ContactCollection([], {
* crmCriteriaModel: criteriaModel
* });
* c.fetch();
* c.get(123).set('property', 'value');
* c.get(456).setDeleted(true);
* c.save();
* @endcode
*
*
* @param Class CollectionClass
* @see tests/qunit/crm-backbone
*/
......@@ -299,6 +312,26 @@
return (this.crmCriteria) ? _.extend({}, this.crmCriteria) : {};
},
/**
* Get an object which represents this collection's criteria
* as a live model. Any changes to the model will be applied
* to the collection, and the collection will be refreshed.
*
* @param criteriaModelClass
*/
setCriteriaModel: function(criteriaModel) {
var collection = this;
this.crmCriteria = criteriaModel.toJSON();
this.listenTo(criteriaModel, 'change', function() {
collection.crmCriteria = criteriaModel.toJSON();
collection.debouncedFetch();
});
},
debouncedFetch: _.debounce(function() {
this.fetch({reset: true});
}, 500),
/**
* Reconcile the server's collection with the client's collection.
* New/modified items from the client will be saved/updated on the
......@@ -327,7 +360,9 @@
sync: CRM.Backbone.sync,
initialize: function(models, options) {
options || (options = {});