Skip to content

Commit

Permalink
Added media counts to admin homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jun 4, 2011
1 parent 926a872 commit 5204f53
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
config.php
.htaccess
media/audio/*
media/image/*
3 changes: 3 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
$searchSuggestions = $searchStats['suggestions'];

$contentStats = Dictionary::getDefinitionService()->getContentStatistics();
$mediaStats = $contentStats['media'];

$changeStats = Dictionary::getChangeService()->getChangeStatistics();
$changePending = isset($changeStats[Status::PENDING]) ? $changeStats[Status::PENDING]['count'] : 0;
Expand All @@ -49,6 +50,8 @@
<ul>
<li><strong><?php echo $contentStats['entries']; ?></strong> entries</li>
<li><strong><a href="entries.php?q=verified:no"><?php echo $contentStats['entries_unverified']; ?></a></strong> unverified entries</li>
<li><strong><?php echo $mediaStats['audio']; ?></strong> entries with audio</li>
<li><strong><?php echo $mediaStats['image']; ?></strong> entries with images</li>
</ul>
</div>
</td>
Expand Down
97 changes: 97 additions & 0 deletions admin/media.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* This file is part of Kumva.
*
* Kumva is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kumva is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kumva. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Rowan Seymour 2010
*
* Purpose: Roles page
*/

include_once '../inc/kumva.php';

$audioCount = 0;
$imageCount = 0;

$function = Request::getPostParam('function', NULL);
if ($function == 'scan' && Session::getCurrent()->hasRole(Role::ADMINISTRATOR)) {
$entries = Dictionary::getDefinitionService()->getEntries();

foreach ($entries as $entry) {
// Check for matching audio and image file
$audioPath = KUMVA_DIR_MEDIA.'/audio/'.$entry->getId().'.mp3';
$imagePath = KUMVA_DIR_MEDIA.'/image/'.$entry->getId().'.jpg';
$flags = 0;
if (file_exists($audioPath)) {
$audioCount++;
$flags = aka_setbit($flags, Media::AUDIO);
}
if (file_exists($imagePath)) {
$imageCount++;
$flags = aka_setbit($flags, Media::IMAGE);
}

// Update entry if flags have changed
if ($entry->getMedia() != $flags) {
$entry->setMedia($flags);
Dictionary::getDefinitionService()->saveEntry($entry);
}
}
}

include_once 'tpl/header.php';
?>
<h3><?php echo KU_STR_MEDIA ?></h3>

<?php if (Session::getCurrent()->hasRole(Role::ADMINISTRATOR)) { ?>
<div class="listcontrols">
<div style="float: right">
<form method="post" action="">
<input type="hidden" name="function" id="function" />
<?php Templates::button('scan', "$('#function').val('scan'); aka_submit(this);", KU_STR_SCAN); ?>
</form>
</div>
</div>
<?php } ?>

<table class="list" cellspacing="0" border="0">
<tr>
<th style="width: 30px">&nbsp;</th>
<th style="width: 20px">&nbsp;</th>
<th><?php echo KU_STR_PATH; ?></th>
<th><?php echo KU_STR_TYPE; ?></th>
<th><?php echo KU_STR_ENTRIES; ?></th>
<th style="width: 30px">&nbsp;</th>
</tr>
<tr>
<td>&nbsp;</td>
<td><?php Templates::icon('folder'); ?></td>
<td class="primarycol">media/audio</td>
<td><?php echo KU_STR_AUDIO; ?></td>
<td style="text-align: center"><?php echo $audioCount; ?></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><?php Templates::icon('folder'); ?></td>
<td class="primarycol">media/image</td>
<td><?php echo KU_STR_IMAGE; ?></td>
<td style="text-align: center"><?php echo $imageCount; ?></td>
<td>&nbsp;</td>
</tr>
</table>
<div class="panel"></div>

<?php include_once 'tpl/footer.php'; ?>
Binary file added gfx/icons/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/icons/media.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/icons/scan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions inc/definition/DefinitionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ public function getContentStatistics() {
$stats['entries'] = $this->database->scalar('SELECT COUNT(*) FROM `'.KUMVA_DB_PREFIX.'definition` WHERE revisionstatus = 1');
$stats['entries_unverified'] = $this->database->scalar(
'SELECT COUNT(*) FROM `'.KUMVA_DB_PREFIX.'definition` WHERE revisionstatus = 1 AND unverified = 1');
$stats['media'] = $this->database->row(
'SELECT
COUNT(CASE WHEN media & 1 THEN 1 ELSE NULL END) AS `audio`,
COUNT(CASE WHEN media & 2 THEN 1 ELSE NULL END) AS `image`
FROM `'.KUMVA_DB_PREFIX.'entry`');
return $stats;
}

Expand Down
48 changes: 48 additions & 0 deletions lib/akabanga/test/UtilsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* This file is part of Akabanga.
*
* Akabanga is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Akabanga is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Akabanga. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Rowan Seymour 2010
*
* Purpose: Unit tests for utils functions
*/

require_once "../akabanga.php";

/**
* Test case for BeanUtils class
*/
class UtilsTest extends PHPUnit_Framework_TestCase {

public function test_getbit() {
$val = 10; // 1010

$this->assertEquals(false, aka_getbit($val, 0));
$this->assertEquals(true, aka_getbit($val, 1));
$this->assertEquals(false, aka_getbit($val, 2));
$this->assertEquals(true, aka_getbit($val, 3));
}

public function test_setbit() {
$val1 = 2; // 0010
$val2 = 15; // 1111

$this->assertEquals(3, aka_setbit($val1, 0, true));
$this->assertEquals(11, aka_setbit($val2, 2, false));
}
}

?>
Empty file added media/image/index.html
Empty file.

0 comments on commit 5204f53

Please sign in to comment.