Get all data needed in the post create form.
Fields, Custom Fields, Categories, Languages.

@param  string $lang
@param  string $postTypeSlug
@return array
@throws \Exception
482043
public function getDataForCreate($lang, $postTypeSlug)
    {
        // Custom field groups
        $customFieldsGroups = CustomFieldGroup::findGroups('post-type', 'create', 0, $postTypeSlug);

        // post type
        $postType = PostType::where('slug', $postTypeSlug)->first();

        // Categories (options to select)
        $categories = array_values(Category::where("postTypeID", $postType->postTypeID)->get()->toArray());

        return [
            'postType' => $postType,
            'languages' => Language::all(),
            'categories' => $categories,
            'customFieldsGroups' => $customFieldsGroups,
            'postTypeFieldsValues' => $this->getPostTypeFieldsValues($postTypeSlug),
            'users' => User::all(),
            'createdByUserID' => Auth::user()->userID,
        ];
    }
924199
public function detailsJSON($lang, $id)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('PostType', 'read')) {
            return $this->noPermission();
        }
        $postType = App\Models\PostType::find($id);

        $categories = [];
        if($postType) {
            // has access into all categories
            if(User::hasAccess($postType->slug, 'categories', 'hasAll')) {
                $categories = DB::table('categories')
                    ->join('post_type', 'post_type.postTypeID', 'categories.postTypeID')
                    ->where('post_type.slug', $postType->slug)
                    ->orderBy('name', 'postTypeID')
                    ->select(
                        'categories.categoryID', 'categories.title', 'categories.slug', 'categories.createdByUserID', 'categories.order', 'categories.featuredImageID',
                        'categories.description', 'categories.created_at', 'categories.updated_at', 'post_type.name'
                    )
                    ->get();
            }else if(User::getPermission($postType->slug, 'categories')) {
                // has access into some categories
                $allowedCategories = User::getPermission()[$postType]['categories']['value'];
                $categories = DB::table('categories')
                    ->join('post_type', 'post_type.postTypeID', 'categories.postTypeID')
                    ->where('post_type.slug', $postType->slug)
                    ->whereIn('categories.categoryID', $allowedCategories)
                    ->orderBy('name', 'postTypeID')
                    ->select(
                        'categories.categoryID', 'categories.categoryID', 'categories.slug', 'categories.createdByUserID', 'categories.order', 'categories.featuredImageID',
                        'categories.description', 'categories.created_at', 'categories.updated_at', 'post_type.name'
                    )
                    ->get();
            }
        }

        $categories = Language::filterRows($categories, false);

        $final = array('details' => $postType, 'categories' => $categories, 'dbTables' => $this->getTables());

        // Fire event
        $final['events'] = Event::fire('postType:pre_update', [$final]);

        return $final;
    }
691236
static function getList ($lang)
    {
        global $config;
        $query = sprintf(
            file_get_contents('sql/getListPages.sql'),
            mysql_real_escape_string($lang)
        );
        $query=$config->connexionBdd->requete($query);
        $result=array();
        while ($row = mysql_fetch_assoc($query)) {
            array_push($result, $row);
        }
        return $result;
    }
55304
public function getAll($lang = "")
    {
        $result = [];
        $postType = PostType::all()->orderBy('postTypeID');
        foreach ($postType as $postType){
            $postType->categories = Category::where("postTypeID", $postType->postTypeID)->get();
            $result[] = $postType;
        }

        return ['data' => $result];
    }
1120838
public function index($lang = "", $view = "")
    {
        $classNameArr = explode("\\", get_class($this));
        $className = str_replace("Controller", "", $classNameArr[4]);
        // check if user has permissions to access this link
        $key = ($view == 'list' || $view == '') ? 'read' : $view;
        if(!User::hasAccess($className, $key)) {
            return view('errors.permissions', compact('lang', 'view'));
        }
        return view('content');
    }
950940
public function getAllWithoutPaginationByPostType($lang = "", $postType = "")
    {
        return DB::table('tags')->join('post_type', 'post_type.postTypeID', 'tags.postTypeID')->where('post_type.slug', $postType)->orderBy('name', 'postTypeID')->get();
    }
