public function store($section) { $section = Section::find($section, 'slug'); $slug = Functions::urlSafe($_POST['f' . $section->slugfield()->id]); $unique_slug = false; while (!$unique_slug) { if ($section->checkslug($slug)) { $unique_slug = true; } else { $slug .= '-'; } } $record = new Record(); $record->section = $section->id; $record->slug = $slug; $record->save(); $this->store_data($section, $record); Functions::redirect(Settings::cloutURL() . '/sections/' . $section->slug); }
public function __construct() { if (GRAFT_CONFIG['DBHost'] == '' || GRAFT_CONFIG['DBName'] == '' || GRAFT_CONFIG['DBUser'] == '') { die('A database connection is required to run clout.'); } // instance everything so the db gets setup // probably need a better way to do this // in the future #TODO \GraftPHP\Clout\Data::build(); \GraftPHP\Clout\Field::build(); \GraftPHP\Clout\FieldType::build(); \GraftPHP\Clout\Record::build(); \GraftPHP\Clout\Section::build(); \GraftPHP\Clout\User::build(); $this->data['sections'] = Section::all(); }
public function checkSlug($slug) { $out = Record::where('section', '=', $this->id)->where('slug', '=', $slug)->get()->count(); return $out == 0 ? true : false; }