CRM-12877, towards report instance api
authorDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Thu, 27 Jun 2013 12:54:08 +0000 (18:24 +0530)
committerDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Thu, 27 Jun 2013 12:54:08 +0000 (18:24 +0530)
----------------------------------------
* CRM-12877: Provide api for creating report instances
  http://issues.civicrm.org/jira/browse/CRM-12877

12 files changed:
CRM/Campaign/BAO/Survey.php
CRM/Core/BAO/Log.php
CRM/Logging/Schema.php
CRM/Report/BAO/ReportInstance.php [moved from CRM/Report/BAO/Instance.php with 92% similarity]
CRM/Report/Form.php
CRM/Report/Form/Instance.php
CRM/Report/Page/Instance.php
CRM/Report/Utils/Report.php
CRM/Upgrade/Incremental/php/FourThree.php
CRM/Upgrade/Incremental/php/ThreeFour.php
api/v3/ReportInstance.php [new file with mode: 0644]
xml/schema/Report/Instance.xml

index a23168ef412075418c4ba344906cbe3140daa990..4270067a13f167ec1333e9aacfacff5b66af24f8 100644 (file)
@@ -389,7 +389,7 @@ SELECT  survey.id    as id,
     }
     $reportId = CRM_Campaign_BAO_Survey::getReportID($id);
     if($reportId){
-      CRM_Report_BAO_Instance::delete($reportId);
+      CRM_Report_BAO_ReportInstance::del($reportId);
     }
     $dao = new CRM_Campaign_DAO_Survey();
     $dao->id = $id;
