@@ -49,6 +49,8 @@ public function getIndex()
49
49
->addTab ('Teams ' , 'teams ' )
50
50
->addTab ('Team Actors ' , 'teamactors ' )
51
51
->addTab ('Actors ' , 'actors ' )
52
+ ->addTab ('Actor Types ' , 'actortypes ' )
53
+ ->addTab ('Characters ' , 'characters ' )
52
54
->buildPanel ()
53
55
->addPanel ()
54
56
->setId ('ADMIN_TYPES ' )
@@ -322,6 +324,69 @@ public function getActordelete($actorId)
322
324
return Redirect::to ('/admin#actors ' );
323
325
}
324
326
327
+ public function getCharacters ()
328
+ {
329
+ $ characters = Character::orderByNameAsc ()->paginate (20 );
330
+
331
+ // Set up the one page crud main details
332
+ Crud::setTitle ('Characters ' )
333
+ ->setSortProperty ('firstName ' )
334
+ ->setDeleteLink ('/admin/characterdelete/ ' )
335
+ ->setDeleteProperty ('id ' )
336
+ ->setPaginationFlag (true )
337
+ ->setResources ($ characters );
338
+
339
+ // Add the display columns
340
+ Crud::addDisplayField ('name ' , '/characters/view/ ' , 'id ' )
341
+ ->addDisplayField ('actor_name ' );
342
+
343
+ // Add the form fields
344
+ Crud::addFormField ('name ' , 'text ' )
345
+ ->addFormField ('keyName ' , 'text ' )
346
+ ->addFormField ('actor_id ' , 'select ' , Actor::orderByNameAsc ()->get ()->toSelectArray ('Select an actor ' ));
347
+
348
+ // Set the view data
349
+ Crud::make ();
350
+ }
351
+
352
+ public function postCharacters ()
353
+ {
354
+ $ this ->skipView ();
355
+
356
+ // Set the input data
357
+ $ input = e_array (Input::all ());
358
+
359
+ if ($ input != null ) {
360
+ // Get the object
361
+ $ character = (isset ($ input ['id ' ]) && strlen ($ input ['id ' ]) == 10 ? Character::find ($ input ['id ' ]) : new Character );
362
+ $ character ->name = $ input ['name ' ];
363
+ $ character ->keyName = $ input ['keyName ' ];
364
+ $ character ->actor_id = $ input ['actor_id ' ] != '0 ' ? $ input ['actor_id ' ] : null ;
365
+
366
+ // Attempt to save the object
367
+ $ this ->save ($ character );
368
+
369
+ // Handle errors
370
+ if ($ this ->errorCount () > 0 ) {
371
+ Ajax::addErrors ($ this ->getErrors ());
372
+ } else {
373
+ Ajax::setStatus ('success ' )->addData ('resource ' , $ character ->toArray ());
374
+ }
375
+
376
+ // Send the response
377
+ return Ajax::sendResponse ();
378
+ }
379
+ }
380
+
381
+ public function getCharacterdelete ($ characterId )
382
+ {
383
+ $ this ->skipView ();
384
+
385
+ Character::find ($ characterId )->delete ();
386
+
387
+ return Redirect::to ('/admin#characters ' );
388
+ }
389
+
325
390
public function getTeamactors ()
326
391
{
327
392
$ teams = Team::orderByNameAsc ()->paginate (10 );
@@ -395,6 +460,79 @@ public function postTeamactors()
395
460
}
396
461
}
397
462
463
+ public function getActortypes ()
464
+ {
465
+ $ actors = Actor::orderByNameAsc ()->paginate (10 );
466
+ $ types = Type::orderByNameAsc ()->get ();
467
+ $ typesArray = $ this ->arrayToSelect ($ types , 'id ' , 'name ' , 'None ' );
468
+ $ actorsArray = $ this ->arrayToSelect ($ actors , 'id ' , 'fullName ' , 'Select an actor ' );
469
+
470
+ // Set up the one page crud
471
+ Crud::setTitle ('Actor Types ' )
472
+ ->setSortProperty ('fullName ' )
473
+ ->setPaginationFlag (true )
474
+ ->setDeleteFlag (false )
475
+ ->setMulti ($ actors , 'types ' )
476
+ ->setMultiColumns (array ('Actors ' , 'Types ' ))
477
+ ->setMultiDetails (array ('name ' => 'fullName ' , 'field ' => 'actor_id ' ))
478
+ ->setMultiPropertyDetails (array ('name ' => 'name ' , 'field ' => 'type_id ' ));
479
+
480
+ // Add the form fields
481
+ Crud::addFormField ('actor_id ' , 'select ' , $ actorsArray )
482
+ ->addFormField ('type_id ' , 'multiselect ' , $ typesArray );
483
+
484
+ Crud::make ();
485
+ }
486
+
487
+ public function postActortypes ()
488
+ {
489
+ $ this ->skipView ();
490
+
491
+ // Set the input data
492
+ $ input = e_array (Input::all ());
493
+
494
+ if ($ input != null ) {
495
+ // Remove all existing roles
496
+ $ actorTypes = Actor_Type::where ('actor_id ' , $ input ['actor_id ' ])->get ();
497
+
498
+ if ($ actorTypes ->count () > 0 ) {
499
+ foreach ($ actorTypes as $ actorType ) {
500
+ $ actorType ->delete ();
501
+ }
502
+ }
503
+
504
+ // Add any new roles
505
+ if (count ($ input ['type_id ' ]) > 0 ) {
506
+ foreach ($ input ['type_id ' ] as $ type_id ) {
507
+ if ($ type_id == '0 ' ) continue ;
508
+
509
+ $ actorType = new Actor_Type ;
510
+ $ actorType ->actor_id = $ input ['actor_id ' ];
511
+ $ actorType ->type_id = $ type_id ;
512
+
513
+ $ this ->save ($ actorType );
514
+ }
515
+ }
516
+
517
+ // Handle errors
518
+ if ($ this ->errorCount () > 0 ) {
519
+ Ajax::addErrors ($ this ->getErrors ());
520
+ } else {
521
+ $ actor = Actor::find ($ input ['actor_id ' ]);
522
+
523
+ $ main = $ actor ->toArray ();
524
+ $ main ['multi ' ] = $ actor ->types ->id ->toJson ();
525
+
526
+ Ajax::setStatus ('success ' )
527
+ ->addData ('resource ' , $ actor ->types ->toArray ())
528
+ ->addData ('main ' , $ main );
529
+ }
530
+
531
+ // Send the response
532
+ return Ajax::sendResponse ();
533
+ }
534
+ }
535
+
398
536
public function getTypes ()
399
537
{
400
538
$ types = Type::orderByNameAsc ()->get ();
0 commit comments