Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
justinfreeman (Agileware)
Core
Commits
84f61951
Commit
84f61951
authored
11 years ago
by
deepak-srivastava
Browse files
Options
Downloads
Plain Diff
Merge pull request #1056 from deepak-srivastava/reportsapi
CRM-12877
parents
e4d8474f
e41b14ce
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/Report/BAO/Instance.php
+193
-1
193 additions, 1 deletion
CRM/Report/BAO/Instance.php
CRM/Report/Form/Instance.php
+16
-151
16 additions, 151 deletions
CRM/Report/Form/Instance.php
with
209 additions
and
152 deletions
CRM/Report/BAO/Instance.php
+
193
−
1
View file @
84f61951
...
...
@@ -35,6 +35,199 @@
*/
class
CRM_Report_BAO_Instance
extends
CRM_Report_DAO_Instance
{
/**
* takes an associative array and creates an instance object
*
* the function extract all the params it needs to initialize the create a
* instance object. the params array could contain additional unused name/value
* pairs
*
* @param array $params (reference ) an assoc array of name/value pairs
*
* @return object CRM_Report_DAO_Instance object
* @access public
* @static
*/
static
function
add
(
&
$params
)
{
$instance
=
new
CRM_Report_DAO_Instance
();
if
(
empty
(
$params
))
{
return
NULL
;
}
$config
=
CRM_Core_Config
::
singleton
();
$params
[
'domain_id'
]
=
CRM_Core_Config
::
domainID
();
// convert roles array to string
if
(
isset
(
$params
[
'grouprole'
])
&&
is_array
(
$params
[
'grouprole'
]))
{
$grouprole_array
=
array
();
foreach
(
$params
[
'grouprole'
]
as
$key
=>
$value
)
{
$grouprole_array
[
$value
]
=
$value
;
}
$params
[
'grouprole'
]
=
implode
(
CRM_Core_DAO
::
VALUE_SEPARATOR
,
array_keys
(
$grouprole_array
)
);
}
$params
[
'is_reserved'
]
=
CRM_Utils_Array
::
value
(
'is_reserved'
,
$params
,
FALSE
);
$instanceID
=
CRM_Utils_Array
::
value
(
'id'
,
$params
);
if
(
CRM_Utils_Array
::
value
(
'instance_id'
,
$params
))
{
$instanceID
=
CRM_Utils_Array
::
value
(
'instance_id'
,
$params
);
}
if
(
$instanceID
)
{
CRM_Utils_Hook
::
pre
(
'edit'
,
'ReportInstance'
,
$instanceID
,
$params
);
}
else
{
CRM_Utils_Hook
::
pre
(
'create'
,
'ReportInstance'
,
NULL
,
$params
);
}
$instance
=
new
CRM_Report_DAO_Instance
();
$instance
->
copyValues
(
$params
);
if
(
$config
->
userFramework
==
'Joomla'
)
{
$instance
->
permission
=
'null'
;
}
// explicitly set to null if params value is empty
if
(
empty
(
$params
[
'grouprole'
]))
{
$instance
->
grouprole
=
'null'
;
}
if
(
$instanceID
)
{
$instance
->
id
=
$instanceID
;
}
if
(
$reportID
=
CRM_Utils_Array
::
value
(
'report_id'
,
$params
))
{
$instance
->
report_id
=
$reportID
;
}
else
if
(
$instanceID
)
{
$instance
->
report_id
=
CRM_Report_Utils_Report
::
getValueFromUrl
(
$instanceID
);
}
else
{
// just take it from current url
$instance
->
report_id
=
CRM_Report_Utils_Report
::
getValueFromUrl
();
}
// unset params that doesn't match with DB columns, and also not required in form-values for sure
$fields
=
array
(
'title'
,
'to_emails'
,
'cc_emails'
,
'header'
,
'footer'
,
'qfKey'
,
'_qf_default'
,
'report_header'
,
'report_footer'
,
'grouprole'
,
);
foreach
(
$fields
as
$field
)
{
unset
(
$params
[
$field
]);
}
$instance
->
form_values
=
serialize
(
$params
);
$instance
->
save
();
if
(
$instanceID
)
{
CRM_Utils_Hook
::
pre
(
'edit'
,
'ReportInstance'
,
$instance
->
id
,
$instance
);
}
else
{
CRM_Utils_Hook
::
pre
(
'create'
,
'ReportInstance'
,
$instance
->
id
,
$instance
);
}
return
$instance
;
}
/**
* Function to create instance
* takes an associative array and creates a instance object and does any related work like permissioning, adding to dashboard etc.
*
* This function is invoked from within the web form layer and also from the api layer
*
* @param array $params (reference ) an assoc array of name/value pairs
*
* @return object CRM_Report_BAO_Instance object
* @access public
* @static
*/
static
function
&
create
(
&
$params
)
{
$params
[
'header'
]
=
CRM_Utils_Array
::
value
(
'report_header'
,
$params
);
$params
[
'footer'
]
=
CRM_Utils_Array
::
value
(
'report_footer'
,
$params
);
// build navigation parameters
if
(
CRM_Utils_Array
::
value
(
'is_navigation'
,
$params
))
{
if
(
!
array_key_exists
(
'navigation'
,
$params
))
{
$params
[
'navigation'
]
=
array
();
}
$navigationParams
=&
$params
[
'navigation'
];
$navigationParams
[
'permission'
]
=
array
();
$navigationParams
[
'label'
]
=
$params
[
'title'
];
$navigationParams
[
'name'
]
=
$params
[
'title'
];
$navigationParams
[
'current_parent_id'
]
=
CRM_Utils_Array
::
value
(
'parent_id'
,
$navigationParams
);
$navigationParams
[
'parent_id'
]
=
CRM_Utils_Array
::
value
(
'parent_id'
,
$params
);
$navigationParams
[
'is_active'
]
=
1
;
if
(
$permission
=
CRM_Utils_Array
::
value
(
'permission'
,
$params
))
{
$navigationParams
[
'permission'
][]
=
$permission
;
}
// unset the navigation related elements, not used in report form values
unset
(
$params
[
'parent_id'
]);
unset
(
$params
[
'is_navigation'
]);
}
// add to dashboard
$dashletParams
=
array
();
if
(
CRM_Utils_Array
::
value
(
'addToDashboard'
,
$params
))
{
$dashletParams
=
array
(
'label'
=>
$params
[
'title'
],
'is_active'
=>
1
,
);
if
(
$permission
=
CRM_Utils_Array
::
value
(
'permission'
,
$params
))
{
$dashletParams
[
'permission'
][]
=
$permission
;
}
}
$transaction
=
new
CRM_Core_Transaction
();
$instance
=
self
::
add
(
$params
);
if
(
is_a
(
$instance
,
'CRM_Core_Error'
))
{
$transaction
->
rollback
();
return
$instance
;
}
// add / update navigation as required
if
(
!
empty
(
$navigationParams
))
{
if
(
!
CRM_Utils_Array
::
value
(
'id'
,
$params
)
&&
!
CRM_Utils_Array
::
value
(
'instance_id'
,
$params
)
&&
CRM_Utils_Array
::
value
(
'id'
,
$navigationParams
))
{
unset
(
$navigationParams
[
'id'
]);
}
$navigationParams
[
'url'
]
=
"civicrm/report/instance/
{
$instance
->
id
}
&reset=1"
;
$navigation
=
CRM_Core_BAO_Navigation
::
add
(
$navigationParams
);
if
(
CRM_Utils_Array
::
value
(
'is_active'
,
$navigationParams
))
{
//set the navigation id in report instance table
CRM_Core_DAO
::
setFieldValue
(
'CRM_Report_DAO_Instance'
,
$instance
->
id
,
'navigation_id'
,
$navigation
->
id
);
}
else
{
// has been removed from the navigation bar
CRM_Core_DAO
::
setFieldValue
(
'CRM_Report_DAO_Instance'
,
$instance
->
id
,
'navigation_id'
,
'NULL'
);
}
//reset navigation
CRM_Core_BAO_Navigation
::
resetNavigation
();
}
// add to dashlet
if
(
!
empty
(
$dashletParams
))
{
$section
=
2
;
$chart
=
''
;
if
(
CRM_Utils_Array
::
value
(
'charts'
,
$params
))
{
$section
=
1
;
$chart
=
"&charts="
.
$params
[
'charts'
];
}
$dashletParams
[
'url'
]
=
"civicrm/report/instance/
{
$instance
->
id
}
&reset=1§ion=
{
$section
}
&snippet=5
{
$chart
}
&context=dashlet"
;
$dashletParams
[
'fullscreen_url'
]
=
"civicrm/report/instance/
{
$instance
->
id
}
&reset=1§ion=
{
$section
}
&snippet=5
{
$chart
}
&context=dashletFullscreen"
;
$dashletParams
[
'instanceURL'
]
=
"civicrm/report/instance/
{
$instance
->
id
}
"
;
CRM_Core_BAO_Dashboard
::
addDashlet
(
$dashletParams
);
}
$transaction
->
commit
();
return
$instance
;
}
/**
* Delete the instance of the Report
*
...
...
@@ -60,4 +253,3 @@ class CRM_Report_BAO_Instance extends CRM_Report_DAO_Instance {
return
NULL
;
}
}
This diff is collapsed.
Click to expand it.
CRM/Report/Form/Instance.php
+
16
−
151
View file @
84f61951
...
...
@@ -241,170 +241,35 @@ class CRM_Report_Form_Instance {
}
static
function
postProcess
(
&
$form
,
$redirect
=
TRUE
)
{
$params
=
$form
->
getVar
(
'_params'
);
$config
=
CRM_Core_Config
::
singleton
();
$params
[
'header'
]
=
CRM_Utils_Array
::
value
(
'report_header'
,
$params
);
$params
[
'footer'
]
=
CRM_Utils_Array
::
value
(
'report_footer'
,
$params
);
$params
[
'domain_id'
]
=
CRM_Core_Config
::
domainID
();
//navigation parameters
if
(
CRM_Utils_Array
::
value
(
'is_navigation'
,
$params
))
{
$form
->
_navigation
[
'permission'
]
=
array
();
$form
->
_navigation
[
'label'
]
=
$params
[
'title'
];
$form
->
_navigation
[
'name'
]
=
$params
[
'title'
];
$permission
=
CRM_Utils_Array
::
value
(
'permission'
,
$params
);
$form
->
_navigation
[
'current_parent_id'
]
=
CRM_Utils_Array
::
value
(
'parent_id'
,
$form
->
_navigation
);
$form
->
_navigation
[
'parent_id'
]
=
CRM_Utils_Array
::
value
(
'parent_id'
,
$params
);
$form
->
_navigation
[
'is_active'
]
=
1
;
if
(
$permission
)
{
$form
->
_navigation
[
'permission'
][]
=
$permission
;
}
//unset the navigation related element,
//not used in report form values
unset
(
$params
[
'parent_id'
]);
unset
(
$params
[
'is_navigation'
]);
}
// convert roles array to string
if
(
isset
(
$params
[
'grouprole'
])
&&
is_array
(
$params
[
'grouprole'
]))
{
$grouprole_array
=
array
();
foreach
(
$params
[
'grouprole'
]
as
$key
=>
$value
)
{
$grouprole_array
[
$value
]
=
$value
;
}
$params
[
'grouprole'
]
=
implode
(
CRM_Core_DAO
::
VALUE_SEPARATOR
,
array_keys
(
$grouprole_array
)
);
}
// add to dashboard
$dashletParams
=
array
();
if
(
CRM_Utils_Array
::
value
(
'addToDashboard'
,
$params
))
{
$dashletParams
=
array
(
'label'
=>
$params
[
'title'
],
'is_active'
=>
1
,
);
$permission
=
CRM_Utils_Array
::
value
(
'permission'
,
$params
);
if
(
$permission
)
{
$dashletParams
[
'permission'
][]
=
$permission
;
}
}
$params
[
'is_reserved'
]
=
CRM_Utils_Array
::
value
(
'is_reserved'
,
$params
,
FALSE
);
$dao
=
new
CRM_Report_DAO_Instance
();
$dao
->
copyValues
(
$params
);
if
(
$config
->
userFramework
==
'Joomla'
)
{
$dao
->
permission
=
'null'
;
}
// explicitly set to null if params value is empty
if
(
empty
(
$params
[
'grouprole'
]))
{
$dao
->
grouprole
=
'null'
;
}
// unset all the params that we use
$fields
=
array
(
'title'
,
'to_emails'
,
'cc_emails'
,
'header'
,
'footer'
,
'qfKey'
,
'_qf_default'
,
'report_header'
,
'report_footer'
,
'grouprole'
,
);
foreach
(
$fields
as
$field
)
{
unset
(
$params
[
$field
]);
}
$dao
->
form_values
=
serialize
(
$params
);
$params
=
$form
->
getVar
(
'_params'
);
$instanceID
=
$form
->
getVar
(
'_id'
);
$isNew
=
$form
->
getVar
(
'_createNew'
);
$isCopy
=
0
;
if
(
$instanceID
)
{
if
(
!
$isNew
)
{
// updating an existing report instance
$dao
->
id
=
$instanceID
;
}
else
{
// making a copy of an existing instance
$isCopy
=
1
;
}
}
$dao
->
report_id
=
CRM_Report_Utils_Report
::
getValueFromUrl
(
$instanceID
);
$dao
->
save
();
$form
->
set
(
'id'
,
$dao
->
id
);
if
(
!
empty
(
$form
->
_navigation
))
{
if
(
$isNew
&&
CRM_Utils_Array
::
value
(
'id'
,
$form
->
_navigation
))
{
unset
(
$form
->
_navigation
[
'id'
]);
}
$form
->
_navigation
[
'url'
]
=
"civicrm/report/instance/
{
$dao
->
id
}
&reset=1"
;
$navigation
=
CRM_Core_BAO_Navigation
::
add
(
$form
->
_navigation
);
if
(
CRM_Utils_Array
::
value
(
'is_active'
,
$form
->
_navigation
))
{
//set the navigation id in report instance table
CRM_Core_DAO
::
setFieldValue
(
'CRM_Report_DAO_Instance'
,
$dao
->
id
,
'navigation_id'
,
$navigation
->
id
);
}
else
{
// has been removed from the navigation bar
CRM_Core_DAO
::
setFieldValue
(
'CRM_Report_DAO_Instance'
,
$dao
->
id
,
'navigation_id'
,
'NULL'
);
}
//reset navigation
CRM_Core_BAO_Navigation
::
resetNavigation
();
if
(
$isNew
=
$form
->
getVar
(
'_createNew'
))
{
// set the report_id since base template is going to be same, and we going to unset $instanceID
// which will make it difficult later on, to compute report_id
$params
[
'report_id'
]
=
CRM_Report_Utils_Report
::
getValueFromUrl
(
$instanceID
);
$instanceID
=
NULL
;
//unset $instanceID so a new copy would be created
}
// add to dashlet
if
(
!
empty
(
$dashletParams
))
{
$section
=
2
;
$chart
=
''
;
if
(
CRM_Utils_Array
::
value
(
'charts'
,
$params
))
{
$section
=
1
;
$chart
=
"&charts="
.
$params
[
'charts'
];
}
$dashletParams
[
'url'
]
=
"civicrm/report/instance/
{
$dao
->
id
}
&reset=1§ion=
{
$section
}
&snippet=5
{
$chart
}
&context=dashlet"
;
$dashletParams
[
'fullscreen_url'
]
=
"civicrm/report/instance/
{
$dao
->
id
}
&reset=1§ion=
{
$section
}
&snippet=5
{
$chart
}
&context=dashletFullscreen"
;
$dashletParams
[
'instanceURL'
]
=
"civicrm/report/instance/
{
$dao
->
id
}
"
;
CRM_Core_BAO_Dashboard
::
addDashlet
(
$dashletParams
);
$params
[
'instance_id'
]
=
$instanceID
;
if
(
CRM_Utils_Array
::
value
(
'is_navigation'
,
$params
))
{
$params
[
'navigation'
]
=
$form
->
_navigation
;
}
$instanceParams
=
array
(
'value'
=>
$dao
->
report_id
);
$instanceDefaults
=
array
();
$cmpName
=
"Contact"
;
$statusMsg
=
"null"
;
CRM_Core_DAO
::
commonRetrieve
(
'CRM_Core_DAO_OptionValue'
,
$instanceParams
,
$instanceDefaults
);
if
(
$cmpID
=
CRM_Utils_Array
::
value
(
'component_id'
,
$instanceDefaults
))
{
$cmpName
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Core_DAO_Component'
,
$cmpID
,
'name'
,
'id'
);
$cmpName
=
substr
(
$cmpName
,
4
);
}
$instance
=
CRM_Report_BAO_Instance
::
create
(
$params
);
$form
->
set
(
'id'
,
$instance
->
id
);
if
(
$instanceID
&&
!
$isNew
)
{
// updating existing instance
$statusMsg
=
ts
(
'"%1" report has been updated.'
,
array
(
1
=>
$
dao
->
title
));
}
elseif
(
$
isCopy
)
{
$statusMsg
=
ts
(
'Your report has been successfully copied as "%1". You are currently viewing the new copy.'
,
array
(
1
=>
$
dao
->
title
));
$statusMsg
=
ts
(
'"%1" report has been updated.'
,
array
(
1
=>
$
instance
->
title
));
}
elseif
(
$
form
->
getVar
(
'_id'
)
&&
$isNew
)
{
$statusMsg
=
ts
(
'Your report has been successfully copied as "%1". You are currently viewing the new copy.'
,
array
(
1
=>
$
instance
->
title
));
}
else
{
$statusMsg
=
ts
(
'"%1" report has been successfully created. You are currently viewing the new report instance.'
,
array
(
1
=>
$
dao
->
title
));
$statusMsg
=
ts
(
'"%1" report has been successfully created. You are currently viewing the new report instance.'
,
array
(
1
=>
$
instance
->
title
));
}
$instanceUrl
=
CRM_Utils_System
::
url
(
"civicrm/report/instance/
{
$dao
->
id
}
"
,
"reset=1"
);
CRM_Core_Session
::
setStatus
(
$statusMsg
);
if
(
$redirect
)
{
CRM_Utils_System
::
redirect
(
$instanceUrl
);
CRM_Utils_System
::
redirect
(
CRM_Utils_System
::
url
(
"civicrm/report/instance/
{
$instance
->
id
}
"
,
"reset=1"
)
);
}
}
}
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