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 NoticeDirectory filter : [ all ] / postnuke_official / html / modules / categories [ view in CVS ]
Date | Directory [filter] | File(s) [view] | Author [filter] |
31 Jul 2002 02:13:35 | postnuke_official/html/modules/categories | pnuserapi.php,1.6,1.7 | Mike |
leftjoin expanded & used - countitems no longer accepts external table/field/where |
Update of /home/cvsroot/postnuke_official/html/modules/categories In directory ns7.hostnuke.net:/tmp/cvs-serv7393 Modified Files: pnuserapi.php Log Message: leftjoin expanded & used - countitems no longer accepts external table/field/where Index: pnuserapi.php =================================================================== RCS file: /home/cvsroot/postnuke_official/html/modules/categories/pnuserapi.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** pnuserapi.php 30 Jul 2002 22:14:19 -0000 1.6 --- pnuserapi.php 31 Jul 2002 02:13:33 -0000 1.7 *************** *** 304,309 **** * @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 'cids' ! * else the keys are the 'iids' * @returns array * @return item array, or false on failure --- 304,309 ---- * @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 *************** *** 316,350 **** // Get database setup list($dbconn) = pnDBGetConn(); - $pntable = pnDBGetTables(); - $categorieslinkagetable = $pntable['categories_linkage']; - $categorieslinkagecolumn = &$pntable['categories_linkage_column']; ! // Get item IDs ! $sql = "SELECT $categorieslinkagecolumn[iid], $categorieslinkagecolumn[cid]"; ! ! $sql .=" FROM $categorieslinkagetable WHERE "; ! ! // Handle out the proper restrictions for the input Arrays ! if (isset($cids) && is_array($cids) && count($cids) > 0) ! { ! $allcids = join(', ', $cids); ! $sql .= "$categorieslinkagecolumn[cid] IN (" . pnVarPrepForStore($allcids) . ") "; ! } ! if (isset($iids) && is_array($iids) && count($iids) > 0) ! { ! if (isset($allcids)) { ! $sql .= " AND "; ! } ! $alliids = join(', ', $iids); ! $sql .= "$categorieslinkagecolumn[iid] IN (" . pnVarPrepForStore($alliids) . ") "; } ! ! if (isset($modid)) ! { ! if (isset($allcids) || isset($alliids)) { ! $sql .= " AND "; ! } ! $sql .= " $categorieslinkagecolumn[modid] IN (" . pnVarPrepForStore($modid) . ") "; } --- 316,335 ---- // Get database setup list($dbconn) = pnDBGetConn(); ! // Get the field names and LEFT JOIN ... ON ... parts from categories ! // By passing on the $args, we can let leftjoin() create the WHERE for ! // the categories-specific columns too now ! $categoriesdef = pnModAPIFunc('categories','user','leftjoin',$args); ! // 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']; } *************** *** 353,357 **** if ($dbconn->ErrorNo() != 0) { ! pnSessionSetVar('errormsg', _DBSELECTERROR); return false; } --- 338,342 ---- if ($dbconn->ErrorNo() != 0) { ! pnSessionSetVar('errormsg', _DBSELECTERROR . ' error ' . $dbconn->ErrorMsg()); return false; } *************** *** 360,376 **** $answer = array(); - // Reverse the order if reverse is set to 1 - if ($reverse == 1) - { - $f = 0; - $s = 1; - } else { - $f = 1; - $s = 0; - } - for(; !$result->EOF; $result->MoveNext()) { ! $answer[$result->fields[$f]][] = $result->fields[$s]; } --- 345,351 ---- $answer = array(); for(; !$result->EOF; $result->MoveNext()) { ! $answer[$result->fields[0]][] = $result->fields[1]; } *************** *** 382,385 **** --- 357,409 ---- /** + * count number of items + * @param $args['cids'] array of cids that we are counting for + * @returns int + * @return number of items + */ + function categories_userapi_countitems($args) + { + // Get arguments from argument array + extract($args); + + // Optional arguments + if (!isset($cids)) { + $cids = array(); + } + + // Security check + if (!pnSecAuthAction(0, 'categories::item', '::', ACCESS_OVERVIEW)) { + return; + } + + // Get database setup + list($dbconn) = pnDBGetConn(); + + // Get the field names and LEFT JOIN ... ON ... parts from categories + // By passing on the $args, we can let leftjoin() create the WHERE for + // the categories-specific columns too now + $categoriesdef = pnModAPIFunc('categories','user','leftjoin',$args); + + $sql = 'SELECT COUNT(DISTINCT ' . $categoriesdef['iid']; + $sql .= ' FROM ' . $categoriesdef['table']; + if (!empty($categoriesdef['where'])) { + $sql .= ' WHERE ' . $categoriesdef['where']; + } + + $result = $dbconn->Execute($sql); + + if ($dbconn->ErrorNo() != 0) { + pnSessionSetVar('errormsg', _DBSELECTERROR); + return false; + } + + $num = $result->fields[0]; + + $result->Close(); + + return $num; + } + + /** * count number of items (optionally depending on external module criteria) * @param $args['cids'] array of cids that we are counting for *************** *** 389,394 **** * @returns int * @return number of items ! */ ! function categories_userapi_countitems($args) { // Get arguments from argument array --- 413,423 ---- * @returns int * @return number of items ! * ! // This was not a good idea, actually - it's better to count your items ! // in your own module, and use e.g. ! // $categoriesdef = pnModAPIFunc('categories','user','leftjoin',$args); ! // to get the relevant LEFT JOIN ... ON ... [WHERE ...] parts from categories ! * ! function categories_userapi_countitems_deprecated($args) { // Get arguments from argument array *************** *** 397,401 **** // Optional arguments if (!isset($cids)) { ! $cids = array(-1); } --- 426,430 ---- // Optional arguments if (!isset($cids)) { ! $cids = array(); } *************** *** 412,416 **** // Check if we have active CIDs ! if ((isset($cids[0])) && ($cids[0] != -1)) { // We do. We just need to know how many articles there are in these // categories --- 441,445 ---- // Check if we have active CIDs ! if (count($cids) > 0) { // We do. We just need to know how many articles there are in these // categories *************** *** 472,475 **** --- 501,506 ---- return $num; } + * end of not-so-good idea + */ /** *************** *** 497,521 **** // Get database setup list($dbconn) = pnDBGetConn(); ! $pntable = pnDBGetTables(); ! $categorieslinkagetable = $pntable['categories_linkage']; ! $categorieslinkagecolumn = &$pntable['categories_linkage_column']; if ($groupby == 'item') { ! $sql = "SELECT $categorieslinkagecolumn[iid], COUNT(*) ! FROM $categorieslinkagetable "; ! if (isset($modid)) { ! $sql .= " WHERE $categorieslinkagecolumn[modid] = '" . ! pnVarPrepForStore($modid) . "'"; ! } ! $sql .= " GROUP BY $categorieslinkagecolumn[iid]"; } else { ! $sql = "SELECT $categorieslinkagecolumn[cid], COUNT(*) ! FROM $categorieslinkagetable "; ! if (isset($modid)) { ! $sql .= " WHERE $categorieslinkagecolumn[modid] = '" . ! pnVarPrepForStore($modid) . "'"; ! } ! $sql .= " GROUP BY $categorieslinkagecolumn[cid]"; } $result = $dbconn->Execute($sql); --- 528,548 ---- // Get database setup list($dbconn) = pnDBGetConn(); ! ! // Get the field names and LEFT JOIN ... ON ... parts from categories ! // By passing on the $args, we can let leftjoin() create the WHERE for ! // the categories-specific columns too now ! $categoriesdef = pnModAPIFunc('categories','user','leftjoin',$args); if ($groupby == 'item') { ! $field = $categoriesdef['iid']; } else { ! $field = $categoriesdef['cid']; } + $sql = 'SELECT ' . $field . ', COUNT(*)'; + $sql .= ' FROM ' . $categoriesdef['table']; + if (!empty($categoriesdef['where'])) { + $sql .= ' WHERE ' . $categoriesdef['where']; + } + $sql .= ' GROUP BY ' . $field; $result = $dbconn->Execute($sql); *************** *** 598,609 **** * ON $field = <name of itemid field in your module> * WHERE ... ! * AND $modid = <module ID> // this is *required* for categories ! * AND $where * ! * @param $args['cids'] optional array of cids that we are selecting on * @returns array * @return array('table' => 'nuke_categories_linkage', * 'field' => 'nuke_categories_linkage.pn_iid', ! * 'where' => 'nuke_categories_linkage.pn_cid IN (...)', * 'cid' => 'nuke_categories_linkage.pn_cid', * ... --- 625,639 ---- * ON $field = <name of itemid field in your module> * WHERE ... ! * AND $where // this includes pn_modid = <your module ID> * ! * @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', * 'field' => 'nuke_categories_linkage.pn_iid', ! * 'where' => 'nuke_categories_linkage.pn_modid = ... ! * AND nuke_categories_linkage.pn_cid IN (...)', * 'cid' => 'nuke_categories_linkage.pn_cid', * ... *************** *** 615,622 **** --- 645,664 ---- extract($args); + // Required argument ? + if (!isset($modid) || !is_numeric($modid)) { + $msg = pnML('Missing parameter #(1) for #(2)', + 'modid','categories'); + pnExceptionSet(PN_SYSTEM_EXCEPTION, 'BAD_PARAM', + new SystemException($msg)); + return array(); + } + // Optional argument if (!isset($cids)) { $cids = array(); } + if (!isset($iids)) { + $iids = array(); + } // Security check *************** *** 638,641 **** --- 680,693 ---- } } + // Note: your module should be checking security for the iids too ! + foreach ($iids as $iid) { + if (!pnSecAuthAction(0, 'categories::item', '::$iid', ACCESS_OVERVIEW)) { + $msg = pnML('Not authorized to view #(1) #(2)', + 'category item',pnVarPrepForStore($iid)); + pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', + new SystemException($msg)); + return array(); + } + } // Table definition *************** *** 645,663 **** $leftjoin = array(); // Specify LEFT JOIN ... ON ... [WHERE ...] parts $leftjoin['table'] = $categorieslinkagetable; ! $leftjoin['field'] = $categorieslinkagetable . '.pn_iid'; if (count($cids) > 0) { $allcids = join(', ', $cids); ! $leftjoin['where'] = $categorieslinkagetable . '.pn_cid IN (' . ! pnVarPrepForStore($allcids) . ')'; } else { $leftjoin['where'] = ''; - } - - // Add available columns in the categories table - $columns = array('cid','iid','modid'); - foreach ($columns as $column) { - $leftjoin[$column] = $categorieslinkagetable . '.pn_' . $column; } --- 697,729 ---- $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']; ! ! // Specify the WHERE part ! $where = array(); ! if (!empty($modid) && is_numeric($modid)) { ! $where[] = $leftjoin['modid'] . ' = ' . $modid; ! } if (count($cids) > 0) { $allcids = join(', ', $cids); ! $where[] = $leftjoin['cid'] . ' IN (' . ! pnVarPrepForStore($allcids) . ')'; ! } ! if (count($iids) > 0) { ! $alliids = join(', ', $iids); ! $where[] = $leftjoin['iid'] . ' IN (' . ! pnVarPrepForStore($alliids) . ')'; ! } ! if (count($where) > 0) { ! $leftjoin['where'] = join(' AND ', $where); } else { $leftjoin['where'] = ''; }
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 |