fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [9291] Added search statistics


From: Alexander Stevenson
Subject: [Fmsystem-commits] [9291] Added search statistics
Date: Mon, 07 May 2012 08:59:07 +0000

Revision: 9291
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9291
Author:   andvare
Date:     2012-05-07 08:59:06 +0000 (Mon, 07 May 2012)
Log Message:
-----------
Added search statistics

Modified Paths:
--------------
    branches/dev-thomasez/booking/inc/class.menu.inc.php
    branches/dev-thomasez/booking/inc/class.uireports.inc.php
    branches/dev-thomasez/booking/setup/phpgw_no.lang
    branches/dev-thomasez/booking/setup/setup.inc.php
    branches/dev-thomasez/booking/setup/tables_current.inc.php
    branches/dev-thomasez/booking/setup/tables_update.inc.php
    branches/dev-thomasez/bookingfrontend/inc/class.bosearch.inc.php
    branches/dev-thomasez/bookingfrontend/setup/setup.inc.php

Added Paths:
-----------
    branches/dev-thomasez/booking/inc/class.sosearchcount.inc.php
    branches/dev-thomasez/booking/templates/base/report_searchterms.xsl
    branches/dev-thomasez/bookingfrontend/setup/tables_update.inc.php

Modified: branches/dev-thomasez/booking/inc/class.menu.inc.php
===================================================================
--- branches/dev-thomasez/booking/inc/class.menu.inc.php        2012-05-07 
08:05:41 UTC (rev 9290)
+++ branches/dev-thomasez/booking/inc/class.menu.inc.php        2012-05-07 
08:59:06 UTC (rev 9291)
@@ -212,6 +212,12 @@
                             'text'  => lang('Free time'),
                             'url'   => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction'=> 'booking.uireports.freetime') ),
                                                        'image' => 
array('property', 'report'),
+                        ),
+                        'search_terms' => array
+                        (
+                            'text'  => lang('Search terms'),
+                            'url'   => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction'=> 'booking.uireports.searchterms') ),
+                                                                       'image' 
=> array('property', 'report'),
                         )
                     )       
                 ),      

Added: branches/dev-thomasez/booking/inc/class.sosearchcount.inc.php
===================================================================
--- branches/dev-thomasez/booking/inc/class.sosearchcount.inc.php               
                (rev 0)
+++ branches/dev-thomasez/booking/inc/class.sosearchcount.inc.php       
2012-05-07 08:59:06 UTC (rev 9291)
@@ -0,0 +1,45 @@
+<?php
+       phpgw::import_class('booking.socommon');
+       
+       /*
+       *       Class for search counter. Refers to database table 
bb_searchcount
+       *       Database object has these attribues:
+       *       id - sequence number
+       *       term - a term that is being searched for
+       *       period - YYYYMM, which month/year the search is done
+       */
+       class booking_searchcount extends booking_socommon
+       {
+               function __construct()
+               {
+                       parent::__construct( 'bb_searchcount', 
+                               array(
+                                       'id'            => array( 'type' => 
'int'),
+                                       'term'  => array( 'type' => 'string', 
'query' => true),
+                                       'period'        => array( 'type' => 
'int', 'required' => true),
+                                       'count' => array( 'type' => 'int', 
'required' => true ),
+                               )
+                       );
+               }
+
+               function increaseTerm( $term, $period = -1 ) {
+
+                       // Set period to now if not specified
+                       if( $period == -1 ) $period = date( "Ym" );
+
+                       // Make sure term always is lower case. We can skip 
this if phpGroupware supports CITEXT?
+                       $term = strtolower( $term );
+
+                       // Check for existing record
+                       $query = "SELECT count FROM bb_searchcount WHERE 
term='" . $term . "' AND period=" . $period . ";";
+//                     error_log( $query );
+                       $this->db->query( $query, __LINE__, __FILE__ );
+                       if( $GLOBALS['phpgw']->db->next_record())
+                       {
+                               // $previousCount = $GLOBALS['phpgw']->db->f( 
'count', false );
+                               $this->db->query( "UPDATE bb_searchcount SET 
count=count+1 WHERE term='" . $term . "' AND period=" . $period . ";", 
__LINE__, __FILE__ );
+                       } else {
+                               $this->db->query( "INSERT INTO bb_searchcount ( 
term, period, count ) VALUES ( '" . $term . "', " . $period . ", 1 );" );
+                       }
+               }
+       }

