本文整理汇总了PHP中plgFabrik_Element::getDefaultAttribs方法的典型用法代码示例。如果您正苦于以下问题:PHP plgFabrik_Element::getDefaultAttribs方法的具体用法?PHP plgFabrik_Element::getDefaultAttribs怎么用?PHP plgFabrik_Element::getDefaultAttribs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plgFabrik_Element
的用法示例。
在下文中一共展示了plgFabrik_Element::getDefaultAttribs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeElementsFromFields
/**
* take a table name and make elements for all of its fields
* @param int group id
* @param string $tableName
*/
function makeElementsFromFields($groupId, $tableName)
{
$fabrikDb =& $this->getFEModel()->getDb();
$dispatcher = JDispatcher::getInstance();
$elementModel = new plgFabrik_Element($dispatcher);
$pluginManager = $this->getFormModel()->getPluginManager();
$user = JFactory::getUser();
$elementTypes = JRequest::getVar('elementtype', array(), 'default', 'array');
$fields = $fabrikDb->getTableFields(array($tableName));
$fields = $fields[$tableName];
$createdate = JFactory::getDate()->toMySQL();
$key = $this->getFEModel()->getPrimaryKeyAndExtra($tableName);
$ordering = 0;
// no existing fabrik table so we take a guess at the most
//relavent element types to create
$elementLabels = JRequest::getVar('elementlabels', array(), 'default', 'array');
foreach ($fields as $label => $type) {
$element = FabTable::getInstance('Element', 'FabrikTable');
if (array_key_exists($ordering, $elementTypes)) {
//if importing from a CSV file then we have userselect field definitions
$plugin = $elementTypes[$ordering];
} else {
//if the field is the primary key and it's an INT type set the plugin to be the fabrik internal id
if ($key[0]['colname'] == $label && strtolower(substr($key[0]['type'], 0, 3)) === 'int') {
$plugin = 'internalid';
} else {
//otherwise guestimate!
switch ($type) {
case "int":
case "tinyint":
case "varchar":
$plugin = 'field';
break;
case "text":
case "tinytext":
case "mediumtext":
case "longtext":
$plugin = 'textarea';
break;
case "datetime":
case "date":
case "time":
case "timestamp":
$plugin = 'date';
break;
default:
$plugin = 'field';
break;
}
}
}
$element->plugin = $plugin;
$element->hidden = $element->label == 'id' ? '1' : '0';
$element->group_id = $groupId;
$element->name = $label;
$element->created = $createdate;
$element->created_by = $user->get('id');
$element->created_by_alias = $user->get('username');
$element->published = '1';
$element->show_in_list_summary = '1';
switch ($plugin) {
case 'textarea':
$element->width = '40';
break;
case 'date':
$element->width = '10';
break;
default:
$element->width = '30';
break;
}
$element->height = '6';
$element->ordering = $ordering;
$element->params = $elementModel->getDefaultAttribs();
$element->label = JArrayHelper::getValue($elementLabels, $ordering, str_replace("_", " ", $label));
if (!$element->store()) {
return JError::raiseError(500, $element->getError());
}
$elementModel =& $pluginManager->getPlugIn($element->plugin, 'element');
$elementModel->setId($element->id);
$elementModel->_element = $element;
// hack for user element
$details = array('group_id' => $element->group_id);
JRequest::setVar('details', $details);
$elementModel->onSave();
$ordering++;
}
}
示例2: makeDateTimeElement
/**
* @since Fabrik 3.0
* make datetime element
* @param int $groupId
*/
public function makeDateTimeElement($groupId)
{
$now = JFactory::getDate()->toMySQL();
$dispatcher = JDispatcher::getInstance();
$elementModel = new plgFabrik_Element($dispatcher);
$user = JFactory::getUser();
$element = FabTable::getInstance('Element', 'FabrikTable');
$element->name = "date_time";
$element->label = "date";
$element->plugin = 'date';
$element->hidden = 1;
$element->eval = 1;
$element->default = "return date('Y-m-d h:i:s');";
$element->group_id = $groupId;
$element->primary_key = 0;
$element->auto_increment = 0;
$element->created = $now;
$element->created_by = $user->get('id');
$element->created_by_alias = $user->get('username');
$element->published = '1';
$element->show_in_list_summary = '1';
$element->width = '10';
$element->ordering = 1;
$element->params = $elementModel->getDefaultAttribs();
if (!$element->store()) {
JError::raiseWarning(500, $element->getError());
return false;
}
return true;
}
示例3: makeElementsFromFields
//.........这里部分代码省略.........
$maxLength2 = 0;
}
}
// Get the basic type
$type = explode(" ", $type);
$type = JArrayHelper::getValue($type, 0, '');
$type = preg_replace("/\\((.*)\\)/i", '', $type);
$element = FabTable::getInstance('Element', 'FabrikTable');
if (array_key_exists($ordering, $elementTypes)) {
// If importing from a CSV file then we have userselect field definitions
$plugin = $elementTypes[$ordering];
} else {
// If the field is the primary key and it's an INT type set the plugin to be the fabrik internal id
if ($key[0]['colname'] == $label && JString::strtolower(substr($key[0]['type'], 0, 3)) === 'int') {
$plugin = 'internalid';
} else {
// Otherwise guestimate!
switch ($type) {
case "int":
case "decimal":
case "tinyint":
case "smallint":
case "mediumint":
case "bigint":
case "varchar":
$plugin = 'field';
break;
case "text":
case "tinytext":
case "mediumtext":
case "longtext":
$plugin = 'textarea';
break;
case "datetime":
case "date":
case "time":
case "timestamp":
$plugin = 'date';
break;
default:
$plugin = 'field';
break;
}
}
}
$element->plugin = $plugin;
$element->hidden = $element->label == 'id' ? '1' : '0';
$element->group_id = $groupId;
$element->name = $label;
$element->created = $createdate;
$element->created_by = $user->get('id');
$element->created_by_alias = $user->get('username');
$element->published = '1';
$element->show_in_list_summary = '1';
switch ($plugin) {
case 'textarea':
$element->width = '40';
break;
case 'date':
$element->width = '10';
break;
default:
$element->width = '30';
break;
}
if ($element->width > $maxLength) {
$element->width = $maxLength;
}
$element->height = '6';
$element->ordering = $ordering;
$p = json_decode($elementModel->getDefaultAttribs());
if (in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && $plugin == 'field') {
$p->integer_length = $maxLength;
$p->text_format = 'integer';
$p->maxlength = '255';
$element->width = '30';
} elseif ($type == 'decimal' && $plugin == 'field') {
$p->text_format = 'decimal';
$p->decimal_length = $maxLength2;
$p->integer_length = $maxLength - $maxLength2;
$p->maxlength = '255';
$element->width = '30';
} else {
$p->maxlength = $maxLength;
}
$element->params = json_encode($p);
$element->label = JArrayHelper::getValue($elementLabels, $ordering, str_replace("_", " ", $label));
if (!$element->store()) {
return JError::raiseError(500, $element->getError());
}
$elementModel = $pluginManager->getPlugIn($element->plugin, 'element');
$elementModel->setId($element->id);
$elementModel->_element = $element;
// Hack for user element
$details = array('group_id' => $element->group_id);
JRequest::setVar('details', $details);
$elementModel->onSave();
$ordering++;
}
}