View Issue Details

IDProjectCategoryView StatusLast Update
0008656mantisbtapi soappublic2023-02-17 19:13
Reportermwietscher Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status confirmedResolutionopen 
Product Version1.1.0rc3 
Summary0008656: please provide function that return issue count of current filter
Description

to be able to design a usable browsing functionality (first, previous, 1, 2, 3, ... 99, next, last) it would be necessary to know the number of issues that fit to current filter

please please provide us with function like

int mc_filter_get_issue_count(username, password, project_id, filter_id)

i know too less about php to do it on my own

TagsNo tags attached.
Attached Files
mantis-8656.patch (5,004 bytes)   
diff -urN mantis.orig/api/soap/mantisconnect.wsdl mantis/api/soap/mantisconnect.wsdl
--- mantis.orig/api/soap/mantisconnect.wsdl     2015-01-25 18:00:30.000000000 -0500
+++ mantis/api/soap/mantisconnect.wsdl  2015-10-25 16:34:05.000000000 -0400
@@ -738,6 +738,13 @@
   <part name="per_page" type="xsd:integer" /></message>
 <message name="mc_filter_get_issuesResponse">
   <part name="return" type="tns:IssueDataArray" /></message>
+<message name="mc_filter_get_issue_countRequest">
+  <part name="username" type="xsd:string" />
+  <part name="password" type="xsd:string" />
+  <part name="project_id" type="xsd:integer" />
+  <part name="filter_id" type="xsd:integer" /></message>
+<message name="mc_filter_get_issue_countResponse">
+  <part name="return" type="xsd:integer" /></message>
 <message name="mc_filter_get_issue_headersRequest">
   <part name="username" type="xsd:string" />
   <part name="password" type="xsd:string" />
@@ -1089,6 +1096,11 @@
     <input message="tns:mc_filter_get_issuesRequest"/>
     <output message="tns:mc_filter_get_issuesResponse"/>
   </operation>
+  <operation name="mc_filter_get_issue_count">
+    <documentation>Get the count of issues that match the specified filter.</documentation>
+    <input message="tns:mc_filter_get_issue_countRequest"/>
+    <output message="tns:mc_filter_get_issue_countResponse"/>
+  </operation>
   <operation name="mc_filter_get_issue_headers">
     <documentation>Get the issue headers that match the specified filter and paging details.  Pass &quot;-1&quot; for the per_page parameter to get all issues.</documentation>
     <input message="tns:mc_filter_get_issue_headersRequest"/>
@@ -1427,6 +1439,11 @@
     <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
     <output><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
   </operation>
+  <operation name="mc_filter_get_issue_count">
+    <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_filter_get_issue_count" style="rpc"/>
+    <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
+    <output><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
+  </operation>
   <operation name="mc_filter_get_issue_headers">
     <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_filter_get_issue_headers" style="rpc"/>
     <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
diff -urN mantis.orig/api/soap/mc_filter_api.php mantis/api/soap/mc_filter_api.php
--- mantis.orig/api/soap/mc_filter_api.php      2015-01-25 18:00:30.000000000 -0500
+++ mantis/api/soap/mc_filter_api.php   2015-10-25 16:38:23.000000000 -0400
@@ -84,6 +84,46 @@
 }
 
 /**
+ * Get count of issues matching the specified filter.
+ *
+ * @param string $p_username  The name of the user trying to access the filters.
+ * @param string $p_password  The password of the user.
+ * @param integer $p_project_id  The id of the project to retrieve filters for.
+ * @param integer $p_filter_id  The id of the filter to apply.
+ * @return Array that represents an IssueDataArray structure
+ */
+function mc_filter_get_issue_count( $p_username, $p_password, $p_project_id, $p_filter_id) {
+       $t_user_id = mci_check_login( $p_username, $p_password );
+       if( $t_user_id === false ) {
+               return mci_soap_fault_login_failed();
+       }
+       $t_lang = mci_get_user_lang( $t_user_id );
+       
+       if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
+               return mci_soap_fault_access_denied( $t_user_id );
+       }
+
+       $p_page_number = 0;
+       $p_per_page = -1;
+
+       $t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
+       $t_page_count = 0;
+       $t_bug_count = 0;
+       $t_filter = filter_db_get_filter( $p_filter_id );
+       $t_filter_detail = explode( '#', $t_filter, 2 );
+       if( !isset( $t_filter_detail[1] ) ) {
+               return SoapObjectsFactory::newSoapFault( 'Server',  'Invalid Filter' );
+       }
+       $t_filter = unserialize( $t_filter_detail[1] );
+       $t_filter = filter_ensure_valid_filter( $t_filter );
+
+       $t_result = array();
+       $t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, $t_filter, $p_project_id );
+
+       return $t_bug_count;
+}
+
+/**
  * Get the issue headers that match the specified filter and paging details.
  *
  * @param string $p_username  The name of the user trying to access the filters.

mantis-8656.patch (5,004 bytes)   

Relationships

related to 0025881 new Get ticket count from REST API 
related to 0017121 closeddregad phpunit FilterTest fail if there are more than 50 issues in the tracker 

Activities

winston

winston

2012-12-03 11:44

reporter   ~0034453

Doesn't using mc_filter_get_issues() or mc_filter_get_issue_headers() with per_page = -1 solve this issue?

rombert

rombert

2012-12-08 07:15

reporter   ~0034506

How would that work?

winston

winston

2012-12-08 07:58

reporter   ~0034507

Documentation of those functions says: 'Pass "-1" for the per_page parameter to get all issues.' - so there is a way to know the number of bugs that fit the filter.

rombert

rombert

2012-12-09 07:25

reporter   ~0034509

Right, but you'll always retrieve the full bug listing which probably isn't what you want from a performance point of view.

atrol

atrol

2014-01-21 16:20

developer   ~0039124

Unassigned after having been assigned for a long time without progress.

rewt

rewt

2015-10-25 18:20

reporter   ~0051723

Attached is a patch for this issue which applies to Mantis 1.2.19 to add mc_filter_get_issue_count.

rombert

rombert

2015-10-26 05:49

reporter   ~0051724

@rewt, thanks for the patch! I have a couple of comments

dregad

dregad

2015-10-26 08:19

developer   ~0051725

Also, if it's not too much trouble for you, we would prefer to receive patch submissions as a pull request on our Github repo [1], as it facilitates the code review and merging process.

Thanks !

[1] https://github.com/mantisbt/mantisbt

rewt

rewt

2015-10-26 09:01

reporter   ~0051726

@rombert - unfortunately it's filter_get_bug_rows that does all the heavy lifting. You could shim that and inject a COUNT(*) instead of the DISTINCT clause if you want to avoid the overhead of loading all the data but the performance of this was good enough for my limited needs.

Adding tests and submitting pull requests via Github both have too much friction for me right now. I don't want/need to set up a dev environment for this - it was a quick hack to scratch a particular itch that I had and I thought others might find it useful. YMMV.

dregad

dregad

2015-10-27 04:25

developer   ~0051733

OK fair enough.