예제 #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $series = $this->argument('series');
     $data = json_decode($this->filesystem->get(base_path('resources/assets/json/' . $series . '_full.json')));
     $series = $this->series->create((array) $data);
     $this->db->table('cards')->whereNull('series_id')->update(['series_id' => $series->id]);
 }
예제 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $faker = Faker\Factory::create();
     foreach (range(1, 10) as $index) {
         Series::create(['name' => $faker->name, 'description' => $faker->sentence(), 'count' => $faker->randomDigit()]);
     }
 }
예제 #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $faker = Faker\Factory::create();
     $teachers = Teacher::lists('id')->toarray();
     $series = Series::lists('id')->toarray();
     foreach (range(1, 50) as $index) {
         Video::create(['title' => $faker->title, 'description' => $faker->sentence(10), 'video_url' => $faker->url, 'cover_url' => $faker->url, 'user_id' => $faker->randomElement($teachers), 'series_id' => $faker->randomElement($series), 'watch_count' => $faker->randomDigit(), 'reply_count' => $faker->randomDigit(), 'favorite_count' => $faker->randomDigit()]);
     }
 }
 /**
  * Store a newly created series in storage.
  *
  * @return Response
  */
 public function store()
 {
     $currentUser = $this->getUser();
     Validator::extend('valid_uuid', function ($attribute, $value, $parameters) {
         if (preg_match("/^(\\{)?[a-f\\d]{8}(-[a-f\\d]{4}){4}[a-f\\d]{8}(?(1)\\})\$/i", $value)) {
             return true;
         } else {
             return false;
         }
     });
     Validator::extend('series_exists', function ($attribute, $value, $parameters) use($currentUser) {
         if (Series::find($value)) {
             return false;
         } else {
             return true;
         }
     });
     $messages = ['id.valid_uuid' => 'The :attribute field is not a valid ID.', 'comic_id.valid_uuid' => 'The :attribute field is not a valid ID.', 'id.series_exists' => 'The :attribute field is not a valid ID.'];
     $validator = Validator::make($data = $this->request->all(), ['id' => 'required|valid_uuid|series_exists', 'comic_id' => 'required|valid_uuid', 'series_title' => 'required', 'series_start_year' => 'date_format:Y'], $messages);
     if ($validator->fails()) {
         $pretty_errors = array_map(function ($item) {
             return ['title' => 'Missing Required Field', 'detail' => $item, 'status' => 400, 'code' => ''];
         }, $validator->errors()->all());
         return $this->respondBadRequest($pretty_errors);
     }
     $comic = $currentUser->comics()->find($data['comic_id']);
     if ($comic) {
         $old_series_id = $comic->series_id;
         $series = new Series();
         $series->id = $data['id'];
         $series->user_id = $currentUser->id;
         $series->series_title = $data['series_title'];
         $series->series_start_year = !empty($data['series_start_year']) ? $data['series_start_year'] : date('Y');
         $series->series_publisher = !empty($data['series_publisher']) ? $data['series_publisher'] : "Unknown";
         $series->save();
         $comic->series_id = $series->id;
         $comic->save();
         $seriesCount = Series::find($old_series_id)->comics()->get()->count();
         if ($seriesCount == 0) {
             Series::find($old_series_id)->delete();
         }
         return $this->respondCreated(['series' => [$series]]);
     }
     return $this->respondBadRequest([['title' => 'Invalid Comic ID', 'detail' => 'Invalid Comic ID', 'status' => 400, 'code' => '']]);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $currentUser = $this->getUser();
     $comic = $currentUser->comics()->find($id);
     if ($comic) {
         $series_id = $comic['series']['id'];
         $currentUser->comics()->find($id)->delete();
         $comic_count = Series::find($series_id)->comics()->get()->count();
         if ($comic_count == 0) {
             Series::find($series_id)->delete();
         }
         return $this->respondSuccessful('Comic Deleted');
     }
     return $this->respondNotFound([['title' => 'Comic Not Found', 'detail' => 'Comic Not Found', 'status' => 404, 'code' => '']]);
 }
예제 #6
0
use app\models\Series;
use app\models\Status;
use dosamigos\datepicker\DatePicker;
/* @var $this yii\web\View */
/* @var $model app\models\Card */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="card-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'seriesId')->dropDownList(ArrayHelper::map(Series::find()->asArray()->all(), 'id', 'seriesName'));
?>

    <?php 
echo $form->field($model, 'number')->textInput();
?>

    <?php 
