コード例 #1
0
ファイル: GuideObserver.php プロジェクト: stevebauman/ithub
 /**
  * Catches and runs operations when a guide is deleted.
  *
  * @param Guide $guide
  */
 public function deleting(Guide $guide)
 {
     if (!$guide->deleted_at) {
         $steps = $guide->steps()->get();
         foreach ($steps as $step) {
             $step->delete();
         }
     }
 }
コード例 #2
0
 /**
  * Persist the changes.
  *
  * @param Guide $guide
  *
  * @return bool
  */
 public function persist(Guide $guide)
 {
     if ($guide->hasFavorite() && $guide->unFavorite()) {
         // If the guide is currently already a favorite, we'll assume
         // the user is wanting to 'un-favorite' the guide.
         return true;
     } elseif ($guide->favorite()) {
         return true;
     }
     return false;
 }
コード例 #3
0
 /**
  * Deletes the specified guide step image.
  *
  * @param int|string $id
  * @param int|string $stepId
  * @param int|string $fileUuid
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id, $stepId, $fileUuid)
 {
     $this->authorize('guides.steps.images.destroy');
     $guide = $this->guide->locate($id);
     $step = $guide->findStep($stepId);
     $file = $step->findFile($fileUuid);
     if ($file->delete()) {
         flash()->success('Success!', 'Successfully deleted image.');
         return redirect()->back();
     }
     flash()->error('Error!', 'There was an issue deleting this image. Please try again.');
     return redirect()->back();
 }
コード例 #4
0
ファイル: GuideTest.php プロジェクト: stevebauman/ithub
 public function test_delete_guide()
 {
     $this->test_guide_store();
     $guide = Guide::first();
     $this->delete(route('resources.guides.destroy', [$guide->slug]));
     $this->dontSeeInDatabase('guides', ['id' => 1]);
 }
コード例 #5
0
ファイル: Upload.php プロジェクト: stevebauman/ithub
 /**
  * Execute the job.
  *
  * @return int
  */
 public function handle()
 {
     $images = $this->request->file('images');
     $uploaded = 0;
     foreach ($images as $image) {
         if ($image instanceof UploadedFile) {
             $step = $this->guide->addStep($image->getClientOriginalName());
             if ($step instanceof GuideStep) {
                 if ($step->uploadFile($image, $path = null, $resize = true)) {
                     $uploaded++;
                 }
             }
         }
     }
     return $uploaded;
 }
コード例 #6
0
ファイル: GuideStepTest.php プロジェクト: stevebauman/ithub
 public function test_delete_guide_step_image()
 {
     $this->test_guide_step_store_with_attachment();
     $guide = Guide::first();
     $step = $guide->steps()->first();
     $image = $step->images()->first();
     $this->delete(route('resources.guides.steps.images.destroy', [$guide->slug, $step->id, $image->uuid]));
     $this->dontSeeInDatabase('uploads', ['id' => 1]);
 }
コード例 #7
0
ファイル: Store.php プロジェクト: stevebauman/ithub
 /**
  * Execute the job.
  *
  * @return GuideStep|false
  */
 public function handle()
 {
     $title = $this->request->input('title');
     $description = $this->request->input('description');
     $step = $this->guide->addStep($title, $description);
     // Make sure we've created a step successfully.
     if ($step instanceof GuideStep) {
         // Retrieve the image for the step.
         $file = $this->request->file('image');
         if ($file instanceof UploadedFile) {
             // Looks like an image was uploaded, we'll move
             // it into storage and add it to the step.
             $step->uploadFile($file, $path = null, $resize = true);
         }
         // No image was uploaded, we'll return the step.
         return $step;
     }
     return false;
 }
