Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created May 17, 2014 00:31
Show Gist options
  • Save shadowhand/116de7b2a6ba67804dcc to your computer and use it in GitHub Desktop.
Save shadowhand/116de7b2a6ba67804dcc to your computer and use it in GitHub Desktop.
<?php
/**
* Ushahidi Platform Admin Tag Create Use Case
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Platform
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
namespace Ushahidi\Usecase\Admin\Tag;
use Ushahidi\Entity\Tag;
use Ushahidi\Tool\Validator;
class Create
{
private $repo;
private $valid;
public function __construct(CreateTagRepository $repo, Validator $valid)
{
$this->repo = $repo;
$this->valid = $valid;
}
private function createSlugForTag($title)
{
// todo: this won't work well for non-English tag titles.
// a quick survery (of one: Al Jezeera) shows that it might be
// better to use UUID for everything. need to address this for
// Arabic translations.
return preg_replace('/\s++/', '-', strtolower($title));
}
public function interact($tag, $type)
{
$slug = $this->createSlugForTag($tag);
$this->valid->checkTag(compact('tag', 'type', 'slug'));
$this->repo->createTag($tag, $slug, $type);
$id = $this->repo->getCreatedTagID();
$ts = $this->repo->getCreatedTagTimestamp();
return new TagEntity($id, $tag, $slug, $type, $ts);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment