Improved category integration, adapted the fields generator to allow one field to be used multiple times in the same view
This commit is contained in:
@ -529,6 +529,14 @@ class Get
|
||||
|
||||
// Load the results as a list of stdClass objects
|
||||
$component = $this->db->loadObject();
|
||||
|
||||
// set component place holders
|
||||
$this->placeholders['###component###'] = ComponentbuilderHelper::safeString($component->name_code);
|
||||
$this->placeholders['###Component###'] = ComponentbuilderHelper::safeString($component->name_code, 'F');
|
||||
$this->placeholders['###COMPONENT###'] = ComponentbuilderHelper::safeString($component->name_code, 'U');
|
||||
$this->placeholders['[[[component]]]'] = $this->placeholders['###component###'];
|
||||
$this->placeholders['[[[Component]]]'] = $this->placeholders['###Component###'];
|
||||
$this->placeholders['[[[COMPONENT]]]'] = $this->placeholders['###COMPONENT###'];
|
||||
// set component sales name
|
||||
$component->sales_name = ComponentbuilderHelper::safeString($component->system_name);
|
||||
// ensure version naming is correct
|
||||
@ -669,7 +677,7 @@ class Get
|
||||
}
|
||||
|
||||
// set the site_view data
|
||||
$site_views = json_decode($component->addsite_views,true);
|
||||
$site_views = json_decode($component->addsite_views,true);
|
||||
if (ComponentbuilderHelper::checkArray($site_views))
|
||||
{
|
||||
foreach ($site_views as $option => $values)
|
||||
@ -690,11 +698,14 @@ class Get
|
||||
$this->lang = 'site';
|
||||
$this->target = 'site';
|
||||
// load the view and field data
|
||||
foreach ($component->site_views as $key => &$view)
|
||||
if (isset($component->site_views) && ComponentbuilderHelper::checkArray($component->site_views))
|
||||
{
|
||||
// has become a lacacy issue, can't remove this
|
||||
$view['view'] = $view['siteview'];
|
||||
$view['settings'] = $this->getCustomViewData($view['view']);
|
||||
foreach ($component->site_views as $key => &$view)
|
||||
{
|
||||
// has become a lacacy issue, can't remove this
|
||||
$view['view'] = $view['siteview'];
|
||||
$view['settings'] = $this->getCustomViewData($view['view']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -720,11 +731,14 @@ class Get
|
||||
$this->lang = 'admin';
|
||||
$this->target = 'custom_admin';
|
||||
// load the view and field data
|
||||
foreach ($component->custom_admin_views as $key => &$view)
|
||||
if (isset($component->custom_admin_views) && ComponentbuilderHelper::checkArray($component->custom_admin_views))
|
||||
{
|
||||
// has become a lacacy issue, can't remove this
|
||||
$view['view'] = $view['customadminview'];
|
||||
$view['settings'] = $this->getCustomViewData($view['view'], 'custom_admin_view');
|
||||
foreach ($component->custom_admin_views as $key => &$view)
|
||||
{
|
||||
// has become a lacacy issue, can't remove this
|
||||
$view['view'] = $view['customadminview'];
|
||||
$view['settings'] = $this->getCustomViewData($view['view'], 'custom_admin_view');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,14 @@ class Fields extends Structure
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fieldsNames = array();
|
||||
public $fieldsNames = array();
|
||||
|
||||
/**
|
||||
* Set unique Names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $uniqueNames = array();
|
||||
|
||||
/**
|
||||
* Default Fields
|
||||
@ -368,6 +375,19 @@ class Fields extends Structure
|
||||
// setup the list view and single view name
|
||||
$listViewName = ComponentbuilderHelper::safeString($view['settings']->name_list);
|
||||
$viewName = ComponentbuilderHelper::safeString($view['settings']->name_single);
|
||||
// set some place holder for this view
|
||||
$this->placeholders['###view###'] = $viewName;
|
||||
$this->placeholders['###VIEW###'] = strtoupper($viewName);
|
||||
$this->placeholders['###View###'] = ucfirst($viewName);
|
||||
$this->placeholders['[[[view]]]'] = $this->placeholders['###view###'];
|
||||
$this->placeholders['[[[VIEW]]]'] = $this->placeholders['###VIEW###'];
|
||||
$this->placeholders['[[[View]]]'] = $this->placeholders['###View###'];
|
||||
$this->placeholders['###views###'] = $listViewName;
|
||||
$this->placeholders['###VIEWS###'] = strtoupper($listViewName);
|
||||
$this->placeholders['###Views###'] = ucfirst($listViewName);
|
||||
$this->placeholders['[[[views]]]'] = $this->placeholders['###views###'];
|
||||
$this->placeholders['[[[VIEWS]]]'] = $this->placeholders['###VIEWS###'];
|
||||
$this->placeholders['[[[Views]]]'] = $this->placeholders['###Views###'];
|
||||
// add metadata to the view
|
||||
if ($view['metadata'])
|
||||
{
|
||||
@ -385,12 +405,12 @@ class Fields extends Structure
|
||||
$readOnly = "\t\t\t" . 'readonly="true"' . PHP_EOL."\t\t\t" . 'disabled="true"';
|
||||
}
|
||||
// main lang prefix
|
||||
$langView = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($view['settings']->name_single, 'U');
|
||||
$langViews = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($view['settings']->name_list, 'U');
|
||||
$langView = $this->langPrefix . '_' . $this->placeholders['###VIEW###'];
|
||||
$langViews = $this->langPrefix . '_' . $this->placeholders['###VIEWS###'];
|
||||
// set default lang
|
||||
$this->langContent[$this->lang][$langView] = $view['settings']->name_single;
|
||||
$this->langContent[$this->lang][$langViews] = $view['settings']->name_list;
|
||||
// set the singel name
|
||||
// set the single name
|
||||
$viewSingleName = ComponentbuilderHelper::safeString($view['settings']->name_single, 'W');
|
||||
// set global item strings
|
||||
$this->langContent[$this->lang][$langViews . '_N_ITEMS_ARCHIVED'] = "%s " . $view['settings']->name_list . " archived.";
|
||||
@ -427,6 +447,12 @@ class Fields extends Structure
|
||||
$this->langContent[$this->lang][$langView . '_VERSION_DESC'] = "A count of the number of times this " . $view['settings']->name_single . " has been revised.";
|
||||
$this->langContent[$this->lang][$langView . '_SAVE_WARNING'] = "Alias already existed so a number was added at the end. You can re-edit the " . $view['settings']->name_single . " to customise the alias.";
|
||||
|
||||
// check if the same field is added multiple times
|
||||
foreach ($view['settings']->fields as $field)
|
||||
{
|
||||
$name = ComponentbuilderHelper::safeString($field['settings']->name);
|
||||
$this->setUniqueNameKeeper($field, $view['settings']->type, $name, $viewName);
|
||||
}
|
||||
// start adding dynamc fields
|
||||
$dynamcfields = '';
|
||||
// place holders
|
||||
@ -633,6 +659,8 @@ class Fields extends Structure
|
||||
$fieldSet[] = "\t\t</fieldset>";
|
||||
$fieldSet[] = "\t</fields>";
|
||||
}
|
||||
// just to be safe, lets clear the view placeholders
|
||||
$this->clearFromPlaceHolders('view');
|
||||
// retunr the set
|
||||
return implode(PHP_EOL, $fieldSet);
|
||||
}
|
||||
@ -1135,18 +1163,18 @@ class Fields extends Structure
|
||||
/**
|
||||
* set field attributes
|
||||
*
|
||||
* @param array $field The field data
|
||||
* @param int $viewType The view type
|
||||
* @param string $name The field name
|
||||
* @param string $typeName The field type
|
||||
* @param boolean $multiple The switch to set multiple selection option
|
||||
* @param string $langLabel The language string for field label
|
||||
* @param string $langView The language string of the view
|
||||
* @param array $field The field data
|
||||
* @param int $viewType The view type
|
||||
* @param string $name The field name
|
||||
* @param string $typeName The field type
|
||||
* @param boolean $multiple The switch to set multiple selection option
|
||||
* @param string $langLabel The language string for field label
|
||||
* @param string $langView The language string of the view
|
||||
* @param string $spacerCounter The space counter value
|
||||
* @param string $listViewName The list view name
|
||||
* @param string $viewName The singel view name
|
||||
* @param array $placeholders The place holder and replace values
|
||||
* @param boolean $repeatable The repeatable field switch
|
||||
* @param string $listViewName The list view name
|
||||
* @param string $viewName The singel view name
|
||||
* @param array $placeholders The place holder and replace values
|
||||
* @param boolean $repeatable The repeatable field switch
|
||||
*
|
||||
* @return array The field attributes
|
||||
*
|
||||
@ -1264,12 +1292,16 @@ class Fields extends Structure
|
||||
// use field core name only if not found in xml
|
||||
if (!ComponentbuilderHelper::checkString($xmlValue))
|
||||
{
|
||||
// make sure the XML name is uniqe, so we can add one field multiple times
|
||||
$name = $this->uniqueName($name, $viewName);
|
||||
$xmlValue = $name;
|
||||
}
|
||||
// set the name if found
|
||||
else
|
||||
{
|
||||
$name = $xmlValue;
|
||||
// make sure the XML name is uniqe, so we can add one field multiple times
|
||||
$xmlValue = $this->uniqueName($xmlValue, $viewName);
|
||||
$name = $this->setPlaceholders($xmlValue);
|
||||
}
|
||||
}
|
||||
elseif ($property['name'] === 'extension' || $property['name'] === 'directory')
|
||||
@ -1381,6 +1413,14 @@ class Fields extends Structure
|
||||
// check if translatable
|
||||
if (ComponentbuilderHelper::checkString($xmlValue) && $property['translatable'] == 1)
|
||||
{
|
||||
// update lable if field use multiple times
|
||||
if ($property['name'] === 'label')
|
||||
{
|
||||
if (isset($fieldAttributes['name']) && isset($this->uniqueNames[$viewName]['names'][$fieldAttributes['name']]))
|
||||
{
|
||||
$xmlValue .= ' (' . ComponentbuilderHelper::safeString($this->uniqueNames[$viewName]['names'][$fieldAttributes['name']]) . ')';
|
||||
}
|
||||
}
|
||||
// replace placeholders
|
||||
$xmlValue = $this->setPlaceholders($xmlValue, $placeholders);
|
||||
// insure custom lables dont get messed up
|
||||
@ -1432,18 +1472,17 @@ class Fields extends Structure
|
||||
$xmlValue = $property['example'];
|
||||
}
|
||||
}
|
||||
|
||||
$fieldAttributes[$property['name']] = $xmlValue;
|
||||
|
||||
// load to langBuilder down the line
|
||||
if ($property['name'] === 'label')
|
||||
{
|
||||
$langLabel = $xmlValue;
|
||||
if ($setCustom)
|
||||
{
|
||||
$fieldAttributes['custom']['label'] = $customLabel;
|
||||
}
|
||||
$langLabel = $xmlValue;
|
||||
}
|
||||
// now set the value
|
||||
$fieldAttributes[$property['name']] = $xmlValue;
|
||||
}
|
||||
}
|
||||
// do some nice twigs beyond the default
|
||||
@ -1460,6 +1499,123 @@ class Fields extends Structure
|
||||
return $fieldAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep track of the field names, to see if it used multiple times
|
||||
*
|
||||
* @param array $field The field data
|
||||
* @param string $typeName The field type
|
||||
* @param string $name The field name
|
||||
* @param string $viewName The singel view name
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
protected function setUniqueNameKeeper(&$field, &$typeName, &$name, $viewName)
|
||||
{
|
||||
// setup a default field
|
||||
if (ComponentbuilderHelper::checkArray($field['settings']->properties))
|
||||
{
|
||||
foreach ($field['settings']->properties as $property)
|
||||
{
|
||||
// reset
|
||||
$xmlValue = '';
|
||||
if ($property['name'] === 'name')
|
||||
{
|
||||
// if category then name must be catid (only one per view)
|
||||
if ($typeName === 'category')
|
||||
{
|
||||
// only one allowed
|
||||
return;
|
||||
}
|
||||
// if tag is set then enable all tag options for this view (only one per view)
|
||||
elseif ($typeName === 'tag')
|
||||
{
|
||||
// only one allowed
|
||||
return;
|
||||
}
|
||||
// if the field is set as alias it must be called alias
|
||||
elseif (isset($field['alias']) && $field['alias'])
|
||||
{
|
||||
// only one allowed
|
||||
return;
|
||||
}
|
||||
elseif ($typeName === 'spacer')
|
||||
{
|
||||
// not needed here
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$xmlValue = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field['settings']->xml, 'name="', '"'));
|
||||
}
|
||||
|
||||
// use field core name only if not found in xml
|
||||
if (!ComponentbuilderHelper::checkString($xmlValue))
|
||||
{
|
||||
$xmlValue = $name;
|
||||
}
|
||||
// make sure the XML name is uniqe, so we can add one field multiple times
|
||||
return $this->setUniqueNameCounter($xmlValue, $viewName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many times the same field is used per view
|
||||
*
|
||||
* @param string $name The name of the field
|
||||
* @param string $view The name of the view
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
protected function setUniqueNameCounter($name, $view)
|
||||
{
|
||||
if (!isset($this->uniqueNames[$view]))
|
||||
{
|
||||
$this->uniqueNames[$view] = array();
|
||||
$this->uniqueNames[$view]['counter'] = array();
|
||||
$this->uniqueNames[$view]['names'] = array();
|
||||
}
|
||||
if (!isset($this->uniqueNames[$view]['counter'][$name]))
|
||||
{
|
||||
$this->uniqueNames[$view]['counter'][$name] = 1;
|
||||
return;
|
||||
}
|
||||
// count how many times the field is used
|
||||
$this->uniqueNames[$view]['counter'][$name]++;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Naming each field with an unique name
|
||||
*
|
||||
* @param string $name The name of the field
|
||||
* @param string $view The name of the view
|
||||
*
|
||||
* @return string the name
|
||||
*
|
||||
*/
|
||||
protected function uniqueName($name, $view)
|
||||
{
|
||||
// only increment if the field name is used multiple times
|
||||
if (isset($this->uniqueNames[$view]['counter'][$name]) && $this->uniqueNames[$view]['counter'][$name] > 1)
|
||||
{
|
||||
$counter = $this->uniqueNames[$view]['counter'][$name];
|
||||
$uniqueName = ComponentbuilderHelper::safeString($name . '_' . $counter);
|
||||
while (isset($this->uniqueNames[$view]['names'][$uniqueName]))
|
||||
{
|
||||
$counter--;
|
||||
$uniqueName = ComponentbuilderHelper::safeString($name . '_' . $counter);
|
||||
}
|
||||
// set the new name
|
||||
$this->uniqueNames[$view]['names'][$uniqueName] = $counter;
|
||||
return $uniqueName;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set Builders
|
||||
|
@ -9208,6 +9208,31 @@ class Interpretation extends Fields
|
||||
$otherViews = $viewName_list;
|
||||
$otherView = $viewName_single;
|
||||
}
|
||||
// load the category helper details in not already loaded
|
||||
if (!isset($this->fileContentDynamic['category'.$otherViews]['###view###']))
|
||||
{
|
||||
// lets also set the category helper for this view
|
||||
$target = array('site' => 'category'.$viewName_list);
|
||||
$this->buildDynamique($target, 'category');
|
||||
// insure the file gets updated
|
||||
$this->fileContentDynamic['category'.$otherViews]['###view###'] = $otherView;
|
||||
$this->fileContentDynamic['category'.$otherViews]['###View###'] = ucfirst($otherView);
|
||||
$this->fileContentDynamic['category'.$otherViews]['###views###'] = $otherViews;
|
||||
$this->fileContentDynamic['category'.$otherViews]['###Views###'] = ucfirst($otherViews);
|
||||
// set script to global helper file
|
||||
$includeHelper = array();
|
||||
$includeHelper[] = "\n//".$this->setLine(__LINE__)."Insure this view category file is loaded.";
|
||||
$includeHelper[] = "\$classname = '".$this->fileContentStatic['###component###'] . ucfirst($viewName_list) . "Categories';";
|
||||
$includeHelper[] = "if (!class_exists(\$classname))";
|
||||
$includeHelper[] = "{";
|
||||
$includeHelper[] = "\t\$path = JPATH_SITE . '/components/com_".$this->fileContentStatic['###component###']."/helpers/category" . $viewName_list . ".php';";
|
||||
$includeHelper[] = "\tif (is_file(\$path))";
|
||||
$includeHelper[] = "\t{";
|
||||
$includeHelper[] = "\t\tinclude_once \$path;";
|
||||
$includeHelper[] = "\t}";
|
||||
$includeHelper[] = "}";
|
||||
$this->fileContentStatic['###CATEGORY_CLASS_TREES###'] .= implode("\n",$includeHelper);
|
||||
}
|
||||
// return category view string
|
||||
if (isset($this->fileContentStatic['###ROUTER_CATEGORY_VIEWS###']) && ComponentbuilderHelper::checkString($this->fileContentStatic['###ROUTER_CATEGORY_VIEWS###']))
|
||||
{
|
||||
|
@ -80,13 +80,13 @@ class Infusion extends Interpretation
|
||||
if (isset($this->componentData->admin_views) && ComponentbuilderHelper::checkArray($this->componentData->admin_views))
|
||||
{
|
||||
// ###COMPONENT###
|
||||
$this->fileContentStatic['###COMPONENT###'] = ComponentbuilderHelper::safeString($this->componentData->name_code, 'U');
|
||||
$this->fileContentStatic['###COMPONENT###'] = $this->placeholders['###COMPONENT###'];
|
||||
|
||||
// ###Component###
|
||||
$this->fileContentStatic['###Component###'] = ComponentbuilderHelper::safeString($this->componentData->name_code, 'F');
|
||||
$this->fileContentStatic['###Component###'] = $this->placeholders['###Component###'];
|
||||
|
||||
// ###component###
|
||||
$this->fileContentStatic['###component###'] = ComponentbuilderHelper::safeString($this->componentData->name_code);
|
||||
$this->fileContentStatic['###component###'] = $this->placeholders['###component###'];
|
||||
|
||||
// ###COMPANYNAME###
|
||||
$this->fileContentStatic['###COMPANYNAME###'] = trim(JFilterOutput::cleanText($this->componentData->companyname));
|
||||
@ -132,20 +132,13 @@ class Infusion extends Interpretation
|
||||
|
||||
// ###ACCESS_SECTIONS###
|
||||
$this->fileContentStatic['###ACCESS_SECTIONS###'] = $this->setAccessSections();
|
||||
|
||||
// set component place holders
|
||||
$this->placeholders = array(
|
||||
'###Component###' => $this->fileContentStatic['###Component###'],
|
||||
'###component###' => $this->fileContentStatic['###component###'],
|
||||
'###COMPONENT###' => $this->fileContentStatic['###COMPONENT###'],
|
||||
'[[[Component]]]' => $this->fileContentStatic['###Component###'],
|
||||
'[[[component]]]' => $this->fileContentStatic['###component###'],
|
||||
'[[[COMPONENT]]]' => $this->fileContentStatic['###COMPONENT###']
|
||||
);
|
||||
|
||||
// ###CONFIG_FIELDSETS###
|
||||
$keepLang = $this->lang;
|
||||
$this->lang = 'admin';
|
||||
|
||||
// start loading the category tree scripts
|
||||
$this->fileContentStatic['###CATEGORY_CLASS_TREES###'] = '';
|
||||
// run the field sets for first time
|
||||
$this->setConfigFieldsets(1);
|
||||
$this->lang = $keepLang;
|
||||
@ -216,6 +209,9 @@ class Infusion extends Interpretation
|
||||
// start dynamic build
|
||||
foreach ($this->componentData->admin_views as $view)
|
||||
{
|
||||
// just to be safe, lets clear the view placeholders
|
||||
$this->clearFromPlaceHolders('view');
|
||||
// set the target
|
||||
$this->target = 'admin';
|
||||
$this->lang = 'admin';
|
||||
// set main keys
|
||||
@ -253,11 +249,11 @@ class Infusion extends Interpretation
|
||||
|
||||
// set some place holder for the views
|
||||
$this->placeholders['###view###'] = $viewName_single;
|
||||
$this->placeholders['###VIEW###'] = $viewName_u;
|
||||
$this->placeholders['###View###'] = $viewName_f;
|
||||
$this->placeholders['###VIEW###'] = $viewName_u;
|
||||
$this->placeholders['[[[view]]]'] = $viewName_single;
|
||||
$this->placeholders['[[[VIEW]]]'] = $viewName_u;
|
||||
$this->placeholders['[[[View]]]'] = $viewName_f;
|
||||
$this->placeholders['[[[VIEW]]]'] = $viewName_u;
|
||||
|
||||
// set license per view if needed
|
||||
$this->setLockLicensePer($viewName_single, $this->target);
|
||||
@ -389,11 +385,11 @@ class Infusion extends Interpretation
|
||||
|
||||
// set some place holder for the views
|
||||
$this->placeholders['###views###'] = $viewName_list;
|
||||
$this->placeholders['###VIEWS###'] = $viewsName_u;
|
||||
$this->placeholders['###Views###'] = $viewsName_f;
|
||||
$this->placeholders['###VIEWS###'] = $viewsName_u;
|
||||
$this->placeholders['[[[views]]]'] = $viewName_list;
|
||||
$this->placeholders['[[[VIEWS]]]'] = $viewsName_u;
|
||||
$this->placeholders['[[[Views]]]'] = $viewsName_f;
|
||||
$this->placeholders['[[[VIEWS]]]'] = $viewsName_u;
|
||||
|
||||
// set the export/import option
|
||||
if ($view['port'])
|
||||
|
Reference in New Issue
Block a user