Modified: branches/dev-thomasez/booking/inc/class.uireports.inc.php
===================================================================
--- branches/dev-thomasez/booking/inc/class.uireports.inc.php   2012-05-07 
08:05:41 UTC (rev 9290)
+++ branches/dev-thomasez/booking/inc/class.uireports.inc.php   2012-05-07 
08:59:06 UTC (rev 9291)
@@ -9,6 +9,7 @@
                        'index'                 =>      true,
                        'participants'          =>      true,
                        'freetime'              =>      true,
+                       'searchterms'              =>      true,
                );
 
        public function __construct()
@@ -23,6 +24,7 @@
        {
                $reports[] = array('name' => lang('Participants Per Age Group 
Per Month'), 'url' => self::link(array('menuaction' => 
'booking.uireports.participants')));
                $reports[] = array('name' => lang('Free time'), 'url' => 
self::link(array('menuaction' => 'booking.uireports.freetime')));
+               $reports[] = array('name' => lang('Search terns'), 'url' => 
self::link(array('menuaction' => 'booking.uireports.searchterms')));
 
                self::render_template('report_index',
                array('reports' => $reports));
@@ -136,6 +138,66 @@
                                array('show' => $show, 'from' => $from, 'to' => 
$to, 'buildings' => $buildings['results'], 'allocations' => 
$allocations['results']));
        }
 
+       // Merge similar terms from different months. Used when displaying 
search counters from several months and/or years.
+       private function mergeSimilarTerms( $terms ) {
+               $newTerms = array();
+               $newTermsIntKey = array();
+               foreach( $terms as $id => $data ) {
+                       error_log( $id );
+                       if( array_key_exists( $data['term'], $newTerms ) ) {
+                               $newTerms[$data['term']]['count'] += 
$data['count'];
+                       } else {
+                               $newTerms[$data['term']] = array( 'term' => 
$data['term'], 'count' => $data['count'] );
+                       }
+               }
+
+               // Convert to integer keys. phpGroupware needs keys to be 
integer in order to traverse them
+               $i = 0;
+               foreach( $newTerms as $key => $data ) {
+                       $newTermsIntKey[$i] = $data;
+                       $i++;
+               }
+               return $newTermsIntKey;
+       }
+
+
+       public function searchterms()
+       {
+               self::set_active_menu('booking::reportcenter::search_terms');
+
+               $errors = array();
+               $db = & $GLOBALS['phpgw']->db;
+
+               // Set period
+               $form_period = ( $_POST['period'] ? $_POST['period'] : 
date("Y-m-d" ) );
+               $year = date( "Y", strtotime( $form_period ) );
+               $month = date( "m", strtotime( $form_period ) );
+               $database_period = $year . $month;
+
+               // Get search terms
+               switch( $_POST['dimension'] ) {
+                       case "forever":
+                               $sql = "SELECT term,count FROM bb_searchcount 
ORDER BY count DESC";
+                               break;
+                       case "year":
+                               $sql = "SELECT term,count FROM bb_searchcount 
WHERE period>=" . $year . "01 AND period<=" . $year . "12 ORDER BY count DESC";
+                               break;
+                       default: // Month
+                               $sql = "SELECT term,count FROM bb_searchcount 
WHERE period=" . $database_period . " ORDER BY count DESC";
+                               break;
+               }
+               $db->query( $sql );
+               $terms = $db->resultSet;
+               error_log( var_export( $terms, true ) );
+               $terms = $this->mergeSimilarTerms(  $terms );
+               error_log( var_export( $terms, true ) );
+               self::render_template('report_searchterms', array(
+                       "period" => $form_period,
+                       "terms" => $terms,
+                       "dimension" => $_POST['dimension']
+               ) );
+       }
+
        private function get_free_allocations($buildings, $from, $to, $weekdays)
        {
                $db = & $GLOBALS['phpgw']->db;

Modified: branches/dev-thomasez/booking/setup/phpgw_no.lang
===================================================================
--- branches/dev-thomasez/booking/setup/phpgw_no.lang   2012-05-07 08:05:41 UTC 
(rev 9290)
+++ branches/dev-thomasez/booking/setup/phpgw_no.lang   2012-05-07 08:59:06 UTC 
(rev 9291)
@@ -568,3 +568,11 @@
 Animals        booking no      Tillatt med dyr?
 Internett/phone        booking no      Internett/telefon
 Handicap       booking no      Handikap
+Search terms   booking no      Søkeord
+View results from...   booking no      Vis resultat fra...
+Month  booking no      Måned
+Year   booking no      År
+Forever        booking no      All tid
+View search terms      booking no      Vis søkeord
+Term   booking no      Ord/begrep
+Count  booking no      Antall

Modified: branches/dev-thomasez/booking/setup/setup.inc.php
===================================================================
--- branches/dev-thomasez/booking/setup/setup.inc.php   2012-05-07 08:05:41 UTC 
(rev 9290)
+++ branches/dev-thomasez/booking/setup/setup.inc.php   2012-05-07 08:59:06 UTC 
(rev 9291)
@@ -1,5 +1,5 @@
 <?php
-       $setup_info['booking']['version'] = '0.2.13';
+       $setup_info['booking']['version'] = '0.2.14';
        $setup_info['booking']['name'] = 'booking';
        $setup_info['booking']['app_order'] = 9;
        $setup_info['booking']['enable'] = 1;
@@ -55,7 +55,8 @@
                'bb_system_message',
                'bb_office',
                'bb_office_user',
-               'bb_documentation'
+               'bb_documentation',
+               'bb_searchcount'
        );
 
        $setup_info['booking']['description'] = 'Bergen kommune booking';

