/** * Get datetime of the last post/item * @todo dh> Optimize this, if this can be said after having done {@link query()} already. * @todo dh> Cache result * @param string Date format (see {@link date()}) * @return string 'Y-m-d H:i:s' formatted; If there are no items this will be {@link $localtimenow}. */ function get_lastpostdate($dateformat = 'Y-m-d H:i:s') { global $localtimenow, $DB; if (empty($this->filters)) { // Filters have no been set before, we'll use the default filterset: // echo ' Query:Setting default filterset '; $this->set_filters($this->default_filters); } // GENERATE THE QUERY: // The SQL Query object: $lastpost_ItemQuery = new ItemQuery($this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname); /* * filtering stuff: */ $lastpost_ItemQuery->where_chapter2($this->Blog, $this->filters['cat_array'], $this->filters['cat_modifier'], $this->filters['cat_focus'], $this->filters['coll_IDs']); $lastpost_ItemQuery->where_author($this->filters['authors']); $lastpost_ItemQuery->where_author_logins($this->filters['authors_login']); $lastpost_ItemQuery->where_assignees($this->filters['assignees']); $lastpost_ItemQuery->where_assignees_logins($this->filters['assignees_login']); $lastpost_ItemQuery->where_locale($this->filters['lc']); $lastpost_ItemQuery->where_statuses($this->filters['statuses']); $lastpost_ItemQuery->where_types($this->filters['types']); $lastpost_ItemQuery->where_keywords($this->filters['keywords'], $this->filters['phrase'], $this->filters['exact'], $this->filters['keyword_scope']); $lastpost_ItemQuery->where_ID($this->filters['post_ID'], $this->filters['post_title']); $lastpost_ItemQuery->where_datestart($this->filters['ymdhms'], $this->filters['week'], $this->filters['ymdhms_min'], $this->filters['ymdhms_max'], $this->filters['ts_min'], $this->filters['ts_max']); $lastpost_ItemQuery->where_visibility($this->filters['visibility_array']); /* * order by stuff: * LAST POST FIRST!!! (That's the whole point!) */ $lastpost_ItemQuery->order_by($this->Cache->dbprefix . 'datestart DESC'); /* * Paging limits: * ONLY THE LAST POST!!! */ $lastpost_ItemQuery->LIMIT('1'); // Select the datestart: $lastpost_ItemQuery->select($this->Cache->dbprefix . 'datestart'); $lastpostdate = $DB->get_var($lastpost_ItemQuery->get(), 0, 0, 'Get last post date'); if (empty($lastpostdate)) { // echo 'we have no last item'; $lastpostdate = date($dateformat, $localtimenow); } elseif ($dateformat != 'Y-m-d H:i:s') { $lastpostdate = date($dateformat, strtotime($lastpostdate)); } // echo $lastpostdate; return $lastpostdate; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Book is new, it will return * an empty collection; or if this Book has previously * been saved, it will retrieve related Items from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Book. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelCollection|array Item[] List of Item objects */ public function getItemsJoinItemRelatedByPackageId($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = ItemQuery::create(null, $criteria); $query->joinWith('ItemRelatedByPackageId', $join_behavior); return $this->getItems($query, $con); }
/** * Load items by the given categories or collection ID * After the Items are loaded create a map of loaded items by categories * * @param array of category ids * @param integer collection ID * @return boolean true if load items was required and it was loaded successfully, false otherwise */ function load_by_categories($cat_array, $coll_ID) { global $DB, $posttypes_specialtypes; if (empty($cat_array) && empty($coll_ID)) { // Nothing to load return false; } // In case of an empty cat_array param, use categoriesfrom the given collection if (empty($cat_array)) { // Get all categories from the given subset $ChapterCache =& get_ChapterCache(); $subset_chapters = $ChapterCache->get_chapters_by_subset($coll_ID); $cat_array = array(); foreach ($subset_chapters as $Chapter) { $cat_array[] = $Chapter->ID; } } // Check which category is not loaded $not_loaded_cat_ids = array(); foreach ($cat_array as $cat_ID) { if (!isset($this->items_by_cat_map[$cat_ID])) { // This category is not loaded $not_loaded_cat_ids[] = $cat_ID; // Initialize items_by_cat_map for this cat_ID $this->items_by_cat_map[$cat_ID] = array('items' => array(), 'sorted' => false); } } if (empty($not_loaded_cat_ids)) { // Requested categories items are all loaded return false; } // Query to load all Items from the given categories $sql = 'SELECT postcat_cat_ID as cat_ID, postcat_post_ID as post_ID FROM T_postcats WHERE postcat_cat_ID IN ( ' . implode(', ', $not_loaded_cat_ids) . ' ) ORDER BY postcat_post_ID'; $cat_posts = $DB->get_results($sql, ARRAY_A, 'Get all category post ids pair by category'); // Initialize $Blog from coll_ID $BlogCache =& get_BlogCache(); $Blog = $BlogCache->get_by_ID($coll_ID); $visibility_statuses = is_admin_page() ? get_visibility_statuses('keys', array('trash')) : get_inskin_statuses($coll_ID, 'post'); // Create ItemQuery for loading visible items $ItemQuery = new ItemQuery($this->dbtablename, $this->dbprefix, $this->dbIDname); // Set filters what to select $ItemQuery->SELECT($this->dbtablename . '.*'); $ItemQuery->where_chapter2($Blog, $not_loaded_cat_ids, ""); $ItemQuery->where_visibility($visibility_statuses); $ItemQuery->where_datestart(NULL, NULL, NULL, NULL, $Blog->get_timestamp_min(), $Blog->get_timestamp_max()); $ItemQuery->where_types('-' . implode(',', $posttypes_specialtypes)); // Clear previous items from the cache and load by the defined SQL $this->clear(true); $this->load_by_sql($ItemQuery); foreach ($cat_posts as $row) { // Iterate through the post - cat pairs and fill the map if (empty($this->cache[$row['post_ID']])) { // The Item was not loaded because it does not correspond to the defined filters continue; } // Add to the map $this->items_by_cat_map[$row['cat_ID']]['items'][] = $this->get_by_ID($row['post_ID']); } }
public static function getComponents(array $itemIds) { $query = ItemQuery::create()->filterByPackageId($itemIds)->orderBy('Item.Title')->find(); return $query; }
/** * Get links to navigate between month / year. * * Unless min/max_timestamp='query' has been specified, this will not do any (time consuming!) queries to check where the posts are. * * @param string 'prev' / 'next' * @return array */ function getNavLinks($direction) { global $DB, $localtimenow; //pre_dump( 'get_nav_links', $direction ); $r = array(); if ($this->params['min_timestamp'] == 'query' || $this->params['max_timestamp'] == 'query') { // Do inits: // WE NEED SPECIAL QUERY PARAMS WHEN MOVING THOUGH MONTHS ( NO dstart especially! ) $nav_ItemQuery = new ItemQuery($this->dbtable, $this->dbprefix, $this->dbIDname); // TEMP object // Restrict to selected blog/categories: $nav_ItemQuery->where_chapter2($this->ItemQuery->Blog, $this->ItemQuery->cat_array, $this->ItemQuery->cat_modifier); // Restrict to the statuses we want to show: $nav_ItemQuery->where_visibility($this->ItemQuery->show_statuses); // Restrict to selected authors: $nav_ItemQuery->where_author($this->ItemQuery->author); // if a month is specified in the querystring, load that month: $nav_ItemQuery->where_datestart('', '', '', '', $this->ItemQuery->timestamp_min, $this->ItemQuery->timestamp_max); // Keyword search stuff: $nav_ItemQuery->where_keywords($this->ItemQuery->keywords, $this->ItemQuery->phrase, $this->ItemQuery->exact); // Exclude pages and intros: $nav_ItemQuery->where_types($this->ItemQuery->types); } switch ($direction) { case 'prev': //pre_dump( $this->params['min_timestamp'] ); $r[] = ''; if (empty($this->month)) { // if $this->month is empty, we're in mode "year" with no selected month $use_range_month = 12; $use_range_day = 31; } else { $use_range_month = $this->month; $use_range_day = 1; // Note: cannot use current day since all months do not have same number of days } /* * << (PREV YEAR) */ if ($this->browseyears) { // We want arrows to move one year at a time if ($this->params['min_timestamp'] == 'query') { // Let's query to find the correct year: if ($row = $DB->get_row('SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) AS month FROM (' . $this->dbtable . ' INNER JOIN T_postcats ON ' . $this->dbIDname . ' = postcat_post_ID) INNER JOIN T_categories ON postcat_cat_ID = cat_ID WHERE EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) < ' . $this->year . ' ' . $nav_ItemQuery->get_where(' AND ') . $nav_ItemQuery->get_group_by(' GROUP BY ') . ' ORDER BY EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) DESC, ABS( ' . $use_range_month . ' - EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) ) ASC LIMIT 1', OBJECT, 0, 'Calendar: find prev year with posts')) { $prev_year_year = $row->year; $prev_year_month = $row->month; } } else { // Let's see if the previous year is in the desired navigation range: $prev_year_ts = mktime(0, 0, 0, $use_range_month, $use_range_day, $this->year - 1); if ($prev_year_ts >= $this->params['min_timestamp']) { $prev_year_year = date('Y', $prev_year_ts); $prev_year_month = date('m', $prev_year_ts); } } } if (!empty($prev_year_year)) { // We have a link to display: $r[] = $this->archive_link('<<', sprintf($this->mode == 'month' ? T_('Previous year (%04d-%02d)') : T_('Previous year (%04d)'), $prev_year_year, $prev_year_month), $prev_year_year, $this->mode == 'month' ? $prev_year_month : NULL); } /* * < (PREV MONTH) */ if ($this->mode == 'month') { // We are browsing months, we'll display arrows to move one month at a time: if ($this->params['min_timestamp'] == 'query') { // Let's query to find the correct month: if ($row = $DB->get_row('SELECT EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) AS month, EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year FROM (' . $this->dbtable . ' INNER JOIN T_postcats ON ' . $this->dbIDname . ' = postcat_post_ID) INNER JOIN T_categories ON postcat_cat_ID = cat_ID WHERE ( EXTACT(YEAR FROM ' . $this->dbprefix . 'datestart) < ' . $this->year . ' OR ( EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) = ' . $this->year . ' AND EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) < ' . $this->month . ' ) ) ' . $nav_ItemQuery->get_where(' AND ') . $nav_ItemQuery->get_group_by(' GROUP BY ') . ' ORDER BY EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) DESC, EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) DESC LIMIT 1', OBJECT, 0, 'Calendar: Find prev month with posts')) { $prev_month_year = $row->year; $prev_month_month = $row->month; } } else { // Let's see if the previous month is in the desired navigation range: $prev_month_ts = mktime(0, 0, 0, $this->month - 1, 1, $this->year); // Note: cannot use current day since all months do not have same number of days if ($prev_month_ts >= $this->params['min_timestamp']) { $prev_month_year = date('Y', $prev_month_ts); $prev_month_month = date('m', $prev_month_ts); } } } if (!empty($prev_month_year)) { // We have a link to display: $r[] = $this->archive_link('<', sprintf(T_('Previous month (%04d-%02d)'), $prev_month_year, $prev_month_month), $prev_month_year, $prev_month_month); } break; case 'next': //pre_dump( $this->params['max_timestamp'] ); /* * > (NEXT MONTH) */ if ($this->mode == 'month') { // We are browsing months, we'll display arrows to move one month at a time: if ($this->params['max_timestamp'] == 'query') { // Let's query to find the correct month: if ($row = $DB->get_row('SELECT EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) AS month, EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year FROM (' . $this->dbtable . ' INNER JOIN T_postcats ON ' . $this->dbIDname . ' = postcat_post_ID) INNER JOIN T_categories ON postcat_cat_ID = cat_ID WHERE ( EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) > ' . $this->year . ' OR ( EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) = ' . $this->year . ' AND EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) > ' . $this->month . ' ) ) ' . $nav_ItemQuery->get_where(' AND ') . $nav_ItemQuery->get_group_by(' GROUP BY ') . ' ORDER BY EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart), EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) ASC LIMIT 1', OBJECT, 0, 'Calendar: Find next month with posts')) { $next_month_year = $row->year; $next_month_month = $row->month; } } else { // Let's see if the next month is in the desired navigation range: $next_month_ts = mktime(0, 0, 0, $this->month + 1, 1, $this->year); // Note: cannot use current day since all months do not have same number of days if ($next_month_ts <= $this->params['max_timestamp']) { $next_month_year = date('Y', $next_month_ts); $next_month_month = date('m', $next_month_ts); } } } if (!empty($next_month_year)) { // We have a link to display: $r[] = $this->archive_link('>', sprintf(T_('Next month (%04d-%02d)'), $next_month_year, $next_month_month), $next_month_year, $next_month_month); } if (empty($this->month)) { // if $this->month is empty, we're in mode "year" with no selected month $use_range_month = 12; $use_range_day = 31; } else { $use_range_month = $this->month; $use_range_day = 1; // Note: cannot use current day since all months do not have same number of days } /* * >> (NEXT YEAR) */ if ($this->browseyears) { // We want arrows to move one year at a time if ($this->params['max_timestamp'] == 'query') { // Let's query to find the correct year: if ($row = $DB->get_row('SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) AS month FROM (' . $this->dbtable . ' INNER JOIN T_postcats ON ' . $this->dbIDname . ' = postcat_post_ID) INNER JOIN T_categories ON postcat_cat_ID = cat_ID WHERE EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) > ' . $this->year . ' ' . $nav_ItemQuery->get_where(' AND ') . $nav_ItemQuery->get_group_by(' GROUP BY ') . ' ORDER BY EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) ASC, ABS( ' . $use_range_month . ' - EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) ) ASC LIMIT 1', OBJECT, 0, 'Calendar: find next year with posts')) { $next_year_year = $row->year; $next_year_month = $row->month; } } else { // Let's see if the next year is in the desired navigation range: $next_year_ts = mktime(0, 0, 0, $use_range_month, $use_range_day, $this->year + 1); if ($next_year_ts <= $this->params['max_timestamp']) { $next_year_year = date('Y', $next_year_ts); $next_year_month = date('m', $next_year_ts); } } if (!empty($next_year_year)) { // We have a link to display: $r[] = $this->archive_link('>>', sprintf($this->mode == 'month' ? T_('Next year (%04d-%02d)') : T_('Next year (%04d)'), $next_year_year, $next_year_month), $next_year_year, $this->mode == 'month' ? $next_year_month : NULL); } } break; } return $r; }
/** * Skip to previous/next Item * * If several items share the same spot (like same issue datetime) then they'll get all skipped at once. * * @param string prev | next (relative to the current sort order) */ function &get_prevnext_Item($direction = 'next', $types = '', $featured = NULL, $post_navigation = 'same_blog') { global $DB, $ItemCache, $posttypes_specialtypes; if (!$this->single_post) { // We are not on a single post: $r = NULL; return $r; } /** * @var Item */ $current_Item = $this->get_by_idx(0); if (is_null($current_Item)) { // This happens if we are on a single post that we do not actually have permission to view $r = NULL; return $r; } if (in_array($current_Item->ptyp_ID, $posttypes_specialtypes)) { // We are not on a REGULAR post -- we cannot navigate: $r = NULL; return $r; } if (!empty($this->prevnext_Item[$direction][$post_navigation])) { return $this->prevnext_Item[$direction][$post_navigation]; } $next_Query = new ItemQuery($this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname); // GENERATE THE QUERY: /* * filtering stuff: */ $next_Query->where_chapter2($this->Blog, $this->filters['cat_array'], $this->filters['cat_modifier'], $this->filters['cat_focus']); $next_Query->where_author($this->filters['authors']); $next_Query->where_author_logins($this->filters['authors_login']); $next_Query->where_assignees($this->filters['assignees']); $next_Query->where_assignees_logins($this->filters['assignees_login']); $next_Query->where_author_assignee($this->filters['author_assignee']); $next_Query->where_locale($this->filters['lc']); $next_Query->where_statuses($this->filters['statuses']); // types param is kept only for the case when some custom types should be displayed $next_Query->where_types(!empty($types) ? $types : $this->filters['types']); $next_Query->where_keywords($this->filters['keywords'], $this->filters['phrase'], $this->filters['exact']); // $next_Query->where_ID( $this->filters['post_ID'], $this->filters['post_title'] ); $next_Query->where_datestart($this->filters['ymdhms'], $this->filters['week'], $this->filters['ymdhms_min'], $this->filters['ymdhms_max'], $this->filters['ts_min'], $this->filters['ts_max']); $next_Query->where_visibility($this->filters['visibility_array']); $next_Query->where_featured($featured); /* * ORDER BY stuff: */ if ($direction == 'next' && $this->filters['order'] == 'DESC' || $direction == 'prev' && $this->filters['order'] == 'ASC') { $order = 'DESC'; $operator = ' < '; } else { $order = 'ASC'; $operator = ' > '; } $orderby = str_replace(' ', ',', $this->filters['orderby']); $orderby_array = explode(',', $orderby); // Format each order param with default column names: $orderbyorder_array = preg_replace('#^(.+)$#', $this->Cache->dbprefix . '$1 ' . $order, $orderby_array); // Add an ID parameter to make sure there is no ambiguity in ordering on similar items: $orderbyorder_array[] = $this->Cache->dbIDname . ' ' . $order; $order_by = implode(', ', $orderbyorder_array); // Special case for RAND: $order_by = str_replace($this->Cache->dbprefix . 'RAND ', 'RAND() ', $order_by); $next_Query->order_by($order_by); // LIMIT to 1 single result $next_Query->LIMIT('1'); // fp> TODO: I think some additional limits need to come back here (for timespans) /* * Position right after the current element depending on current sorting params * * If there are several items on the same issuedatetime for example, we'll then differentiate on post ID * WARNING: you cannot combine criterias with AND here; you need stuf like a>a0 OR (a=a0 AND b>b0) */ switch ($orderby_array[0]) { case 'datestart': // special var name: $next_Query->WHERE_and($this->Cache->dbprefix . $orderby_array[0] . $operator . $DB->quote($current_Item->issue_date) . ' OR ( ' . $this->Cache->dbprefix . $orderby_array[0] . ' = ' . $DB->quote($current_Item->issue_date) . ' AND ' . $this->Cache->dbIDname . $operator . $current_Item->ID . ')'); break; case 'title': case 'ptyp_ID': case 'datecreated': case 'datemodified': case 'last_touched_ts': case 'urltitle': case 'priority': $next_Query->WHERE_and($this->Cache->dbprefix . $orderby_array[0] . $operator . $DB->quote($current_Item->{$orderby_array[0]}) . ' OR ( ' . $this->Cache->dbprefix . $orderby_array[0] . ' = ' . $DB->quote($current_Item->{$orderby_array[0]}) . ' AND ' . $this->Cache->dbIDname . $operator . $current_Item->ID . ')'); break; case 'order': // We have to integrate a rounding error margin $comp_order_value = $current_Item->order; $and_clause = ''; if (is_null($comp_order_value)) { // current Item has NULL order if ($operator == ' < ') { // This is needed when browsing through a descending ordered list and we reach the limit where orders are not set/NULL (ex: b2evo screenshots) $and_clause .= $this->Cache->dbprefix . $orderby_array[0] . ' IS NULL AND '; } else { // This is needed when browsing through a descending ordered list and we want to browse back into the posts that have numbers (pb appears if first NULL posts is the highest ID) $and_clause .= $this->Cache->dbprefix . $orderby_array[0] . ' IS NOT NULL OR '; } $and_clause .= $this->Cache->dbIDname . $operator . $current_Item->ID; } else { if ($operator == ' < ') { // This is needed when browsing through a descending ordered list and we reach the limit where orders are not set/NULL (ex: b2evo screenshots) $and_clause .= $this->Cache->dbprefix . $orderby_array[0] . ' IS NULL OR '; } $and_clause .= $this->Cache->dbprefix . $orderby_array[0] . $operator . ($operator == ' < ' ? $comp_order_value - 1.0E-9 : $comp_order_value + 1.0E-9) . ' OR ( ' . $this->Cache->dbprefix . $orderby_array[0] . ($operator == ' < ' ? ' <= ' . ($comp_order_value + 1.0E-9) : ' >= ' . ($comp_order_value - 1.0E-9)) . ' AND ' . $this->Cache->dbIDname . $operator . $current_Item->ID . ')'; } $next_Query->WHERE_and($and_clause); break; case 'RAND': // Random order. Don't show current item again. $next_Query->WHERE_and($this->Cache->dbprefix . 'ID <> ' . $current_Item->ID); break; default: echo 'WARNING: unhandled sorting: ' . htmlspecialchars($orderby_array[0]); } // GET DATA ROWS: // We are going to proceed in two steps (we simulate a subquery) // 1) we get the IDs we need // 2) we get all the other fields matching these IDs // This is more efficient than manipulating all fields at once. // Step 1: $step1_sql = 'SELECT DISTINCT ' . $this->Cache->dbIDname . $next_Query->get_from() . $next_Query->get_where() . $next_Query->get_group_by() . $next_Query->get_order_by() . $next_Query->get_limit(); //echo $DB->format_query( $step1_sql ); // Get list of the IDs we need: $next_ID = $DB->get_var($step1_sql, 0, 0, 'Get ID of next item'); //pre_dump( $next_ID ); // Step 2: get the item (may be NULL): $this->prevnext_Item[$direction][$post_navigation] =& $ItemCache->get_by_ID($next_ID, true, false); return $this->prevnext_Item[$direction][$post_navigation]; }
/** * Restrict to a specific post comments by post_datestart * * @param timestamp min - Do not show comments from posts before this timestamp * @param timestamp max - Do not show comments from posts after this timestamp */ function where_post_datestart($timestamp_min, $timestamp_max) { if (empty($timestamp_min) && empty($timestamp_max)) { // Don't restrict return; } $dbtable = 'T_items__item'; $dbprefix = 'post_'; $dbIDname = 'ID'; $ItemQuery = new ItemQuery($dbtable, $dbprefix, $dbIDname); $ItemQuery->where_datestart('', '', '', '', $timestamp_min, $timestamp_max); $this->WHERE_and($ItemQuery->get_where('')); }
/** * Create new item's query object * * @return ItemQuery */ public function newItemQuery() { $itemQuery = new ItemQuery(); $itemQuery->setFeedUri($this->_getItemsUri()); return $itemQuery; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Item is new, it will return * an empty collection; or if this Item has previously * been saved, it will retrieve related ItemsRelatedById from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Item. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelCollection|array Item[] List of Item objects */ public function getItemsRelatedByIdJoinBook($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = ItemQuery::create(null, $criteria); $query->joinWith('Book', $join_behavior); return $this->getItemsRelatedById($query, $con); }
/** * Get the associated Item object * * @param PropelPDO Optional Connection object. * @return Item The associated Item object. * @throws PropelException */ public function getItem(PropelPDO $con = null) { if ($this->aItem === null && $this->item_id !== null) { $this->aItem = ItemQuery::create()->findPk($this->item_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aItem->addSectionHasItems($this); */ } return $this->aItem; }
/** * Returns a new ItemQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ItemQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof ItemQuery) { return $criteria; } $query = new ItemQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Display the widget! * * @param array MUST contain at least the basic display params */ function display($params) { global $localtimenow, $DB, $Blog; $this->init_display($params); $blog_ID = intval($this->disp_params['blog_ID']); if (empty($blog_ID)) { // Use current blog by default $blog_ID = $Blog->ID; } $BlogCache =& get_BlogCache(); if (!$BlogCache->get_by_ID($blog_ID, false, false)) { // No blog exists return; } // Display photos: // TODO: permissions, complete statuses... // TODO: A FileList object based on ItemListLight but adding File data into the query? // overriding ItemListLigth::query() for starters ;) // Init caches $FileCache =& get_FileCache(); $ItemCache =& get_ItemCache(); // Query list of files and posts fields: // Note: We use ItemQuery to get attachments from all posts which should be visible ( even in case of aggregate blogs ) $ItemQuery = new ItemQuery($ItemCache->dbtablename, $ItemCache->dbprefix, $ItemCache->dbIDname); $ItemQuery->SELECT('post_ID, post_datestart, post_datemodified, post_main_cat_ID, post_urltitle, post_canonical_slug_ID, post_tiny_slug_ID, post_ityp_ID, post_title, post_excerpt, post_url, file_ID, file_type, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc, file_path_hash'); $ItemQuery->FROM_add('INNER JOIN T_links ON post_ID = link_itm_ID'); $ItemQuery->FROM_add('INNER JOIN T_files ON link_file_ID = file_ID'); $ItemQuery->where_chapter($blog_ID); if ($this->disp_params['item_visibility'] == 'public') { // Get images only of the public items $ItemQuery->where_visibility(array('published')); } else { // Get image of all available posts for current user $ItemQuery->where_visibility(NULL); } $ItemQuery->WHERE_and('( file_type = "image" ) OR ( file_type IS NULL )'); $ItemQuery->WHERE_and('post_datestart <= \'' . remove_seconds($localtimenow) . '\''); $ItemQuery->WHERE_and('link_position != "cover"'); if (!empty($this->disp_params['item_type'])) { // Get items only with specified type $ItemQuery->WHERE_and('post_ityp_ID = ' . intval($this->disp_params['item_type'])); } $ItemQuery->GROUP_BY('link_ID'); // fp> TODO: because no way of getting images only, we get 4 times more data than requested and hope that 25% at least will be images :/ // asimo> This was updated and we get images and those files where we don't know the file type yet. Now we get 2 times more data than requested. // Maybe it would be good to get only the requested amount of files, because after a very short period the file types will be set for all images. $ItemQuery->LIMIT(intval($this->disp_params['limit']) * 2); $ItemQuery->ORDER_BY(gen_order_clause($this->disp_params['order_by'], $this->disp_params['order_dir'], 'post_', 'post_ID ' . $this->disp_params['order_dir'] . ', link_ID')); // Init FileList with the above defined query $FileList = new DataObjectList2($FileCache); $FileList->sql = $ItemQuery->get(); $FileList->query(false, false, false, 'Media index widget'); $layout = $this->disp_params['thumb_layout']; $nb_cols = $this->disp_params['grid_nb_cols']; $count = 0; $r = ''; /** * @var File */ while ($File =& $FileList->get_next()) { if ($count >= $this->disp_params['limit']) { // We have enough images already! break; } if (!$File->is_image()) { // Skip anything that is not an image // Only images are selected or those files where we don't know the file type yet. // This check is only for those files where we don't know the filte type. The file type will be set during the check. continue; } if ($layout == 'grid') { // Grid layout if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colstart']; } $r .= $this->disp_params['grid_cellstart']; } elseif ($layout == 'flow') { // Flow block layout $r .= $this->disp_params['flow_block_start']; } else { // List layout $r .= $this->disp_params['item_start']; } // 1/ Hack a dirty permalink( will redirect to canonical): // $link = url_add_param( $Blog->get('url'), 'p='.$post_ID ); // 2/ Hack a link to the right "page". Very daring!! // $link = url_add_param( $Blog->get('url'), 'paged='.$count ); // 3/ Instantiate a light object in order to get permamnent url: $ItemLight = new ItemLight($FileList->get_row_by_idx($FileList->current_idx - 1)); // index had already been incremented $r .= '<a href="' . $ItemLight->get_permanent_url() . '">'; // Generate the IMG THUMBNAIL tag with all the alt, title and desc if available $r .= $File->get_thumb_imgtag($this->disp_params['thumb_size'], '', '', $ItemLight->title); $r .= '</a>'; if ($this->disp_params['disp_image_title']) { // Dislay title of image or item $title = $File->get('title') ? $File->get('title') : $ItemLight->title; if (!empty($title)) { $r .= '<span class="note">' . $title . '</span>'; } } ++$count; if ($layout == 'grid') { // Grid layout $r .= $this->disp_params['grid_cellend']; if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colend']; } } elseif ($layout == 'flow') { // Flow block layout $r .= $this->disp_params['flow_block_end']; } else { // List layout $r .= $this->disp_params['item_end']; } } // Exit if no files found if (empty($r)) { return; } echo $this->disp_params['block_start']; // Display title if requested $this->disp_title(); echo $this->disp_params['block_body_start']; if ($layout == 'grid') { // Grid layout echo $this->disp_params['grid_start']; } elseif ($layout == 'flow') { // Flow block layout echo $this->disp_params['flow_start']; } else { // List layout echo $this->disp_params['list_start']; } echo $r; if ($layout == 'grid') { // Grid layout if ($count && $count % $nb_cols != 0) { echo $this->disp_params['grid_colend']; } echo $this->disp_params['grid_end']; } elseif ($layout == 'flow') { // Flow block layout echo $this->disp_params['flow_end']; } else { // List layout echo $this->disp_params['list_end']; } echo $this->disp_params['block_body_end']; echo $this->disp_params['block_end']; return true; }
/** * Gets the number of Item objects related by a many-to-many relationship * to the current object by way of the section_has_item cross-reference table. * * @param Criteria $criteria Optional query object to filter the query * @param boolean $distinct Set to true to force count distinct * @param PropelPDO $con Optional connection object * * @return int the number of related Item objects */ public function countItems($criteria = null, $distinct = false, PropelPDO $con = null) { if (null === $this->collItems || null !== $criteria) { if ($this->isNew() && null === $this->collItems) { return 0; } else { $query = ItemQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterBySection($this)->count($con); } } else { return count($this->collItems); } }