/** * Constructor * * If provided, executes SQL query via parent Results object * * @param string Name of table in database * @param string Prefix of fields in the table * @param string Name of the ID field (including prefix) * @param string Name of Class for objects within this list * @param string SQL query * @param integer number of lines displayed on one screen * @param string prefix to differentiate page/order params when multiple Results appear one same page * @param string default ordering of columns (special syntax) */ function DataObjectList($tablename, $prefix = '', $dbIDname = 'ID', $objType = 'Item', $sql = NULL, $limit = 20, $param_prefix = '', $default_order = NULL) { $this->dbtablename = $tablename; $this->dbprefix = $prefix; $this->dbIDname = $dbIDname; $this->objType = $objType; if (!is_null($sql)) { // We have an SQL query to execute: parent::Results($sql, $param_prefix, $default_order, $limit); } else { // TODO: do we want to autogenerate a query here??? // Temporary... parent::Results($sql, $param_prefix, $default_order, $limit); } }
/** * Constructor * * @param string fieldname of item ID to select on * @param string * @param string * @param string * @param string * @param string * @param string * @param integer current selection ID * @param string SQL query * @param NULL|string SQL query used to count the total # of rows (if NULL, we'll try to COUNT(*) by ourselves) * @param string prefix to differentiate page/order params when multiple Results appear one same page * @param string default ordering of columns (special syntax) if not URL specified * @param integer number of lines displayed on one screen */ function ResultSel($field_ID, $table_selections, $field_sel_ID, $field_sel_name, $table_objsel, $field_selected, $field_selection, $current_selection_ID, $sql, $count_sql = NULL, $param_prefix = '', $default_order = '', $limit = 20) { global $current_User; // Call parent: parent::Results($sql, $param_prefix, $default_order, $limit, $count_sql); if (!$current_User->check_perm('selections', 'view')) { // User is NOT allowed to view selections // Don't do any more then base class: return; } $this->current_selection_ID = $current_selection_ID; $this->table_selections = $table_selections; $this->field_sel_ID = $field_sel_ID; $this->field_sel_name = $field_sel_name; $this->table_objsel = $table_objsel; $this->field_selected = $field_selected; $this->field_selection = $field_selection; // Presets a selection checkbox: $this->cols[] = array('th' => T_('Sel'), 'td_class' => 'shrinkwrap', 'td' => '%selection_checkbox( #' . $field_ID . '#, \'' . $param_prefix . '\' )%'); }
/** * Constructor * * Note: Weekly archives use MySQL's week numbering and MySQL default if applicable. * In MySQL < 4.0.14, WEEK() always uses mode 0: Week starts on Sunday; * Value range is 0 to 53; week 1 is the first week that starts in this year. * * @link http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html * * @todo categories combined with 'ALL' are not supported (will output too many archives, * some of which will resolve to no results). We need subqueries to support this efficiently. * * @param string * @param integer * @param boolean */ function ArchiveList($archive_mode = 'monthly', $limit = 100, $sort_order = 'date', $preserve_context = false, $dbtable = 'T_items__item', $dbprefix = 'post_', $dbIDname = 'ID') { global $DB; global $blog, $cat, $catsel; global $show_statuses; global $author, $assgn, $status; global $timestamp_min, $timestamp_max; global $s, $sentence, $exact; $this->dbtable = $dbtable; $this->dbprefix = $dbprefix; $this->dbIDname = $dbIDname; $this->archive_mode = $archive_mode; /* * WE ARE GOING TO CONSTRUCT THE WHERE CLOSE... */ $this->ItemQuery =& new ItemQuery($this->dbtable, $this->dbprefix, $this->dbIDname); // TEMPORARY OBJ // - - Select a specific Item: // $this->ItemQuery->where_ID( $p, $title ); if ($preserve_context) { // We want to preserve the current context: // * - - Restrict to selected blog/categories: $this->ItemQuery->where_chapter($blog, $cat, $catsel); // * Restrict to the statuses we want to show: $this->ItemQuery->where_visibility($show_statuses); // Restrict to selected authors: $this->ItemQuery->where_author($author); // Restrict to selected assignees: $this->ItemQuery->where_assignees($assgn); // Restrict to selected satuses: $this->ItemQuery->where_statuses($status); // - - - + * * timestamp restrictions: $this->ItemQuery->where_datestart('', '', '', '', $timestamp_min, $timestamp_max); // Keyword search stuff: $this->ItemQuery->where_keywords($s, $sentence, $exact); } else { // We want to preserve only the minimal context: // * - - Restrict to selected blog/categories: $this->ItemQuery->where_chapter($blog, '', array()); // * Restrict to the statuses we want to show: $this->ItemQuery->where_visibility($show_statuses); // - - - + * * timestamp restrictions: $this->ItemQuery->where_datestart('', '', '', '', $timestamp_min, $timestamp_max); } $this->from = $this->ItemQuery->get_from(); $this->where = $this->ItemQuery->get_where(); $this->group_by = $this->ItemQuery->get_group_by(); switch ($this->archive_mode) { case 'monthly': // ------------------------------ MONTHLY ARCHIVES ------------------------------------ $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) AS month, COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . ' GROUP BY year, month ORDER BY year DESC, month DESC'; break; case 'daily': // ------------------------------- DAILY ARCHIVES ------------------------------------- $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, MONTH(' . $this->dbprefix . 'datestart) AS month, DAYOFMONTH(' . $this->dbprefix . 'datestart) AS day, COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . ' GROUP BY year, month, day ORDER BY year DESC, month DESC, day DESC'; break; case 'weekly': // ------------------------------- WEEKLY ARCHIVES ------------------------------------- $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, ' . $DB->week($this->dbprefix . 'datestart', locale_startofweek()) . ' AS week, COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . ' GROUP BY year, week ORDER BY year DESC, week DESC'; break; case 'postbypost': default: // ----------------------------- POSY BY POST ARCHIVES -------------------------------- $sql = 'SELECT DISTINCT ' . $this->dbIDname . ', ' . $this->dbprefix . 'datestart, ' . $this->dbprefix . 'title ' . $this->from . $this->where . $this->group_by . ' ORDER BY '; if ($sort_order == 'title') { $sql .= $this->dbprefix . 'title ASC'; } else { if ($sort_order == 'date') { $sql .= $this->dbprefix . 'datestart DESC'; } } } // dh> Temp fix for MySQL bug - apparently in/around 4.1.21/5.0.24. // See http://forums.b2evolution.net/viewtopic.php?p=42529#42529 if (in_array($this->archive_mode, array('monthly', 'daily', 'weekly'))) { $sql_version = $DB->get_var('SELECT VERSION()'); // fp> TODO: $DB->get_mysql_version() if (version_compare($sql_version, '4', '>')) { $sql = 'SELECT SQL_CALC_FOUND_ROWS ' . substr($sql, 7); // "SQL_CALC_FOUND_ROWS" available since MySQL 4 } } parent::Results($sql, 'archivelist_', '', $limit); $this->restart(); }
/** * Constructor * * Note: Weekly archives use MySQL's week numbering and MySQL default if applicable. * In MySQL < 4.0.14, WEEK() always uses mode 0: Week starts on Sunday; * Value range is 0 to 53; week 1 is the first week that starts in this year. * * @link http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html * * @todo categories combined with 'ALL' are not supported (will output too many archives, * some of which will resolve to no results). We need subqueries to support this efficiently. * * @param string * @param integer * @param boolean */ function ArchiveList($archive_mode = 'monthly', $limit = 100, $sort_order = 'date', $preserve_context = false, $dbtable = 'T_items__item', $dbprefix = 'post_', $dbIDname = 'ID') { global $DB; global $blog, $cat, $catsel; global $Blog; global $show_statuses; global $author, $assgn, $status, $types; global $s, $sentence, $exact; global $posttypes_specialtypes; $this->dbtable = $dbtable; $this->dbprefix = $dbprefix; $this->dbIDname = $dbIDname; $this->archive_mode = $archive_mode; /* * WE ARE GOING TO CONSTRUCT THE WHERE CLOSE... */ $this->ItemQuery = new ItemQuery($this->dbtable, $this->dbprefix, $this->dbIDname); // TEMPORARY OBJ // - - Select a specific Item: // $this->ItemQuery->where_ID( $p, $title ); if (is_admin_page()) { // Don't restrict by date in the Back-office $timestamp_min = NULL; $timestamp_max = NULL; } else { // Restrict posts by date started $timestamp_min = $Blog->get_timestamp_min(); $timestamp_max = $Blog->get_timestamp_max(); } if ($preserve_context) { // We want to preserve the current context: // * - - Restrict to selected blog/categories: $this->ItemQuery->where_chapter($blog, $cat, $catsel); // * Restrict to the statuses we want to show: $this->ItemQuery->where_visibility($show_statuses); // Restrict to selected authors: $this->ItemQuery->where_author($author); // Restrict to selected assignees: $this->ItemQuery->where_assignees($assgn); // Restrict to selected satuses: $this->ItemQuery->where_statuses($status); // - - - + * * timestamp restrictions: $this->ItemQuery->where_datestart('', '', '', '', $timestamp_min, $timestamp_max); // Keyword search stuff: $this->ItemQuery->where_keywords($s, $sentence, $exact); $this->ItemQuery->where_types($types); } else { // We want to preserve only the minimal context: // * - - Restrict to selected blog/categories: $this->ItemQuery->where_chapter($blog, '', array()); // * Restrict to the statuses we want to show: $this->ItemQuery->where_visibility($show_statuses); // - - - + * * timestamp restrictions: $this->ItemQuery->where_datestart('', '', '', '', $timestamp_min, $timestamp_max); // Include all types except pages, intros and sidebar links: $this->ItemQuery->where_types('-' . implode(',', $posttypes_specialtypes)); } $this->from = $this->ItemQuery->get_from(); $this->where = $this->ItemQuery->get_where(); $this->group_by = $this->ItemQuery->get_group_by(); switch ($this->archive_mode) { case 'monthly': // ------------------------------ MONTHLY ARCHIVES ------------------------------------ $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) AS month, COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . ' GROUP BY year, month ORDER BY year DESC, month DESC'; break; case 'daily': // ------------------------------- DAILY ARCHIVES ------------------------------------- $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, MONTH(' . $this->dbprefix . 'datestart) AS month, DAYOFMONTH(' . $this->dbprefix . 'datestart) AS day, COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . ' GROUP BY year, month, day ORDER BY year DESC, month DESC, day DESC'; break; case 'weekly': // ------------------------------- WEEKLY ARCHIVES ------------------------------------- $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, ' . $DB->week($this->dbprefix . 'datestart', locale_startofweek()) . ' AS week, COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . ' GROUP BY year, week ORDER BY year DESC, week DESC'; break; case 'postbypost': default: // ----------------------------- POSY BY POST ARCHIVES -------------------------------- $this->count_total_rows(); $archives_list = new ItemListLight($Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), $this->total_rows); $archives_list->set_filters(array('visibility_array' => array('published'), 'types' => '-' . implode(',', $posttypes_specialtypes))); if ($sort_order == 'title') { $archives_list->set_filters(array('orderby' => 'title', 'order' => 'ASC')); } $archives_list->query(); $this->rows = array(); while ($Item = $archives_list->get_item()) { $this->rows[] = $Item; } $this->result_num_rows = $archives_list->result_num_rows; $this->current_idx = 0; $this->arc_w_last = ''; return; } // dh> Temp fix for MySQL bug - apparently in/around 4.1.21/5.0.24. // See http://forums.b2evolution.net/viewtopic.php?p=42529#42529 if (in_array($this->archive_mode, array('monthly', 'daily', 'weekly'))) { $sql_version = $DB->get_version(); if (version_compare($sql_version, '4', '>')) { $sql = 'SELECT SQL_CALC_FOUND_ROWS ' . substr($sql, 7); // "SQL_CALC_FOUND_ROWS" available since MySQL 4 } } parent::Results($sql, 'archivelist_', '', $limit); $this->restart(); }