[Isocial-svn] SF.net SVN: isocial: [215] app
Status: Pre-Alpha
Brought to you by:
aguidrevitch
From: <fsn...@us...> - 2008-05-21 17:41:39
|
Revision: 215 http://isocial.svn.sourceforge.net/isocial/?rev=215&view=rev Author: fsnobody Date: 2008-05-21 10:24:33 -0700 (Wed, 21 May 2008) Log Message: ----------- add, delete photo -> album photos_count set from triggers Modified Paths: -------------- app/controllers/photoapp/album_controller.php app/installers/photoapp/album_installer.php app/installers/user_installer.php app/models/photoapp_photo.php Removed Paths: ------------- app/installers/photoapp/photo_installer.php Modified: app/controllers/photoapp/album_controller.php =================================================================== --- app/controllers/photoapp/album_controller.php 2008-05-21 09:03:08 UTC (rev 214) +++ app/controllers/photoapp/album_controller.php 2008-05-21 17:24:33 UTC (rev 215) @@ -58,12 +58,12 @@ //$this->debug($this->params); $photo = $this->PhotoappPhoto->findFirst(array('id' => $this->params['id'])); if ($photo) { - $album = $this->PhotoappAlbum->findFirst(array('id' => $photo->album_id)); - if ($album && $album->owner == $this->current_user->getId()) { - if ($photo->destroyAll("id = " . $photo->id)) { - $album->photos_count = $album->photos_count - 1; - $album->save(); - $this->redirectTo(array('action' => 'view', 'id' => $album->id)); + $photo->album->load(); + if ($photo->album->getId() && $photo->album->owner == $this->current_user->getId()) { + if ($photo->destroy()) { + //$photo->album->photos_count = $photo->album->photos_count - 1; + //$photo->album->save(); + $this->redirectTo(array('action' => 'view', 'id' => $photo->album->id)); } else { $this->importErrors( $this->PhotoappPhoto->getErrors() ); } @@ -177,16 +177,17 @@ $copy_from = $_FILES['album']['tmp_name'][$field]; if (move_uploaded_file($copy_from, $copy_to)) { $album = $this->PhotoappAlbum->find($this->params['id']); - $photo = new PhotoappPhoto (); $photo->img = $this->current_user->getId() . "@" . $photo_name; $photo->album_id = $album->getId(); + $photo->save(); + + $album = $this->PhotoappAlbum->find($this->params['id']); if( empty($album->img)) { $photo->is_cover = 1; $album->img = $photo->img; } - $photo->save(); - $album->photos_count += 1; + //$album->photos_count += 1; $album->save(); } } Modified: app/installers/photoapp/album_installer.php =================================================================== --- app/installers/photoapp/album_installer.php 2008-05-21 09:03:08 UTC (rev 214) +++ app/installers/photoapp/album_installer.php 2008-05-21 17:24:33 UTC (rev 215) @@ -19,10 +19,41 @@ ) ENGINE=InnoDB"); + $this->execute( + "CREATE TABLE `photoapp_photos` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `album_id` int(11) NOT NULL , + `is_cover` int(1) UNSIGNED NOT NULL DEFAULT '0', + `name` char(100) NOT NULL DEFAULT '', + `caption` char(255) NOT NULL DEFAULT '', + `created_at` datetime NOT NULL , + `img` char(255) NOT NULL DEFAULT '' + + ) ENGINE=InnoDB"); + + + $this->execute( + "CREATE TRIGGER papp_photo_insert AFTER INSERT ON photoapp_photos + FOR EACH ROW BEGIN + UPDATE `photoapp_albums` SET photos_count = photos_count + 1 WHERE id = NEW.album_id; + END; + "); + + $this->execute( + "CREATE TRIGGER papp_photo_delete AFTER DELETE ON photoapp_photos + FOR EACH ROW BEGIN + UPDATE `photoapp_albums` SET photos_count = photos_count - 1 WHERE id = OLD.album_id; + END; + "); + + } + + function down_1() { + $this->dropTable('photoapp_photos'); $this->dropTable('photoapp_albums'); } } Deleted: app/installers/photoapp/photo_installer.php =================================================================== --- app/installers/photoapp/photo_installer.php 2008-05-21 09:03:08 UTC (rev 214) +++ app/installers/photoapp/photo_installer.php 2008-05-21 17:24:33 UTC (rev 215) @@ -1,29 +0,0 @@ -<?php -class PhotoInstaller extends AkInstaller -{ - var $module = 'photoapp'; - - function up_1() - { - - $this->execute( - "CREATE TABLE `photoapp_photos` ( - `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, - `album_id` int(11) NOT NULL , - `is_cover` int(1) UNSIGNED NOT NULL DEFAULT '0', - `name` char(100) NOT NULL DEFAULT '', - `caption` char(255) NOT NULL DEFAULT '', - `created_at` datetime NOT NULL , - `img` char(255) NOT NULL DEFAULT '' - - ) ENGINE=InnoDB"); - - } - - function down_1() - { - $this->dropTable('photoapp_photos'); - } -} - -?> \ No newline at end of file Modified: app/installers/user_installer.php =================================================================== --- app/installers/user_installer.php 2008-05-21 09:03:08 UTC (rev 214) +++ app/installers/user_installer.php 2008-05-21 17:24:33 UTC (rev 215) @@ -23,7 +23,7 @@ `created_at` datetime NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id), INDEX user_idx (user_id) - ) ENGINE=innoDB"); + ) ENGINE=InnoDB"); $this->execute( "CREATE TABLE `friends` ( Modified: app/models/photoapp_photo.php =================================================================== --- app/models/photoapp_photo.php 2008-05-21 09:03:08 UTC (rev 214) +++ app/models/photoapp_photo.php 2008-05-21 17:24:33 UTC (rev 215) @@ -4,12 +4,18 @@ { var $belongs_to = array('album' => array('class_name' => 'PhotoappAlbum', 'primary_key_name' => 'album_id') ); + /*function __constructor() { + echo 1; + die(); + $album = new PhotoappAlbum(); + return parent::__constructor(); + }*/ + function beforeDestroy() { if ($this->is_cover) { $this->album->load(); - - $this->album->img = "xxx"; + $this->album->img = ""; $this->album->save(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |