-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of OpenSong Set Creator
- Loading branch information
Wouter Lemcke
committed
Jan 5, 2016
1 parent
ed6c81d
commit a2bfef7
Showing
6 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |