Ignore:
Timestamp:
May 28, 2004, 11:56:07 PM (21 years ago)
Author:
z0rglub
Message:

table user_category dropped

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r394 r423  
    276276  mysql_query( $query );
    277277
    278   // destruction of the categories informations linked with the user
    279   $query = 'DELETE FROM '.PREFIX_TABLE.'user_category';
    280   $query.= ' WHERE user_id = '.$user_id;
    281   $query.= ';';
    282   mysql_query( $query );
    283 
    284278  // destruction of the user
    285279  $query = 'DELETE FROM '.USERS_TABLE;
     
    632626
    633627/**
    634  * prepares the query to update the table user_category
    635  *
    636  * Prepares the query (global variable $values) to update table
    637  * user_category : for a couple (user,category) the number of sub-categories
    638  * and the last date of the category (all sub-categories taken into
    639  * account). It also calls function update_uppercats for each category. The
    640  * function is recursive.
    641  *
    642  * @param array $categories
    643  * @return void
    644  */
    645 function update_user_category( $categories )
    646 {
    647   global $page,$user_restrictions,$value_num,$values;
    648 
    649   foreach ( $categories as $category ) {
    650     // recursive call
    651     update_user_category( $category['subcats'] );
    652     // 1. update the table user_category
    653     foreach ( $user_restrictions as $user_id => $restrictions ) {
    654       // if the category is forbidden to this user, go to next user
    655       if ( in_array( $category['id'], $restrictions ) ) continue;
    656 
    657       // how many sub_categories for this user ?
    658       $user_subcats = array_diff(
    659         $page['plain_structure'][$category['id']]['direct_subcats_ids'],
    660         $restrictions );
    661       $user_nb_subcats = count( array_unique( $user_subcats ) );
    662       // last date of the category
    663       $user_all_subcats = array_unique( array_diff(
    664         $page['plain_structure'][$category['id']]['all_subcats_ids'],
    665         $restrictions ) );
    666            
    667       $query = 'SELECT MAX(date_last) AS last_date';
    668       $query.= ' FROM '.CATEGORIES_TABLE;
    669       $query.= ' WHERE id IN ('.$category['id'];
    670       if ( count( $user_all_subcats ) > 0 )
    671         $query.= ','.implode( ',', $user_all_subcats );
    672       $query.= ')';
    673       $query.= ';';
    674       $row = mysql_fetch_array( mysql_query( $query ) );
    675 
    676       // insert a new line in database
    677       if ( $value_num++ > 0 ) $values.= ', ';
    678       else                    $values.= ' ';
    679       $values.= '('.$user_id.",".$category['id'];
    680       if ( isset( $row['last_date'] ) ) $values.= ",'".$row['last_date']."'";
    681       else                              $values.= ',NULL';
    682       $values.= ','.$user_nb_subcats.')';
    683     }
    684     update_uppercats( $category['id'] );
    685   }
    686 }
    687 
    688 /**
    689628 * updates the column categories.uppercats
    690629 *
     
    799738
    800739/**
    801  * finalizes operation for user_category table update
    802  *
    803  * This function is called by synchronization_*. It creates the
    804  * $page['plain_structure'] and $page['structure'], get the SQL query to
    805  * update user_category, clean user_category, and finally update the
    806  * table. The users updates depends on the global array $user_restrictions.
    807  *
    808  * @return void
    809  */
    810 function synchronize()
    811 {
    812   global $user_restrictions,$page,$values;
    813 
    814   update_user_category( $page['structure'] );
    815 
    816   // cleaning user_category table for users to update
    817   foreach( $user_restrictions as $user_id => $restrictions ) {
    818     $query = 'DELETE';
    819     $query.= ' FROM '.USER_CATEGORY_TABLE;
    820     $query.= ' WHERE user_id = '.$user_id;
    821     $query.= ';';
    822     mysql_query( $query );
    823   }
    824 
    825   $query = 'INSERT INTO '.USER_CATEGORY_TABLE;
    826   $query.= ' (user_id,category_id,date_last,nb_sub_categories) VALUES ';
    827   $query.= $values;
    828   $query.= ';';
    829   mysql_query( $query );
    830 }
    831 
    832 /**
    833  * synchronizes all users calculated informations
    834  *
    835  * fills global array $user_restrictions with all users and related
    836  * restrictions before calling synchronize.
    837  *
    838  * @return void
    839  */
    840 function synchronize_all_users()
    841 {
    842   global $user_restrictions,$page;
    843 
    844   $page['plain_structure'] = get_plain_structure();
    845   $page['structure']       = create_structure( '' );
    846  
    847   $user_restrictions = array();
    848  
    849   $query = 'SELECT id';
    850   $query.= ' FROM '.USERS_TABLE;
    851   $query.= ';';
    852   $result = mysql_query( $query );
    853   while ( $row = mysql_fetch_array( $result ) )
    854   {
    855     $user_restrictions[$row['id']] = update_user_restrictions( $row['id'] );
    856   }
    857   synchronize();
    858 }
    859 
    860 /**
    861  * synchronizes 1 user calculated informations
    862  *
    863  * fills global array $user_restrictions with the user id and its related
    864  * restrictions before calling synchronize.
    865  *
    866  * @param int $user_id
    867  * @return void
    868  */
    869 function synchronize_user( $user_id )
    870 {
    871   global $user_restrictions,$page;
    872 
    873   $page['plain_structure'] = get_plain_structure();
    874   $page['structure']       = create_structure( '' );
    875  
    876   $user_restrictions = array();
    877   $user_restrictions[$user_id] = update_user_restrictions( $user_id );
    878   synchronize();
    879 }
    880 
    881 /**
    882  * synchronizes all users (belonging to the group) calculated informations
    883  *
    884  * fills global array $user_restrictions with all users and related
    885  * restrictions before calling synchronize.
    886  *
    887  * @return void
    888  */
    889 function synchronize_group( $group_id )
    890 {
    891   global $user_restrictions,$page;
    892 
    893   $page['plain_structure'] = get_plain_structure();
    894   $page['structure']       = create_structure( '' );
    895  
    896   $user_restrictions = array();
    897  
    898   $query = 'SELECT id';
    899   $query.= ' FROM '.USERS_TABLE;
    900   $query.= ', '.USER_GROUP_TABLE;
    901   $query.= ' WHERE group_id = '.$group_id;
    902   $query.= ' AND id = user_id';
    903   $query.= ';';
    904   $result = mysql_query( $query );
    905   while ( $row = mysql_fetch_array( $result ) )
    906   {
    907     $user_restrictions[$row['id']] = update_user_restrictions( $row['id'] );
    908   }
    909   synchronize();
    910 }
    911 
    912 /**
    913740 * updates the calculated data users.forbidden_categories, it includes
    914741 * sub-categories of the direct forbidden categories
Note: See TracChangeset for help on using the changeset viewer.