diff options
author | jbalogh@mozilla.com <jbalogh@mozilla.com@4eb1ac78-321c-0410-a911-ec516a8615a5> | 2009-02-14 18:50:06 (GMT) |
---|---|---|
committer | jbalogh@mozilla.com <jbalogh@mozilla.com@4eb1ac78-321c-0410-a911-ec516a8615a5> | 2009-02-14 18:50:06 (GMT) |
commit | f207721d23b41e3c45acf36b82835c892465de75 (patch) | |
tree | 4f1963172978439152f8bf836cb1eb2743b3b0b2 | |
parent | d94571b08f841fe05b397690b0b7a13c40a3257e (diff) |
bug 435806, listing other addons from all authors
Also: not limiting other-addon search to extensions & themes, and truncating the
addon names so they don't stretch the page.
addons_display_other_addons_by handles plurals better, translation already
updated in r22259.
git-svn-id: http://svn.mozilla.org/addons/trunk@22272 4eb1ac78-321c-0410-a911-ec516a8615a5
-rw-r--r-- | site/app/controllers/addons_controller.php | 31 | ||||
-rw-r--r-- | site/app/models/addon.php | 14 | ||||
-rw-r--r-- | site/app/tests/models/addon.test.php | 17 | ||||
-rw-r--r-- | site/app/tests/views/helpers/addons_html.test.php | 6 | ||||
-rw-r--r-- | site/app/views/addons/display.thtml | 15 | ||||
-rw-r--r-- | site/app/views/elements/addon_author_addons.thtml | 65 | ||||
-rw-r--r-- | site/app/views/helpers/addons_html.php | 8 |
7 files changed, 129 insertions, 27 deletions
diff --git a/site/app/controllers/addons_controller.php b/site/app/controllers/addons_controller.php index e30f38f..4e5d264 100644 --- a/site/app/controllers/addons_controller.php +++ b/site/app/controllers/addons_controller.php @@ -109,24 +109,21 @@ class AddonsController extends AppController $this->publish('isAuthor', false); } - // get author's other addons - $this->User->bindFully(); // we need their addons as well - $thisuser = $this->User->findById($addon_data['User'][0]['id']); - if (!empty($thisuser)) { + // get other addons for the author(s) + foreach ($addon_data['User'] as $_user) + $_userids[] = $_user['id']; + $_addonids = $this->Addon->getAddonsForAuthors($_userids); + + if (!empty($_addonids)) { // re-fetch the addons to get the translations too - $_useraddons = array(); - foreach($thisuser['Addon'] as $_addon) $_addonids[] = $_addon['id']; - if (!empty($_addonids)) { - $_addoncriteria = array( - 'Addon.id' => $_addonids, - 'Addon.addontype_id' => array(ADDON_EXTENSION, ADDON_THEME), - 'Addon.inactive' => 0, - 'Addon.status' => $this->status - ); - $authorAddons = $this->Addon->findAll($_addoncriteria, null, 'Translation.name'); - } else { - $authorAddons = array(); - } + $_addoncriteria = array( + 'Addon.id' => $_addonids, + 'Addon.inactive' => 0, + 'Addon.status' => $this->status + ); + $authorAddons = $this->Addon->findAll($_addoncriteria, null, 'Translation.name'); + } else { + $authorAddons = array(); } $this->publish('authorAddons',$authorAddons); diff --git a/site/app/models/addon.php b/site/app/models/addon.php index 82a3ffe..b7a6418 100644 --- a/site/app/models/addon.php +++ b/site/app/models/addon.php @@ -656,6 +656,20 @@ class Addon extends AppModel return $date['0']['addons_collections']['added']; } + /** + * Return the ids of addons authored by any of the User ids. + */ + function getAddonsForAuthors($author_ids) { + $addon_id_sql = "SELECT DISTINCT addons.id + FROM addons + INNER JOIN addons_users + ON (addons.id=addons_users.addon_id AND + addons_users.user_id IN (".implode(', ', $author_ids)."))"; + foreach($this->query($addon_id_sql) as $addon) + $addon_ids[] = $addon['addons']['id']; + return $addon_ids; + } + /* * * * * * deprecated functions * * * * * */ /** diff --git a/site/app/tests/models/addon.test.php b/site/app/tests/models/addon.test.php new file mode 100644 index 0000000..0f59c7e --- /dev/null +++ b/site/app/tests/models/addon.test.php @@ -0,0 +1,17 @@ +<?php + +class AddonModelTest extends UnitTestCase { + + function AddonModelTest() { + loadModel('Addon'); + $this->Addon = new Addon(); + } + + function testGetAddonsForAuthors() { + $this->assertEqual($this->Addon->getAddonsForAuthors(array(4)), + array(6)); + $this->assertEqual(sort($this->Addon->getAddonsForAuthors(array(1, 3))), + array(1, 2, 3, 4, 5)); + } +} +?> diff --git a/site/app/tests/views/helpers/addons_html.test.php b/site/app/tests/views/helpers/addons_html.test.php index 786544b..44ce4c9 100644 --- a/site/app/tests/views/helpers/addons_html.test.php +++ b/site/app/tests/views/helpers/addons_html.test.php @@ -94,5 +94,11 @@ class AddonsHtmlHelperTest extends UnitTestCase { $result = $this->html->unsanitize($test); $this->assertEqual($expected, $result, 'sanitized strings can be reverted'); } + + function testTruncate() { + $this->assertEqual('abc', $this->html->truncateChars(5, 'abc')); + $this->assertEqual('abcde', $this->html->truncateChars(5, 'abcde')); + $this->assertEqual('ab...', $this->html->truncateChars(5, 'abcdef')); + } } ?> diff --git a/site/app/views/addons/display.thtml b/site/app/views/addons/display.thtml index f302b47..c06b389 100644 --- a/site/app/views/addons/display.thtml +++ b/site/app/views/addons/display.thtml @@ -418,25 +418,20 @@ if (in_array($addon['Addon']['status'], $experimental_status)) { ?> <?php if (count($authorAddons) > 1): ?> - <h4><?=sprintf(_('addons_display_other_addons_by'),$html->linkUsersFromModel($addon['User'], 0));?></h4> + <h4><?=sprintf(n___('addons_display_other_addons_by', 'addons_display_other_addons_by', count($addon['User'])), + $html->linkUsersFromModel($addon['User'], 0));?> + </h4> <ul> <?php if (count($authorAddons) > 3) { echo '<form id="addons-author-addons" method="get" action="">'; echo '<select id="addons-author-addons-select" name="addons-author-addons-select" onchange="this.form.submit()">'; - foreach ($authorAddons as $authorAddon) { - $selected = ($authorAddon['Addon']['id'] == $addon['Addon']['id']) ? ' selected="selected" ' : ''; - echo "<option value='{$authorAddon['Addon']['id']}' {$selected}>{$authorAddon['Translation']['name']['string']}</option>\n"; - } + echo $this->renderElement('addon_author_addons', array('tag' => 'option')); echo '</select>'; echo '<input class="hidden" type="submit" value="'._('addons_author_addons_submit').'"/>'; echo '</form>'; } else { - foreach ($authorAddons as $authorAddon) { - if ($authorAddon['Addon']['id'] != $addon['Addon']['id']) { - echo "<li>".$html->link($authorAddon['Translation']['name']['string'],'/addon/'.$authorAddon['Addon']['id'])."</li>\n"; - } - } + echo $this->renderElement('addon_author_addons', array('tag' => 'li')); } ?> </ul> diff --git a/site/app/views/elements/addon_author_addons.thtml b/site/app/views/elements/addon_author_addons.thtml new file mode 100644 index 0000000..5b915f4 --- /dev/null +++ b/site/app/views/elements/addon_author_addons.thtml @@ -0,0 +1,65 @@ +<?php +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is addons.mozilla.org site. + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Jeff Balogh <jbalogh@mozilla.com (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +/** + * This element uses the following local variables: + * - $tag (either 'option' or 'li'; what kind of elements to output) + * - $addon (the current addon being displayed) + * - $authorAddons (list of other addons by the authors) + */ + +foreach ($authorAddons as $authorAddon) { + $id = $authorAddon['Addon']['id']; + // Truncating at 25 because that lines the select box up with the natural + // border of the page layout. + $name = $html->truncateChars(25, $authorAddon['Translation']['name']['string']); + + $nicknames = array(); + foreach ($authorAddon['User'] as $user) + $nicknames[] = empty($user['nickname']) ? $user['firstname'].' '.$user['lastname'] : $user['nickname']; + $title = implode(', ', $nicknames); + + if ($tag == 'li' && $id != $addon['Addon']['id']) { + echo "<li><a href='{$html->url('/addon/'.$id)}' title='{$title}'>{$name}</a></li>"; + } else if ($tag == 'option') { + $selected = $id == $addon['Addon']['id'] ? 'selected="selected"' : ''; + echo "<option value='{$id}' title='{$title}' {$selected}>{$name}</option>"; + } +} +?> diff --git a/site/app/views/helpers/addons_html.php b/site/app/views/helpers/addons_html.php index a275e9d..a74b69f 100644 --- a/site/app/views/helpers/addons_html.php +++ b/site/app/views/helpers/addons_html.php @@ -483,5 +483,13 @@ class AddonsHtmlHelper extends HtmlHelper return $this->output(implode("\n", $select), $return); } + function truncateChars($length, $string) { + if (strlen($string) <= $length) { + return $string; + } else { + $sub = substr($string, 0, $length - 3); + return $sub.'...'; + } + } } ?> |