[Isocial-svn] SF.net SVN: isocial: [234] app
Status: Pre-Alpha
Brought to you by:
aguidrevitch
From: <fsn...@us...> - 2008-06-02 15:21:23
|
Revision: 234 http://isocial.svn.sourceforge.net/isocial/?rev=234&view=rev Author: fsnobody Date: 2008-06-02 08:21:28 -0700 (Mon, 02 Jun 2008) Log Message: ----------- photoappPhoto - now use Media Item and Store File Modified Paths: -------------- app/controllers/photoapp/album_controller.php app/installers/photoapp/album_installer.php app/installers/user_installer.php app/models/photoapp_photo.php app/views/photoapp/album/edit_photo.tpl app/views/photoapp/album/index.tpl app/views/photoapp/album/uploaded.tpl Added Paths: ----------- app/models/media_item.php Modified: app/controllers/photoapp/album_controller.php =================================================================== --- app/controllers/photoapp/album_controller.php 2008-06-01 17:32:12 UTC (rev 233) +++ app/controllers/photoapp/album_controller.php 2008-06-02 15:21:28 UTC (rev 234) @@ -41,9 +41,9 @@ if ($photo) { $album = $this->PhotoappAlbum->find($photo->album_id); if ($album) { - - $album->img = $photo->img; - $album->save(); + $photo->stored_file->load(); + $album->img = $photo->stored_file->url(); + $album->save(); } } $this->redirectTo(array('action' => 'view', 'id' => $photo->album_id)); @@ -65,7 +65,22 @@ if ($photo) { $album = $this->PhotoappAlbum->findFirst(array('id' => $photo->album_id)); if ($album->owner == $this->current_user->getId()) { + $photo->setAttributes($this->params['photo']); + + // counters + if ($photo_old->album_id != $photo->album_id) { + $old_album = $this->PhotoappAlbum->find($photo_old->album_id); + $old_album->photos_count -= 1; + $old_album->save(); + $new_album = $this->PhotoappAlbum->find($photo->album_id); + $new_album->photos_count += 1; + $new_album->save(); + } + + $photo->media_item = $photo->media_item->load(); + $photo->media_item->setAttributes($this->params['media_item']); + $photo->media_item->save(); // check for old album. cases: 1 just update info, 2 moving to another album if ($this->Request->isPost() && $photo->save()){ $this->redirectTo(array('action' => 'view', 'id' => $album->id)); @@ -76,6 +91,11 @@ } } else if (!empty($this->params['id']) && $this->PhotoappPhoto->find($this->params['id'])) { $this->photo = $this->PhotoappPhoto->find($this->params['id']); + + $this->media_item = $this->photo->media_item->load(); + $this->photo->body = $this->media_item->body; + //$this->debug($this->photo->body); + $this->album = $this->PhotoappAlbum->find($this->photo->album_id); $this->albums = $this->PhotoappAlbum->find('all', array('conditions' => array('owner = ' . $this->current_user->getId()))); } @@ -96,6 +116,7 @@ $photo->album->load(); if ($photo->album->getId() && $photo->album->owner == $this->current_user->getId()) { if ($photo->destroy()) { + $photo->album->reload(); $photo->album->photos_count -= 1; $photo->album->save(); $this->redirectTo(array('action' => 'view', 'id' => $photo->album->id)); @@ -113,7 +134,13 @@ unset($this->params['photo']['action_comment']); foreach ($this->params['photo'] as $k => $v) { $photo = $this->PhotoappPhoto->findFirst(array('id' => $k)); + + $photo->media_item->load(); + $photo->media_item->setAttributes($v); + $photo->media_item->save(); + $photo->setAttributes($v); + $photo->is_new = 0; $photo->save(); } //$this->redirectTo(array('action' => 'index')); @@ -125,7 +152,7 @@ // pre delete $this->album = $this->PhotoappAlbum->find($this->params['id']); } - $this->uploaded_photos = $this->PhotoappPhoto->find('all', array('conditions' => array("name =''", "caption =''"))); + $this->uploaded_photos = $this->PhotoappPhoto->find('all', array('conditions' => array("is_new =1"))); return; } } @@ -156,9 +183,20 @@ unset($photo); $photo = $this->album->photo->build(); $photo->base_file_id = $file->id; + + $photo->media_item->build(); + $photo->media_item->user_id = $this->current_user->getId(); + $photo->media_item->save(); + $photo->media_item_id = $photo->media_item->getId(); + //echo "#" . $photo->media_item->getId() . "#"; + //die(); //$photo->stored_file->assign($file); //$photo->stored_file->build(); //$photo->stored_file->assign($file); + if (empty($this->album->img)) { + $this->album->img = $file->url(); + } + $photo->save(); $this->album->photos_count += 1; } Modified: app/installers/photoapp/album_installer.php =================================================================== --- app/installers/photoapp/album_installer.php 2008-06-01 17:32:12 UTC (rev 233) +++ app/installers/photoapp/album_installer.php 2008-06-02 15:21:28 UTC (rev 234) @@ -24,10 +24,11 @@ `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `album_id` int(11) NOT NULL, `base_file_id` int(11) NOT NULL, - `name` char(100) NOT NULL DEFAULT '', - `caption` char(255) NOT NULL DEFAULT '', + `media_item_id` int(11) NOT NULL, + `is_new` int(1) NOT NULL DEFAULT 1, FOREIGN KEY (album_id) REFERENCES photoapp_albums(id), FOREIGN KEY (base_file_id) REFERENCES base_files(id), + FOREIGN KEY (media_item_id) REFERENCES media_items(id), INDEX album_idx (album_id) ) ENGINE=InnoDB"); Modified: app/installers/user_installer.php =================================================================== --- app/installers/user_installer.php 2008-06-01 17:32:12 UTC (rev 233) +++ app/installers/user_installer.php 2008-06-02 15:21:28 UTC (rev 234) @@ -26,6 +26,17 @@ FOREIGN KEY (user_id) REFERENCES users(id), INDEX user_idx (user_id) ) ENGINE=InnoDB"); + + $this->execute( + "CREATE TABLE `media_items` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `user_id` int(11), + `title` char(255) NOT NULL, + `body` text NOT NULL, + `created_at` datetime NOT NULL, + FOREIGN KEY (user_id) REFERENCES users(id), + INDEX user_idx (user_id) + ) ENGINE=InnoDB"); $this->execute( "CREATE TABLE `confirmations` ( Added: app/models/media_item.php =================================================================== --- app/models/media_item.php (rev 0) +++ app/models/media_item.php 2008-06-02 15:21:28 UTC (rev 234) @@ -0,0 +1,10 @@ +<?php + +class MediaItem extends ActiveRecord +{ + var $table_name = 'media_items'; + var $belongs_to = array('User'); + +} + +?> Modified: app/models/photoapp_photo.php =================================================================== --- app/models/photoapp_photo.php 2008-06-01 17:32:12 UTC (rev 233) +++ app/models/photoapp_photo.php 2008-06-02 15:21:28 UTC (rev 234) @@ -3,10 +3,33 @@ class PhotoappPhoto extends ActiveRecord { var $belongs_to = array('album' => array('class_name' => 'PhotoappAlbum', 'primary_key_name' => 'album_id'), - 'stored_file' => array('class_name' => 'StoredFile', 'primary_key_name' => 'base_file_id')); + 'stored_file' => array('class_name' => 'StoredFile', 'primary_key_name' => 'base_file_id'), + 'media_item' => array('class_name' => 'MediaItem', 'primary_key_name' => 'media_item_id') + ); + //var $has_one = array('media_item' => array('class_name' => 'MediaItem', 'primary_key_name' => 'media_item_id')); + +/* + function beforeDestroy() { + $this->stored_file->load(); + //echo "@" . $this->stored_file->url() . "@"; + + $albums_cover = $this->album->find('all', array('conditions' => array("img = '" . $this->stored_file->url() . "'"))); + if ($albums_cover) + foreach ($albums_cover as $album) { + if ($album) { + //echo $album->getId() . "#"; + $album->img = ""; + $album->save(); + } + } + return parent::beforeDestroy(); + } +*/ + function afterDestroy() { + /* $albums_cover = $this->album->find('all', array('conditions' => array("img = '" . $this->img . "'"))); if ($albums_cover) @@ -20,7 +43,24 @@ $this->stored_file->load(); + + //echo "@" . $this->stored_file->url() . "@"; + + $albums_cover = $this->album->find('all', array('conditions' => array("img = '" . $this->stored_file->url() . "'"))); + if ($albums_cover) + foreach ($albums_cover as $calbum) { + if ($calbum) { + //echo $calbum->getId() . "#"; + $calbum->img = ""; + $calbum->save(); +//die(); + } + } + + $this->stored_file->destroy(); + $this->media_item->load(); + $this->media_item->destroy(); return parent::afterDestroy(); } Modified: app/views/photoapp/album/edit_photo.tpl =================================================================== --- app/views/photoapp/album/edit_photo.tpl 2008-06-01 17:32:12 UTC (rev 233) +++ app/views/photoapp/album/edit_photo.tpl 2008-06-02 15:21:28 UTC (rev 234) @@ -10,14 +10,14 @@ <?= $form_helper->hidden_field('photo_old', 'album_id', array('value' => $photo->get('album_id')))?> <div class="edit_container"> - <div class="photo_comment"><? $photo->stored_file->load();?> + <div class="photo_comment"><? $photo->stored_file->load(); $photo->media_item->load();?> <div class="img_medium"><img src="/preview/620x500/<?= $photo->stored_file->url() ?>" /></div> <div class="data_medium"> <div class="form_create_row"> <label >_{Name}:</label> <div class="form_create_col"> - <?= $form_helper->text_field('photo', 'name', array('class' => 'textinput small')) ?> + <?= $form_helper->text_field('media_item', 'title', array('class' => 'textinput small', )) ?> </div> </div><div class="clearfix"></div> @@ -33,7 +33,8 @@ <div class="form_create_row"> <label >_{Description}:</label> <div class="form_create_col"> - <?= $form_helper->text_area('photo', 'caption', array('rows' => '5', 'class' => 'small')) ?> + <?= $form_helper->text_area('media_item', 'body', array('rows' => '5', 'class' => 'small')) ?> + </div> </div><div class="clearfix"></div> Modified: app/views/photoapp/album/index.tpl =================================================================== --- app/views/photoapp/album/index.tpl 2008-06-01 17:32:12 UTC (rev 233) +++ app/views/photoapp/album/index.tpl 2008-06-02 15:21:28 UTC (rev 234) @@ -26,7 +26,7 @@ <div class="container"> {loop my_albums} <div class="album"> - <div class="img"><? if ($my_album->get('img') != '' || $my_album->get('img')) {?><img src="/preview/index/100x100/<?= $my_album->get('img')?>" /><? + <div class="img"><? if ($my_album->get('img') != '' || $my_album->get('img')) {?><img src="/preview/100x100/<?= $my_album->get('img')?>" /><? } else {?>_{No cover choosed}<? } ?></div> Modified: app/views/photoapp/album/uploaded.tpl =================================================================== --- app/views/photoapp/album/uploaded.tpl 2008-06-01 17:32:12 UTC (rev 233) +++ app/views/photoapp/album/uploaded.tpl 2008-06-02 15:21:28 UTC (rev 234) @@ -24,7 +24,7 @@ <div class="form_create_row"> <label >_{Name}:</label> <div class="form_create_col"> - <?= $form_helper->text_field('photo[' . $uploaded_photo->getId() . ']', 'name', array('class' => 'text_input small')) ?> + <?= $form_helper->text_field('photo[' . $uploaded_photo->getId() . ']', 'title', array('class' => 'text_input small')) ?> </div> </div> <div class="clearfix"></div> @@ -32,7 +32,7 @@ <div class="form_create_row"> <label >_{Description}:</label> <div class="form_create_col"> - <?= $form_helper->text_area('photo[' . $uploaded_photo->getId() . ']', 'caption', array('rows' => '5', 'class' => 'small')) ?> + <?= $form_helper->text_area('photo[' . $uploaded_photo->getId() . ']', 'body', array('rows' => '5', 'class' => 'small')) ?> </div> </div> <div class="clearfix"></div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |