Ejemplo n.º 1
0
 /**
  * @param array $categorisedBlocks
  * @param array $blockContents
  * @param int $pageId
  * @return array
  */
 public static function getTabs($categorisedBlocks, $blockContents, $pageId = 0)
 {
     $tabHeaders = [];
     $tabContents = [];
     foreach ($categorisedBlocks as $categoryId => $categoryBlocks) {
         $category = BlockCategory::preload($categoryId);
         $tabIndex = $category->order;
         while (!empty($tabHeaders[$tabIndex])) {
             $tabIndex++;
         }
         $tabHeaders[$tabIndex] = $category->name;
         $tabContents[$tabIndex] = '';
         foreach ($categoryBlocks as $blockId => $block) {
             /** @var Block $block */
             $blockContent = isset($blockContents[$blockId][Language::current()]) ? $blockContents[$blockId][Language::current()]->content : '';
             $tabContents[$tabIndex] .= $block->setPageId($pageId)->getTypeObject()->edit($blockContent);
         }
     }
     return [$tabHeaders, $tabContents];
 }
Ejemplo n.º 2
0
 private function _categoryList()
 {
     $blockCategoryNames = [];
     $blockCategories = BlockCategory::orderBy('order')->get();
     foreach ($blockCategories as $blockCategory) {
         $blockCategoryNames[$blockCategory->id] = $blockCategory->name;
     }
     return $blockCategoryNames;
 }
 /**
  * @param $categoryName
  * @return mixed
  */
 protected function _getBlockCategoryIdFromName($categoryName)
 {
     if (!isset($this->blockCategoryIds)) {
         foreach (BlockCategory::all() as $category) {
             $this->blockCategoryIds[trim(strtolower($category->name))] = $category;
         }
         $categoryCsv = base_path('resources/views/themes/' . $this->theme . '/import/blocks/categories.csv');
         if (file_exists($categoryCsv) && ($fileHandle = fopen($categoryCsv, 'r')) !== false) {
             $row = 0;
             while (($data = fgetcsv($fileHandle)) !== false) {
                 if ($row++ == 0 && $data[0] == 'Block Category') {
                     continue;
                 }
                 if (!empty($data[0])) {
                     list($name, $order) = $data;
                     if (empty($this->blockCategoryIds[trim(strtolower($name))])) {
                         $newBlockCategory = new BlockCategory();
                         $newBlockCategory->name = trim($name);
                         $newBlockCategory->order = $order;
                         $newBlockCategory->save();
                         $this->blockCategoryIds[trim(strtolower($name))] = $newBlockCategory;
                     } else {
                         $this->blockCategoryIds[trim(strtolower($name))]->order = $order;
                         $this->blockCategoryIds[trim(strtolower($name))]->save();
                     }
                 }
             }
             fclose($fileHandle);
         }
     }
     if (empty($this->blockCategoryIds[trim(strtolower($categoryName))])) {
         $newBlockCategory = new BlockCategory();
         $newBlockCategory->name = trim($categoryName);
         $newBlockCategory->order = 0;
         $newBlockCategory->save();
         $this->blockCategoryIds[trim(strtolower($categoryName))] = $newBlockCategory;
     }
     return $this->blockCategoryIds[trim(strtolower($categoryName))]->id;
 }
Ejemplo n.º 4
0
 private static function _categoryGuess($block, $type = '')
 {
     if (!isset(self::$_guessedCategoryIds)) {
         $findKeys = ['main' => ['main'], 'banner' => ['banner', 'carousel'], 'seo' => ['seo'], 'footer' => ['foot'], 'header' => ['head']];
         self::$_guessedCategoryIds = [];
         $first = true;
         foreach (BlockCategory::all() as $category) {
             if ($first) {
                 $first = false;
                 $keys['main'] = $category->id;
             }
             foreach ($findKeys as $key => $matches) {
                 foreach ($matches as $match) {
                     if (stristr($category->name, $match)) {
                         self::$_guessedCategoryIds[$key] = $category->id;
                     }
                 }
             }
         }
     } else {
         $findKeys = [];
     }
     if ($type == 'repeater') {
         $findKeys[str_plural(str_replace('_', ' ', $block))] = [$block];
     }
     if (!empty($findKeys)) {
         $order = 0;
         foreach ($findKeys as $key => $matches) {
             $order += 10;
             if (!isset(self::$_guessedCategoryIds[$key])) {
                 $newBlockCategory = new BlockCategory();
                 $newBlockCategory->name = ucwords($key);
                 $newBlockCategory->order = $key == 'seo' ? 100 : $order;
                 $newBlockCategory->save();
                 self::$_guessedCategoryIds[$key] = $newBlockCategory->id;
             }
         }
     }
     $categoryFound = self::$_guessedCategoryIds['main'];
     $categoriesArr = [];
     $categoriesArr[self::$_guessedCategoryIds['seo']] = ['meta'];
     $categoriesArr[self::$_guessedCategoryIds['header']] = ['header_html', 'head', 'logo', 'phone'];
     $categoriesArr[self::$_guessedCategoryIds['footer']] = ['footer_html', 'foot', 'address', 'email', 'copyright'];
     $categoriesArr[self::$_guessedCategoryIds['banner']] = ['banner', 'carousel'];
     foreach ($categoriesArr as $_guessedCategoryIds => $matches) {
         foreach ($matches as $match) {
             if (stristr($block, $match)) {
                 $categoryFound = $_guessedCategoryIds;
             }
         }
     }
     return $categoryFound;
 }