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 ]

Date Directory [filter] File(s) [view] Author [filter]
16 Aug 2002 14:12:31postnuke_official/html/modules/categoriespnuserapi.php,1.9,1.10Mike
 improve params for AND-ing categories

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

Modified Files:
	pnuserapi.php 
Log Message:
improve params for AND-ing categories


Index: pnuserapi.php
===================================================================
RCS file: /home/cvsroot/postnuke_official/html/modules/categories/pnuserapi.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** pnuserapi.php	13 Aug 2002 22:13:11 -0000	1.9
--- pnuserapi.php	16 Aug 2002 14:12:29 -0000	1.10
***************
*** 240,247 ****
  
  /**
!  * get info on a specific category
!  * @param $args['cid'] id of category to get info
   * @returns array
!  * @return category array, or false on failure
   */
  
--- 240,248 ----
  
  /**
!  * get info on a specific (list of) category
!  * @param $args['cid'] id of category to get info, or
!  * @param $args['cids'] array of category ids to get info
   * @returns array
!  * @return category info array, or array of cat info arrays, false on failure
   */
  
***************
*** 253,257 ****
      extract($args);
  
!     if (!isset($cid)) {
         pnSessionSetVar('errormsg', _MODARGSERROR);
         return false;
--- 254,258 ----
      extract($args);
  
!     if (!isset($cid) && !isset($cids)) {
         pnSessionSetVar('errormsg', _MODARGSERROR);
         return false;
***************
*** 270,275 ****
                          ".$categoriescolumn['left'].",
                          ".$categoriescolumn['right']."
!                    FROM $categoriestable
!                   WHERE ".$categoriescolumn['cid']."=".pnVarPrepForStore($cid);
  
      // TODO - check that start is correct (might be -1)
--- 271,281 ----
                          ".$categoriescolumn['left'].",
                          ".$categoriescolumn['right']."
!                    FROM $categoriestable ";
!     if (isset($cid)) {
!         $SQLquery .= "WHERE ".$categoriescolumn['cid']."=".pnVarPrepForStore($cid);
!     } else {
!         $allcids = join(', ',$cids);
!         $SQLquery .= "WHERE ".$categoriescolumn['cid']." IN (".pnVarPrepForStore($allcids).")";
!     }
  
      // TODO - check that start is correct (might be -1)
***************
*** 286,312 ****
      }
  
!     list($cid, $name, $description, $image, $left, $right) = $result->fields;
!     $info = Array(
!                   "cid"         => $cid,
!                   "name"        => $name,
!                   "description" => $description,
!                   "image"       => $image,
!                   "left"        => $left,
!                   "right"       => $right
!                   );
! 
!     return $info;
  }
  
  /**
   * 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
--- 292,333 ----
      }
  
!     if (isset($cid)) {
!         list($cid, $name, $description, $image, $left, $right) = $result->fields;
!         $info = Array(
!                       "cid"         => $cid,
!                       "name"        => $name,
!                       "description" => $description,
!                       "image"       => $image,
!                       "left"        => $left,
!                       "right"       => $right
!                      );
!         return $info;
!     } else {
!         $info = array();
!         while (!$result->EOF) {
!             list($cid, $name, $description, $image, $left, $right) = $result->fields;
!             $info[$cid] = Array(
!                                 "cid"         => $cid,
!                                 "name"        => $name,
!                                 "description" => $description,
!                                 "image"       => $image,
!                                 "left"        => $left,
!                                 "right"       => $right
!                                );
!             $result->MoveNext();
!         }
!         return $info;
!     }
  }
  
  /**
   * get links
!  * @param $args['cids'] array of ids of categories to get linkage for (OR/AND)
   * @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'
!  * @param $args['andcids'] true means AND-ing categories listed in cids
!  * @param $args['groupcids'] the number of categories you want items grouped by
   * @returns array
   * @return item array, or false on failure
***************
*** 328,334 ****
      $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'];
--- 349,353 ----
      $sql = 'SELECT ' . $categoriesdef['cid'] . ', ' . $categoriesdef['iid'];
      $sql .= ' FROM ' . $categoriesdef['table'];
!     $sql .= $categoriesdef['more'];
      if (!empty($categoriesdef['where'])) {
          $sql .= ' WHERE ' . $categoriesdef['where'];
***************
*** 352,358 ****
          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
--- 371,377 ----
          if ($reverse == 1) {
              // the list of categories is in the N first fields here
!             if (isset($cids) && count($cids) > 1 && $andcids) {
                  $answer[$iid] = $fields;
!             } elseif (isset($groupcids) && $groupcids > 1) {
                  $answer[$iid] = $fields;
              // we get 1 category per record here
***************
*** 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
--- 394,399 ----
  /**
   * count number of items
!  * @param $args['cids'] optional array of cids we're counting for (OR/AND)
!  * @param $args['andcids'] true means AND-ing categories listed in cids
   * @returns int
   * @return number of items
***************
*** 406,412 ****
      $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'];
--- 424,428 ----
      $sql = 'SELECT COUNT(DISTINCT ' . $categoriesdef['iid'] . ')';
      $sql .= ' FROM ' . $categoriesdef['table'];
!     $sql .= $categoriesdef['more'];
      if (!empty($categoriesdef['where'])) {
          $sql .= ' WHERE ' . $categoriesdef['where'];
***************
*** 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
--- 546,552 ----
   * @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/AND)
!  * @param $args['andcids'] true means AND-ing categories listed in cids
!  * @param $args['groupcids'] the number of categories you want items grouped by
   * @returns array
   * @return number of items per category, or caterogies per item
***************
*** 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'];
--- 582,586 ----
      $sql = 'SELECT ' . $field . ', COUNT(*)';
      $sql .= ' FROM ' . $categoriesdef['table'];
!     $sql .= $categoriesdef['more'];
      if (!empty($categoriesdef['where'])) {
          $sql .= ' WHERE ' . $categoriesdef['where'];
***************
*** 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',
--- 674,681 ----
   * @param $args['modid'] your module ID (use pnModGetIDFromName('mymodule'))
   *
   * @param $args['iids'] optional array of item ids that we are selecting on
!  * @param $args['cids'] optional array of cids we're counting for (OR/AND)
!  * @param $args['andcids'] true means AND-ing categories listed in cids
!  * @param $args['groupcids'] the number of categories you want items grouped by
   * @returns array
   * @return array('table' => 'nuke_categories_linkage',
***************
*** 699,703 ****
      }
      if (!isset($andcids)) {
!         $andcids = array();
      }
  
--- 709,713 ----
      }
      if (!isset($andcids)) {
!         $andcids = false;
      }
  
***************
*** 720,732 ****
          }
      }
-     foreach ($andcids 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();
-         }
-     }
  // Note: your module should be checking security for the iids too !
      foreach ($iids as $iid) {
--- 730,733 ----
***************
*** 740,748 ****
      }
  
!     // 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 {
--- 741,750 ----
      }
  
!     // dummy cids array when we're going for x categories at a time
!     if (isset($groupcids) && count($cids) == 0) {
!         $andcids = true;
          $isdummy = 1;
!         for ($i = 0; $i < $groupcids; $i++) {
!             $cids[] = $i;
          }
      } else {
***************
*** 757,763 ****
  
      // 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;
          }
--- 759,765 ----
  
      // create list of tables we'll be left joining for AND
!     if (count($cids) > 0 && $andcids) {
          $catlinks = array();
!         for ($i = 0; $i < count($cids); $i++) {
              $catlinks[] = 'catlink' . $i;
          }
***************
*** 774,778 ****
  
      // Specify LEFT JOIN ... ON ... [WHERE ...] parts
!     if (count($andcids) > 0) {
          $leftjoin['table'] = $categorieslinkagetable . ' as ' . $catlinks[0];
          $leftjoin['more'] = ' ';
--- 776,780 ----
  
      // Specify LEFT JOIN ... ON ... [WHERE ...] parts
!     if (count($cids) > 0 && $andcids) {
          $leftjoin['table'] = $categorieslinkagetable . ' as ' . $catlinks[0];
          $leftjoin['more'] = ' ';
***************
*** 800,806 ****
      }
      if (count($cids) > 0) {
!         $allcids = join(', ', $cids);
!         $where[] = $leftjoin['cid'] . ' IN (' .
!                    pnVarPrepForStore($allcids) . ')';
      }
      if (count($iids) > 0) {
--- 802,829 ----
      }
      if (count($cids) > 0) {
!         if ($andcids) {
!             // 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($cids); $i++) {
!                     $where[] = $catlinks[$i] . '.pn_cid = ' .
!                                    pnVarPrepForStore($cids[$i]);
!                 }
!             }
!             // include all cids here
!             $leftjoin['cid'] = join(', ',$leftjoin['cids']);
!         } else {
!             $allcids = join(', ', $cids);
!             $where[] = $leftjoin['cid'] . ' IN (' .
!                        pnVarPrepForStore($allcids) . ')';
!         }
      }
      if (count($iids) > 0) {
***************
*** 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) {
--- 831,834 ----


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