<commit_before><?php

namespace App\Http\Controllers\Frontend;

use App\Http\Requests\ProjectRequest as StoreRequest;
use App\Http\Requests\ProjectRequest as UpdateRequest;
use Auth;
use App\Http\Controllers\CustomCrudController as CrudController;
use Backpack\CRUD\app\Http\Requests\CrudRequest;

// VALIDATION: change the requests to match your own file names if you need form validation
class ProjectCrudController extends CrudController
{

    public function setUp()
    {

        /*
        |--------------------------------------------------------------------------
        | BASIC CRUD INFORMATION
        |--------------------------------------------------------------------------
        */
        $this->crud->setModel('App\Models\Project');
        $this->crud->setRoute(config('backpack.base.route_prefix') . '/projects');
        $this->crud->setEntityNameStrings('project', 'projects');

        /*
        |--------------------------------------------------------------------------
        | BASIC CRUD INFORMATION
        |--------------------------------------------------------------------------
        */

        $this->crud->setFromDb();

        // ------ CRUD FIELDS
        // $this->crud->addField($options, 'update/create/both');
        // $this->crud->addFields($array_of_arrays, 'update/create/both');
        // $this->crud->removeFields($array_of_names, 'update/create/both');

        // ------ CRUD COLUMNS
        // $this->crud->addColumn(); // add a single column, at the end of the stack
        // $this->crud->addColumns(); // add multiple columns, at the end of the stack
        // $this->crud->removeColumn('column_name'); // remove a column from the stack
        // $this->crud->removeColumns(['column_name_1', 'column_name_2']); // remove an array of columns from the stack
        $this->crud->setColumnDetails('is_private', ['type' => 'boolean', 'label'=>'Private?',
                                                     'options' => [ 0 => '', 1 => 'Yes' ]]); // adjusts the properties of the passed in column (by name)
        $this->crud->addColumn([
            'label'         => "Vocabularies",
            'type'          => "model_function",
            'function_name' => 'getVocabColumn',
        ]);
        $this->crud->addColumn([
            'label'         => "Element Sets",
            'type'          => "model_function",
            'function_name' => 'getElementColumn',
        ]);
        // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']);

        // ------ CRUD BUTTONS
        // possible positions: 'beginning' and 'end'; defaults to 'beginning' for the 'line' stack, 'end' for the others;
        // $this->crud->addButton($stack, $name, $type, $content, $position); // add a button; possible types are: view, model_function
        // $this->crud->addButtonFromModelFunction($stack, $name, $model_function_name, $position); // add a button whose HTML is returned by a method in the CRUD model
        // $this->crud->addButtonFromView($stack, $name, $view, $position); // add a button whose HTML is in a view placed at resources\views\vendor\backpack\crud\buttons
        // $this->crud->removeButton($name);
        // $this->crud->removeButtonFromStack($name, $stack);
      if (Auth::guest()) {
        $this->crud->removeAllButtonsFromStack('line');
      }

        // ------ CRUD ACCESS
      $this->crud->allowAccess([ 'list', 'show']);
      $this->crud->denyAccess([ 'create', 'update', 'delete' ]);
      if (Auth::check()) {
        $this->crud->allowAccess('create');
      }

        // ------ CRUD REORDER
        // $this->crud->enableReorder('label_name', MAX_TREE_LEVEL);
        // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('reorder');

        // ------ CRUD DETAILS ROW
        // $this->crud->enableDetailsRow();
        // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('details_row');
        // NOTE: you also need to do overwrite the showDetailsRow($id) method in your EntityCrudController to show whatever you'd like in the details row OR overwrite the views/backpack/crud/details_row.blade.php

        // ------ REVISIONS
        // You also need to use \Venturecraft\Revisionable\RevisionableTrait;
        // Please check out: https://laravel-backpack.readme.io/docs/crud#revisions
        // $this->crud->allowAccess('revisions');

        // ------ AJAX TABLE VIEW
        // Please note the drawbacks of this though:
        // - 1-n and n-n columns are not searchable
        // - date and datetime columns won't be sortable anymore
        // $this->crud->enableAjaxTable();

        // ------ DATATABLE EXPORT BUTTONS
        // Show export to PDF, CSV, XLS and Print buttons on the table view.
        // Does not work well with AJAX datatables.
        // $this->crud->enableExportButtons();

        // ------ ADVANCED QUERIES
        // $this->crud->addClause('active');
        // $this->crud->addClause('type', 'car');
        // $this->crud->addClause('where', 'name', '==', 'car');
        // $this->crud->addClause('whereName', 'car');
        // $this->crud->addClause('whereHas', 'posts', function($query) {
        //     $query->activePosts();
        // });
        // $this->crud->addClause('withoutGlobalScopes');
        // $this->crud->addClause('withoutGlobalScope', VisibleScope::class);
        // $this->crud->with(); // eager load relationships
        // $this->crud->orderBy();
        // $this->crud->groupBy();
        // $this->crud->limit();
    }

