diff --git a/app/controllers/admin/CustomFieldsController.php b/app/controllers/admin/CustomFieldsController.php index de08ab802f..a9f97d5265 100644 --- a/app/controllers/admin/CustomFieldsController.php +++ b/app/controllers/admin/CustomFieldsController.php @@ -8,6 +8,7 @@ use Validator; use Redirect; use Model; use Lang; +use Sentry; class CustomFieldsController extends \BaseController { @@ -19,7 +20,11 @@ class CustomFieldsController extends \BaseController { public function index() { // - return View::make("backend.custom_fields.index")->with("custom_fieldsets",CustomFieldset::all())->with("custom_fields",CustomField::all()); + $fieldsets=CustomFieldset::with("fields","models")->get(); + //$fieldsets=CustomFieldset::all(); + $fields=CustomField::with("fieldset")->get(); + //$fields=CustomField::all(); + return View::make("backend.custom_fields.index")->with("custom_fieldsets",$fieldsets)->with("custom_fields",$fields); } @@ -43,7 +48,7 @@ class CustomFieldsController extends \BaseController { public function store() { // - $cfset=new CustomFieldset(["name" => Input::get("name")]); + $cfset=new CustomFieldset(["name" => Input::get("name"),"user_id" => Sentry::getUser()->id]); $validator=Validator::make(Input::all(),$cfset->rules); if($validator->passes()) { $cfset->save(); @@ -76,7 +81,7 @@ class CustomFieldsController extends \BaseController { public function storeField() { - $field=new CustomField(["name" => Input::get("name"),"element" => Input::get("element")]); + $field=new CustomField(["name" => Input::get("name"),"element" => Input::get("element"),"user_id" => Sentry::getUser()->id]); if(!in_array(Input::get('format'),["ALPHA","NUMERIC","MAC","IP"])) { $field->format=Input::get("custom_format"); } else { diff --git a/app/database/migrations/2015_09_22_003413_migrate_mac_address.php b/app/database/migrations/2015_09_22_003413_migrate_mac_address.php index f1bf411c93..e87c15a921 100644 --- a/app/database/migrations/2015_09_22_003413_migrate_mac_address.php +++ b/app/database/migrations/2015_09_22_003413_migrate_mac_address.php @@ -15,6 +15,7 @@ class MigrateMacAddress extends Migration { DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); $f2=new CustomFieldset(['name' => "Asset with MAC Address"]); + $f2->timestamps=false; //when this model was first created, it had no timestamps. But later on it gets them. if(!$f2->save()) { throw new Exception("couldn't save customfieldset"); } diff --git a/app/database/migrations/2015_12_30_233509_add_timestamp_and_userId_to_custom_fields.php b/app/database/migrations/2015_12_30_233509_add_timestamp_and_userId_to_custom_fields.php new file mode 100644 index 0000000000..9b7854615a --- /dev/null +++ b/app/database/migrations/2015_12_30_233509_add_timestamp_and_userId_to_custom_fields.php @@ -0,0 +1,34 @@ +integer("user_id")->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('custom_fields', function(Blueprint $table) + { + $table->dropColumn("user_id"); + }); + } + +} diff --git a/app/database/migrations/2015_12_30_233658_add_timestamp_and_userId_to_custom_fieldsets.php b/app/database/migrations/2015_12_30_233658_add_timestamp_and_userId_to_custom_fieldsets.php new file mode 100644 index 0000000000..1d2ba523ee --- /dev/null +++ b/app/database/migrations/2015_12_30_233658_add_timestamp_and_userId_to_custom_fieldsets.php @@ -0,0 +1,38 @@ +timestamps(); + $table->integer("user_id")->nullable(); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('custom_fieldsets', function(Blueprint $table) + { + $table->dropTimestamps(); + $table->dropColumn("user_id"); + }); + } + +} diff --git a/app/models/CustomField.php b/app/models/CustomField.php index d04a246480..708fc0ae35 100644 --- a/app/models/CustomField.php +++ b/app/models/CustomField.php @@ -71,6 +71,10 @@ class CustomField extends Elegant public function fieldset() { return $this->belongsToMany('CustomFieldset'); //?!?!?!?!?!? } + + public function user() { + return $this->belongsTo('User'); + } //public function diff --git a/app/models/CustomFieldset.php b/app/models/CustomFieldset.php index 2af4ae9b9f..c6ef39e92a 100644 --- a/app/models/CustomFieldset.php +++ b/app/models/CustomFieldset.php @@ -2,7 +2,6 @@ class CustomFieldset extends Elegant { protected $guarded=["id"]; - public $timestamps=false; public $rules=[ "name" => "required|unique:custom_fieldsets" @@ -16,6 +15,10 @@ class CustomFieldset extends Elegant return $this->hasMany('Model',"fieldset_id"); } + public function user() { + return $this->belongsTo('User'); //WARNING - not all CustomFieldsets have a User!! + } + public function validation_rules() { $rules=[];