Ejemplo n.º 1
0
 static function retrieve($params, &$defaults)
 {
     $instance = new CRM_Report_DAO_Instance();
     $instance->copyValues($params);
     if ($instance->find(true)) {
         CRM_Core_DAO::storeValues($instance, $defaults);
         $instance->free();
         return $instance;
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields =& self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['report_instance'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
 static function postProcess(&$form)
 {
     $params = $form->getVar('_params');
     $config = CRM_Core_Config::singleton();
     $params['header'] = $params['report_header'];
     $params['footer'] = $params['report_footer'];
     $params['domain_id'] = CRM_Core_Config::domainID();
     $form->_navigation['permission'] = array();
     $form->_navigation['label'] = $params['title'];
     $form->_navigation['name'] = $params['title'];
     //navigation parameters
     if (CRM_Utils_Array::value('is_navigation', $params)) {
         $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);
     $instanceID = $form->getVar('_id');
     $isNew = $form->getVar('_createNew');
     if ($instanceID && !$isNew) {
         $dao->id = $instanceID;
     }
     $dao->report_id = CRM_Report_Utils_Report::getValueFromUrl($instanceID);
     $dao->save();
     $form->set('id', $dao->id);
     $reloadTemplate = FALSE;
     if ($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();
             // in order to reflect change in navigation, template needs to be reloaded
             $reloadTemplate = TRUE;
         }
         // 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&section={$section}&snippet=5{$chart}&context=dashlet";
             $dashletParams['fullscreen_url'] = "civicrm/report/instance/{$dao->id}&reset=1&section={$section}&snippet=5{$chart}&context=dashletFullscreen";
             $dashletParams['instanceURL'] = "civicrm/report/instance/{$dao->id}";
             CRM_Core_BAO_Dashboard::addDashlet($dashletParams);
         }
         $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);
         }
         // Url to view this report and others created FROM this template
         $instanceUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1&ovid={$instanceDefaults['id']}");
         $statusMsg = ts('Report "%1" has been created and is now available in the <a href="%3">report listings under "%2" Reports</a>.', array(1 => $dao->title, 2 => $cmpName, 3 => $instanceUrl));
         if ($instanceID && !$isNew) {
             $statusMsg = ts('Report "%1" has been updated.', array(1 => $dao->title));
         }
         CRM_Core_Session::setStatus($statusMsg);
     }
     if ($reloadTemplate) {
         // as there's been change in navigation, reload the template
         return CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'force=1'));
     }
 }
Ejemplo n.º 4
0
 private function deleteReports()
 {
     // disable logging templates
     CRM_Core_DAO::executeQuery("\n            UPDATE civicrm_option_value\n            SET is_active = 0\n            WHERE value IN ('" . implode("', '", $this->reports) . "')\n        ");
     // delete report instances
     $domain_id = CRM_Core_Config::domainID();
     foreach ($this->reports as $report) {
         $dao = new CRM_Report_DAO_Instance();
         $dao->domain_id = $domain_id;
         $dao->report_id = $report;
         $dao->delete();
     }
 }
 function upgrade_3_4_6($rev)
 {
     $modifiedReportIds = array('event/summary', 'activity', 'Mailing/bounce', 'Mailing/clicks', 'Mailing/opened');
     $instances = CRM_Core_DAO::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')");
     while ($instances->fetch()) {
         $formValues = unserialize($instances->form_values);
         switch ($instances->report_id) {
             case 'event/summary':
                 $eventDates = array('event_start_date_from', 'event_start_date_to', 'event_end_date_from', 'event_end_date_to');
                 foreach ($eventDates as $date) {
                     if (isset($formValues[$date]) && $formValues[$date] == ' ') {
                         $formValues[$date] = '';
                     }
                 }
                 break;
             case 'activity':
                 if (isset($formValues['group_bys'])) {
                     if (is_array($formValues['group_bys'])) {
                         $orderBy = array();
                         $count = 0;
                         foreach ($formValues['group_bys'] as $col => $isSet) {
                             if (!$isSet) {
                                 continue;
                             }
                             $orderBy[++$count] = array('column' => $col, 'order' => 'ASC');
                         }
                         if (!empty($orderBy)) {
                             $formValues['order_bys'] = $orderBy;
                         }
                     }
                     unset($formValues['group_bys']);
                 }
                 break;
             case 'Mailing/bounce':
             case 'Mailing/clicks':
             case 'Mailing/opened':
                 $formValues['fields']['mailing_name'] = 1;
                 break;
         }
         // save updated instance criteria
         $dao = new CRM_Report_DAO_Instance();
         $dao->id = $instances->id;
         $dao->form_values = serialize($formValues);
         $dao->save();
         $dao->free();
     }
     $bulkEmailActivityType = CRM_Core_DAO::singleValueQuery("\nSELECT v.id\nFROM   civicrm_option_value v, \n       civicrm_option_group g \nWHERE  v.option_group_id = g.id \n  AND  g.name      = %1 \n  AND  g.is_active = 1  \n  AND  v.name      = %2", array(1 => array('activity_type', 'String'), 2 => array('Bulk Email', 'String')));
     // CRM-8852, reset contact field cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->assign('bulkEmailActivityType', $bulkEmailActivityType);
     $upgrade->processSQL($rev);
 }