  public function edit($id)
  {
    if (Auth::check() && Auth::user()->isAdminForProjectId($id)) {
      $this->crud->allowAccess([ 'update']);
    }
    return parent::edit($id);
  }

  public function destroy($id)
  {
    if (Auth::check() && Auth::user()->isAdminForProjectId($id)) {
      $this->crud->allowAccess([ 'delete' ]);
    }
    return parent::destroy($id);
  }


  public function store(StoreRequest $request)
    {
      if (Auth::check()) {
        $this->crud->allowAccess('store');
      }
        // your additional operations before save here
        $redirect_location = parent::storeCrud();
      Auth::user()->projects()->attach($this->crud->entry,
                                      [ 'is_registrar_for' => true, 'is_admin_for' => true, ]);
      // your additional operations after save here
        // use $this->data['entry'] or $this->crud->entry
        return $redirect_location;
    }

    public function update(UpdateRequest $request)
    {
      if (Auth::check() && Auth::user()->isAdminForProjectId($request->id)) {
        $this->crud->allowAccess([ 'update' ]);
      }
      // your additional operations before save here
        $redirect_location = parent::updateCrud();
        // your additional operations after save here
        // use $this->data['entry'] or $this->crud->entry
        return $redirect_location;
    }
}
<commit_msg>move hidden columns into project crud controller<commit_after><?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\CustomCrudController as CrudController;
use App\Http\Requests\ProjectRequest as StoreRequest;
use App\Http\Requests\ProjectRequest as UpdateRequest;
use Auth;

// VALIDATION: change the requests to match your own file names if you need form validation
class ProjectCrudController extends CrudController
{

