Skip to content
This repository was archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
KieranFYI committed Jan 6, 2020
0 parents commit dfccc3b
Show file tree
Hide file tree
Showing 38 changed files with 2,160 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

_releases
_output
15 changes: 15 additions & 0 deletions Admin/Controller/Bans.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Kieran\Bans\Admin\Controller;

use XF\Mvc\ParameterBag;
use Kieran\Support\Entity\TicketType;

class Bans extends \XF\Admin\Controller\AbstractController
{

public function actionTypes(ParameterBag $params)
{
return $this->rerouteController('Kieran\Bans:Types', 'index', $params);
}
}
94 changes: 94 additions & 0 deletions Admin/Controller/Types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Kieran\Bans\Admin\Controller;

use XF\Mvc\ParameterBag;
use Kieran\Bans\Entity\BanType;

class Types extends \XF\Admin\Controller\AbstractController
{

public function actionIndex(ParameterBag $params)
{
return $this->view('Kieran\Bans:BanType', 'kieran_bans_types', ['types' => $this->getTypeRepo()->getTypes()]);
}

public function actionEdit(ParameterBag $params)
{
$type = $this->assertTypeExists($params['type_id']);
return $this->typeAddEdit($type);
}

public function actionAdd(ParameterBag $params)
{
$type = $this->getTypeRepo()->setupBaseType();
return $this->typeAddEdit($type);
}

protected function typeAddEdit(BanType $type)
{
$viewParams = [
'type' => $type,
'success' => $this->filter('success', 'bool'),
];
return $this->view('Kieran\Bans:BanType\Add', 'kieran_bans_types_edit', $viewParams);
}

public function actionSave(ParameterBag $params)
{
$this->assertPostOnly();

if ($params->type_id)
{
$type = $this->assertTypeExists($params->type_id);
}
else
{
$type = $this->getTypeRepo()->setupBaseType();
}

$this->typeSaveProcess($type)->run();

return $this->redirect($this->buildLink('bans/types'));
}

public function actionDelete(ParameterBag $params)
{
$type = $this->assertTypeExists($params->type_id);

if (!$type->canDelete())
{
return $this->error(\XF::phrase('type_cannot_be_deleted_associated_with_ban_explain'));
}

$type->delete();

return $this->redirect($this->buildLink('bans/types'));
}

protected function typeSaveProcess(BanType $type)
{

$form = $this->formAction();

$input = $this->filter([
'type_id' => 'str',
'name' => 'str',
]);

$form->basicEntitySave($type, $input);
$form->run();

return $form;
}

protected function assertTypeExists($id, $with = null, $phraseKey = null)
{
return $this->assertRecordExists('Kieran\Bans:BanType', $id, $with, $phraseKey);
}

protected function getTypeRepo()
{
return $this->repository('Kieran\Bans:BanType');
}
}
73 changes: 73 additions & 0 deletions Attachment/Ban.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Kieran\Bans\Attachment;

use XF\Attachment\AbstractHandler;
use XF\Entity\Attachment;
use XF\Mvc\Entity\Entity;

class Ban extends AbstractHandler
{
public function canView(Attachment $attachment, Entity $container, &$error = null)
{
return $container->canView();
}

public function canManageAttachments(array $context, &$error = null)
{
return true;
}

public function onAttachmentDelete(Attachment $attachment, Entity $container = null)
{
if (!$container)
{
return;
}

$container->attach_count--;
$container->save();
}

public function getConstraints(array $context)
{
$constraints = \XF::repository('XF:Attachment')->getDefaultAttachmentConstraints();
$constraints['extensions'][] = 'dem';
$constraints['extensions'][] = 'mp4';
$constraints['size'] = 5242880;
return $constraints;
}

public function getContainerIdFromContext(array $context)
{
return isset($context['note_id']) ? intval($context['note_id']) : null;
}

public function getContainerLink(Entity $container, array $extraParams = [])
{
return \XF::app()->router('public')->buildLink('bans', $container, $extraParams);
}

public function getContext(Entity $entity = null, array $extraContext = [])
{

if ($entity instanceof \Kieran\Bans\Entity\Ban)
{
$extraContext['ban_id'] = $entity->ban_id;
}
else if ($entity instanceof \Kieran\Bans\Entity\BanNote)
{
$extraContext['note_id'] = $entity->note_id;
}
else if (!$entity)
{
// need nothing
}
else
{
throw new \InvalidArgumentException("Entity must be ban");
}

return $extraContext;
}
}
Loading

0 comments on commit dfccc3b

Please sign in to comment.