/**
  * Allow custom options to be added (comma separated)
  * @param array $postContent
  * @return static
  */
 public function submit($postContent)
 {
     $postContent['select'] = !empty($postContent['select']) ? $postContent['select'] : [];
     if ($postContent['custom']) {
         $newOptions = explode(',', $postContent['custom']);
         $optionsArr = [];
         $options = BlockSelectOption::where('block_id', '=', $this->_block->id)->get();
         if (!$options->isEmpty()) {
             foreach ($options as $option) {
                 $optionsArr[$option->value] = $option->option;
             }
         }
         foreach ($newOptions as $newOption) {
             $newOption = trim($newOption);
             if ($newOption && empty($optionsArr[$newOption])) {
                 $optionsArr[$newOption] = $newOption;
             }
         }
         BlockSelectOption::import($this->_block->id, $optionsArr);
         $postContent['select'] = array_merge($postContent['select'], $newOptions);
     }
     return $this->save(!empty($postContent['select']) ? serialize($postContent['select']) : '');
 }
 public function postSelects($blockId, $import = 0)
 {
     $inputOptions = [];
     if ($import) {
         $optionText = Request::get('selectOptionText');
         $optionValue = Request::get('selectOptionValue');
         $importOption = Request::get('selectOptionImport');
         $importUrls = ['fa-4.6' => 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css'];
         $importRegex = ['fa-4.6' => '.(fa-\\w+):before{content:"\\\\\\w{4}"}'];
         $client = new Client();
         $response = $client->get($importUrls[$importOption]);
         $matches = [];
         preg_match_all('#' . $importRegex[$importOption] . '#', $response->getBody(), $matches);
         if (!empty($matches[1])) {
             foreach ($matches[1] as $match) {
                 $inputOptions[str_replace('$match', $match, $optionValue)] = str_replace('$match', $match, $optionText);
             }
         }
     } else {
         $options = Request::get('selectOption');
         if (!empty($options)) {
             foreach ($options as $option) {
                 $inputOptions[$option['value']] = $option['option'];
             }
         }
     }
     BlockSelectOption::import($blockId, $inputOptions);
     return \redirect()->route('coaster.admin.themes.selects');
 }
Пример #3
0
 public static function saveBlock($block, $blockData)
 {
     if (isset(self::$_fileBlocks[$block])) {
         $blockData['category_id'] = !empty($blockData['category_id']) ? $blockData['category_id'] : 0;
         if (!empty(self::$_allBlocks[$block])) {
             $existingBlock = self::$_allBlocks[$block];
             if ($existingBlock->type != $blockData['type'] || $existingBlock->label != $blockData['label'] || $existingBlock->category_id != $blockData['category_id']) {
                 $existingBlock->category_id = $blockData['category_id'];
                 $existingBlock->type = $blockData['type'];
                 $existingBlock->label = $blockData['label'];
                 $existingBlock->order = self::$_fileBlocks[$block]['order'];
                 $existingBlock->save();
             }
         } else {
             $newBlock = new Block();
             $newBlock->category_id = $blockData['category_id'];
             $newBlock->name = $block;
             $newBlock->type = $blockData['type'];
             $newBlock->note = !empty($blockData['note']) ? $blockData['note'] : '';
             $newBlock->label = $blockData['label'];
             $newBlock->order = self::$_fileBlocks[$block]['order'];
             $newBlock->save();
             self::$_allBlocks[$block] = $newBlock;
         }
     }
     if (!empty(self::$_selectBlocks[$block])) {
         BlockSelectOption::import(self::$_allBlocks[$block]->id, self::$_selectBlocks[$block]);
     }
 }