From 14811beeba174ff4af6951bfeccaf8d1c7ef9416 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Tue, 2 Sep 2008 23:31:43 +0200 Subject: [PATCH] Fixed issue 9, do not show the deprecated files by default. --- src/IDF/Project.php | 12 +++++++-- src/IDF/Views/Download.php | 34 +++++++++++++++++++++++++- src/IDF/templates/downloads/index.html | 14 ++++++++--- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/IDF/Project.php b/src/IDF/Project.php index 515e8ae..4bc6f87 100644 --- a/src/IDF/Project.php +++ b/src/IDF/Project.php @@ -287,13 +287,21 @@ class IDF_Project extends Pluf_Model 'LEFT JOIN '.$what_t.' ON idf_issue_id='.$what_t.'.id '."\n". 'WHERE idf_tag_id IS NOT NULL AND '.$what_t.'.status IN (%s) AND '.$what_t.'.project='.$this->id.' GROUP BY '.$tag_t.'.id, '.$tag_t.'.class, '.$tag_t.'.name ORDER BY '.$tag_t.'.class ASC, '.$tag_t.'.name ASC', implode(', ', $ostatus)); - } else { + } elseif ($what == 'downloads') { + $dep_ids = IDF_Views_Download::getDeprecatedFilesIds($this); + $extra = ''; + if (count($dep_ids) and $what == 'downloads') { + $extra = ' AND idf_upload_id NOT IN ('.implode(', ', $dep_ids).') '; + } + if (count($dep_ids) and $what != 'downloads') { + $extra = ' AND idf_upload_id IN ('.implode(', ', $dep_ids).') '; + } $what_t = Pluf::factory('IDF_Upload')->getSqlTable(); $asso_t = $this->_con->pfx.'idf_tag_idf_upload_assoc'; $sql = 'SELECT '.$tag_t.'.id AS id, COUNT(*) AS nb_use FROM '.$tag_t.' '."\n". 'LEFT JOIN '.$asso_t.' ON idf_tag_id='.$tag_t.'.id '."\n". 'LEFT JOIN '.$what_t.' ON idf_upload_id='.$what_t.'.id '."\n". - 'WHERE idf_tag_id IS NOT NULL AND '.$what_t.'.project='.$this->id.' GROUP BY '.$tag_t.'.id, '.$tag_t.'.class, '.$tag_t.'.name ORDER BY '.$tag_t.'.class ASC, '.$tag_t.'.name ASC'; + 'WHERE idf_tag_id IS NOT NULL '.$extra.' AND '.$what_t.'.project='.$this->id.' GROUP BY '.$tag_t.'.id, '.$tag_t.'.class, '.$tag_t.'.name ORDER BY '.$tag_t.'.class ASC, '.$tag_t.'.name ASC'; } $tags = array(); foreach ($this->_con->select($sql) as $idc) { diff --git a/src/IDF/Views/Download.php b/src/IDF/Views/Download.php index 049d633..23fa425 100644 --- a/src/IDF/Views/Download.php +++ b/src/IDF/Views/Download.php @@ -51,7 +51,15 @@ class IDF_Views_Download $pag->summary = __('This table shows the files to download.'); $pag->action = array('IDF_Views_Download::index', array($prj->shortname)); $pag->edit_action = array('IDF_Views_Download::view', 'shortname', 'id'); - $pag->forced_where = new Pluf_SQL('project=%s', array($prj->id)); + $sql = 'project=%s'; + $ptags = self::getDownloadTags($prj); + $dtag = array_pop($ptags); // The last tag is the deprecated tag. + $ids = self::getDeprecatedFilesIds($prj); + if (count($ids)) { + $sql .= ' AND id NOT IN ('.implode(',', $ids).')'; + } + $pag->forced_where = new Pluf_SQL($sql, array($prj->id)); + $list_display = array( 'file' => __('File'), array('summary', 'IDF_Views_Download_SummaryAndLabels', __('Summary')), @@ -69,6 +77,8 @@ class IDF_Views_Download 'page_title' => $title, 'downloads' => $pag, 'tags' => $tags, + 'deprecated' => count($ids), + 'dlabel' => $dtag, ), $request); @@ -246,6 +256,8 @@ class IDF_Views_Download $title = sprintf(__('%1$s Downloads with Label %2$s'), (string) $prj, (string) $tag); // Paginator to paginate the downloads + $ptags = self::getDownloadTags($prj); + $dtag = array_pop($ptags); // The last tag is the deprecated tag. $pag = new Pluf_Paginator(new IDF_Upload()); $pag->model_view = 'join_tags'; $pag->class = 'recent-issues'; @@ -273,6 +285,7 @@ class IDF_Views_Download 'label' => $tag, 'downloads' => $pag, 'tags' => $tags, + 'dlabel' => $dtag, ), $request); } @@ -289,6 +302,25 @@ class IDF_Views_Download IDF_Form_UploadConf::init_predefined); } + + /** + * Get deprecated file ids. + * + * @return array Ids of the deprecated files. + */ + public static function getDeprecatedFilesIds($project) + { + $ptags = self::getDownloadTags($project); + $dtag = array_pop($ptags); // The last tag is the deprecated tag. + $sql = new Pluf_SQL('project=%s AND idf_tag_id=%s', array($project->id, + $dtag->id)); + $ids = array(); + foreach (Pluf::factory('IDF_Upload')->getList(array('filter' => $sql->gen(), 'view' => 'join_tags')) + as $file) { + $ids[] = (int) $file->id; + } + return $ids; + } } /** diff --git a/src/IDF/templates/downloads/index.html b/src/IDF/templates/downloads/index.html index 3363052..e58e0ca 100644 --- a/src/IDF/templates/downloads/index.html +++ b/src/IDF/templates/downloads/index.html @@ -10,10 +10,16 @@ {block context}

{trans 'Number of files:'} {$downloads.nb_items}

{assign $class = ''}{assign $i = 0} -

{foreach $tags as $label} -{aurl 'url', 'IDF_Views_Download::listLabel', array($project.shortname, $label.id)} -{if $class != $label.class}{if $i != 0}
{/if}{$label.class}: {/if} -{$label.name},{assign $i = $i + 1}{assign $class = $label.class}{/foreach}

+{if !$label or $label.id != $dlabel.id} +

{foreach $tags as $lab} +{aurl 'url', 'IDF_Views_Download::listLabel', array($project.shortname, $lab.id)} +{if $class != $lab.class}{if $i != 0}
{/if}{$lab.class}: {/if} +{$lab.name},{assign $i = $i + 1}{assign $class = $lab.class}{/foreach}

+{/if} +{if $deprecated > 0} +{aurl 'url', 'IDF_Views_Download::listLabel', array($project.shortname, $dlabel.id)} +

{blocktrans}See the deprecated files.{/blocktrans}

+{/if} {/block}