New Pack entitiy. Modified DB schema.
authorCameron Ball <cameron@getapproved.com.au>
Mon, 17 Nov 2014 08:50:05 +0000 (16:50 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Mon, 17 Nov 2014 08:50:05 +0000 (16:50 +0800)
DataAccess/DataMapper/DataMapper.php
Domain/Entities/StepMania/IPack.php [new file with mode: 0644]
Domain/Entities/StepMania/Pack.php [new file with mode: 0644]
divinelegy.sql

index c33b9a4..624e03e 100644 (file)
@@ -56,11 +56,6 @@ class DataMapper implements IDataMapper
     public function save(IDivineEntity $entity)\r
     {\r
         $queries = AbstractPopulationHelper::generateUpdateSaveQuery($this->_maps, $entity, $entity->getId(), $this->_db);\r
-\r
-        echo '<pre>';\r
-        print_r($queries);\r
-        echo '</pre>';\r
-        echo '<br /><br />';\r
         \r
         $flattened = array();\r
         $flattened_tables = array();\r
diff --git a/Domain/Entities/StepMania/IPack.php b/Domain/Entities/StepMania/IPack.php
new file mode 100644 (file)
index 0000000..0f7eddf
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+namespace Domain\Entities;
+
+use Domain\Entities\IDivineEntity;
+
+interface IPack extends IDivineEntity
+{
+    public function getTitle();
+    public function getUploader();
+    public function getContributors();
+    public function getSimfiles();
+    public function getFile();
+}
diff --git a/Domain/Entities/StepMania/Pack.php b/Domain/Entities/StepMania/Pack.php
new file mode 100644 (file)
index 0000000..b58ca12
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+
+namespace Domain\Entities\StepMania;
+
+use Exception;
+use Domain\Entities\StepMania\ISimfile;
+use Domain\Entities\IUser;
+use Domain\Entities\IFile;
+use Domain\Entities\IPack;
+use Domain\Entities\AbstractEntity;
+
+class Pack extends AbstractEntity implements IPack
+{    
+    private $_title;
+    private $_uploader;
+    private $_simfiles;
+    private $_file;
+    
+    public function __construct(
+        $title,
+        IUser $uploader,
+        array $simfiles,
+        IFile $file = null)
+    {
+        $this->_title = $title;
+        $this->_uploader = $uploader;
+        $this->_file = $file;
+        
+        foreach($simfiles as $simfile) {
+            if(!$simfile instanceof ISimfile) {
+                throw new Exception('Invalid Simfile array. All elements must be an instance of ISimfile.');
+            }
+        }
+        
+        $this->_simfiles = $simfiles;
+    }
+    
+    public function getContributors() {
+        $contributors = array();
+        foreach($this->_simfiles as $simfile)
+        {
+            /* @var $simfile \Domain\Entities\StepMania\Simfile */
+            $contributors = array_unique(
+                array_merge($contributors, $this->getAllStepArtistsFromSimfile($simfile))
+            );
+        }
+        
+        return $contributors;
+    }
+    
+    public function getFile()
+    {
+        return $this->_file;
+    }
+    
+    public function getSimfiles()
+    {
+        return $this->_file;
+    }
+    
+    public function getTitle()
+    {
+        return $this->_title;
+    }
+    
+    public function getUploader()
+    {
+        return $this->_uploader;
+    }
+    
+    private function getAllStepArtistsFromSimfile(ISimfile $simfile)
+    {
+        $artists = array();
+        foreach($simfile->getSteps() as $steps)
+        {
+            /* @var $steps \Domain\VOs\StepMania\IStepChart */
+            if(!in_array($steps->getArtist(), $artists)) $artists[] = $steps->getArtist ();
+        }
+        
+        return $artists;
+    }
+}
\ No newline at end of file
index 1dab053..789fbf2 100644 (file)
--- MySQL dump 10.13  Distrib 5.6.12, for Win64 (x86_64)\r
---\r
--- Host: localhost    Database: divinelegy\r
--- ------------------------------------------------------\r
--- Server version      5.6.12\r
-\r
-/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\r
-/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\r
-/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\r
-/*!40101 SET NAMES utf8 */;\r
-/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\r
-/*!40103 SET TIME_ZONE='+00:00' */;\r
-/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\r
-/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\r
-/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\r
-/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\r
-\r
---\r
--- Table structure for table `artists`\r
---\r
-\r
-DROP TABLE IF EXISTS `artists`;\r
-/*!40101 SET @saved_cs_client     = @@character_set_client */;\r
-/*!40101 SET character_set_client = utf8 */;\r
-CREATE TABLE `artists` (\r
-  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
-  `name` varchar(255) NOT NULL,\r
-  PRIMARY KEY (`id`)\r
-) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;\r
-/*!40101 SET character_set_client = @saved_cs_client */;\r
-\r
---\r
--- Dumping data for table `artists`\r
---\r
-\r
-LOCK TABLES `artists` WRITE;\r
-/*!40000 ALTER TABLE `artists` DISABLE KEYS */;\r
-INSERT INTO `artists` VALUES (1,'atpunk01'),(2,'FaggotForce');\r
-/*!40000 ALTER TABLE `artists` ENABLE KEYS */;\r
-UNLOCK TABLES;\r
-\r
---\r
--- Table structure for table `simfiles`\r
---\r
-\r
-DROP TABLE IF EXISTS `simfiles`;\r
-/*!40101 SET @saved_cs_client     = @@character_set_client */;\r
-/*!40101 SET character_set_client = utf8 */;\r
-CREATE TABLE `simfiles` (\r
-  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
-  `title` varchar(255) NOT NULL,\r
-  `artist_id` mediumint(8) unsigned NOT NULL,\r
-  `user_id` mediumint(8) unsigned NOT NULL,\r
-  `bpm_high` int(11) NOT NULL,\r
-  `bpm_low` int(11) NOT NULL,\r
-  `bpm_changes` bit(1) NOT NULL,\r
-  `stops` bit(1) NOT NULL,\r
-  `fg_changes` bit(1) NOT NULL,\r
-  `bg_changes` bit(1) NOT NULL,\r
-  PRIMARY KEY (`id`)\r
-) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;\r
-/*!40101 SET character_set_client = @saved_cs_client */;\r
-\r
---\r
--- Dumping data for table `simfiles`\r
---\r
-\r
-LOCK TABLES `simfiles` WRITE;\r
-/*!40000 ALTER TABLE `simfiles` DISABLE KEYS */;\r
-INSERT INTO `simfiles` VALUES (1,'BaBoom',1,1,177,177,'\ 1','\0','\0','\0'),(2,'Some Faggot Chart',2,2,230,230,'\0','\0','\0','\0'),(3,'More Bullshit',2,2,210,210,'\0','\0','\0','\0');\r
-/*!40000 ALTER TABLE `simfiles` ENABLE KEYS */;\r
-UNLOCK TABLES;\r
-\r
---\r
--- Table structure for table `step_artists`\r
---\r
-\r
-DROP TABLE IF EXISTS `step_artists`;\r
-/*!40101 SET @saved_cs_client     = @@character_set_client */;\r
-/*!40101 SET character_set_client = utf8 */;\r
-CREATE TABLE `step_artists` (\r
-  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
-  `tag` varchar(255) NOT NULL,\r
-  `user_id` mediumint(8) unsigned DEFAULT NULL,\r
-  PRIMARY KEY (`id`)\r
-) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;\r
-/*!40101 SET character_set_client = @saved_cs_client */;\r
-\r
---\r
--- Dumping data for table `step_artists`\r
---\r
-\r
-LOCK TABLES `step_artists` WRITE;\r
-/*!40000 ALTER TABLE `step_artists` DISABLE KEYS */;\r
-INSERT INTO `step_artists` VALUES (1,'(-[Jayce]-)',1),(2,'Zaia',2),(3,'Serenade',2);\r
-/*!40000 ALTER TABLE `step_artists` ENABLE KEYS */;\r
-UNLOCK TABLES;\r
-\r
---\r
--- Table structure for table `steps`\r
---\r
-\r
-DROP TABLE IF EXISTS `steps`;\r
-/*!40101 SET @saved_cs_client     = @@character_set_client */;\r
-/*!40101 SET character_set_client = utf8 */;\r
-CREATE TABLE `steps` (\r
-  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
-  `simfile_id` mediumint(8) unsigned NOT NULL,\r
-  `mode` enum('dance-single','dance-double') NOT NULL,\r
-  `rating` int(10) unsigned NOT NULL,\r
-  `difficulty` enum('beginner','easy','medium','hard','challenge','edit') NOT NULL,\r
-  `step_artist_id` mediumint(8) unsigned NOT NULL,\r
-  PRIMARY KEY (`id`)\r
-) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;\r
-/*!40101 SET character_set_client = @saved_cs_client */;\r
-\r
---\r
--- Dumping data for table `steps`\r
---\r
-\r
-LOCK TABLES `steps` WRITE;\r
-/*!40000 ALTER TABLE `steps` DISABLE KEYS */;\r
-INSERT INTO `steps` VALUES (1,1,'dance-single',10,'challenge',1),(2,1,'dance-single',9,'hard',1),(3,1,'dance-single',7,'medium',1),(4,1,'dance-single',4,'easy',1),(5,1,'dance-single',2,'beginner',1),(6,2,'dance-single',15,'beginner',2),(7,3,'dance-single',16,'beginner',3);\r
-/*!40000 ALTER TABLE `steps` ENABLE KEYS */;\r
-UNLOCK TABLES;\r
-\r
---\r
--- Table structure for table `users`\r
---\r
-\r
-DROP TABLE IF EXISTS `users`;\r
-/*!40101 SET @saved_cs_client     = @@character_set_client */;\r
-/*!40101 SET character_set_client = utf8 */;\r
-CREATE TABLE `users` (\r
-  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
-  `email` varchar(255) NOT NULL,\r
-  `display_name` varchar(255) NOT NULL,\r
-  PRIMARY KEY (`id`)\r
-) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;\r
-/*!40101 SET character_set_client = @saved_cs_client */;\r
-\r
---\r
--- Dumping data for table `users`\r
---\r
-\r
-LOCK TABLES `users` WRITE;\r
-/*!40000 ALTER TABLE `users` DISABLE KEYS */;\r
-INSERT INTO `users` VALUES (1,'jayce@divinelegy.com','Jayce'),(2,'chino@chino.net','Chino');\r
-/*!40000 ALTER TABLE `users` ENABLE KEYS */;\r
-UNLOCK TABLES;\r
-\r
---\r
--- Table structure for table `users_meta`\r
---\r
-\r
-DROP TABLE IF EXISTS `users_meta`;\r
-/*!40101 SET @saved_cs_client     = @@character_set_client */;\r
-/*!40101 SET character_set_client = utf8 */;\r
-CREATE TABLE `users_meta` (\r
-  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
-  `user_id` mediumint(8) unsigned NOT NULL,\r
-  `firstname` varchar(255) DEFAULT NULL,\r
-  `lastname` varchar(255) DEFAULT NULL,\r
-  `country` varchar(255) NOT NULL,\r
-  PRIMARY KEY (`id`)\r
-) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;\r
-/*!40101 SET character_set_client = @saved_cs_client */;\r
-\r
---\r
--- Dumping data for table `users_meta`\r
---\r
-\r
-LOCK TABLES `users_meta` WRITE;\r
-/*!40000 ALTER TABLE `users_meta` DISABLE KEYS */;\r
-INSERT INTO `users_meta` VALUES (1,1,'Jayce','Newton','Australia'),(2,2,'Chino','Wood','Australia');\r
-/*!40000 ALTER TABLE `users_meta` ENABLE KEYS */;\r
-UNLOCK TABLES;\r
-/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\r
-\r
-/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\r
-/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\r
-/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\r
-/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\r
-/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\r
-/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\r
-/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\r
-\r
--- Dump completed on 2014-08-31 19:53:16\r
+-- MySQL dump 10.13  Distrib 5.5.38, for debian-linux-gnu (i686)
+--
+-- Host: localhost    Database: divinelegy
+-- ------------------------------------------------------
+-- Server version      5.5.38-0ubuntu0.12.04.1
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+--
+-- Table structure for table `artists`
+--
+
+DROP TABLE IF EXISTS `artists`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `artists` (
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `name` varchar(255) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `files`
+--
+
+DROP TABLE IF EXISTS `files`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `files` (
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `filename` varchar(255) NOT NULL,
+  `hash` varchar(255) NOT NULL,
+  `path` varchar(255) NOT NULL,
+  `mimetype` varchar(255) NOT NULL,
+  `size` int(10) unsigned NOT NULL,
+  `uploaded` int(10) unsigned NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `packs`
+--
+
+DROP TABLE IF EXISTS `packs`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `packs` (
+  `title` varchar(255) NOT NULL,
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `file_id` mediumint(8) unsigned DEFAULT NULL,
+  `user_id` mediumint(8) unsigned NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `simfiles`
+--
+
+DROP TABLE IF EXISTS `simfiles`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `simfiles` (
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `title` varchar(255) NOT NULL,
+  `artist_id` mediumint(8) unsigned NOT NULL,
+  `user_id` mediumint(8) unsigned NOT NULL,
+  `bpm_high` int(11) NOT NULL,
+  `bpm_low` int(11) NOT NULL,
+  `bpm_changes` int(1) DEFAULT NULL,
+  `stops` int(1) DEFAULT NULL,
+  `fg_changes` int(1) DEFAULT NULL,
+  `bg_changes` int(1) DEFAULT NULL,
+  `banner_file_id` mediumint(8) unsigned DEFAULT NULL,
+  `simfile_file_id` mediumint(8) unsigned DEFAULT NULL,
+  `pack_id` mediumint(8) unsigned DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `step_artists`
+--
+
+DROP TABLE IF EXISTS `step_artists`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `step_artists` (
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `tag` varchar(255) NOT NULL,
+  `user_id` mediumint(8) unsigned DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `steps`
+--
+
+DROP TABLE IF EXISTS `steps`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `steps` (
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `simfile_id` mediumint(8) unsigned NOT NULL,
+  `mode` enum('dance-single','dance-double') NOT NULL,
+  `rating` int(10) unsigned NOT NULL,
+  `difficulty` enum('Beginner','Easy','Medium','Hard','Challenge','Edit') NOT NULL,
+  `step_artist_id` mediumint(8) unsigned NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `users`
+--
+
+DROP TABLE IF EXISTS `users`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `users` (
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `email` varchar(255) NOT NULL,
+  `display_name` varchar(255) NOT NULL,
+  `facebook_id` varchar(255) DEFAULT NULL,
+  `auth_token` varchar(255) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `users_meta`
+--
+
+DROP TABLE IF EXISTS `users_meta`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `users_meta` (
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `user_id` mediumint(8) unsigned NOT NULL,
+  `firstname` varchar(255) DEFAULT NULL,
+  `lastname` varchar(255) DEFAULT NULL,
+  `country` varchar(255) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2014-11-17 16:49:39