コード例 #8
0
ファイル: GuideController.php プロジェクト: stevebauman/ithub
 /**
  * Deletes the specified guide.
  *
  * @param int|string $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     $guide = $this->guide->locate($id);
     $this->authorize('manage.guides');
     if ($guide->delete()) {
         flash()->success('Success!', 'Successfully deleted guide!');
         return redirect()->route('resources.guides.index');
     }
     flash()->error('Error!', 'There was an issue deleting this guide. Please try again.');
     return redirect()->route('resources.guides.show', [$id]);
 }
コード例 #9
0
 public function postDestroy($id)
 {
     $guide = Guide::find($id);
     $user = User::getUserLoggedIn();
     if ($user->isAdmin() || $user->id == $guide->creator_id) {
         flash('Ohje poistettu onnistuneesti');
         $guide->destroy();
     } else {
         flash()->error('Ei oikeuksia ohjeen poistoon');
     }
     return redirect()->to('/');
 }
コード例 #10
0
 /**
  * Creates steps for the specified guide per image.
  *
  * @param GuideStepImagesRequest $request
  * @param int|string             $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function upload(GuideStepImagesRequest $request, $id)
 {
     $guide = $this->guide->locate($id);
     $step = $guide->steps()->getRelated();
     $uploaded = $this->dispatch(new Upload($request, $guide, $step));
     if ($uploaded > 0) {
         flash()->success('Success!', "Successfully uploaded: {$uploaded} images.");
         return redirect()->route('resources.guides.show', [$id]);
     }
     flash()->error('Error!', 'There was an issue uploading images. Please try again.');
     return redirect()->route('resources.guides.images', [$id]);
 }
コード例 #11
0
ファイル: _versions.php プロジェクト: rulzgz/yiiframework.com
?>
        <?php 
echo DropdownList::widget(['tag' => 'li', 'selection' => $guide->getLanguageName(), 'items' => array_map(function ($language) use($section, $guide) {
    $options = $guide->getLanguageOptions();
    if (isset($section)) {
        $url = ['guide/view', 'section' => $section->name, 'version' => $guide->version, 'language' => $language, 'type' => $guide->typeUrlName];
    } else {
        $url = ['guide/index', 'version' => $guide->version, 'language' => $language, 'type' => $guide->typeUrlName];
    }
    return ['label' => $options[$language], 'url' => $url];
}, array_keys($guide->getLanguageOptions()))]);
?>
        <?php 
echo DropdownList::widget(['tag' => 'li', 'selection' => "Version {$guide->version}", 'items' => array_map(function ($version) use($section, $guide) {
    $language = $guide->language;
    $otherGuide = Guide::load($version, $language, $guide->type);
    if ($otherGuide === null) {
        $language = 'en';
        $otherGuide = Guide::load($version, $language, $guide->type);
    }
    if (isset($section) && $guide->version[0] === $version[0] && $otherGuide->loadSection($section->name) !== null) {
        $url = ['guide/view', 'section' => $section->name, 'version' => $version, 'language' => $language, 'type' => $guide->typeUrlName];
    } else {
        $url = ['guide/index', 'version' => $version, 'language' => $language, 'type' => $guide->typeUrlName];
    }
    return ['label' => $version, 'url' => $url];
}, $guide->getVersionOptions())]);
?>
    </ul>
</nav>
コード例 #12
0
 /**
  * Returns a new table of the guide steps.
  *
  * @param Guide $guide
  *
  * @return \Orchestra\Contracts\Html\Builder
  */
 public function table(Guide $guide)
 {
     $steps = $guide->steps()->orderBy('position');
     return $this->table->of('resources.guides', function (TableGrid $table) use($guide, $steps) {
         $table->with($steps);
         $table->layout('pages.resources.guides.steps._table');
         $table->column('move')->attributes(function (GuideStep $step) {
             return ['class' => 'sortable-handle', 'data-id' => $step->id];
         })->value(function () {
             return '<i class="fa fa-sort"></i>';
         });
         $table->column('Step', 'position')->attributes(function () {
             return ['class' => 'position'];
         });
         $table->column('title')->value(function (GuideStep $step) use($guide) {
             return link_to_route('resources.guides.steps.edit', $step->title, [$guide->slug, $step->getPosition()]);
         });
         $table->column('description')->value(function (GuideStep $step) {
             return $step->description ? str_limit($step->description, 25) : '<em>None</em>';
         });
         $table->column('delete')->value(function (GuideStep $step) use($guide) {
             $attribues = ['class' => 'btn btn-sm btn-danger', 'data-title' => 'Delete Step?', 'data-message' => 'Are you sure you want to delete this step?', 'data-post' => 'DELETE'];
             return link_to_route('resources.guides.steps.destroy', 'Delete', [$guide->slug, $step->getPosition()], $attribues);
         });
     });
 }
コード例 #13
0
<?php

/**
 * @var $this yii\web\View
 * @var $versions array all available API versions
 * @var $version string the currently chosen API version
 * @var $section string the currently active API file
 */
use app\components\DropdownList;
use app\models\Guide;
use yii\helpers\Html;
?>
<nav class="version-selector" role="navigation">
    <div class="btn-group btn-group-justified">
	    <?php 
$guide = Guide::load($version, 'en');
$items = [];
if ($guide->getDownloadFile('tar.gz') !== false) {
    $items[] = ['label' => 'Offline HTML (tar.gz)', 'url' => ['guide/download', 'version' => $guide->version, 'language' => $guide->language, 'format' => 'tar.gz']];
}
if ($guide->getDownloadFile('tar.bz2') !== false) {
    $items[] = ['label' => 'Offline HTML (tar.bz2)', 'url' => ['guide/download', 'version' => $guide->version, 'language' => $guide->language, 'format' => 'tar.bz2']];
}
if (!empty($items)) {
    echo DropdownList::widget(['tag' => 'div', 'selection' => 'Download', 'items' => $items, 'options' => ['class' => 'btn-group btn-group-sm']]);
}
?>
        <?php 
echo DropdownList::widget(['tag' => 'div', 'selection' => "Version {$version}", 'items' => array_map(function ($ver) use($version, $section) {
    return ['label' => $ver, 'url' => ['api/view', 'version' => $ver, 'section' => $version[0] === $ver[0] ? $section : 'index']];
}, $versions), 'options' => ['class' => 'btn-group btn-group-sm']]);
コード例 #14
0
ファイル: GuideRequest.php プロジェクト: stevebauman/ithub
 /**
  * Create a conversation slug.
  *
  * @param string $title
  *
  * @return string
  */
 public function makeSlugFromTitle($title)
 {
     $slug = Str::slug($title);
     $count = Guide::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?\$'")->count();
     return $count ? "{$slug}-{$count}" : $slug;
 }