Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
a7aaa707
Commit
a7aaa707
authored
11 years ago
by
Kurund Jalmi
Browse files
Options
Downloads
Plain Diff
Merge pull request
#1305
from davecivicrm/CRM-13090
CRM-13090 uniqueness on title + activity type + campaign (optional).
parents
7d8fa600
db55935b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Campaign/Form/Petition.php
+48
-3
48 additions, 3 deletions
CRM/Campaign/Form/Petition.php
CRM/Campaign/Form/Survey/Results.php
+0
-27
0 additions, 27 deletions
CRM/Campaign/Form/Survey/Results.php
with
48 additions
and
30 deletions
CRM/Campaign/Form/Petition.php
+
48
−
3
View file @
a7aaa707
...
...
@@ -41,10 +41,11 @@
class
CRM_Campaign_Form_Petition
extends
CRM_Core_Form
{
/**
* Making this public so we can reference it in the formRule
* @var int
* @p
rotected
* @p
ublic
*/
p
rotected
$_surveyId
;
p
ublic
$_surveyId
;
public
function
preProcess
()
{
if
(
!
CRM_Campaign_BAO_Campaign
::
accessCampaign
())
{
...
...
@@ -248,7 +249,51 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form {
);
// add a form rule to check default value
$this
->
addFormRule
(
array
(
'CRM_Campaign_Form_Survey_Results'
,
'formRule'
),
$this
);
$this
->
addFormRule
(
array
(
'CRM_Campaign_Form_Petition'
,
'formRule'
),
$this
);
}
/**
* global validation rules for the form
*
*/
static
function
formRule
(
$fields
,
$files
,
$form
)
{
$errors
=
array
();
// Petitions should be unique by: title, campaign ID (if assigned) and activity type ID
// NOTE: This class is called for both Petition create / update AND for Survey Results tab, but this rule is only for Petition.
$where
=
array
(
'activity_type_id = %1'
,
'title = %2'
);
$params
=
array
(
1
=>
array
(
$fields
[
'activity_type_id'
],
'Integer'
),
2
=>
array
(
$fields
[
'title'
],
'String'
),
);
$uniqueRule
=
ts
(
'activity type'
);
if
(
empty
(
$fields
[
'campaign_id'
]))
{
$where
[]
=
'campaign_id IS NULL'
;
}
else
{
$where
[]
=
'campaign_id = %3'
;
$params
[
3
]
=
array
(
$fields
[
'campaign_id'
],
'Integer'
);
$uniqueRule
=
ts
(
'campaign and activity type'
);
}
// Exclude current Petition row if UPDATE.
if
(
$form
->
_surveyId
)
{
$where
[]
=
'id != %4'
;
$params
[
4
]
=
array
(
$form
->
_surveyId
,
'Integer'
);
}
$whereClause
=
implode
(
' AND '
,
$where
);
$query
=
"
SELECT COUNT(*) AS row_count
FROM civicrm_survey
WHERE
$whereClause
"
;
$result
=
CRM_Core_DAO
::
singleValueQuery
(
$query
,
$params
);
if
(
$result
>=
1
)
{
$errors
[
'title'
]
=
ts
(
'This title is already associated with the selected %1. Please specify a unique title.'
,
array
(
1
=>
$uniqueRule
));
}
return
empty
(
$errors
)
?
TRUE
:
$errors
;
}
...
...
This diff is collapsed.
Click to expand it.
CRM/Campaign/Form/Survey/Results.php
+
0
−
27
View file @
a7aaa707
...
...
@@ -206,33 +206,6 @@ class CRM_Campaign_Form_Survey_Results extends CRM_Campaign_Form_Survey {
*/
static
function
formRule
(
$fields
,
$files
,
$form
)
{
$errors
=
array
();
// Petitions and Surveys are unique by: title, campaign ID and activity type ID
if
(
!
CRM_Utils_Rule
::
integer
(
$fields
[
'campaign_id'
]))
{
$errors
[
'campaign_id'
]
=
ts
(
'Please enter a valid integer.'
);
}
else
if
(
!
CRM_Utils_Rule
::
integer
(
$fields
[
'activity_type_id'
]))
{
$errors
[
'activity_type_id'
]
=
ts
(
'Please enter a valid integer.'
);
}
else
{
$query
=
"
SELECT COUNT(*) AS row_count
FROM civicrm_survey
WHERE campaign_id = %1
AND activity_type_id = %2
AND title = %3
"
;
$params
=
array
(
1
=>
array
(
$fields
[
'campaign_id'
],
'Integer'
),
2
=>
array
(
$fields
[
'activity_type_id'
],
'Integer'
),
3
=>
array
(
$fields
[
'title'
],
'String'
),
);
$result
=
CRM_Core_DAO
::
singleValueQuery
(
$query
,
$params
);
if
(
$result
>=
1
)
{
$errors
[
'title'
]
=
ts
(
'Title is already associated with the specified campaign and activity type. Please specify a unique title.'
);
}
}
if
(
CRM_Utils_Array
::
value
(
'option_label'
,
$fields
)
&&
CRM_Utils_Array
::
value
(
'option_value'
,
$fields
)
&&
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment