Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to delete plugin data #17

Merged
merged 2 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function patch( $url, $body ) {
* @throws ApiException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function delete( $url, $body ) {
public function delete( $url, $body = null ) {
try {
$request = $this->createRequestNoJson( 'DELETE', $this->formatUrl( $url, 'delete' ), $body );
$response = $this->client()->send( $request );
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/Plugins/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Eduframe\Resources\Plugins;

use Eduframe\Resource;
use Eduframe\Traits\Removable;
use Eduframe\Traits\Storable;

class Data extends Resource {

use Storable;
use Storable, Removable;

/**
* @var array
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasPluginData.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function get_plugin_data_value( $title ) {
* @param $name
* @return mixed
*/
private function get_plugin_data( $title ) {
public function get_plugin_data( $title ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why public, was this necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes was necessary

$results = array_filter( $this->plugin_data, function ( $plugin_data ) use ( $title ) {
return ( $plugin_data->field->title === $title );
} );
Expand Down
21 changes: 21 additions & 0 deletions src/Traits/Removable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Eduframe\Traits;

/**
* Class Removable
* @package Eduframe\Traits
*/
trait Removable {

use BaseTrait;

/**
* @return mixed
* @throws \Eduframe\Exceptions\ApiException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function delete() {
return $this->connection()->delete( $this->getEndpoint() . '/' . urlencode( $this->id ) );
}
}