Skip to content

Commit

Permalink
cs (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
HLeithner authored May 25, 2020
1 parent 13e44cc commit 831efc0
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 79 deletions.
2 changes: 0 additions & 2 deletions libraries/src/Button/TransitionButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public function __construct(array $options = [])
* @param integer|null $value Current value of this item.
* @param integer|null $row The row number of this item.
* @param array $options The options to override group options.
* @param string|Date $publishUp The date which item publish up.
* @param string|Date $publishDown The date which item publish down.
*
* @return string Rendered HTML.
*
Expand Down
16 changes: 13 additions & 3 deletions libraries/src/Event/View/DisplayEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,24 @@ class DisplayEvent extends AbstractImmutableEvent
*/
public function __construct($name, array $arguments = array())
{
if (!isset($arguments['subject']) || !($arguments['subject'] instanceof ViewInterface))
if (!isset($arguments['subject']))
{
throw new BadMethodCallException("Argument 'subject' of event {$this->name} is required but has not been provided or is not of type 'ViewInterface'");
throw new BadMethodCallException("Argument 'subject' of event {$this->name} is required but has not been provided");
}

if (!($arguments['subject'] instanceof ViewInterface))
{
throw new BadMethodCallException("Argument 'subject' of event {$this->name} is not of type 'ViewInterface'");
}

if (!isset($arguments['extension']))
{
throw new BadMethodCallException("Argument 'extension' of event {$this->name} is required but has not been provided");
}

if (!isset($arguments['extension']) || !is_string($arguments['extension']))
{
throw new BadMethodCallException("Argument 'extension' of event {$this->name} is required but has not been provided or is not of type 'string'");
throw new BadMethodCallException("Argument 'extension' of event {$this->name} is not of type 'string'");
}

if (strpos($arguments['extension'], '.') === false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function __construct($name, array $arguments = array())
/**
* Set used parameter to true
*
* @since 1.0
* @param bool $value The value to set
*
* @return void
*
* @since 4.0.0
*/
public function setUsed($value = true)
{
Expand Down
6 changes: 5 additions & 1 deletion libraries/src/Event/Workflow/WorkflowTransitionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function __construct($name, array $arguments = array())
/**
* Set used parameter to true
*
* @since 1.0
* @param bool $value The value to set
*
* @return void
*
* @since 4.0.0
*/
public function setStopTransition($value = true)
{
Expand Down
71 changes: 36 additions & 35 deletions libraries/src/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ public function executeTransition(array $pks, int $transition_id): bool
$db->quoteName('t.workflow_id'),
]
)
->from($db->quoteName('#__workflow_transitions', 't'))
->join('LEFT', $db->quoteName('#__workflow_stages', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('t.to_stage_id'))
->where($db->quoteName('t.id') . ' = :id')
->where($db->quoteName('t.published') . ' = 1')
->bind(':id', $transition_id, ParameterType::INTEGER);
->from($db->quoteName('#__workflow_transitions', 't'))
->join('LEFT', $db->quoteName('#__workflow_stages', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('t.to_stage_id'))
->where($db->quoteName('t.id') . ' = :id')
->where($db->quoteName('t.published') . ' = 1')
->bind(':id', $transition_id, ParameterType::INTEGER);

$transition = $db->setQuery($query)->loadObject();

Expand All @@ -202,7 +202,8 @@ public function executeTransition(array $pks, int $transition_id): bool
if (!\in_array($transition->from_stage_id, [
$assoc->stage_id,
-1
]) || $transition->workflow_id !== $assoc->workflow_id)
]
) || $transition->workflow_id !== $assoc->workflow_id)
{
return false;
}
Expand Down Expand Up @@ -272,17 +273,17 @@ public function createAssociation(int $pk, int $state): bool
$query = $db->getQuery(true);

$query->insert($db->quoteName('#__workflow_associations'))
->columns(
[
$db->quoteName('item_id'),
$db->quoteName('stage_id'),
$db->quoteName('extension'),
]
)
->values(':pk, :state, :extension')
->bind(':pk', $pk, ParameterType::INTEGER)
->bind(':state', $state, ParameterType::INTEGER)
->bind(':extension', $this->extension);
->columns(
[
$db->quoteName('item_id'),
$db->quoteName('stage_id'),
$db->quoteName('extension'),
]
)
->values(':pk, :state, :extension')
->bind(':pk', $pk, ParameterType::INTEGER)
->bind(':state', $state, ParameterType::INTEGER)
->bind(':extension', $this->extension);

$db->setQuery($query)->execute();
}
Expand Down Expand Up @@ -314,11 +315,11 @@ public function updateAssociations(array $pks, int $state): bool
$query = $db->getQuery(true);

$query->update($db->quoteName('#__workflow_associations'))
->set($db->quoteName('stage_id') . ' = :state')
->whereIn($db->quoteName('item_id'), $pks)
->where($db->quoteName('extension') . ' = :extension')
->bind(':state', $state, ParameterType::INTEGER)
->bind(':extension', $this->extension);
->set($db->quoteName('stage_id') . ' = :state')
->whereIn($db->quoteName('item_id'), $pks)
->where($db->quoteName('extension') . ' = :extension')
->bind(':state', $state, ParameterType::INTEGER)
->bind(':extension', $this->extension);

$db->setQuery($query)->execute();
}
Expand Down Expand Up @@ -385,19 +386,19 @@ public function getAssociation(int $item_id): ?\stdClass
$db->quoteName('s.workflow_id'),
]
)
->from($db->quoteName('#__workflow_associations', 'a'))
->innerJoin(
$db->quoteName('#__workflow_stages', 's'),
$db->quoteName('a.stage_id') . ' = ' . $db->quoteName('s.id')
)
->where(
[
$db->quoteName('item_id') . ' = :id',
$db->quoteName('extension') . ' = :extension',
]
)
->bind(':id', $item_id, ParameterType::INTEGER)
->bind(':extension', $this->extension);
->from($db->quoteName('#__workflow_associations', 'a'))
->innerJoin(
$db->quoteName('#__workflow_stages', 's'),
$db->quoteName('a.stage_id') . ' = ' . $db->quoteName('s.id')
)
->where(
[
$db->quoteName('item_id') . ' = :id',
$db->quoteName('extension') . ' = :extension',
]
)
->bind(':id', $item_id, ParameterType::INTEGER)
->bind(':extension', $this->extension);

