<commit_before><?php
/**
 * Author: <NAME> <<EMAIL>>
 * Date: 30.11.2016
 * Time: 18:45
 */

namespace odanylevskyi\sitemap\components;

use yii\helpers\Url;

class SitemapHelper
{
    /*
     * Return selected attributes in url.
     * This function should be used just to avoid getting all the information from database
     *
     * @param array $urls  - contains url and sitemap spec information
     * @param string $tableName - model table name
     *
     * @return array - list of attributes that should be selected from database
     */
    public static function getSelect($urls, $tableName) {
        $select = [];
        foreach ($urls as $url) {
            $url = count($url) > 1 && isset($url['path']) ? $url['path'] : $url;
            $select = array_merge($select, self::getAttributes($url, $tableName));
        }
        return array_unique($select);
    }

    /*
     * Return selected attributes in url.
     *
     * @param array $url  - contains only url information
     * @param string $tableName - model table name
     *
     * @return array - list of attributes that should be selected from database for specific url
     */
    public static function getAttributes($url, $tableName) {
        $attributes = [];
        foreach ($url as $key => $attribute) {
            if ($key !== 0 && strcmp($key, 'url') != 0 && strpos($attribute, ":") !== false) {
                $attributes[] = $tableName.'.'.trim($attribute, ':');
            }
        }
        return $attributes;
    }

    /*
     * Build sitemap url
     *
     * @param mixed - url information
     * @param object - model object
     *
     * @return string - url for sitemap.xml
     */
    public static function buildUrl($url, $model = null) {
        if(is_array($url)) {
            $url[0] = "/{$url[0]}";
            if ($model) {
                foreach($url as $key => $value) {
                    if ($key !== 0 && $key != 'url' && !is_int($value)) {
                        $url[$key] = $model->{trim($value, ':')};
                    } else {<commit_msg>Add combined key<commit_after><?php
/**
 * Author: <NAME> <<EMAIL>>
 * Date: 30.11.2016
 * Time: 18:45
 */

namespace odanylevskyi\sitemap\components;

use yii\helpers\Url;

class SitemapHelper
{
    /*
     * Return selected attributes in url.
     * This function should be used just to avoid getting all the information from database
     *
     * @param array $urls  - contains url and sitemap spec information
     * @param string $tableName - model table name
     *
     * @return array - list of attributes that should be selected from database
     */
    public static function getSelect($urls, $tableName) {
        $select = [];
        foreach ($urls as $url) {
            $url = count($url) > 1 && isset($url['path']) ? $url['path'] : $url;
            $select = array_merge($select, self::getAttributes($url, $tableName));
        }
        return array_unique($select);
    }

    /*
     * Return selected attributes in url.
     *
     * @param array $url  - contains only url information
     * @param string $tableName - model table name
     *
     * @return array - list of attributes that should be selected from database for specific url
     */
    public static function getAttributes($url, $tableName) {
        $attributes = [];
        foreach ($url as $key => $attribute) {
            if ($key !== 0 && strcmp($key, 'url') != 0) {
              if (is_array($attribute)) {
                $attributes[] = array_map(function($attr) use ($tableName) {
                  if (strpos($attr, '.') !== false) {
                    $attr = trim($attr, ':');
                  } else {
                    $attr = $tableName . '.' . trim($attr, ':');
                  }
                }, $attribute);
              } elseif (strpos($attribute, ":") !== false) {
                $attributes[] = $tableName . '.' . trim($attribute, ':');
              }
            }
        }
        return $attributes;
    }

    /*
     * Build sitemap url
     *
     * @param mixed - url information
     * @param object - model object
     *
     * @return string - url for sitemap.xml
     */
    public static function buildUrl($url, $model = null) {
        if(is_array($url)) {
            $url[0] = "/{$url[0]}";
            if ($model) {
                foreach($url as $key => $value) {
                    if ($key !== 0 && $key != 'url' && !is_int($value)) {
                        $url[$key] = $model->{trim($value, ':')};
                    } else {
{'fraction_non_alphanumeric': 0.1457507705856451, 'fraction_numerical': 0.007926023778071334, 'mean_word_length': 1.8698673404927353, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2625645', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1277, 'n_words': 372}