index 15772e8c65606730fe5fb490a7a1e9efc7abfafc..690f2e292b83cb51467e4b39ea2c03b756bffba4 100644 (file)
@@ -165,7 +165,7 @@ UPDATE civicrm_log
     if ($loggingSchema->isEnabled()) {
       $params = array('report_id' => 'logging/contact/summary');
       $instance = array();
-      CRM_Report_BAO_Instance::retrieve($params, $instance);
+      CRM_Report_BAO_ReportInstance::retrieve($params, $instance);
 
       if (!empty($instance) &&
         (!CRM_Utils_Array::value('permission', $instance) ||
index beeed84620e86250fea80da880b65ef377d5ede7..dc02bb590e77a52be767505e8bb99df150f8c5ef 100644 (file)
@@ -255,7 +255,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
     // add report instances
     $domain_id = CRM_Core_Config::domainID();
     foreach ($this->reports as $report) {
-      $dao             = new CRM_Report_DAO_Instance;
+      $dao             = new CRM_Report_DAO_ReportInstance;
       $dao->domain_id  = $domain_id;
       $dao->report_id  = $report;
       $dao->title      = $titles[$report];
@@ -342,7 +342,7 @@ COLS;
     // delete report instances
     $domain_id = CRM_Core_Config::domainID();
     foreach ($this->reports as $report) {
-      $dao            = new CRM_Report_DAO_Instance;
+      $dao            = new CRM_Report_DAO_ReportInstance;
       $dao->domain_id = $domain_id;
       $dao->report_id = $report;
       $dao->delete();
similarity index 92%
rename from CRM/Report/BAO/Instance.php
rename to CRM/Report/BAO/ReportInstance.php
index 857fca272bbd53ceada3b7ed09fc8921840062df..6585e2942518444307e944ac5da3372f3bf67ed4 100644 (file)
@@ -33,7 +33,7 @@
  * $Id$
  *
  */
-class CRM_Report_BAO_Instance extends CRM_Report_DAO_Instance {
+class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance {
 
   /**
    * takes an associative array and creates an instance object
@@ -44,12 +44,12 @@ class CRM_Report_BAO_Instance extends CRM_Report_DAO_Instance {
    *
    * @param array  $params (reference ) an assoc array of name/value pairs
    *
-   * @return object CRM_Report_DAO_Instance object
+   * @return object CRM_Report_DAO_ReportInstance object
    * @access public
    * @static
    */
   static function add(&$params) {
-    $instance = new CRM_Report_DAO_Instance();
+    $instance = new CRM_Report_DAO_ReportInstance();
     if (empty($params)) {
       return NULL;
     }
@@ -82,7 +82,7 @@ class CRM_Report_BAO_Instance extends CRM_Report_DAO_Instance {
       CRM_Utils_Hook::pre('create', 'ReportInstance', NULL, $params);
     }
 
-    $instance = new CRM_Report_DAO_Instance();
+    $instance = new CRM_Report_DAO_ReportInstance();
     $instance->copyValues($params);
 
     if ($config->userFramework == 'Joomla') {
@@ -135,7 +135,7 @@ class CRM_Report_BAO_Instance extends CRM_Report_DAO_Instance {
    *
    * @param array   $params      (reference ) an assoc array of name/value pairs
    *
-   * @return object CRM_Report_BAO_Instance object
+   * @return object CRM_Report_BAO_ReportInstance object
    * @access public
    * @static
    */
@@ -199,11 +199,11 @@ class CRM_Report_BAO_Instance extends CRM_Report_DAO_Instance {
 
       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);
+        CRM_Core_DAO::setFieldValue('CRM_Report_DAO_ReportInstance', $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');
+        CRM_Core_DAO::setFieldValue('CRM_Report_DAO_ReportInstance', $instance->id, 'navigation_id', 'NULL');
       }
       //reset navigation
       CRM_Core_BAO_Navigation::resetNavigation();
@@ -235,14 +235,14 @@ class CRM_Report_BAO_Instance extends CRM_Report_DAO_Instance {
    * @access public
    *
    */
-  function delete($id = NULL) {
-    $dao = new CRM_Report_DAO_Instance();
+  static function del($id = NULL) {
+    $dao = new CRM_Report_DAO_ReportInstance();
     $dao->id = $id;
     return $dao->delete();
   }
 
   static function retrieve($params, &$defaults) {
-    $instance = new CRM_Report_DAO_Instance();
+    $instance = new CRM_Report_DAO_ReportInstance();
     $instance->copyValues($params);
 
     if ($instance->find(TRUE)) {
index 75c9eba974452da9cfb29c064d9649069da7c5f6..bfa11a967b9ab19bd8562c5c2808f6ebaef6783d 100644 (file)
@@ -328,7 +328,7 @@ class CRM_Report_Form extends CRM_Core_Form {
       $this->assign('instanceId', $this->_id);
       $params = array('id' => $this->_id);
       $this->_instanceValues = array();
-      CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_Instance',
+      CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_ReportInstance',
         $params,
         $this->_instanceValues
       );
index 064da4726aa3be344ed391b206c07addf02d21b1..785be24d6399cce3dd62b0b8d6752f3fe67b8672 100644 (file)
@@ -49,7 +49,7 @@ class CRM_Report_Form_Instance {
       );
     }
 
-    $attributes = CRM_Core_DAO::getAttribute('CRM_Report_DAO_Instance');
+    $attributes = CRM_Core_DAO::getAttribute('CRM_Report_DAO_ReportInstance');
 
     $form->add('text',
       'title',
@@ -255,7 +255,7 @@ class CRM_Report_Form_Instance {
       $params['navigation'] = $form->_navigation;
     }
 
-    $instance = CRM_Report_BAO_Instance::create($params);
+    $instance = CRM_Report_BAO_ReportInstance::create($params);
     $form->set('id', $instance->id);
 
     if ($instanceID && !$isNew) {
index 84cb0a54cd909a8941a8d644208422d5592651d0..7c9377e97ccf2605590a918820b597995aa50d99 100644 (file)
@@ -58,8 +58,8 @@ class CRM_Report_Page_Instance extends CRM_Core_Page {
         CRM_Core_Error::statusBounce($statusMessage, $reportUrl);
       }
 
-      $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_Instance', $instanceId, 'navigation_id', 'id');
-      CRM_Report_BAO_Instance::delete($instanceId);
+      $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceId, 'navigation_id', 'id');
+      CRM_Report_BAO_ReportInstance::del($instanceId);
 
       //delete navigation if exists
       if ($navId) {
@@ -88,7 +88,7 @@ class CRM_Report_Page_Instance extends CRM_Core_Page {
 
       if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) {
         $instanceInfo = array();
-        CRM_Report_BAO_Instance::retrieve(array('id' => $instanceId), $instanceInfo);
+        CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo);
 
         if (!empty($instanceInfo['title'])) {
           CRM_Utils_System::setTitle($instanceInfo['title']);
index c7afe94ee1494878fcbf966f3b744e69ff482701..8a0ea1719f0dd430e6de16f51251e1416a0d3206 100644 (file)
@@ -37,7 +37,7 @@ class CRM_Report_Utils_Report {
 
   static function getValueFromUrl($instanceID = NULL) {
     if ($instanceID) {
-      $optionVal = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_Instance',
+      $optionVal = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance',
         $instanceID,
         'report_id'
       );
@@ -103,7 +103,7 @@ WHERE  TRIM(BOTH '/' FROM CONCAT(report_id, '/', name)) = %1";
     if ($instanceID) {
       $drilldownInstanceID = false;
       if (array_key_exists($urlValue, $drilldownReport))
-        $drilldownInstanceID = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_Instance', $instanceID, 'drilldown_id', 'id');
+        $drilldownInstanceID = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceID, 'drilldown_id', 'id');
 
       if (!$drilldownInstanceID)
         $drilldownInstanceID = self::getInstanceIDForValue($urlValue);
@@ -150,7 +150,7 @@ WHERE  inst.report_id = %1";
 
     $params = array('id' => $instanceID);
     $instanceInfo = array();
-    CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_Instance',
+    CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_ReportInstance',
       $params,
       $instanceInfo
     );
@@ -280,7 +280,7 @@ WHERE  inst.report_id = %1";
 
     $instanceValues = array();
     $params = array('id' => $instanceId);
-    CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_Instance',
+    CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_ReportInstance',
       $params,
       $instanceValues
     );
@@ -312,7 +312,7 @@ WHERE  inst.report_id = %1";
 
     $instanceValues = array();
     $params = array('id' => $instanceId);
-    CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_Instance',
+    CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_ReportInstance',
       $params,
       $instanceValues
     );
@@ -349,7 +349,7 @@ WHERE  inst.report_id = %1";
     $is_error     = 0;
     if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) {
       $instanceInfo = array();
-      CRM_Report_BAO_Instance::retrieve(array('id' => $instanceId), $instanceInfo);
+      CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo);
 
       if (!empty($instanceInfo['title'])) {
         $obj->assign('reportTitle', $instanceInfo['title']);
index e6469cff87e35c1f38620ecb2d66ca09887f4f87..3b887d6f4141d6774db1a5969669991e7316642d 100644 (file)
@@ -874,7 +874,7 @@ ALTER TABLE civicrm_financial_account
         $saveDao = new CRM_Contact_DAO_SavedSearch();
       }
       else {
-        $saveDao = new CRM_Report_DAO_Instance();
+        $saveDao = new CRM_Report_DAO_ReportInstance();
       }
       $saveDao->id = $dao->id;
 
index 750c7b320cfc67d7c5304228f8c04c3f20fe3198..baa604d5a8ce74cc4d13be9ef602cc4805db9170 100644 (file)
@@ -83,7 +83,7 @@ class CRM_Upgrade_Incremental_php_ThreeFour {
       }
 
       // save updated instance criteria
-      $dao              = new CRM_Report_DAO_Instance();
+      $dao              = new CRM_Report_DAO_ReportInstance();
       $dao->id          = $instances->id;
       $dao->form_values = serialize($formValues);
       $dao->save();
@@ -193,7 +193,7 @@ INSERT INTO civicrm_location_type ( name, description, is_reserved, is_active )
       }
 
       // save updated instance criteria
-      $dao              = new CRM_Report_DAO_Instance();
+      $dao              = new CRM_Report_DAO_ReportInstance();
       $dao->id          = $instances->id;
       $dao->form_values = serialize($formValues);
       $dao->save();
@@ -273,7 +273,7 @@ INSERT INTO civicrm_location_type ( name, description, is_reserved, is_active )
       }
 
       // save updated instance criteria
-      $dao              = new CRM_Report_DAO_Instance();
+      $dao              = new CRM_Report_DAO_ReportInstance();
       $dao->id          = $instances->id;
       $dao->form_values = serialize($formValues);
       $dao->save();
diff --git a/api/v3/ReportInstance.php b/api/v3/ReportInstance.php
new file mode 100644 (file)
index 0000000..3809b4c
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * Retrieve a report instance
+ *
+ * FIXME This is a bare-minimum placeholder
+ *
+ * @param  array  $ params input parameters
+ *
+ * {@example OptionValueGet.php 0}
+ * @example OptionValueGet.php
+ *
+ * @return  array details of found Option Values
+ * {@getfields OptionValue_get}
+ * @access public
+ */
+function civicrm_api3_report_instance_get($params) {
+  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ *  Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions).
+ *
+ * Allowed @params array keys are:
+ *
+ * {@example OptionValueCreate.php}
+ *
+ * @return array of newly created option_value property values.
+ * {@getfields OptionValue_create}
+ * @access public
+ */
+function civicrm_api3_report_instance_create($params) {
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Adjust Metadata for Create action
+ *
+ * The metadata is used for setting defaults, documentation & validation
+ * @param array $params array or parameters determined by getfields
+ */
+function _civicrm_api3_report_instance_create_spec(&$params) {
+  $params['report_id']['api.required'] = 1;
+  $params['title']['api.required'] = 1;
+}
+
+/**
+ * Deletes an existing ReportInstance
+ *
+ * @param  array  $params
+ *
+ * {@example ReportInstanceDelete.php 0}
+ *
+ * @return array Api result
+ * {@getfields ReportInstance_create}
+ * @access public
+ */
+function civicrm_api3_report_instance_delete($params) {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
index aabe93de977bf39057c754fbedc5e838f7617b85..0f0efa1609f49daf951734a95577884162b30fc1 100644 (file)
@@ -2,7 +2,7 @@
 
 <table>
   <base>CRM/Report</base>
-  <class>Instance</class>
+  <class>ReportInstance</class>
   <name>civicrm_report_instance</name>
   <comment>Users can save their report instance and put in a cron tab etc.</comment>
   <add>2.2</add>