    public function setUp()
    {

        /*
        |--------------------------------------------------------------------------
        | BASIC CRUD INFORMATION
        |--------------------------------------------------------------------------
        */
        $this->crud->setModel( 'App\Models\Project' );
        $this->crud->setRoute( config( 'backpack.base.route_prefix' ) . '/projects' );
        $this->crud->setEntityNameStrings( 'project', 'projects' );

        /*
        |--------------------------------------------------------------------------
        | BASIC CRUD INFORMATION
        |--------------------------------------------------------------------------
        */

        $this->crud->setFromDb();

        // ------ CRUD FIELDS
        // $this->crud->addField($options, 'update/create/both');
        // $this->crud->addFields($array_of_arrays, 'update/create/both');
        // $this->crud->removeFields($array_of_names, 'update/create/both');

        // ------ CRUD COLUMNS
        // $this->crud->addColumn(); // add a single column, at the end of the stack
        // $this->crud->addColumns(); // add multiple columns, at the end of the stack
        // $this->crud->removeColumn('column_name'); // remove a column from the stack
        $this->crud->removeColumns( [ 'address1',
                                      'address2',
                                      'base_domain',
                                      'city',
                                      'country',
                                      'created_at',
                                      'created_by',
                                      'default_language_id',
                                      'default_language',
                                      'deleted_at',
                                      'deleted_by',
                                      'description',
                                      'google_sheet_url',
                                      'ind_affiliation',
                                      'ind_role',
                                      'label',
                                      'languages',
                                      'license_uri',
                                      'license',
                                      'name',
                                      'namespace_type',
                                      'org_email',
                                      'phone',
                                      'postal_code',
                                      'prefixes',
                                      'repo',
                                      'starting_number',
                                      'state',
                                      'type',
                                      'updated_at',
                                      'updated_by',
                                      'uri_append',
                                      'uri_prepend',
                                      'uri_strategy',
                                      'uri_type',
                                      'url',
                                      'web_address', ] ); // remove an array of columns from the stack
        $this->crud->setColumnDetails( 'is_private',
            [ 'type'    => 'boolean',
              'label'   => 'Private?',
              'options' => [ 0 => '',
                             1 => 'Yes' ] ] ); // adjusts the properties of the passed in column (by name)
        $this->crud->addColumn( [ 'label'         => "Vocabularies",
                                  'type'          => "model_function",
                                  'function_name' => 'getVocabColumn', ] );
        $this->crud->addColumn( [ 'label'         => "Element Sets",
                                  'type'          => "model_function",
                                  'function_name' => 'getElementColumn', ] );
        // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']);

        // ------ CRUD BUTTONS
        // possible positions: 'beginning' and 'end'; defaults to 'beginning' for the 'line' stack, 'end' for the others;
        // $this->crud->addButton($stack, $name, $type, $content, $position); // add a button; possible types are: view, model_function
        // $this->crud->addButtonFromModelFunction($stack, $name, $model_function_name, $position); // add a button whose HTML is returned by a method in the CRUD model
        // $this->crud->addButtonFromView($stack, $name, $view, $position); // add a button whose HTML is in a view placed at resources\views\vendor\backpack\crud\buttons
        // $this->crud->removeButton($name);
        // $this->crud->removeButtonFromStack($name, $stack);
        if ( Auth::guest() ) {
            $this->crud->removeAllButtonsFromStack( 'line' );
        }

        // ------ CRUD ACCESS
        $this->crud->allowAccess( [ 'list', 'show' ] );
        $this->crud->denyAccess( [ 'create', 'update', 'delete' ] );
        if ( Auth::check() ) {
            $this->crud->allowAccess( 'create' );
        }

        // ------ CRUD REORDER
        // $this->crud->enableReorder('label_name', MAX_TREE_LEVEL);
        // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('reorder');

        // ------ CRUD DETAILS ROW
        // $this->crud->enableDetailsRow();
        // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('details_row');
        // NOTE: you also need to do overwrite the showDetailsRow($id) method in your EntityCrudController to show whatever you'd like in the details row OR overwrite the views/backpack/crud/details_row.blade.php

        // ------ REVISIONS
        // You also need to use \Venturecraft\Revisionable\RevisionableTrait;
        // Please check out: https://laravel-backpack.readme.io/docs/crud#revisions
        // $this->crud->allowAccess('revisions');

        // ------ AJAX TABLE VIEW
        // Please note the drawbacks of this though:
        // - 1-n and n-n columns are not searchable
        // - date and datetime columns won't be sortable anymore
        // $this->crud->enableAjaxTable();

        // ------ DATATABLE EXPORT BUTTONS
        // Show export to PDF, CSV, XLS and Print buttons on the table view.
        // Does not work well with AJAX datatables.
        // $this->crud->enableExportButtons();

        // ------ ADVANCED QUERIES
        // $this->crud->addClause('active');
        // $this->crud->addClause('type', 'car');
        // $this->crud->addClause('where', 'name', '==', 'car');
        // $this->crud->addClause('whereName', 'car');
        // $this->crud->addClause('whereHas', 'posts', function($query) {
        //     $query->activePosts();
        // });
        // $this->crud->addClause('withoutGlobalScopes');
        // $this->crud->addClause('withoutGlobalScope', VisibleScope::class);
        // $this->crud->with(); // eager load relationships
        // $this->crud->orderBy();
        // $this->crud->groupBy();
        // $this->crud->limit();
    }

    public function edit( $id )
    {
        if ( Auth::check() && Auth::user()->isAdminForProjectId( $id ) ) {
            $this->crud->allowAccess( [ 'update' ] );
        }

        return parent::edit( $id );
    }

    public function destroy( $id )
    {
        if ( Auth::check() && Auth::user()->isAdminForProjectId( $id ) ) {
            $this->crud->allowAccess( [ 'delete' ] );
        }

        return parent::destroy( $id );
    }

    public function store( StoreRequest $request )
    {
        if ( Auth::check() ) {
            $this->crud->allowAccess( 'store' );
        }
        // your additional operations before save here
        $redirect_location = parent::storeCrud();
        Auth::user()->projects()->attach( $this->crud->entry,
            [ 'is_registrar_for' => true, 'is_admin_for' => true, ] );
        // your additional operations after save here
        // use $this->data['entry'] or $this->crud->entry
        return $redirect_location;
    }

    public function update( UpdateRequest $request )
    {
        if ( Auth::check() && Auth::user()->isAdminForProjectId( $request->id ) ) {
            $this->crud->allowAccess( [ 'update' ] );
        }
        // your additional operations before save here
        $redirect_location = parent::updateCrud();
        // your additional operations after save here
        // use $this->data['entry'] or $this->crud->entry
        return $redirect_location;
    }
}

{'fraction_non_alphanumeric': 0.18409048303443104, 'fraction_numerical': 0.000874835968255952, 'mean_word_length': 1.5787947147921366, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 245, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 43, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '823526', 'n_tokens_mistral': 4286, 'n_tokens_neox': 4171, 'n_words': 955}