Ejemplo n.º 6
0
 static function postProcess(&$form)
 {
     $params = $form->getVar('_params');
     $config = CRM_Core_Config::singleton();
     $params['header'] = $params['report_header'];
     $params['footer'] = $params['report_footer'];
     $params['domain_id'] = CRM_Core_Config::domainID();
     //navigation parameters
     if (CRM_Utils_Array::value('is_navigation', $params)) {
         $form->_navigation['permission'] = array();
         $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['label'] = $params['title'];
         $form->_navigation['name'] = $params['title'];
         $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']);
     }
     // add to dashboard
     $dashletParams = array();
     if (CRM_Utils_Array::value('addToDashboard', $params)) {
         $dashletParams = array('label' => $params['title'], 'is_active' => 1, 'content' => 'NULL');
         $permission = CRM_Utils_Array::value('permission', $params);
         if ($permission) {
             $dashletParams['permission'][] = $permission;
         }
         unset($params['addToDashboard']);
     }
     require_once 'CRM/Report/DAO/Instance.php';
     $dao = new CRM_Report_DAO_Instance();
     $dao->copyValues($params);
     if ($config->userFramework == 'Joomla') {
         $dao->permission = NULL;
     }
     // unset all the params that we use
     $fields = array('title', 'to_emails', 'cc_emails', 'header', 'footer', 'qfKey', '_qf_default', 'report_header', 'report_footer');
     foreach ($fields as $field) {
         unset($params[$field]);
     }
     $dao->form_values = serialize($params);
     $instanceID = $form->getVar('_id');
     if ($instanceID) {
         $dao->id = $instanceID;
     }
     require_once 'CRM/Report/Utils/Report.php';
     $dao->report_id = CRM_Report_Utils_Report::getValueFromUrl($instanceID);
     $dao->save();
     $form->set('id', $dao->id);
     $reloadTemplate = false;
     if ($dao->id) {
         if (!empty($form->_navigation)) {
             $form->_navigation['url'] = "civicrm/report/instance/{$dao->id}&reset=1";
             $navigation = CRM_Core_BAO_Navigation::add($form->_navigation);
             //set the navigation id in report instance table
             CRM_Core_DAO::setFieldValue('CRM_Report_DAO_Instance', $dao->id, 'navigation_id', $navigation->id);
             //reset navigation
             CRM_Core_BAO_Navigation::resetNavigation();
             // in order to reflect change in navigation, template needs to be reloaded
             $reloadTemplate = true;
         }
         // add to dashlet
         if (!empty($dashletParams)) {
             $section = 2;
             $chart = '';
             if (CRM_Utils_Array::value('charts', $params)) {
                 $section = 1;
                 $chart = "&charts=" . $params['charts'];
                 $dashletParams['is_fullscreen'] = 0;
             }
             $dashletParams['url'] = "civicrm/report/instance/{$dao->id}&reset=1&section={$section}&snippet=4{$chart}";
             $dashletParams['instanceURL'] = "civicrm/report/instance/{$dao->id}";
             require_once 'CRM/Core/BAO/Dashboard.php';
             CRM_Core_BAO_Dashboard::addDashlet($dashletParams);
         }
         $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);
         }
         // Url to view this report and others created FROM this template
         $instanceUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1&ovid={$instanceDefaults['id']}");
         $statusMsg = ts('Report "%1" has been created and is now available in the <a href="%3">report listings under "%2" Reports</a>.', array(1 => $dao->title, 2 => $cmpName, 3 => $instanceUrl));
         if ($instanceID) {
             $statusMsg = ts('Report "%1" has been updated.', array(1 => $dao->title));
         }
         CRM_Core_Session::setStatus($statusMsg);
     }
     if ($reloadTemplate) {
         // as there's been change in navigation, reload the template
         return CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'force=1'));
     }
 }
Ejemplo n.º 7
0
 /**                                                           
  * Delete the instance of the Report
  * 
  * @return $results no of deleted Instance  on success, false otherwise
  * @access public 
  *  
  */
 function delete($id)
 {
     $dao = new CRM_Report_DAO_Instance();
     $dao->id = $id;
     return $dao->delete();
 }