echo $form->field($model, 'issueDateTime')->widget(DatePicker::className(), ['inline' => true, 'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>', 'clientOptions' => ['autoclose' => true, 'format' => 'dd-M-yyyy']]);
?>

    <?php 
echo $form->field($model, 'endingDateTime')->widget(DatePicker::className(), ['inline' => true, 'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>', 'clientOptions' => ['autoclose' => true, 'format' => 'dd-M-yyyy']]);
?>

    <?php 
예제 #7
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($society, $series, $id)
 {
     if (Helpers::perm('admin', $society) or Helpers::perm('edit', $society)) {
         $data['society'] = $society;
         $data['allseries'] = Series::where('society_id', '=', $society)->lists('series', 'id')->toArray();
         $data['series'] = $series;
         $data['seriesname'] = Series::find($series)->series;
         $data['ministers'] = Minister::has('individual')->get();
         $data['preachers'] = Preacher::has('individual')->get();
         $data['guests'] = Guest::orderBy('surname')->orderBy('firstname')->get();
         $data['sermon'] = Sermon::find($id);
         return view('sermons.edit', $data);
     } else {
         return view('shared.unauthorised');
     }
 }
예제 #8
0
파일: Card.php 프로젝트: kafeg/starcodetest
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSeries()
 {
     return $this->hasOne(Series::className(), ['id' => 'seriesId']);
 }
예제 #9
0
 public function index()
 {
     return Series::all();
 }
