+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
*/
/**
*
* @return array
*/
- public function &info() {
+ public function info() {
$report = '';
if ($this->ovID) {
elseif ($this->grouping) {
$report .= " AND v.grouping = '{$this->grouping}' ";
}
+ elseif ($this->myReports) {
+ $report .= " AND inst.owner_id = " . CRM_Core_Session::getLoggedInContactID();
+ }
$sql = "
- SELECT inst.id, inst.title, inst.report_id, inst.description, v.label, v.grouping,
+ SELECT inst.id, inst.title, inst.report_id, inst.description, inst.owner_id, v.label, v.grouping, v.name as class_name,
CASE
WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5)
WHEN v.grouping IS NOT NULL THEN v.grouping
$config = CRM_Core_Config::singleton();
$rows = array();
$url = 'civicrm/report/instance';
+ $my_reports_grouping = 'My';
while ($dao->fetch()) {
if (in_array($dao->report_id, self::$_exceptions)) {
continue;
if ($dao->compName == 'Contact' || $dao->compName == $dao->grouping) {
$enabled = TRUE;
}
+
+ // filter report listings for private reports
+ if (!empty($dao->owner_id) && CRM_Core_Session::getLoggedInContactID() != $dao->owner_id) {
+ continue;
+ }
+
//filter report listings by permissions
if (!($enabled && CRM_Report_Utils_Report::isInstancePermissioned($dao->id))) {
continue;
if ($this->ovID) {
$this->title = ts("Report(s) created from the template: %1", array(1 => $dao->label));
}
- $rows[$dao->compName][$dao->id]['title'] = $dao->title;
- $rows[$dao->compName][$dao->id]['label'] = $dao->label;
- $rows[$dao->compName][$dao->id]['description'] = $dao->description;
- $rows[$dao->compName][$dao->id]['url'] = CRM_Utils_System::url("{$url}/{$dao->id}", "reset=1");
- if (CRM_Core_Permission::check('administer Reports')) {
- $rows[$dao->compName][$dao->id]['deleteUrl'] = CRM_Utils_System::url("{$url}/{$dao->id}", 'action=delete&reset=1');
+
+ $report_grouping = $dao->compName;
+ if ($dao->owner_id != NULL) {
+ $report_grouping = $my_reports_grouping;
}
+ $rows[$report_grouping][$dao->id]['title'] = $dao->title;
+ $rows[$report_grouping][$dao->id]['label'] = $dao->label;
+ $rows[$report_grouping][$dao->id]['description'] = $dao->description;
+ $rows[$report_grouping][$dao->id]['url'] = CRM_Utils_System::url("{$url}/{$dao->id}", "reset=1&output=criteria");
+ $rows[$report_grouping][$dao->id]['viewUrl'] = CRM_Utils_System::url("{$url}/{$dao->id}", 'force=1&reset=1');
+ $rows[$report_grouping][$dao->id]['actions'] = $this->getActionLinks($dao->id, $dao->class_name);
}
}
+ // Move My Reports to the beginning of the reports list
+ if (isset($rows[$my_reports_grouping])) {
+ $my_reports = $rows[$my_reports_grouping];
+ unset($rows[$my_reports_grouping]);
+ $rows = array($my_reports_grouping => $my_reports) + $rows;
+ }
return $rows;
}
public function run() {
//Filters by source report template or by component
$this->ovID = CRM_Utils_Request::retrieve('ovid', 'Positive', $this);
+ $this->myReports = CRM_Utils_Request::retrieve('myreports', 'String', $this);
$this->compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this);
$this->grouping = CRM_Utils_Request::retrieve('grp', 'String', $this);
$this->assign('newButton', $newButton);
$this->assign('templateUrl', $templateUrl);
$this->assign('compName', $this->_compName);
+ $this->assign('myReports', $this->myReports);
}
return parent::run();
}
+ /**
+ * Get action links.
+ *
+ * @param int $instanceID
+ * @param string $className
+ *
+ * @return array
+ */
+ protected function getActionLinks($instanceID, $className) {
+ $urlCommon = 'civicrm/report/instance/' . $instanceID;
+ $actions = array(
+ 'copy' => array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&output=copy'),
+ 'label' => ts('Save a Copy'),
+ ),
+ 'pdf' => array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&force=1&output=pdf'),
+ 'label' => ts('View as pdf'),
+ ),
+ 'print' => array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&force=1&output=print'),
+ 'label' => ts('Print report'),
+ ),
+ );
+ // Hackery, Hackera, Hacker ahahahahahaha a super nasty hack.
+ // Almost all report classes support csv & loading each class to call the method seems too
+ // expensive. We also have on our later list 'do they support charts' which is instance specific
+ // e.g use of group by might affect it. So, lets just skip for the few that don't for now.
+ $csvBlackList = array(
+ 'CRM_Report_Form_Contact_Detail',
+ 'CRM_Report_Form_Event_Income',
+ );
+ if (!in_array($className, $csvBlackList)) {
+ $actions['csv'] = array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&force=1&output=csv'),
+ 'label' => ts('Export to csv'),
+ );
+ }
+ if (CRM_Core_Permission::check('administer Reports')) {
+ $actions['delete'] = array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&action=delete'),
+ 'label' => ts('Delete report'),
+ 'confirm_message' => ts('Are you sure you want delete this report? This action cannot be undone.'),
+ );
+ }
+
+ return $actions;
+ }
+
}