public function handle() { $modelRoot = $this->argument("modelRoot"); $this->info("Destroying Generated Migration Files and Tables"); $class = $this->argument("class"); if (!$class) { $classes = \Config::get('app.buildmodels'); if ($classes && is_array($classes) && count($classes)) { foreach ($classes as $class) { $this->info("Deleting Migrations for: [{$class}]"); $class::deleteMigrationFiles(); $this->info("Migration deletion for [{$class}] done"); $this->info("Dropping table for: [{$class}]"); $class::dropTable(); $this->info("Table dropped for [{$class}]"); } #If all classes, drop the Migrations, session & password tables, too. $this->info("Model drops/deletions completed; now the rest:"); $systables = ['migrations', 'password_resets', 'sessions']; foreach ($systables as $systable) { $this->info("Dropping {$systable}..."); PkModel::dropTable($systable); } } else { $this->info("No Models to delete for!"); die; } } else { $migratontobuild = $modelRoot . '\\' . $class; $this->info("Starting migration build for: [{$migratontobuild}]"); $migratontobuild::buildMigrationDefinition(); $this->info("Migration building for [{$migratontobuild}] done"); } }
public function __construct(array $attributes = []) { $this->fillable = $this->getAttributeNames(); unset($this->fillable['id']); return parent::__construct($attributes); }
/** * This returns an HTML string representing either an input field or a display * value, depending on permissions. * @param string $name - the name of the TABLE field * @param string $type - the type of input. If just scalar input, default to * 'text', if choice/array, default to 'select' * @param PkExtensions\PkModel $object - the object to check for allowable edits * @return string - HTML representing the existing display value OR the relevant HTML * input control */ public function customInputField($name, PkModel $object, $value = null, $type = null, $options = []) { $valids = $object->canEditThisField($name); if ($valids === false) { return "\n<div class='display_val val'>" . $object->displayValue($name, $value) . "</div>\n"; } if ($valids === true) { if (!$type) { $type = 'text'; } if ($type === 'boolean') { return $this->boolean($name, 1, $object->{$name}, $options); } if ($type === 'textarea') { return $this->textarea($name, $object->{$name}, $options); } //return "\n<input type='text' class='display_val val' value='".$object->displayValue($name)."'/>\n"; return $this->input($type, $name, $object->{$name}, $options); } if (is_array($valids)) { #Make a select option control, limited to the options if (!$type) { $type = 'select'; } return $this->{$type}($name, $valids, $object->{$name}, $options); } throw new \Exception("Invalid 'valids' result from PkModel instance"); }
/** Takes a PkModel instance & $attname, and formats/wraps them as * a label & value. If $tpl is provided, should have keys for 'pk_lbl' & * 'pk_val'. Otherwise, a default is constructed * * @param PkModel $model * @param string $attname * @param PartialSet $tpl * @return stringable HTML representation */ public function mkAttDesc($model, $attname, $tpl = null) { if (!$model instanceof PkModel) { return null; } if (!ne_string($attname)) { return null; } if ($tpl instanceof PartialSet) { $tpl = $tpl->copy(); } else { $tpl = new PkHtmlRenderer(); $tpl[] = "<div class='pk-wrapper'>\n<div class='pk-lbl'>\n"; $tpl['pk_lbl'] = null; $tpl[] = "\n</div>\n<div class='pk-val'>\n"; $tpl['pk_val'] = null; $tpl[] = "\n</div>\n</div>\n"; } $tpl['pk_lbl'] = $model->attdesc($attname); $tpl['pk_val'] = $model->{$attname}; return $tpl; }
/** Special handling to reset passwords in a form, then calls parent method */ public function saveRelations(array $arr = []) { if (!$this->authUpdate()) { throw new Exception("Not authorized to update this object"); } ## Check for password reset if (isset($arr['new_password'])) { $new_password = $arr['new_password']; $confirm_password = keyVal('confirm_password', $arr); if ($new_password !== $confirm_password) { $redirback = redirect()->back()->withInput()->with('error_dialog', "Passwords didn't match"); pkdebug("Type of redirback: ", typeOf($redirback)); return $redirback; } //$arr['password'] = $new_password; $this->password = bcrypt($new_password); } return parent::saveRelations($arr); }
/** * Default authCreate, depends on authUpdate permission of "owning" object * Model classes that can be created by users should implement this method... * Top level objects which have no "owners" (like, "User" or "Project" * should override this method without requiring a "owner" or "parent" */ public static function authCreate(PkModel $parent = null, User $user = null) { return true; if (isCli()) { return true; } if ($parent && $parent instanceof PkModel) { return $parent->authUpdate($user); } return false; }