summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/welcome.php11
-rw-r--r--core/helpers/album.php3
-rw-r--r--core/helpers/photo.php3
-rw-r--r--core/models/item.php1
-rw-r--r--modules/info/views/info_block.html.php12
-rw-r--r--modules/user/helpers/user_installer.php7
-rw-r--r--themes/default/views/album.html.php2
7 files changed, 28 insertions, 11 deletions
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php
index 8bf5138a..b411e314 100644
--- a/core/controllers/welcome.php
+++ b/core/controllers/welcome.php
@@ -91,15 +91,22 @@ class Welcome_Controller extends Template_Controller {
function add($count) {
srand(time());
$parents = ORM::factory("item")->where("type", "album")->find_all()->as_array();
+ $user_module = ORM::factory("module")->where("name", "user")->find();
+
+ if ($user_module->loaded) {
+ $user_id = ORM::factory("user")->find()->id;
+ } else {
+ $user_id = null;
+ }
for ($i = 0; $i < $count; $i++) {
$parent = $parents[array_rand($parents)];
if (!rand(0, 10)) {
- $parents[] = album::create($parent->id, "rnd_" . rand(), "Rnd $i", "rnd $i")
+ $parents[] = album::create($parent->id, "rnd_" . rand(), "Rnd $i", "rnd $i", "random album $i", $user_id)
->set_thumbnail(DOCROOT . "core/tests/test.jpg", 200, 150)
->save();
} else {
photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg",
- "thumbnail.jpg", "rnd_" . rand(), "sample thumbnail");
+ "thumbnail.jpg", "rnd_" . rand(), "sample thumbnail", $user_id);
}
if (!($i % 100)) {
diff --git a/core/helpers/album.php b/core/helpers/album.php
index 021c09f3..3c97f7e8 100644
--- a/core/helpers/album.php
+++ b/core/helpers/album.php
@@ -32,12 +32,13 @@ class Album_Core {
* @param string $description (optional) the longer description of this album
* @return Item_Model
*/
- static function create($parent_id, $name, $title, $description=null) {
+ static function create($parent_id, $name, $title, $description=null, $user_id = null) {
$album = ORM::factory("item");
$album->type = "album";
$album->title = $title;
$album->description = $description;
$album->name = $name;
+ $album->user_id = $user_id;
while (ORM::Factory("item")
->where("parent_id", $parent_id)
diff --git a/core/helpers/photo.php b/core/helpers/photo.php
index ef94f52b..231e3a9c 100644
--- a/core/helpers/photo.php
+++ b/core/helpers/photo.php
@@ -33,12 +33,13 @@ class Photo_Core {
* @param string $description (optional) the longer description of this photo
* @return Item_Model
*/
- static function create($parent_id, $filename, $name, $title, $description=null) {
+ static function create($parent_id, $filename, $name, $title, $description=null, $user_id = null) {
$photo = ORM::factory("item");
$photo->type = "photo";
$photo->title = $title;
$photo->description = $description;
$photo->name = $name;
+ $photo->user_id = $user_id;
$pi = pathinfo(basename($filename));
if (empty($pi["extension"])) {
diff --git a/core/models/item.php b/core/models/item.php
index 3a9faea0..c8d8d1e2 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -19,6 +19,7 @@
*/
class Item_Model extends ORM_MPTT {
protected $children = 'items';
+ protected $has_one = array('user');
/**
* Is this item an album?
diff --git a/modules/info/views/info_block.html.php b/modules/info/views/info_block.html.php
index eac76b40..543ce3db 100644
--- a/modules/info/views/info_block.html.php
+++ b/modules/info/views/info_block.html.php
@@ -3,19 +3,19 @@
<tbody>
<tr>
<th>Title:</th>
- <td>Christmas 2007</td>
+ <td><?= $item->title; ?></td>
</tr>
<tr>
- <th>Taken:</th>
- <td>January 21, 2008</td>
+ <th>Description:</th>
+ <td><?= $item->description; ?></td>
</tr>
<tr>
- <th>Uploaded:</th>
- <td>January 27, 2008</td>
+ <th>Name:</th>
+ <td><?= $item->name; ?></td>
</tr>
<tr>
<th>Owner:</th>
- <td><a href="#">username</a></td>
+ <td><a href="#"><?= isset($item->user_id) ? $item->user->name : "anonymous"?></a></td>
</tr>
<tr>
<td colspan="2" class="toggle">
diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php
index c69781e5..82221f10 100644
--- a/modules/user/helpers/user_installer.php
+++ b/modules/user/helpers/user_installer.php
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_installer {
+ protected $has_many = array('items');
+
public static function install() {
Kohana::log("debug", "user_installer::install");
$db = Database::instance();
@@ -56,6 +58,8 @@ class user_installer {
PRIMARY KEY (`group_id`, `user_id`),
UNIQUE KEY(`user_id`, `group_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+
+ $db->query("ALTER TABLE `items` ADD `user_id` INT(9) NULL");
$user_module = ORM::factory("module")->where("name", "user")->find();
$user_module->name = "user";
@@ -66,6 +70,8 @@ class user_installer {
$user->name = "admin";
$user->display_name = "Gallery Administrator";
$user->save();
+ $id = $user->id;
+ $db->query("UPDATE `items` SET `user_id` = $id ");
foreach (array("administrator", "registered") as $group_name) {
$group = ORM::factory("group")->where("name", $group_name)->find();
@@ -81,6 +87,7 @@ class user_installer {
public static function uninstall() {
$db = Database::instance();
+ $db->query("ALTER TABLE `items` DROP `user_id`");
$db->query("DROP TABLE IF EXISTS `users`;");
$db->query("DROP TABLE IF EXISTS `groups`;");
$db->query("DROP TABLE IF EXISTS `groups_users`;");
diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php
index 19ba5998..abac6d3f 100644
--- a/themes/default/views/album.html.php
+++ b/themes/default/views/album.html.php
@@ -21,7 +21,7 @@
<h2><?= $child->title ?></h2>
<ul class="gMetadata">
<li>Views: 321</li>
- <li>By: <a href="#">username</a></li>
+ <li>By: <a href="#"><?= isset($child->user_id) ? $child->user->name : "anonymous"?></a></li>
</ul>
</li>
<? endforeach ?>