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_modules / articles [ view in CVS ]
Date | Directory [filter] | File(s) [view] | Author [filter] |
30 Jul 2002 23:48:02 | postnuke_modules/articles | pnadmin.php,1.23,1.24 pnuserapi.php,1.25,1.26 | Mike |
extend leftjoin and countitems to allow selection on lots of things (also for external blocks/modules) |
Update of /home/cvsroot/postnuke_modules/articles In directory ns7.hostnuke.net:/tmp/cvs-serv6925 Modified Files: pnadmin.php pnuserapi.php Log Message: extend leftjoin and countitems to allow selection on lots of things (also for external blocks/modules) Index: pnadmin.php =================================================================== RCS file: /home/cvsroot/postnuke_modules/articles/pnadmin.php,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** pnadmin.php 29 Jul 2002 14:57:32 -0000 1.23 --- pnadmin.php 30 Jul 2002 23:47:59 -0000 1.24 *************** *** 328,333 **** array('startnum' => $startnum, 'numitems' => pnModGetVar('articles', 'itemsperpage'), ! 'ptid' => $ptid, ! 'cids' => false)); $items = array(); --- 328,332 ---- array('startnum' => $startnum, 'numitems' => pnModGetVar('articles', 'itemsperpage'), ! 'ptid' => $ptid)); $items = array(); Index: pnuserapi.php =================================================================== RCS file: /home/cvsroot/postnuke_modules/articles/pnuserapi.php,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** pnuserapi.php 30 Jul 2002 22:22:11 -0000 1.25 --- pnuserapi.php 30 Jul 2002 23:47:59 -0000 1.26 *************** *** 50,53 **** --- 50,54 ---- * @param $args['numitems'] number of articles to get * @param $args['startnum'] starting article number + * @param $args['authorid'] the ID of the author * @param $args['ptid'] publication type ID (for news, sections, reviews, ...) * @param $args['cids'] array of category IDs for which to get articles *************** *** 72,76 **** $startnum = 1; } ! if (!isset($cids)) { $cids = array(); } --- 73,77 ---- $startnum = 1; } ! if (empty($cids)) { $cids = array(); } *************** *** 92,100 **** } ! // Fields required by the calling function $required = array(); foreach ($fields as $field) { $required[$field] = 1; } if (count($cids) > 0) { $required['cids'] = 1; --- 93,105 ---- } ! // Fields requested by the calling function $required = array(); foreach ($fields as $field) { $required[$field] = 1; } + // mandatory fields for security + $required['aid'] = 1; + $required['title'] = 1; + // force cids as required when categories are given if (count($cids) > 0) { $required['cids'] = 1; *************** *** 105,109 **** // Get the field names and LEFT JOIN ... ON ... parts from articles ! $articlesdef = pnModAPIFunc('articles','user','leftjoin'); if (!empty($required['author'])) { --- 110,116 ---- // Get the field names and LEFT JOIN ... ON ... parts from articles ! // By passing on the $args, we can let leftjoin() create the WHERE for ! // the articles-specific columns too now ! $articlesdef = pnModAPIFunc('articles','user','leftjoin',$args); if (!empty($required['author'])) { *************** *** 167,185 **** $sql .= ' FROM ' . $from; // Create the WHERE part $where = array(); ! // TODO: check the order of the conditions for brain-dead databases ? ! if (!empty($ptid) && is_numeric($ptid)) { ! $where[] = $articlesdef['pubtypeid'] . ' = ' . $ptid; ! } ! if (!empty($startdate) && is_numeric($startdate)) { ! $where[] = $articlesdef['pubdate'] . ' >= ' . $startdate; ! } ! if (!empty($enddate) && is_numeric($enddate)) { ! $where[] = $articlesdef['pubdate'] . ' < ' . $enddate; } if (count($cids) > 0) { $where[] = $categoriesdef['where']; ! // required for categories ! $where[] = $categoriesdef['modid'] . ' = ' . pnModGetIDFromName('articles'); --- 174,188 ---- $sql .= ' FROM ' . $from; + // TODO: check the order of the conditions for brain-dead databases ? // Create the WHERE part $where = array(); ! // we rely on leftjoin() to create the necessary articles clauses now ! if (!empty($articlesdef['where'])) { ! $where[] = $articlesdef['where']; } if (count($cids) > 0) { + // we rely on leftjoin() to create the necessary categories clauses $where[] = $categoriesdef['where']; ! // but this is required for categories too ! $where[] = $categoriesdef['modid'] . ' = ' . pnModGetIDFromName('articles'); *************** *** 201,205 **** if ($dbconn->ErrorNo() != 0) { ! $msg = 'DATABASE_ERROR :'.$sql.' -> '. mysql_error(); pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR', new SystemException(__FILE__.'('.__LINE__.'): '.$msg)); --- 204,208 ---- if ($dbconn->ErrorNo() != 0) { ! $msg = 'DATABASE_ERROR :'.$sql.' -> '. $dbconn->ErrorMsg(); pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR', new SystemException(__FILE__.'('.__LINE__.'): '.$msg)); *************** *** 467,477 **** } - // TODO: we're passing some article-specific selection criteria on - // to the categories module, so it can do the final select - // Check if this sounds good & re-usable elsewhere or not /** * count number of items depending on additional module criteria * @param $args['cids'] array of cids that we are counting for ! * @param $args['ptid'] publication type ID we're interested in * @returns int * @return number of items --- 470,484 ---- } /** * count number of items depending on additional module criteria + * * @param $args['cids'] array of cids that we are counting for ! * ! * @param $args['authorid'] the ID of the author ! * @param $args['ptid'] publication type ID (for news, sections, reviews, ...) ! * @param $args['startdate'] articles published at startdate or later ! * (unix timestamp format) ! * @param $args['enddate'] articles published before enddate ! * (unix timestamp format) * @returns int * @return number of items *************** *** 479,500 **** function articles_userapi_countitems($args) { ! if (!empty($args['ptid'])) { ! $pntable = pnDBGetTables(); ! $articlestable = $pntable['articles']; ! $args['table'] = $articlestable; ! $args['field'] = $articlestable . '.pn_aid'; ! $args['where'] = $articlestable . '.pn_pubtypeid = ' . pnVarPrepForStore($args['ptid']); ! } ! // Load API ! if (!pnModAPILoad('categories', 'user')) { ! $msg = pnML('Unable to load (#(1))�s module (#(2))�s functions.', ! pnML('categories'), pnML('user')); ! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD', ! new SystemException(__FILE__.'('.__LINE__.'): '.$msg)); return; } ! return pnModAPIFunc('categories','user','countitems',$args); } --- 486,556 ---- function articles_userapi_countitems($args) { ! // Database information ! list($dbconn) = pnDBGetConn(); ! // Get the field names and LEFT JOIN ... ON ... parts from articles ! // By passing on the $args, we can let leftjoin() create the WHERE for ! // the articles-specific columns too now ! $articlesdef = pnModAPIFunc('articles','user','leftjoin',$args); ! ! // TODO: make sure this is SQL standard ! // Start building the query ! $sql = 'SELECT COUNT(DISTINCT ' . $articlesdef['field'] . ')'; ! $sql .= ' FROM ' . $articlesdef['table']; ! ! if (!empty($args['cids']) && is_array($args['cids']) ! && count($args['cids']) > 0) { ! // Load API ! if (!pnModAPILoad('categories', 'user')) { ! $msg = pnML('Unable to load (#(1))�s module (#(2))�s functions.', ! pnML('categories'), pnML('user')); ! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD', ! new SystemException(__FILE__.'('.__LINE__.'): '.$msg)); return; + } + $docid = 1; + // Get the LEFT JOIN ... ON ... and WHERE (!) parts from categories + $categoriesdef = pnModAPIFunc('categories','user','leftjoin', + array('cids' => $args['cids'])); + + $sql .= ' LEFT JOIN ' . $categoriesdef['table']; + $sql .= ' ON ' . $categoriesdef['field'] . ' = ' + . $articlesdef['aid']; } ! // Create the WHERE part ! $where = array(); ! // we rely on leftjoin() to create the necessary articles clauses now ! if (!empty($articlesdef['where'])) { ! $where[] = $articlesdef['where']; ! } ! if (!empty($docid)) { ! // we rely on leftjoin() to create the necessary categories clauses ! $where[] = $categoriesdef['where']; ! // but this is required for categories too ! ! $where[] = $categoriesdef['modid'] . ' = ' . ! pnModGetIDFromName('articles'); ! } ! if (count($where) > 0) { ! $sql .= ' WHERE ' . join(' AND ', $where); ! } ! ! // Run the query - finally :-) ! $result = $dbconn->Execute($sql); ! ! if ($dbconn->ErrorNo() != 0) { ! $msg = 'DATABASE_ERROR :'.$sql.' -> '. $dbconn->ErrorMsg(); ! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR', ! new SystemException(__FILE__.'('.__LINE__.'): '.$msg)); ! return ; ! } ! if ($result->EOF) { ! return; ! } ! ! $num = $result->fields[0]; ! $result->Close(); ! ! return $num; } *************** *** 542,549 **** * ON $field = <name of articleid field in your module> * WHERE ... ! * AND $pubdate > 123456789 * AND $where * * @param $args['aids'] optional array of aids that we are selecting on * @returns array * @return array('table' => 'nuke_articles', --- 598,613 ---- * ON $field = <name of articleid field in your module> * WHERE ... ! * AND $title LIKE 'Hello world%' * AND $where * + * Note : the following arguments are all optional : + * * @param $args['aids'] optional array of aids that we are selecting on + * @param $args['authorid'] the ID of the author + * @param $args['ptid'] publication type ID (for news, sections, reviews, ...) + * @param $args['startdate'] articles published at startdate or later + * (unix timestamp format) + * @param $args['enddate'] articles published before enddate + * (unix timestamp format) * @returns array * @return array('table' => 'nuke_articles', *************** *** 588,607 **** $leftjoin = array(); // Specify LEFT JOIN ... ON ... [WHERE ...] parts $leftjoin['table'] = $articlestable; ! $leftjoin['field'] = $articlestable . '.pn_aid'; if (count($aids) > 0) { $allaids = join(', ', $aids); ! $leftjoin['where'] = $articlestable . '.pn_aid IN (' . ! pnVarPrepForStore($allaids) . ')'; } else { $leftjoin['where'] = ''; - } - - // Add available columns in the articles table (for now) - $columns = array('aid','title','summary','authorid','pubdate','pubtypeid', - 'body'); - foreach ($columns as $column) { - $leftjoin[$column] = $articlestable . '.pn_' . $column; } --- 652,689 ---- $leftjoin = array(); + // Add available columns in the articles table (for now) + $columns = array('aid','title','summary','authorid','pubdate','pubtypeid', + 'body'); + foreach ($columns as $column) { + $leftjoin[$column] = $articlestable . '.pn_' . $column; + } + // Specify LEFT JOIN ... ON ... [WHERE ...] parts $leftjoin['table'] = $articlestable; ! $leftjoin['field'] = $leftjoin['aid']; ! ! // Specify the WHERE part ! $where = array(); ! if (!empty($authorid) && is_numeric($authorid)) { ! $where[] = $leftjoin['authorid'] . ' = ' . $authorid; ! } ! if (!empty($ptid) && is_numeric($ptid)) { ! $where[] = $leftjoin['pubtypeid'] . ' = ' . $ptid; ! } ! if (!empty($startdate) && is_numeric($startdate)) { ! $where[] = $leftjoin['pubdate'] . ' >= ' . $startdate; ! } ! if (!empty($enddate) && is_numeric($enddate)) { ! $where[] = $leftjoin['pubdate'] . ' < ' . $enddate; ! } if (count($aids) > 0) { $allaids = join(', ', $aids); ! $where[] = $articlestable . '.pn_aid IN (' . ! pnVarPrepForStore($allaids) . ')'; ! } ! 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 |