1028062
public function getAllPosts($lang, $postType)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess($postType, 'read')) {
            return $this->noPermission();
        }

        $defaultOrderBy = 'postID';
        $orderBy = (Input::get('order') ) ? Input::get('order') : $defaultOrderBy;
        $orderType = (Input::get('type')) ? Input::get('type') : 'DESC';
        $advancedSearch = (Input::get('advancedSearch')) ? Input::get('advancedSearch') : false;
        $categoryID = (Input::get('categoryID')) ? Input::get('categoryID') : null;

        // get field type in db
        try{
            $orderColumnType = DB::connection()->getDoctrineColumn($postType, $orderBy)->getType()->getName();
        }catch (\Exception $e){
            $orderColumnType = false;
            $orderBy = $defaultOrderBy;
        }

        // make the query
        $queryObject =  (new Post())->setTable($postType);
        // get user relation
        $queryObject = $queryObject->with("users");

        // get categories relations (if post type has categories)
        $postTypeOBJ = getPostType($postType);
        if($postTypeOBJ->hasCategories) {
            $queryObject = $queryObject->with("categories");
        }

        // Advanced Search
        if($advancedSearch) {
            $queryObject = $this->advancedSearch($queryObject, request(), $postType);
        }else if($categoryID) {
            // select based on categories
            $queryObject = $this->selectByCategory($queryObject, $categoryID, $postType);
        }

        // json langauge fields needs to be filtered by their langauge
        if($orderColumnType == "json") {
            $queryObject = $queryObject->orderBy($orderBy."->".App::getLocale(), $orderType);
        }else{
            $queryObject = $queryObject->orderBy($orderBy, $orderType);
        }

        // paginate
        $paginationResult = $queryObject->paginate(Post::$rowsPerPage);

        $response = $this
            ->appendListColumnsFromEvents($postType)
            ->appendListRowsFromEvents($paginationResult, $postType)
            ->toArray();

        $response['inTableColumns'] = $this->getInTableColumns($postType);

        $lang = App::getLocale();
        // set category title and author name
        foreach ($response['data'] as $key => $item){
            if(isset($item['categories']) && count($item['categories'])) {
                array_set($response, "data.$key.category", $item['categories'][0]['title']->$lang);
            }
            array_set($response, "data.$key.author", $item['users']['firstName'] . " ". $item['users']['lastName']);
        }

        return $response;
    }
616308
public static function getLangFiles( $dir_lang , $json_langs = null )
	{
		$langs = array();

		// scan genuine folders first
		foreach ( scandir( $dir_lang ) as $lang )
		{
			if ( ! Tools::isValidDirectory( $dir_lang , $lang ) )
			{
				continue;
			}

			if ( in_array( $lang , self::$vendorsFolders ) )
			{
				$langs[] = new LangFileTypeGenuineVendor( $lang );
			}
			else
			{
				$langs[] = new LangFileTypeGenuine( $lang );
			}

		}

		// generate json langs
		if ( is_array( $json_langs ) )
		{
			foreach ( $json_langs as $lang )
			{
				$langs[] = new LangFileTypeJson( $lang );
			}
		}

		return $langs;
	}
1309908
protected function createDefaultSearchFieldsMapping(Index $index, $lang = 'en')
    {
        $mapping = new Mapping();
        $mapping->setType($index->getType($this->indexType));

        $mapping->setProperties($this->properties);

        return $mapping;
    }
1328398
public static function getInstance($lang, $debug = false)
	{
		if (!isset(self::$languages[$lang . $debug]))
		{
			$language = new self($lang, $debug);

			self::$languages[$lang . $debug] = $language;

			// Check if Language was instantiated with a null $lang param;
			// if so, retrieve the language code from the object and store
			// the instance with the language code as well
			if (is_null($lang))
			{
				self::$languages[$language->getLanguage() . $debug] = $language;
			}
		}

		return self::$languages[$lang . $debug];
	}
441801
public function getAllByPostType($lang = "", $postTypeID)
    {
        $orderBy = (isset($_GET['order'])) ? $orderBy = $_GET['order'] : 'tagID';
        $orderType = (isset($_GET['type'])) ? $orderType = $_GET['type'] : 'DESC';
        // get data
        return Tag::where('postTypeID', $postTypeID)->orderBy($orderBy, $orderType)->paginate(Tag::$rowsPerPage);
    }
