quote($db->getNullDate()) . ' THEN a.created ELSE a.modified END'; break; // use created if publish_up is not set case 'published' : $queryDate = ' CASE WHEN a.publish_up = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END '; break; case 'created' : default : $queryDate = ' a.created '; break; } return $queryDate; } /** * Get join information for the voting query. * * @param JRegistry $param An options object for the article. * * @return array A named array with "select" and "join" keys. * @since 1.5 */ public static function buildVotingQuery($params=null) { if (!$params) { $params = JComponentHelper::getParams('com_content'); } $voting = $params->get('show_vote'); if ($voting) { // calculate voting count $select = ' , ROUND(v.rating_sum / v.rating_count) AS rating, v.rating_count'; $join = ' LEFT JOIN #__content_rating AS v ON a.id = v.content_id'; } else { $select = ''; $join = ''; } $results = array ('select' => $select, 'join' => $join); return $results; } /** * Method to order the intro articles array for ordering * down the columns instead of across. * The layout always lays the introtext articles out across columns. * Array is reordered so that, when articles are displayed in index order * across columns in the layout, the result is that the * desired article ordering is achieved down the columns. * * @param array $articles Array of intro text articles * @param integer $numColumns Number of columns in the layout * * @return array Reordered array to achieve desired ordering down columns * @since 1.6 */ public static function orderDownColumns(&$articles, $numColumns = 1) { $count = count($articles); // just return the same array if there is nothing to change if ($numColumns == 1 || !is_array($articles) || $count <= $numColumns) { $return = $articles; } // we need to re-order the intro articles array else { // we need to preserve the original array keys $keys = array_keys($articles); $maxRows = ceil($count / $numColumns); $numCells = $maxRows * $numColumns; $numEmpty = $numCells - $count; $index = array(); // calculate number of empty cells in the array // fill in all cells of the array // put -1 in empty cells so we can skip later for ($row = 1, $i = 1; $row <= $maxRows; $row++) { for ($col = 1; $col <= $numColumns; $col++) { if ($numEmpty > ($numCells - $i)) { // put -1 in empty cells $index[$row][$col] = -1; } else { // put in zero as placeholder $index[$row][$col] = 0; } $i++; } } // layout the articles in column order, skipping empty cells $i = 0; for ($col = 1; ($col <= $numColumns) && ($i < $count); $col++) { for ($row = 1; ($row <= $maxRows) && ($i < $count); $row++) { if ($index[$row][$col] != - 1) { $index[$row][$col] = $keys[$i]; $i++; } } } // now read the $index back row by row to get articles in right row/col // so that they will actually be ordered down the columns (when read by row in the layout) $return = array(); $i = 0; for ($row = 1; ($row <= $maxRows) && ($i < $count); $row++) { for ($col = 1; ($col <= $numColumns) && ($i < $count); $col++) { $return[$keys[$i]] = $articles[$index[$row][$col]]; $i++; } } } return $return; } }