예제 #10
0
 /**
  * Finds the Series model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Series the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Series::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Store a newly created upload in storage.
  *
  * @return Response
  */
 public function store()
 {
     $currentUser = $this->getUser();
     Validator::extend('valid_cba', function ($attribute, $value, $parameters) {
         $acceptedMimetypes = array('application/zip', 'application/rar', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed', 'application/octet-stream', 'application/x-rar-compressed', 'compressed/rar', 'application/x-rar');
         $acceptedExtensionTypes = array('zip', 'rar', 'cbz', 'cbr');
         if (in_array($value->getMimeType(), $acceptedMimetypes) && in_array($value->getClientOriginalExtension(), $acceptedExtensionTypes)) {
             return true;
         } else {
             return false;
         }
     });
     Validator::extend('valid_uuid', function ($attribute, $value, $parameters) {
         if (preg_match("/^(\\{)?[a-f\\d]{8}(-[a-f\\d]{4}){4}[a-f\\d]{8}(?(1)\\})\$/i", $value)) {
             return true;
         } else {
             return false;
         }
     });
     Validator::extend('user_comics', function ($attribute, $value, $parameters) {
         if (Comic::find($value)) {
             return false;
         }
         return true;
     });
     Validator::extend('user_series', function ($attribute, $value, $parameters) {
         //Check if the series is owned by someone else
         $series = Series::find($value);
         if ($series) {
             if ($series->user_id == $this->getUser()->id) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return true;
         }
     });
     $messages = ['file.valid_cba' => 'Not a valid File.', 'comic_id.user_comics' => 'Not a valid Comic ID', 'series_id.user_series' => 'Not a valid Series ID', 'series_id.valid_uuid' => 'The :attribute field is not a valid ID.', 'comic_id.valid_uuid' => 'The :attribute field is not a valid ID.', 'file.required' => 'A file is required.'];
     $validator = Validator::make($this->request->all(), ['file' => 'required|valid_cba|between:1,150000', 'series_id' => 'required|valid_uuid|user_series', 'comic_id' => 'required|valid_uuid|user_comics', 'series_title' => 'required', 'series_start_year' => 'required|numeric', 'comic_issue' => 'required|numeric'], $messages);
     if ($validator->fails()) {
         $pretty_errors = array_map(function ($item) {
             return ['title' => 'Missing Required Field Or Incorrectly Formatted Data', 'detail' => $item, 'status' => 400, 'code' => ''];
         }, $validator->errors()->all());
         return $this->respondBadRequest($pretty_errors);
     }
     $file = $this->request->file('file');
     $fileHash = hash_file('md5', $file->getRealPath());
     $match_data = $this->request->except('file');
     $upload = (new Upload())->create(["id" => Uuid::uuid4()->toString(), "file_original_name" => $file->getClientOriginalName(), "file_size" => $file->getSize(), "file_original_file_type" => $file->getClientOriginalExtension(), "user_id" => $currentUser->id, "match_data" => json_encode($match_data)]);
     $newFileName = Uuid::uuid4()->toString() . "." . $file->getClientOriginalExtension();
     $cba = ComicBookArchive::where('comic_book_archive_hash', '=', $fileHash)->first();
     $process_cba = false;
     if (!$cba) {
         Storage::disk('user_uploads')->put($newFileName, file_get_contents($file));
         //TODO: Make sure right AWS S3 ACL is used in production
         $permanent_location = getFileUrl("s3", $newFileName);
         $cba = (new ComicBookArchive())->create(["upload_id" => $upload->id, "comic_book_archive_hash" => $fileHash, "comic_book_archive_status" => 0, "comic_book_archive_permanent_location" => $permanent_location]);
         $process_cba = true;
     }
     $series = $currentUser->series()->find($match_data['series_id']);
     if (!$series) {
         $series = (new Series())->create(["id" => $match_data['series_id'], "series_title" => $match_data['series_title'], "series_start_year" => $match_data['series_start_year'], "series_publisher" => 'Unknown', "user_id" => $currentUser->id]);
     }
     $comic_info = ['comic_issue' => $match_data['comic_issue'], 'comic_id' => $match_data['comic_id'], 'series_id' => $series->id, 'comic_writer' => 'Unknown', 'comic_book_archive_id' => $cba->id];
     $comic = (new Comic())->create(["id" => $comic_info['comic_id'], "comic_issue" => $comic_info['comic_issue'], "comic_writer" => $comic_info['comic_writer'], "comic_book_archive_contents" => $cba->comic_book_archive_contents ? $cba->comic_book_archive_contents : '', "user_id" => $currentUser->id, "series_id" => $comic_info['series_id'], "comic_book_archive_id" => $cba->id]);
     //invoke lambda
     if ($process_cba) {
         $temporary_location = getFileUrl("s3", $newFileName, "+10 minutes");
         /*$lambda = AWS::get('Lambda');
                    $lambda->invokeAsync([
                        'FunctionName' => env('LAMBDA_FUNCTION_NAME'),
                        'InvokeArgs' => json_encode([
                            "api_base" => url(),
                            "api_version" => 'v'.env('APP_API_VERSION'),//TODO: This should be processor.
                            "environment" => env('APP_ENV'),
                            "fileLocation" => $temporary_location,
                            "cba_id" => $cba->id
                        ]),
         		]);*/
     }
     return $this->respondCreated(['upload' => $upload]);
 }
예제 #12
0
use yii\helpers\ArrayHelper;
use app\models\Series;
use app\models\Status;
/* @var $this yii\web\View */
/* @var $searchModel app\models\CardSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Cards');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="card-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Create Card'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'seriesId', 'value' => 'series.seriesName', 'filter' => Html::activeDropDownList($searchModel, 'seriesId', ArrayHelper::map(Series::find()->asArray()->all(), 'id', 'seriesName'), ['class' => 'form-control', 'prompt' => 'Выбрать серию'])], 'number', 'issueDateTime', 'endingDateTime', 'lastDateOfUse', 'currentSumm', ['attribute' => 'statusId', 'value' => 'status.statusName', 'filter' => Html::activeDropDownList($searchModel, 'statusId', ArrayHelper::map(Status::find()->asArray()->all(), 'id', 'statusName'), ['class' => 'form-control', 'prompt' => 'Выбрать статус'])]]]);
?>

</div>
예제 #13
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(SeriesRequest $request, $society, $id)
 {
     $series = Series::find($id)->fill($request->except('seriesimage', 'seriesbanner'));
     if ($request->file('seriesimage')) {
         $fileName = "seriesimage_" . $series->id . "." . $request->file('seriesimage')->getClientOriginalExtension();
         $request->file('seriesimage')->move(base_path() . '/storage/app/images/', $fileName);
         $series->seriesimage = '/storage/app/images/' . $fileName;
         $img = Image::make(base_path() . $series->seriesimage);
         $img->resize(250, 250);
         $img->save(base_path() . '/storage/app/images/' . $fileName);
     }
     if ($request->file('seriesbanner')) {
         $fileName = "seriesbanner_" . $series->id . "." . $request->file('seriesbanner')->getClientOriginalExtension();
         $request->file('seriesbanner')->move(base_path() . '/storage/app/images/', $fileName);
         $series->seriesbanner = '/storage/app/images/' . $fileName;
     }
     $series->save();
     return redirect(url('/') . '/' . $series->society_id . '/series')->with('okmessage', 'Series has been updated');
 }