549814
public function getShopUrlByLanguage($lang, $ssl = false)
    {
        $configParameter = $ssl ? 'aLanguageSSLURLs' : 'aLanguageURLs';
        $lang = isset($lang) ? $lang : Registry::getLang()->getBaseLanguage();
        $languageURLs = $this->getConfigParam($configParameter);
        if (isset($lang) && isset($languageURLs[$lang]) && !empty($languageURLs[$lang])) {
            $languageURLs[$lang] = Registry::getUtils()->checkUrlEndingSlash($languageURLs[$lang]);
            return $languageURLs[$lang];
        }
    }
123903
public static function getFields($post_type)
    {
        $postType = PostType::all()->where('slug', $post_type)->first();

        if($postType) {
            return $postType->fields;
        }
        
        return [];
    }
933922
public function getBySlug($lang, $slug)
    {
        $postType = PostType::collection()->where('slug', $slug);
        if(!$postType->isEmpty()) {
            return $postType->first();
        }
        return [];
    }
975371
public static function load(array $langs, $lang = null)
    {
        static::$langs = $langs;
        static::$lang = $lang ?: key($langs);
    }
189711
private function _get_post_types(){
    global $wpdb;

    $query = sprintf('SELECT * FROM %s ORDER BY id',MF_TABLE_POSTTYPES);
    $posttypes = $wpdb->get_results( $query, ARRAY_A );
    return $posttypes;
  }
1194308
public function detailsJSON($lang, $postTypeSlug, $id)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess($postTypeSlug, 'update', $id, true)) {
            return $this->noPermission();
        }

        // post type
        $currentPostType = PostType::findBySlug($postTypeSlug);
        // get post
        $post = (new Post())->setTable($postTypeSlug)->find($id);

        if(!$post) {
            return $this->response("There is no post with ID: " . $id, 404);
        }
        // posts url
        $href = $post->href;

        // we need fields non-translated so we can play around with them in vuejs
        $post->setAutoTranslate(false);

        // the fields that are translatable
        $translatableFields = $this->getTranslatableFields($postTypeSlug);

        // get all related media and structure them for the post
        $media = $this->getPostRelatedMedia($id, $post, $postTypeSlug, $translatableFields);

        // handle custom fields
        $customFieldGroups = CustomFieldGroup::findGroups('post-type', 'update', $id, $postTypeSlug);
        $customFieldOBJ = new CustomField();
        if($post->customFields) {
            $customFieldOBJ->constructValues($customFieldGroups, $post->customFields);
            $media = array_merge($media, $customFieldOBJ->getMedia());
        }

        // Categories (options to select)
        $categories = array_values(Category::where("postTypeID", $currentPostType->postTypeID)->get()->toArray());

        // selected categories of this post
        $selectedCategories = [];
        if($currentPostType->hasCategories) {
            $selectedCategories = $this->getPostSelectedCategories($id, $postTypeSlug);
        }

        // selected tags of this post
        $selectedTags = [];
        if($currentPostType->hasTags) {
            $selectedTags = $this->getPostSelectedTags($id, $postTypeSlug);
        }

        $response = array(
            'post' => [
                'title' => $post->title,
                'content' => $post->content,
                'status' => $post->status,
                'slug' => $post->slug,
                'href' => $href,
                'media' => $media,
                'published_at' => $post->published_at,
                'selectedCategories' => $selectedCategories,
                'postTypeID' => $currentPostType->postTypeID,
                'hasCategories' => $currentPostType->hasCategories,
                'isCategoryRequired' => $currentPostType->isCategoryRequired,
                'selectedTags' => $selectedTags,
                'hasTags' => $currentPostType->hasTags,
                'isTagRequired' => $currentPostType->isTagRequired,
                'isFeaturedImageRequired' => $currentPostType->isFeaturedImageRequired,
                'createdByUserID' => $post->createdByUserID,
            ],
            'customFieldsValues' => $customFieldOBJ->getCustomFieldValues(),
            'customFieldsGroups' => $customFieldGroups,
            'postTypeFieldsValues' => $this->getPostTypeFieldsValues($postTypeSlug, $post),
            'categories' => $categories,
            'languages' => Language::all(),
            'users' => User::all(),
        );

        // Fire event
        $response['events'] = Event::fire('post:pre_update', [$response]);

        return $response;
    }