Skip to content

Commit

Permalink
First version of OpenSong Set Creator
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouter Lemcke committed Jan 5, 2016
1 parent ed6c81d commit a2bfef7
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 0 deletions.
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "OpenSong-SetCreator",
"description": "Library that can create set files for the OpenSong program.",
"require": {},
"autoload": {
"psr-4": {
"OpenSongSetCreator\\": "src/"
}
}
}
112 changes: 112 additions & 0 deletions src/Collection/SlideGroupCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace OpenSongSetCreator\Collection;

use OpenSongSetCreator\SlideGroup\SlideGroup;

class SlideGroupCollection implements \Iterator, \ArrayAccess
{
/**
* @var array
*/
private $collection;

/**
* Return the current element
* @return SlideGroup
*/
public function current()
{
return current($this->collection);
}

/**
* Move forward to next element
* @link http://php.net/manual/en/iterator.next.php
* @return void Any returned value is ignored.
* @since 5.0.0
*/
public function next()
{
next($this->collection);
}

/**
* Return the key of the current element
* @link http://php.net/manual/en/iterator.key.php
* @return mixed scalar on success, or null on failure.
* @since 5.0.0
*/
public function key()
{
return key($this->collection);
}

/**
* Checks if current position is valid
* @link http://php.net/manual/en/iterator.valid.php
* @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
* @since 5.0.0
*/
public function valid()
{
$key = key($this->collection);

return ($key !== null && $key !== false);
}

/**
* Rewind the Iterator to the first element
* @link http://php.net/manual/en/iterator.rewind.php
* @return void Any returned value is ignored.
* @since 5.0.0
*/
public function rewind()
{
reset($this->collection);
}

/**
* Whether a offset exists
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
* @param mixed $offset <p>
* An offset to check for.
* </p>
* @return boolean true on success or false on failure.
* </p>
* <p>
* The return value will be casted to boolean if non-boolean was returned.
* @since 5.0.0
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->collection);
}

/**
* @param mixed $offset
* @return SlideGroup
*/
public function offsetGet($offset)
{
return $this->collection[$offset];
}

/**
* @param mixed $offset
* @param SlideGroup $value
*/
public function offsetSet($offset, $value)
{
$this->collection[$offset] = $value;
}

/**
* @param mixed $offset
*/
public function offsetUnset($offset)
{
unset($this->collection[$offset]);
}
}
41 changes: 41 additions & 0 deletions src/Creator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace OpenSongSetCreator;

use OpenSongSetCreator\Collection\SlideGroupCollection;

class Creator
{
public function createSet($setName, SlideGroupCollection $slideGroupCollection)
{
$xml = new \SimpleXMLElement('<set/>');
$xml->addAttribute("name", $setName);
$slideGroups = $xml->addChild("slide_groups");

foreach ($slideGroupCollection as $slideGroup) {
$slide = $slideGroups->addChild("slide_group");
$slide->addAttribute("name", $slideGroup->getName());
$slide->addAttribute("type", $slideGroup->getType());

switch ($slideGroup->getType()) {
case "song":
$slide->addAttribute("path", $slideGroup->getPath());
$slide->addAttribute("presentation", $slideGroup->getPresentation());
break;
case "custom":
$slide->addAttribute("print", "true");
$slide->addAttribute("seconds", "0");
$slide->addAttribute("loop", "false");
$slide->addAttribute("transition", "0");
$slide->addChild("title", $slideGroup->getName());
$slide->addChild("subtitle");
$slide->addChild("notes");
$slide->addChild("slides")
->addChild("slide")
->addChild("body", $slideGroup->getBody());
}
}

echo $xml->asXML();
}
}
32 changes: 32 additions & 0 deletions src/SlideGroup/Custom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace OpenSongSetCreator\SlideGroup;

class Custom extends SlideGroup
{
/**
* @var string
*/
private $body;

/**
* Custom constructor.
* @param string $name
* @param string $body
*/
public function __construct($name, $body)
{
parent::__construct($name, "custom");

$this->body = (string)$body;
}

/**
* @return string
*/
public function getBody()
{
return $this->body;
}

}
39 changes: 39 additions & 0 deletions src/SlideGroup/SlideGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace OpenSongSetCreator\SlideGroup;

abstract class SlideGroup
{
/**
* @var string
*/
private $name;

/**
* @var string
*/
private $type;

/**
* @param string $name
* @param string $type
*/
public function __construct($name, $type)
{
$this->name = (string)$name;
$this->type = (string)$type;
}

public function getName()
{
return $this->name;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}
}
40 changes: 40 additions & 0 deletions src/SlideGroup/Song.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace OpenSongSetCreator\SlideGroup;

class Song extends SlideGroup
{
/**
* @var string
*/
private $path;

/**
* @var string
*/
private $presentation;

public function __construct($name, $path, $presentation)
{
parent::__construct($name, "song");

$this->path = (string)$path;
$this->presentation = (string)$presentation;
}

/**
* @return string
*/
public function getPath()
{
return $this->path;
}

/**
* @return string
*/
public function getPresentation()
{
return $this->presentation;
}
}

0 comments on commit a2bfef7

Please sign in to comment.