Modified: branches/dev-thomasez/booking/setup/tables_current.inc.php
===================================================================
--- branches/dev-thomasez/booking/setup/tables_current.inc.php  2012-05-07 
08:05:41 UTC (rev 9290)
+++ branches/dev-thomasez/booking/setup/tables_current.inc.php  2012-05-07 
08:59:06 UTC (rev 9291)
@@ -857,4 +857,16 @@
                        'ix' => array(),
                        'uc' => array()
                ),
+               'bb_searchcount' => array(
+                       'fd' => array(
+                               'id' => array('type' => 'auto', 'nullable' => 
False),
+                               'term' => array('type' => 'text', 'nullable' => 
False),
+                               'period' => array('type' => 'int', 'nullable' 
=> False,'precision' => '8', 'default' => '0' ),
+                               'count' => array('type' => 'int', 'nullable' => 
False,'precision' => '8', 'default' => '0' )
+                       ),
+                       'pk' => array('id'),
+                       'fk' => array(),
+                       'ix' => array(),
+                       'uc' => array('id')
+               ),
        );

Modified: branches/dev-thomasez/booking/setup/tables_update.inc.php
===================================================================
--- branches/dev-thomasez/booking/setup/tables_update.inc.php   2012-05-07 
08:05:41 UTC (rev 9290)
+++ branches/dev-thomasez/booking/setup/tables_update.inc.php   2012-05-07 
08:59:06 UTC (rev 9291)
@@ -2746,3 +2746,30 @@
                }
        }
 
+       $test[] = '0.2.13';
+       function booking_upgrade0_2_13()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+               $GLOBALS['phpgw_setup']->oProc->CreateTable(
+                       'bb_searchcount', array(
+                               'fd' => array(
+                                       'id' => array('type' => 'auto', 
'nullable' => False),
+                                       'term' => array('type' => 'text', 
'nullable' => False),
+                                       'period' => array('type' => 'int', 
'nullable' => False, 'precision' => '8', 'default' => '0' ),
+                                       'count' => array('type' => 'int', 
'nullable' => False, 'precision' => '8', 'default' => '0' )
+                               ),
+                               'pk' => array('id'),
+                               'fk' => array(),
+                               'ix' => array(),
+                               'uc' => array('id')
+                       )
+               );
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['booking']['currentver'] = 
'0.2.14';
+                       echo( "SUxESS!!" );
+                       return $GLOBALS['setup_info']['booking']['currentver'];
+               }
+               echo( "Feil!!" );
+       }
+

Added: branches/dev-thomasez/booking/templates/base/report_searchterms.xsl
===================================================================
--- branches/dev-thomasez/booking/templates/base/report_searchterms.xsl         
                (rev 0)
