-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[features] - checklist crud - Questions crud and fill with array - Answer start and respond [test] - Unit test for evreryone [fix] - Uses
- Loading branch information
Victor Ventura
committed
Jun 2, 2017
0 parents
commit 58dfa93
Showing
23 changed files
with
780 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,5 @@ | ||
/vendor/ | ||
.bundle | ||
composer.lock | ||
/build/composer.lock | ||
/build/ |
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,6 @@ | ||
preset: laravel | ||
finder: | ||
exclude: | ||
- "tests" | ||
name: | ||
- "*.php" |
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,23 @@ | ||
# Contributing | ||
|
||
Contributions are **welcome** and will be fully **credited**. We accept contributions via Pull Requests on [Github](https://github.com/convenia/revisionable). | ||
|
||
## Pull Requests | ||
|
||
- **[PSR-2 Coding Standard.](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** The easiest way to apply the conventions is to install [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). | ||
- **Add tests!** Your patch won't be accepted if it doesn't have tests. | ||
- **Document any change in behaviour.** Make sure the `README.md` and any other relevant documentation are kept up-to-date. | ||
- **Consider our release cycle.** We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. | ||
- **Create feature branches.** Don't ask us to pull from your master branch. | ||
- **One pull request per feature.** If you want to do more than one thing, send multiple pull requests. | ||
- **Send coherent history.** Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. | ||
|
||
## Running Tests | ||
|
||
```bash | ||
$ phpunit | ||
``` | ||
|
||
|
||
*Happy coding!* | ||
0 |
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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Davis Peixoto | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,46 @@ | ||
{ | ||
"name": "convenia/checklistable", | ||
"license": "MIT", | ||
"description": "Make any model checklistable with answer per ID", | ||
"keywords": ["checklist", "laravel", "model"], | ||
"homepage": "http://github.com/convenia/checklistable", | ||
"authors": [ | ||
{ | ||
"name": "Victor Ventura", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/convenia/checklistable/issues", | ||
"source": "https://github.com/convenia/checklistable" | ||
}, | ||
"require": { | ||
"php": ">=7", | ||
"illuminate/support": "~5.2|~5.3|~5.4|~5.5" | ||
}, | ||
"require-dev": { | ||
"codacy/coverage": "^1.0", | ||
"friendsofphp/php-cs-fixer": "^1.13", | ||
"mockery/mockery": "^0.9.4", | ||
"orchestra/testbench": "~3.0", | ||
"phpunit/phpunit": "^4.0|^5.0|^6.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Convenia\\Checklistable\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Convenia\\Checklistable\\Tests\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "./vendor/bin/phpunit", | ||
"fixer": "./vendor/bin/php-cs-fixer fix --verbose" | ||
}, | ||
"config": { | ||
"preferred-install": "dist", | ||
"sort-packages": true | ||
} | ||
} |
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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
verbose="true" | ||
> | ||
<testsuite name="Convênia Checklistable Test Suite"> | ||
<directory suffix=".php">./tests</directory> | ||
</testsuite> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">./src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="junit" target="build/report.junit.xml"/> | ||
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
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,33 @@ | ||
<?php | ||
|
||
namespace Convenia\Checklistable; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ChecklistableServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
include __DIR__.'/routes.php'; | ||
|
||
$this->publishes([ | ||
__DIR__ . '/migrations' => $this->app->databasePath() . '/migrations' | ||
], 'migrations'); | ||
|
||
} | ||
|
||
/** | ||
* Register the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
} |
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 Convenia\Checklistable\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
|
||
class CalculatorController extends Controller | ||
{ | ||
public function create() | ||
{ | ||
} | ||
|
||
public function delete() | ||
{ | ||
} | ||
|
||
public function addQuention() | ||
{ | ||
} | ||
|
||
public function deleteQuestion() | ||
{ | ||
} | ||
|
||
public function start() | ||
{ | ||
} | ||
|
||
public function saveAnswer() | ||
{ | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Convenia\Checklistable\Models; | ||
|
||
use \Illuminate\Database\Eloquent\Model; | ||
|
||
class Checklist extends Model | ||
{ | ||
|
||
protected $fillable = ['company_id', 'type', 'answerable']; | ||
|
||
|
||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Convenia\Checklistable\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ChecklistAnswer extends Model | ||
{ | ||
|
||
protected $fillable = ['checklist_id', 'question', 'answer', 'answerable_id']; | ||
|
||
|
||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Convenia\Checklistable\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ChecklistQuestion extends Model | ||
{ | ||
|
||
protected $fillable = ['item', 'checklist_id']; | ||
|
||
|
||
} |
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,65 @@ | ||
<?php | ||
|
||
namespace Convenia\Checklistable\Services; | ||
|
||
use Convenia\Checklistable\Models\Checklist; | ||
use Convenia\Checklistable\Models\ChecklistAnswer; | ||
use Illuminate\Support\Collection; | ||
|
||
class ChecklistableAnswerService | ||
{ | ||
|
||
/** | ||
* @var Checklist | ||
*/ | ||
private $checklist; | ||
|
||
/** | ||
* ChecklistableAnswerService constructor. | ||
* @param Checklist $checklist | ||
*/ | ||
public function __construct(Checklist $checklist) | ||
{ | ||
$this->checklist = $checklist; | ||
} | ||
|
||
/** | ||
* @param $answarableId | ||
* @return Collection | ||
*/ | ||
public function start($answarableId) : Collection | ||
{ | ||
$checkQuestion = new ChecklistableQuestionService($this->checklist); | ||
$questions = $checkQuestion->get(); | ||
|
||
$questions->transform(function($item) use($answarableId) { | ||
$item['answerable_id'] = $answarableId; | ||
return $item; | ||
}); | ||
|
||
ChecklistAnswer::insert($questions->toArray()); | ||
|
||
return $this->get(1); | ||
} | ||
|
||
public function answer($answarableId, $answerId, $answer = true) : bool | ||
{ | ||
$answerMoldel = ChecklistAnswer::findOrFail($answerId); | ||
$answerMoldel->answer = $answer; | ||
return $answerMoldel->save(); | ||
} | ||
|
||
public function get($answarableId) : Collection | ||
{ | ||
$answers = ChecklistAnswer::query() | ||
->where('answerable_id', $answarableId) | ||
->where('checklist_id', $this->checklist->id) | ||
->get(); | ||
|
||
if ($answers->count() == 0) { | ||
return $this->start($answarableId); | ||
} | ||
|
||
return $answers; | ||
} | ||
} |
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,63 @@ | ||
<?php | ||
|
||
namespace Convenia\Checklistable\Services; | ||
|
||
use Convenia\Checklistable\Models\ChecklistQuestion; | ||
|
||
class ChecklistableQuestionService | ||
{ | ||
|
||
private $checklist; | ||
|
||
public $questions; | ||
|
||
public function __construct($checklist) | ||
{ | ||
$this->checklist = $checklist; | ||
} | ||
|
||
public function get() | ||
{ | ||
$this->questions = ChecklistQuestion::query() | ||
->where('checklist_id', $this->checklist->id) | ||
->get(); | ||
|
||
return $this->questions; | ||
} | ||
|
||
|
||
public function fill(Array $questions) | ||
{ | ||
$oldQuestions = $this->get(); | ||
|
||
if ($oldQuestions->count() > 0) { | ||
return $oldQuestions; | ||
} | ||
|
||
$questions = collect($questions)->transform(function ($item) { | ||
$item['checklist_id'] = $this->checklist->id; | ||
return $item; | ||
})->toArray(); | ||
|
||
|
||
ChecklistQuestion::insert($questions); | ||
|
||
return $this->get(); | ||
} | ||
|
||
public function add(Array $question) | ||
{ | ||
$question['checklist_id'] = $this->checklist->id; | ||
|
||
ChecklistQuestion::insert($question); | ||
|
||
return $this->get(); | ||
} | ||
|
||
public function delete($questionId) | ||
{ | ||
return ChecklistQuestion::query()->delete($questionId); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.