Exemplo n.º 1
0
 /**
  * Populate select options with page names (also add no page option)
  * @param string $content
  * @return string
  */
 public function edit($content)
 {
     $parent = BlockSelectOption::where('block_id', '=', $this->_block->id)->where('option', '=', 'parent')->first();
     $parentPageId = !empty($parent) ? $parent->value : 0;
     $this->_editViewData['selectOptions'] = [0 => '-- No Page Selected --'] + Page::get_page_list(['parent' => $parentPageId]);
     return String_::edit($content);
 }
Exemplo n.º 2
0
 /**
  * Get colour option to select with text box
  * @param string $content
  * @return string
  */
 public function edit($content)
 {
     $this->_editViewData['selectOptions'] = ['none' => 'No Colour'];
     $selectOptions = BlockSelectOption::where('block_id', '=', $this->_block->id)->get();
     foreach ($selectOptions as $selectOption) {
         $this->_editViewData['selectOptions'][$selectOption->value] = $selectOption->option;
     }
     $this->_editViewData['selectClass'] = 'select_colour';
     return parent::edit($this->_defaultData($content));
 }
Exemplo n.º 3
0
 /**
  * Edit selectwprice data view
  * @param string $content
  * @return string
  */
 public function edit($content)
 {
     $this->_editViewData['selectOptions'] = [];
     $selectOptions = BlockSelectOption::where('block_id', '=', $this->_block->id)->get();
     foreach ($selectOptions as $selectOption) {
         $this->_editViewData['selectOptions'][$selectOption->value] = $selectOption->option;
     }
     if (preg_match('/^#[a-f0-9]{6}$/i', key($selectOptions))) {
         $this->_editViewData['class'] = 'select_colour';
     }
     return parent::edit($this->_defaultData($content));
 }
Exemplo n.º 4
0
 public function loopDataAndAddToSelectMultpipleWNewBlock($block, $data, $page_id)
 {
     $toSave = [];
     BlockSelectOption::unguard();
     foreach ($data as $item) {
         $selectOpt = BlockSelectOption::firstOrCreate(['block_id' => $block->id, 'option' => $item->name, 'value' => strtolower($item->name)]);
         $toSave[] = strtolower($item->name);
     }
     BlockSelectOption::reguard();
     $block->setPageId($page_id)->getTypeObject()->save(['select' => $toSave]);
     return implode(', ', $toSave);
 }
 /**
  * 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');
 }
Exemplo n.º 7
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]);
     }
 }