+++ branches/dev-thomasez/booking/templates/base/report_searchterms.xsl 
2012-05-07 08:59:06 UTC (rev 9291)
@@ -0,0 +1,58 @@
+<xsl:template match="data" xmlns:php="http://php.net/xsl";>
+       <div id="content">
+
+               <xsl:call-template name="msgbox"/>
+               <xsl:call-template name="yui_booking_i18n"/>
+               <dl class="form">
+                       <dt class="heading">
+                               <xsl:value-of select="php:function('lang', 
'Search terms')" />
+                       </dt>
+               </dl>
+
+               <form action="" method="POST">
+                       <dl class="form-col">
+                               <dt><label for="field_period"><xsl:value-of 
select="php:function('lang', 'Date')" /></label></dt>
+                               <dd>
+                                       <div class="date-picker">
+                                               <input id="field_period" 
name="period" type="text">
+                                                       <xsl:attribute 
name="value"><xsl:value-of select="period"/></xsl:attribute>
+                                               </input>
+                                       </div>
+                               </dd>
+                       </dl>
+                       <dl class="form-col">
+                               <dt><label for="field_dimension"><xsl:value-of 
select="php:function('lang', 'View results from...')" /></label></dt>
+                               <dd>
+                                       <select id="field_dimension" 
name="dimension">
+                                               <option 
value="month"><xsl:value-of select="php:function('lang', 'Month')" /></option>
+                                               <option 
value="year"><xsl:value-of select="php:function('lang', 'Year')" /></option>
+                                               <option 
value="forever"><xsl:value-of select="php:function('lang', 'Forever')" 
/></option>
+                                       </select>
+                               </dd>
+                       </dl>
+                       <dl class="form-col">
+                               <input type="submit">
+                                       <xsl:attribute 
name="value"><xsl:value-of select="php:function('lang', 'View search 
terms')"/></xsl:attribute>
+                               </input>
+                       </dl>
+                       <div class="form-buttons">
+                       </div>
+               </form>
+               <table id="report">
+                       <thead>
+                               <tr>
+                                       <th><xsl:value-of 
select="php:function('lang', 'Term')"/></th>
+                                       <th><xsl:value-of 
select="php:function('lang', 'Count')"/></th>
+                               </tr>
+                       </thead>
+                       <tbody>
+                               <xsl:for-each select="terms">
+                                       <tr>
+                                               <td><xsl:value-of 
select="term"/></td>
+                                               <td><xsl:value-of 
select="count"/></td>
+                                       </tr>
+                               </xsl:for-each>
+                       </tbody>
+               </table>
+       </div>
+</xsl:template>

Modified: branches/dev-thomasez/bookingfrontend/inc/class.bosearch.inc.php
===================================================================
--- branches/dev-thomasez/bookingfrontend/inc/class.bosearch.inc.php    
2012-05-07 08:05:41 UTC (rev 9290)
+++ branches/dev-thomasez/bookingfrontend/inc/class.bosearch.inc.php    
2012-05-07 08:59:06 UTC (rev 9291)
@@ -1,5 +1,6 @@
 <?php
        phpgw::import_class('booking.bocommon');
+       phpgw::import_class( 'booking.sosearchcount' );
        
        class bookingfrontend_bosearch extends booking_bocommon
        {
@@ -234,6 +235,9 @@
                        $final_array = array_merge_recursive($bui_result, 
$org_result, $res_result);
                        $final_array['total_records_sum']       =       
array_sum((array)$final_array['total_records']);
                        
+                       // Finally increase search counter
+                       $counter = new booking_searchcount();
+                       $counter->increaseTerm( $searchterm );
                        return $final_array;
                }
        }

Modified: branches/dev-thomasez/bookingfrontend/setup/setup.inc.php
===================================================================
--- branches/dev-thomasez/bookingfrontend/setup/setup.inc.php   2012-05-07 
08:05:41 UTC (rev 9290)
+++ branches/dev-thomasez/bookingfrontend/setup/setup.inc.php   2012-05-07 
08:59:06 UTC (rev 9291)
@@ -1,6 +1,6 @@
 <?php
        $setup_info['bookingfrontend']['name'] = 'bookingfrontend';
-       $setup_info['bookingfrontend']['version'] = '0.1';
+       $setup_info['bookingfrontend']['version'] = '0.1.1';
        $setup_info['bookingfrontend']['app_order'] = 9;
        $setup_info['bookingfrontend']['enable'] = 1;
        $setup_info['bookingfrontend']['app_group']     = 'office';
@@ -21,7 +21,7 @@
 
        $setup_info['bookingfrontend']['depends'][] = array(
                'appname' => 'booking',
-               'versions' => Array('0.2.00', 
'0.2.01','0.2.02','0.2.03','0.2.04','0.2.05','0.2.06','0.2.07','0.2.08','0.2.09','0.2.10','0.2.11','0.2.12','0.2.13')
+               'versions' => Array( '0.2.14' )
        );
 
        $setup_info['bookingfrontend']['depends'][] = array(

Added: branches/dev-thomasez/bookingfrontend/setup/tables_update.inc.php
===================================================================
--- branches/dev-thomasez/bookingfrontend/setup/tables_update.inc.php           
                (rev 0)
+++ branches/dev-thomasez/bookingfrontend/setup/tables_update.inc.php   
2012-05-07 08:59:06 UTC (rev 9291)
@@ -0,0 +1,9 @@
+<?php
+
+       // Upgrade to 0.1.1 because we have changed dependency requirements. 
Only works with booking v 0.2.14 (or higher) now.
+       $test[] = '0.1';
+       function bookingfrontend_upgrade0_1()
+       {
+               $GLOBALS['setup_info']['bookingfrontend']['currentver'] = 
'0.1.1';
+               return $GLOBALS['setup_info']['bookingfrontend']['currentver'];
+       }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]