return $db->setQuery($query)->loadObject();
}
Expand Down
24 changes: 13 additions & 11 deletions libraries/src/Workflow/WorkflowPluginTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ trait WorkflowPluginTrait
/**
* Add different parameter options to the transition view, we need when executing the transition
*
* @param Form $form The form
* @param \stdClass $data The data
* @param Form $form The form
* @param \stdClass $data The data
*
* @return boolean
*
Expand Down Expand Up @@ -56,7 +56,7 @@ protected function enhanceWorkflowTransitionForm(Form $form, $data)
/**
* Get the workflow for a given ID
*
* @param int|null $workflow_id ID of the workflow
* @param int|null $workflow_id ID of the workflow
*
* @return CMSObject|boolean Object on success, false on failure.
*
Expand All @@ -72,15 +72,15 @@ protected function getWorkflow(int $workflow_id = null)
}

return $this->app->bootComponent('com_workflow')
->getMVCFactory()
->createModel('Workflow', 'Administrator', ['ignore_request' => true])
->getItem($workflow_id);
->getMVCFactory()
->createModel('Workflow', 'Administrator', ['ignore_request' => true])
->getItem($workflow_id);
}

/**
* Check if the current plugin should execute workflow related activities
*
* @param string $context Context to check
* @param string $context Context to check
*
* @return boolean
*
Expand All @@ -94,9 +94,9 @@ protected function isSupported($context)
/**
* Check if the context is listed in the whitelist or in the blacklist and return the result
*
* @param string $context Context to check
* @param string $context Context to check
*
* @return bool
* @return boolean
*/
protected function checkWhiteAndBlacklist($context)
{
Expand Down Expand Up @@ -133,15 +133,17 @@ protected function checkWhiteAndBlacklist($context)
/**
* Check if the context is listed in the whitelist or in the blacklist and return the result
*
* @param string $context Context to check
* @param string $context Context to check
* @param string $functionality The funcationality
*
* @return bool
* @return boolean
*/
protected function checkExtensionSupport($context, $functionality)
{
$parts = explode('.', $context);

$component = $this->app->bootComponent($parts[0]);

if (!$component instanceof WorkflowServiceInterface
|| !$component->isWorkflowActive($context)
|| !$component->isFunctionalityActive($functionality, $context))
Expand Down
18 changes: 9 additions & 9 deletions libraries/src/Workflow/WorkflowServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ public function supportFunctionality($functionality, $context): bool
/**
* Check if the functionality is activated in the component configuration
*
* @param string $functionality
* @param string $extension
* @param string $functionality The functionality
* @param string $extension The extension
*
* @return bool
* @return boolean
* @throws \Exception
*
* @since 4.0.0
*/
public function isFunctionalityActive($functionality, $context): bool
public function isFunctionalityActive($functionality, $extension): bool
{
if (!$this->isWorkflowActive($context))
if (!$this->isWorkflowActive($extension))
{
return false;
}

$parts = explode('.', $context);
$parts = explode('.', $extension);
$config = ComponentHelper::getParams($parts[0]);
$option = 'workflow_functionality_' . str_replace('.', '_', $functionality);

Expand All @@ -99,10 +99,10 @@ public function isFunctionalityActive($functionality, $context): bool
/**
* Check if the functionality is used by a plugin
*
* @param string $functionality
* @param string $extension
* @param string $functionality The functionality
* @param string $extension The extension
*
* @return bool
* @return boolean
* @throws \Exception
*
* @since 4.0.0
Expand Down
9 changes: 6 additions & 3 deletions plugins/workflow/featuring/featuring.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function enhanceItemForm(Form $form, $data)
$modelName = $component->getModelName($context);

$table = $component->getMVCFactory()->createModel($modelName, $this->app->getName(), ['ignore_request' => true])
->getTable();
->getTable();

$fieldname = $table->getColumnAlias('featured');

Expand Down Expand Up @@ -278,7 +278,8 @@ public function onWorkflowBeforeTransition(WorkflowTransitionEvent $event)
$context,
$pks,
$value
]);
]
);

// Release whitelist, the job is done
$this->app->set('plgWorkflowFeaturing.' . $context, []);
Expand Down Expand Up @@ -376,7 +377,9 @@ public function onContentBeforeChangeFeatured(EventInterface $event)
public function onContentBeforeSave(EventInterface $event)
{
$context = $event->getArgument('0');
/* @var TableInterface */

// @var TableInterface

$table = $event->getArgument('1');
$isNew = $event->getArgument('2');
$data = $event->getArgument('3');
Expand Down
23 changes: 12 additions & 11 deletions plugins/workflow/notification/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function onWorkflowAfterTransition(WorkflowTransitionEvent $event)
$user = $this->app->getIdentity();

// Prepare Language for messages
$default_language = ComponentHelper::getParams('com_languages')->get('administrator');
$defaultLanguage = ComponentHelper::getParams('com_languages')->get('administrator');
$debug = $this->app->get('debug_lang');

$modelName = $component->getModelName($context);
Expand Down Expand Up @@ -172,20 +172,21 @@ public function onWorkflowAfterTransition(WorkflowTransitionEvent $event)

// Get the model for private messages
$model_message = $this->app->bootComponent('com_messages')
->getMVCFactory()->createModel('Message', 'Administrator');
->getMVCFactory()->createModel('Message', 'Administrator');

// Get the title of the stage
$model_stage = $this->app->bootComponent('com_workflow')
->getMVCFactory()->createModel('Stage', 'Administrator');
->getMVCFactory()->createModel('Stage', 'Administrator');

$toStage = $model_stage->getItem($transition->to_stage_id)->title;

$hasGetItem = method_exists($model, 'getItem');
$container = Factory::getContainer();

foreach ($pks as $pk)
{
// Get the title of the item which has changed
$title ='';
$title = '';

if ($hasGetItem)
{
Expand All @@ -195,10 +196,10 @@ public function onWorkflowAfterTransition(WorkflowTransitionEvent $event)
// Send Email to receivers
foreach ($userIds as $user_id)
{
$receiver = Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById($user_id);
$receiver = $container->get(UserFactoryInterface::class)->loadUserById($user_id);

// Load language for messaging
$lang = Factory::getContainer()->get(LanguageFactoryInterface::class)->createLanguage($user->getParam('admin_language', $default_language), $debug);
$lang = $container->get(LanguageFactoryInterface::class)->createLanguage($user->getParam('admin_language', $defaultLanguage), $debug);
$lang->load('plg_workflow_notification');
$messageText = sprintf($lang->_('PLG_WORKFLOW_NOTIFICATION_ON_TRANSITION_MSG'), $title, $user->name, $lang->_($toStage));

Expand Down Expand Up @@ -254,7 +255,7 @@ private function getUsersFromGroup($data): Array
if (!empty($groups))
{
// UserIds from usergroups
$model = Factory::getApplication()->bootComponent('com_users')
$model = Factory::getApplication()->bootComponent('com_users')
->getMVCFactory()->createModel('Users', 'Administrator', ['ignore_request' => true]);

$model->setState('list.select', 'id');
Expand Down Expand Up @@ -329,10 +330,10 @@ private function removeLocked(array $userIds): Array
$query = $this->db->getQuery(true);

$query->select($this->db->quoteName('user_id'))
->from($this->db->quoteName('#__messages_cfg'))
->whereIn($this->db->quoteName('user_id'), $userIds)
->where($this->db->quoteName('cfg_name') . ' = ' . $this->db->quote('locked'))
->where($this->db->quoteName('cfg_value') . ' = 1');
->from($this->db->quoteName('#__messages_cfg'))
->whereIn($this->db->quoteName('user_id'), $userIds)
->where($this->db->quoteName('cfg_name') . ' = ' . $this->db->quote('locked'))
->where($this->db->quoteName('cfg_value') . ' = 1');

$locked = $this->db->setQuery($query)->loadColumn();

Expand Down
Loading

0 comments on commit 831efc0

Please sign in to comment.