Xaraya / Postnuke CVS Notices - Message

Note: this list is kept only as a demonstration for CVSNotice. For the latest CVS notices, see the Xaraya and Postnuke sites

View Statistics - Next Notice - Previous Notice

Directory filter : [ all ] / postnuke_official / html / modules / categories [ view in CVS ]


Deprecated: Function gmstrftime() is deprecated in /home/mikespub/www/list.php on line 509
Date Directory [filter] File(s) [view] Author [filter]
13 Aug 2002 22:13:13postnuke_official/html/modules/categoriespnuserapi.php,1.8,1.9Mike
 support AND-ing of categories for item selection/counting

Update of /home/cvsroot/postnuke_official/html/modules/categories
In directory ns7.hostnuke.net:/tmp/cvs-serv12800

Modified Files:
	pnuserapi.php 
Log Message:
support AND-ing of categories for item selection/counting


Index: pnuserapi.php
===================================================================
RCS file: /home/cvsroot/postnuke_official/html/modules/categories/pnuserapi.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** pnuserapi.php	11 Aug 2002 00:49:48 -0000	1.8
--- pnuserapi.php	13 Aug 2002 22:13:11 -0000	1.9
***************
*** 301,309 ****
  /**
   * get links
!  * @param $args['cids'] array of ids of categories to get linkage for
   * @param $args['iids'] array of ids of itens to get linkage for
   * @param $args['modid'] module�s ID
   * @param $args['reverse'] if set to 1 the return will have as keys the 'iids'
   *                         else the keys are the 'cids'
   * @returns array
   * @return item array, or false on failure
--- 301,312 ----
  /**
   * get links
!  * @param $args['cids'] array of ids of categories to get linkage for (OR)
   * @param $args['iids'] array of ids of itens to get linkage for
   * @param $args['modid'] module�s ID
   * @param $args['reverse'] if set to 1 the return will have as keys the 'iids'
   *                         else the keys are the 'cids'
+ // TODO: better name for params
+  * @param $args['andcids'] array of ids of categories to get linkage for (AND)
+  * @param $args['numcids'] the number of categories you want to items grouped by
   * @returns array
   * @return item array, or false on failure
***************
*** 323,333 ****
  
      // Get item IDs
!     // Reverse the order if reverse is set to 1
!     if ($reverse == 1) {
!         $sql = 'SELECT ' . $categoriesdef['iid'] . ', ' . $categoriesdef['cid'];
!     } else {
!         $sql = 'SELECT ' . $categoriesdef['cid'] . ', ' . $categoriesdef['iid'];
!     }
      $sql .= ' FROM ' . $categoriesdef['table'];
      if (!empty($categoriesdef['where'])) {
          $sql .= ' WHERE ' . $categoriesdef['where'];
--- 326,334 ----
  
      // Get item IDs
!     $sql = 'SELECT ' . $categoriesdef['cid'] . ', ' . $categoriesdef['iid'];
      $sql .= ' FROM ' . $categoriesdef['table'];
+     if (!empty($categoriesdef['more'])) {
+         $sql .= $categoriesdef['more'];
+     }
      if (!empty($categoriesdef['where'])) {
          $sql .= ' WHERE ' . $categoriesdef['where'];
***************
*** 347,351 ****
      for(; !$result->EOF; $result->MoveNext())
      {
!         $answer[$result->fields[0]][] = $result->fields[1];
      }
  
--- 348,368 ----
      for(; !$result->EOF; $result->MoveNext())
      {
!         $fields = $result->fields;
!         $iid = array_pop($fields);
!         if ($reverse == 1) {
!             // the list of categories is in the N first fields here
!             if (isset($andcids) && count($andcids) > 1) {
!                 $answer[$iid] = $fields;
!             } elseif (isset($numcids) && $numcids > 1) {
!                 $answer[$iid] = $fields;
!             // we get 1 category per record here
!             } else {
!                 $answer[$iid][] = $fields[0];
!             }
!         } else {
! // TODO: use multi-level array for multi-category grouping ?
!             $cid = join('+',$fields);
!             $answer[$cid][] = $iid;
!         }
      }
  
***************
*** 358,362 ****
  /**
   * count number of items
!  * @param $args['cids'] array of cids that we are counting for
   * @returns int
   * @return number of items
--- 375,381 ----
  /**
   * count number of items
!  * @param $args['cids'] optional array of cids we're counting for (OR)
! // TODO: better name for params
!  * @param $args['andcids'] optional array of cids we're counting for (AND)
   * @returns int
   * @return number of items
***************
*** 385,390 ****
      $categoriesdef = pnModAPIFunc('categories','user','leftjoin',$args);
  
!     $sql = 'SELECT COUNT(DISTINCT ' . $categoriesdef['iid'];
      $sql .= ' FROM ' . $categoriesdef['table'];
      if (!empty($categoriesdef['where'])) {
          $sql .= ' WHERE ' . $categoriesdef['where'];
--- 404,412 ----
      $categoriesdef = pnModAPIFunc('categories','user','leftjoin',$args);
  
!     $sql = 'SELECT COUNT(DISTINCT ' . $categoriesdef['iid'] . ')';
      $sql .= ' FROM ' . $categoriesdef['table'];
+     if (!empty($categoriesdef['more'])) {
+         $sql .= $categoriesdef['more'];
+     }
      if (!empty($categoriesdef['where'])) {
          $sql .= ' WHERE ' . $categoriesdef['where'];
***************
*** 508,511 ****
--- 530,537 ----
   * @param $args['groupby'] group entries by 'category' or by 'item'
   * @param $args['modid'] module�s ID
+  * @param $args['cids'] optional array of cids we're counting for (OR)
+ // TODO: better name for params
+  * @param $args['andcids'] optional array of cids we're counting for (AND), or
+  * @param $args['numcids'] optional grouping of categories for counting (AND)
   * @returns array
   * @return number of items per category, or caterogies per item
***************
*** 541,544 ****
--- 567,573 ----
      $sql = 'SELECT ' . $field . ', COUNT(*)';
      $sql .= ' FROM ' . $categoriesdef['table'];
+     if (!empty($categoriesdef['more'])) {
+         $sql .= $categoriesdef['more'];
+     }
      if (!empty($categoriesdef['where'])) {
          $sql .= ' WHERE ' . $categoriesdef['where'];
***************
*** 555,559 ****
      $count = array();
      while (!$result->EOF) {
!         list($id,$num) = $result->fields;
          $count[$id] = $num;
          $result->MoveNext();
--- 584,591 ----
      $count = array();
      while (!$result->EOF) {
!         $fields = $result->fields;
!         $num = array_pop($fields);
! // TODO: use multi-level array for multi-category grouping ?
!         $id = join('+',$fields);
          $count[$id] = $num;
          $result->MoveNext();
***************
*** 629,634 ****
   * @param $args['modid'] your module ID (use pnModGetIDFromName('mymodule'))
   *
!  * @param $args['cids'] optional array of category ids that we are selecting on
   * @param $args['iids'] optional array of item ids that we are selecting on
   * @returns array
   * @return array('table' => 'nuke_categories_linkage',
--- 661,671 ----
   * @param $args['modid'] your module ID (use pnModGetIDFromName('mymodule'))
   *
!  * @param $args['cids'] opt. array of category ids that we are selecting on (OR)
   * @param $args['iids'] optional array of item ids that we are selecting on
+ // TODO: better name for params
+  * @param $args['andcids'] opt. array of category ids that we are selecting on
+  *                         (AND)
+  * @param $args['numcids'] the number of categories you want to group by/select
+  *                         for etc. (AND)
   * @returns array
   * @return array('table' => 'nuke_categories_linkage',
***************
*** 661,664 ****
--- 698,704 ----
          $iids = array();
      }
+     if (!isset($andcids)) {
+         $andcids = array();
+     }
  
      // Security check
***************
*** 672,676 ****
  // TODO: check this !
      foreach ($cids as $cid) {
!         if (!pnSecAuthAction(0, 'categories::category', 'ID::$cid', ACCESS_OVERVIEW)) {
              $msg = pnML('Not authorized to view #(1) #(2)',
                          'category',pnVarPrepForStore($cid));
--- 712,725 ----
  // TODO: check this !
      foreach ($cids as $cid) {
!         if (!pnSecAuthAction(0, 'categories::category', '::$cid', ACCESS_OVERVIEW)) {
!             $msg = pnML('Not authorized to view #(1) #(2)',
!                         'category',pnVarPrepForStore($cid));
!             pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION',
!                            new SystemException($msg));
!             return array();
!         }
!     }
!     foreach ($andcids as $cid) {
!         if (!pnSecAuthAction(0, 'categories::category', '::$cid', ACCESS_OVERVIEW)) {
              $msg = pnML('Not authorized to view #(1) #(2)',
                          'category',pnVarPrepForStore($cid));
***************
*** 691,694 ****
--- 740,753 ----
      }
  
+     // dummy andcids array when we're going for x categories at a time
+     if (isset($numcids) && count($andcids) == 0) {
+         $isdummy = 1;
+         for ($i = 0; $i < $numcids; $i++) {
+             $andcids[] = $i;
+         }
+     } else {
+         $isdummy = 0;
+     }
+ 
      // Table definition
      $pntable = pnDBGetTables();
***************
*** 697,708 ****
      $leftjoin = array();
  
      // Add available columns in the categories table
      $columns = array('cid','iid','modid');
      foreach ($columns as $column) {
!         $leftjoin[$column] = $categorieslinkagetable . '.pn_' . $column;
      }
  
      // Specify LEFT JOIN ... ON ... [WHERE ...] parts
!     $leftjoin['table'] = $categorieslinkagetable;
      $leftjoin['field'] = $leftjoin['iid'];
  
--- 756,795 ----
      $leftjoin = array();
  
+     // create list of tables we'll be left joining for AND
+     if (count($andcids) > 0) {
+         $catlinks = array();
+         for ($i = 0; $i < count($andcids); $i++) {
+             $catlinks[] = 'catlink' . $i;
+         }
+         $linktable = $catlinks[0];
+     } else {
+         $linktable = $categorieslinkagetable;
+     }
+ 
      // Add available columns in the categories table
      $columns = array('cid','iid','modid');
      foreach ($columns as $column) {
!         $leftjoin[$column] = $linktable . '.pn_' . $column;
      }
  
      // Specify LEFT JOIN ... ON ... [WHERE ...] parts
!     if (count($andcids) > 0) {
!         $leftjoin['table'] = $categorieslinkagetable . ' as ' . $catlinks[0];
!         $leftjoin['more'] = ' ';
!         $leftjoin['cids'] = array();
!         $leftjoin['cids'][] = $catlinks[0] . '.pn_cid';
!         for ($i = 1; $i < count($catlinks); $i++) {
!             $leftjoin['more'] .= ' LEFT JOIN ' . $categorieslinkagetable .
!                                      ' as ' . $catlinks[$i] .
!                                  ' ON ' . $leftjoin['iid'] . ' = ' .
!                                      $catlinks[$i] . '.pn_iid' .
!                                  ' AND ' . $leftjoin['modid'] . ' = ' .
!                                      $catlinks[$i] . '.pn_modid ';
!             $leftjoin['cids'][] = $catlinks[$i] . '.pn_cid';
!         }
!     } else {
!         $leftjoin['table'] = $categorieslinkagetable;
!         $leftjoin['more'] = '';
!     }
      $leftjoin['field'] = $leftjoin['iid'];
  
***************
*** 721,724 ****
--- 808,831 ----
          $where[] = $leftjoin['iid'] . ' IN (' .
                     pnVarPrepForStore($alliids) . ')';
+     }
+     if (count($andcids) > 0) {
+         // select only the 1-2-4 combination, not the 2-1-4, 4-2-1, etc.
+         if ($isdummy) {
+             $oldcid = '';
+             foreach ($leftjoin['cids'] as $cid) {
+                 if (!empty($oldcid)) {
+                     $where[] .= $oldcid . ' < ' . $cid;
+                 }
+                 $oldcid = $cid;
+             }
+         // select the categories you wanted
+         } else {
+             for ($i = 0; $i < count($andcids); $i++) {
+                 $where[] = $catlinks[$i] . '.pn_cid = ' .
+                                pnVarPrepForStore($andcids[$i]);
+             }
+         }
+         // include all cids here
+         $leftjoin['cid'] = join(', ',$leftjoin['cids']);
      }
      if (count($where) > 0) {


Directory filter : [ all ] / postnuke_official / html / modules / categories [ view in CVS ]

View Statistics - Next Notice - Previous Notice


Visit Developer Site - Browse CVS Repository Syndicate via backend.rss
(max. once per hour please)
Powered by CVSNotice 0.1.3