Пример #1
0
 public static function initBlocks($block_name = '')
 {
     if ($block_name == '') {
         //Создаем поля по структуре
         $landing = config('landing');
     } else {
         $landing = [$block_name => config('landing')[$block_name]];
     }
     foreach ($landing as $blockname => $blockstruct) {
         $newBlock = static::find($blockname);
         if (!$newBlock) {
             $newBlock = new static();
             $newBlock->name = $blockname;
             if (array_key_exists('title', $blockstruct)) {
                 $newBlock->title = $blockstruct['title'];
             }
             if (array_key_exists('stringfields', $blockstruct)) {
                 foreach ($blockstruct['stringfields'] as $fieldname) {
                     $stringfield = Stringfield::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('textfields', $blockstruct)) {
                 foreach ($blockstruct['textfields'] as $fieldname) {
                     $textfield = Textfield::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('numbs', $blockstruct)) {
                 foreach ($blockstruct['numbs'] as $fieldname) {
                     $numb = Numb::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('bools', $blockstruct)) {
                 foreach ($blockstruct['bools'] as $fieldname) {
                     $boolitem = Bool::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('pdatetimes', $blockstruct)) {
                 foreach ($blockstruct['pdatetimes'] as $fieldname) {
                     $dtitem = Pdatetime::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('images', $blockstruct)) {
                 foreach ($blockstruct['images'] as $fieldname) {
                     $image = Imageitem::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             $newBlock->save();
         }
     }
     return 'OK';
 }
Пример #2
0
 public function deleteGroupItem()
 {
     $id = $this->id;
     $collection = Stringfield::where('group_id', '=', $id)->get();
     foreach ($collection as $field) {
         $field->delete();
     }
     $collection = Textfield::where('group_id', '=', $id)->get();
     foreach ($collection as $field) {
         $field->delete();
     }
     $collection = Numb::where('group_id', '=', $id)->get();
     foreach ($collection as $field) {
         $field->delete();
     }
     $collection = Bool::where('group_id', '=', $id)->get();
     foreach ($collection as $field) {
         $field->delete();
     }
     $collection = Pdatetime::where('group_id', '=', $id)->get();
     foreach ($collection as $field) {
         $field->delete();
     }
     $collection = Imageitem::where('group_id', '=', $id)->get();
     foreach ($collection as $field) {
         $field->delete();
     }
     $gr = Group::find($id);
     $gr->delete();
 }