本文整理汇总了PHP中FabrikString::shortColName方法的典型用法代码示例。如果您正苦于以下问题:PHP FabrikString::shortColName方法的具体用法?PHP FabrikString::shortColName怎么用?PHP FabrikString::shortColName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FabrikString
的用法示例。
在下文中一共展示了FabrikString::shortColName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _process
/**
* Clone the record
*
* @param object $params plugin params
* @param object &$formModel form model
*
* @return bool
*/
private function _process($params, &$formModel)
{
$clone_times_field_id = $params->get('clone_times_field', '');
$clone_batchid_field_id = $params->get('clone_batchid_field', '');
if ($clone_times_field_id != '') {
$elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_times_field_id);
$element = $elementModel->getElement(true);
if ($clone_batchid_field_id != '') {
$elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_batchid_field_id);
$id_element = $id_elementModel->getElement(true);
$formModel->_formData[$id_element->name] = $formModel->_fullFormData['rowid'];
$formModel->_formData[$id_element->name . '_raw'] = $formModel->_fullFormData['rowid'];
$listModel = $formModel->getlistModel();
$listModel->_oForm = $formModel;
$primaryKey = FabrikString::shortColName($listModel->getTable()->db_primary_key);
$formModel->_formData[$primaryKey] = $formModel->_fullFormData['rowid'];
$formModel->_formData[$primaryKey . '_raw'] = $formModel->_fullFormData['rowid'];
$listModel->storeRow($formModel->_formData, $formModel->_fullFormData['rowid']);
}
// $clone_times_field = $elementModel->getFullName(false, true, false);
$clone_times = $formModel->_formData[$element->name];
if (is_numeric($clone_times)) {
$clone_times = (int) $clone_times;
$formModel->_formData['Copy'] = 1;
for ($x = 1; $x < $clone_times; $x++) {
$formModel->processToDB();
}
return true;
}
}
JError::raiseNotice(JText::_('CLONEERR'), "Couldn't find a valid number of times to clone!");
return true;
}
示例2: _process
/**
* Clone the record
*
* @return bool
*/
private function _process()
{
$params = $this->getParams();
/** @var FabrikFEModelForm $formModel */
$formModel = $this->getModel();
$clone_times_field_id = $params->get('clone_times_field', '');
$clone_batchid_field_id = $params->get('clone_batchid_field', '');
if ($clone_times_field_id != '') {
$elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_times_field_id);
$element = $elementModel->getElement(true);
if ($clone_batchid_field_id != '') {
$elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_batchid_field_id);
$id_element = $elementModel->getElement(true);
$formModel->formData[$id_element->name] = $formModel->fullFormData['rowid'];
$formModel->formData[$id_element->name . '_raw'] = $formModel->fullFormData['rowid'];
$listModel = $formModel->getlistModel();
$listModel->setFormModel($formModel);
$primaryKey = FabrikString::shortColName($listModel->getPrimaryKey());
$formModel->formData[$primaryKey] = $formModel->fullFormData['rowid'];
$formModel->formData[$primaryKey . '_raw'] = $formModel->fullFormData['rowid'];
$listModel->storeRow($formModel->formData, $formModel->fullFormData['rowid']);
}
$clone_times = $formModel->formData[$element->name];
if (is_numeric($clone_times)) {
$clone_times = (int) $clone_times;
$formModel->formData['Copy'] = 1;
for ($x = 1; $x < $clone_times; $x++) {
$formModel->processToDB();
}
return true;
}
}
throw new RuntimeException("Couldn't find a valid number of times to clone!");
}
示例3: getJoinLabelColumn
/**
* get the field name to use as the column that contains the join's label data
* @param bol use step in element name
* @return string join label column either returns concat statement or quotes `tablename`.`elementname`
*/
function getJoinLabelColumn($useStep = false)
{
$params = $this->getParams();
$join = $this->getJoin();
if (($params->get('cascadingdropdown_label_concat') != '') && JRequest::getVar('overide_join_val_column_concat') != 1) {
$val = str_replace("{thistable}", $join->table_join_alias, $params->get('cascadingdropdown_label_concat'));
return "CONCAT(".$val.")";
}
$label = FabrikString::shortColName($join->_params->get('join-label'));
if ($label == '') {
JError::raiseWarning(500, 'Could not find the join label for '.$this->getElement()->name . ' try unlinking and saving it');
$label = $this->getElement()->name;
}
$joinTableName = $join->table_join_alias;
return $useStep ? $joinTableName.'___'.$label : "`$joinTableName`.`$label`";
}
示例4: _process
private function _process(&$params, &$formModel )
{
$user = JFactory::getUser();
$db = FabrikWorker::getDbo();
if ($params->get('limit_allow_anonymous')) {
return true;
}
if (JRequest::getCmd('view') === 'details') {
return true;
}
$listid = (int)$params->get('limit_table');
if ($listid === 0) {
//use the limit setting supplied in the admin params
$limit = (int)$params->get('limit_length');
} else {
//look up the limit from the table spec'd in the admin params
$listModel = JModel::getInstance('List', 'FabrikFEModel');
$listModel->setId($listid);
$max = $db->NameQuote(FabrikString::shortColName($params->get('limit_max')));
$userfield = $db->NameQuote(FabrikString::shortColName($params->get('limit_user')));
$db->setQuery("SELECT $max FROM " . $listModel->getTable()->db_table_name . " WHERE $userfield = " . (int)$user->get('id'));
$limit = (int)$db->loadResult();
}
$field = $params->get('limit_userfield');
$listModel = $formModel->getlistModel();
$list = $listModel->getTable();
$db = $listModel->getDb();
$db->setQuery("SELECT COUNT($field) FROM $list->db_table_name WHERE $field = " . (int)$user->get('id'));
$c = $db->loadResult();
if ($c >= $limit) {
$msg = $params->get('limit_reached_message');
$msg = str_replace('{limit}', $limit, $msg);
JError::raiseNotice(1, $msg);
return false;
} else {
$app = JFactory::getApplication();
$app->enqueueMessage(JText::sprintf('ENTRIES_LEFT_MESSAGE', $limit - $c, $limit));
}
return true;
}
示例5: _process
/**
* Process the plugin
*
* @param object $params plugin params
* @param object &$formModel form model
*
* @return bool
*/
private function _process($params, &$formModel)
{
$user = JFactory::getUser();
$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
if ($params->get('limit_allow_anonymous')) {
return true;
}
if (JRequest::getCmd('view') === 'details' || $formModel->getRowId() > 0) {
return true;
}
$listid = (int) $params->get('limit_table');
if ($listid === 0) {
// Use the limit setting supplied in the admin params
$limit = (int) $params->get('limit_length');
} else {
// Look up the limit from the table spec'd in the admin params
$listModel = JModel::getInstance('List', 'FabrikFEModel');
$listModel->setId($listid);
$max = $db->quoteName(FabrikString::shortColName($params->get('limit_max')));
$userfield = $db->quoteName(FabrikString::shortColName($params->get('limit_user')));
$query->select($max)->from($listModel->getTable()->db_table_name)->where($userfield . ' = ' . (int) $user->get('id'));
$db->setQuery($query);
$limit = (int) $db->loadResult();
}
$field = $params->get('limit_userfield');
$listModel = $formModel->getlistModel();
$list = $listModel->getTable();
$db = $listModel->getDb();
$query->clear()->select(' COUNT(' . $field . ')')->from($list->db_table_name)->where($field . ' = ' . (int) $user->get('id'));
$db->setQuery($query);
$c = $db->loadResult();
if ($c >= $limit) {
$msg = $params->get('limit_reached_message', JText::sprintf('PLG_FORM_LIMIT_LIMIT_REACHED', $limit));
$msg = str_replace('{limit}', $limit, $msg);
JError::raiseNotice(1, $msg);
return false;
} else {
$app = JFactory::getApplication();
$app->enqueueMessage(JText::sprintf('PLG_FORM_LIMIT_ENTRIES_LEFT_MESSAGE', $limit - $c, $limit));
}
return true;
}
示例6: getLabelParamVal
/**
* Get the label parameter's value
*
* @return string
*/
protected function getLabelParamVal()
{
if (isset($this->labelParamVal)) {
return $this->labelParamVal;
}
$params = $this->getParams();
$label = $params->get($this->labelParam);
$label = FabrikString::shortColName($label);
$this->labelParamVal = $label;
return $this->labelParamVal;
}
示例7: setInsertId
/**
* Set various request / input arrays with the main records insert id
*
* @param string $insertId The records insert id
*
* @return void
*/
public function setInsertId($insertId)
{
$input = $this->app->input;
$listModel = $this->getListModel();
$item = $listModel->getTable();
$tmpKey = str_replace("`", "", $item->db_primary_key);
$tmpKey = str_replace('.', '___', $tmpKey);
$this->formData[$tmpKey] = $insertId;
$this->formData[$tmpKey . '_raw'] = $insertId;
$this->formData[FabrikString::shortColName($item->db_primary_key)] = $insertId;
$this->formData[FabrikString::shortColName($item->db_primary_key) . '_raw'] = $insertId;
$this->fullFormData[$tmpKey] = $insertId;
$this->fullFormData[$tmpKey . '_raw'] = $insertId;
$this->fullFormData['rowid'] = $insertId;
$this->formData['rowid'] = $insertId;
$this->formDataWithTableName[$tmpKey] = $insertId;
$this->formDataWithTableName[$tmpKey . '_raw'] = $insertId;
$this->formDataWithTableName['rowid'] = $insertId;
$input->set($tmpKey, $insertId);
$input->set('rowid', $insertId);
// $$$ hugh - pretty sure we need to unset 'usekey' now, as it is not relevant to joined data,
// and it messing with storeRow of joins
$input->set('usekey', '');
}
示例8: save
function save($data)
{
jimport('joomla.utilities.date');
$user = JFactory::getUser();
$app = JFactory::getApplication();
$new = $data['id'] == 0 ? true : false;
$params = $data['params'];
$data['name'] = FabrikString::iclean($data['name']);
$name = $data['name'];
$params['validations'] = JArrayHelper::getValue($data, 'validationrule', array());
$elementModel = $this->getElementPluginModel($data);
$row = $elementModel->getElement();
if ($new) {
//have to forcefully set group id otherwise listmodel id is blank
$elementModel->getElement()->group_id = $data['group_id'];
}
$listModel = $elementModel->getListModel();
$item = $listModel->getTable();
//are we updating the name of the primary key element?
if ($row->name === FabrikString::shortColName($item->db_primary_key)) {
if ($name !== $row->name) {
//yes we are so update the table
$item->db_primary_key = str_replace($row->name, $name, $item->db_primary_key);
$item->store();
}
}
$jsons = array('sub_values', 'sub_labels', 'sub_initial_selection');
foreach ($jsons as $json) {
if (array_key_exists($json, $data)) {
$data[$json] = json_encode($data[$json]);
}
}
//only update the element name if we can alter existing columns, otherwise the name and
//field name become out of sync
$data['name'] = $listModel->canAlterFields() || $new ? $name : JRequest::getVar('name_orig', '', 'post', 'cmd');
$ar = array('published', 'use_in_page_title', 'show_in_list_summary', 'link_to_detail', 'can_order', 'filter_exact_match');
foreach ($ar as $a) {
if (!array_key_exists($a, $data)) {
$data[$a] = 0;
}
}
// $$$ rob - test for change in element type
//(eg if changing from db join to field we need to remove the join
//entry from the #__{package}_joins table
// @TODO test this for j1.6
$elementModel->beforeSave($row);
//unlink linked elements
if (JRequest::getVar('unlink') == 'on') {
$data['parent_id'] = 0;
}
$datenow = new JDate();
if ($row->id != 0) {
$data['modified'] = $datenow->toSql();
$data['modified_by'] = $user->get('id');
} else {
$data['created'] = $datenow->toSql();
$data['created_by'] = $user->get('id');
$data['created_by_alias'] = $user->get('username');
}
$data['params'] = json_encode($params);
$cond = 'group_id = ' . (int) $row->group_id;
if ($new) {
$data['ordering'] = $row->getNextOrder($cond);
}
$row->reorder($cond);
$this->updateChildIds($row);
$elementModel->getElement()->bind($data);
$origName = JRequest::getVar('name_orig', '', 'post', 'cmd');
list($update, $q, $oldName, $newdesc, $origDesc) = $listModel->shouldUpdateElement($elementModel, $origName);
if ($update) {
$origplugin = JRequest::getVar('plugin_orig');
$config = JFactory::getConfig();
$prefix = $config->getValue('dbprefix');
$tablename = $listModel->getTable()->db_table_name;
$hasprefix = strstr($tablename, $prefix) === false ? false : true;
$tablename = str_replace($prefix, '#__', $tablename);
if (in_array($tablename, $this->core)) {
$app->enqueueMessage(JText::_('COM_FABRIK_WARNING_UPDATE_CORE_TABLE'), 'notice');
} else {
if ($hasprefix) {
$app->enqueueMessage(JText::_('COM_FABRIK_WARNING_UPDATE_TABLE_WITH_PREFIX'), 'notice');
}
}
$app->setUserState('com_fabrik.confirmUpdate', 1);
$app->setUserState('com_fabrik.plugin_orig', $origplugin);
$app->setUserState('com_fabrik.q', $q);
$app->setUserState('com_fabrik.newdesc', $newdesc);
$app->setUserState('com_fabrik.origDesc', $origDesc);
$app->setUserState('com_fabrik.origplugin', $origplugin);
$app->setUserState('com_fabrik.oldname', $oldName);
$app->setUserState('com_fabrik.origtask', JRequest::getCmd('task'));
$app->setUserState('com_fabrik.plugin', $data['plugin']);
$task = JRequest::getCmd('task');
$app->setUserState('com_fabrik.redirect', 'index.php?option=com_fabrik&view=element&layout=confirmupdate&id=' . (int) $row->id . "&origplugin={$origplugin}&&origtaks={$task}&plugin={$row->plugin}");
} else {
$app->setUserState('com_fabrik.confirmUpdate', 0);
}
if ((int) $listModel->getTable()->id !== 0) {
$this->updateIndexes($elementModel, $listModel, $row);
}
//.........这里部分代码省略.........
示例9: onStoreRow
/**
* Trigger called when a row is stored.
* If toggle_others on then set other records yesno value to 0
*
* @param array &$data Data to store
* @param int $repeatCounter Repeat group index
*
* @return void
*/
public function onStoreRow(&$data, $repeatCounter = 0)
{
if (!parent::onStoreRow($data, $repeatCounter)) {
return false;
}
$value = $this->getValue($data, $repeatCounter);
if ($value == '1') {
$params = $this->getParams();
$toggle = (bool) $params->get('toggle_others', false);
if ($toggle === false) {
return;
}
$listModel = $this->getListModel();
$name = $this->getElement()->name;
$db = $listModel->getDb();
$query = $db->getQuery(true);
if ($this->isJoin()) {
$joinModel = $this->getJoinModel();
$pk = $joinModel->getJoinedToTablePk('.');
} else {
$pk = $listModel->getPrimaryKey();
}
$shortPk = FabrikString::shortColName($pk);
$rowId = FArrayHelper::getValue($data, $shortPk, null);
$query->update($this->actualTableName())->set($name . ' = 0');
if (!empty($rowId)) {
$query->where($pk . ' <> ' . $rowId);
}
$toggle_where = $params->get('toggle_where', '');
FabrikString::ltrimiword($toggle_where, 'where');
if (!empty($toggle_where)) {
$w = new FabrikWorker();
$toggle_where = $w->parseMessageForPlaceHolder($toggle_where);
$query->where($toggle_where);
}
$db->setQuery($query);
$db->execute();
}
}
示例10: addKey
/**
* Internal function: add a key to the table
*
* @param string $fieldName primary key column name
* @param bool $autoIncrement is the column auto incrementing
* @param string $type the primary keys column type (if autoincrement true then int(6) is always used as the type)
*
* @return mixed false / JError
*/
private function addKey($fieldName, $autoIncrement, $type = "INT(6)")
{
$db = $this->getFEModel()->getDb();
$type = $autoIncrement != true ? $type : 'INT(6)';
$post = JRequest::get('post');
$tableName = $post['jform']['db_table_name'] != '' ? $post['jform']['db_table_name'] : $post['jform']['_database_name'];
$tableName = preg_replace('#[^0-9a-zA-Z_]#', '_', $tableName);
$tableName = FabrikString::safeColName($tableName);
$fieldName = FabrikString::shortColName($fieldName);
if ($fieldName === "") {
return false;
}
$fieldName = $db->quoteName($fieldName);
$sql = 'ALTER TABLE ' . $tableName . ' ADD PRIMARY KEY (' . $fieldName . ')';
/* add a primary key */
$db->setQuery($sql);
if (!$db->query()) {
return JError::raiseWarning(500, $db->getErrorMsg());
}
if ($autoIncrement) {
// Add the autoinc
$sql = 'ALTER TABLE ' . $tableName . ' CHANGE ' . $fieldName . ' ' . $fieldName . ' ' . $type . ' NOT NULL AUTO_INCREMENT';
$db->setQuery($sql);
if (!$db->query()) {
return JError::raiseError(500, 'add key: ' . $db->getErrorMsg());
}
}
return true;
}
示例11: updateFabrikData
function updateFabrikData()
{
if ($this->_isNew && $this->_articleId > 0) {
$articleIdElementName = $this->_elementBaseName($this->_articleIdElement);
$this->_formModel->_formData[$articleIdElementName] = $this->_articleId;
$this->_formModel->_formData[$articleIdElementName . '_raw'] = $this->_articleId;
$listModel = $this->_formModel->getlistModel();
$listModel->_oForm =& $this->_formModel;
$primaryKey = FabrikString::shortColName($listModel->getTable()->db_primary_key);
$this->_formModel->_formData[$primaryKey] = $this->_formModel->_fullFormData['rowid'];
$this->_formModel->_formData[$primaryKey . '_raw'] = $this->_formModel->_fullFormData['rowid'];
$listModel->storeRow($this->_formModel->_formData, $this->_formModel->_fullFormData['rowid']);
}
}
示例12: storeCell
/**
* Save an individual element value to the fabrik db
*
* @param string $rowId row id
* @param string $key key
* @param string $value value
*
* @return void
*/
public function storeCell($rowId, $key, $value)
{
$data[$key] = $value;
// Ensure the primary key is set in $data
$primaryKey = FabrikString::shortColName($this->getPrimaryKey());
$primaryKey = str_replace("`", "", $primaryKey);
if (!isset($data[$primaryKey])) {
$data[$primaryKey] = $rowId;
}
$this->storeRow($data, $rowId);
}
示例13: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success, False on error.
*/
public function save($data)
{
$config = JComponentHelper::getParams('com_fabrik');
if ($config->get('fbConf_wysiwyg_label', 0) == 0) {
// Ensure the data is in the same format as when saved by the wysiwyg element e.g. < becomes <
$data['label'] = htmlspecialchars($data['label']);
}
jimport('joomla.utilities.date');
$input = $this->app->input;
$new = $data['id'] == 0 ? true : false;
$params = $data['params'];
$data['name'] = FabrikString::iclean($data['name']);
$name = $data['name'];
$params['validations'] = FArrayHelper::getValue($data, 'validationrule', array());
$elementModel = $this->getElementPluginModel($data);
$elementModel->getElement()->bind($data);
$origId = $input->getInt('id');
$row = $elementModel->getElement();
if ($new) {
// Have to forcefully set group id otherwise listmodel id is blank
$elementModel->getElement()->group_id = $data['group_id'];
}
$listModel = $elementModel->getListModel();
$item = $listModel->getTable();
// Are we updating the name of the primary key element?
if ($row->name === FabrikString::shortColName($item->db_primary_key)) {
if ($name !== $row->name) {
// Yes we are so update the table
$item->db_primary_key = str_replace($row->name, $name, $item->db_primary_key);
$item->store();
}
}
$jsons = array('sub_values', 'sub_labels', 'sub_initial_selection');
foreach ($jsons as $json) {
if (array_key_exists($json, $data)) {
$data[$json] = json_encode($data[$json]);
}
}
// Only update the element name if we can alter existing columns, otherwise the name and field name become out of sync
$data['name'] = $listModel->canAlterFields() || $new || $listModel->noTable() ? $name : $input->get('name_orig', '');
$ar = array('published', 'use_in_page_title', 'show_in_list_summary', 'link_to_detail', 'can_order', 'filter_exact_match');
foreach ($ar as $a) {
if (!array_key_exists($a, $data)) {
$data[$a] = 0;
}
}
/**
* $$$ rob - test for change in element type
* (eg if changing from db join to field we need to remove the join
* entry from the #__{package}_joins table
*/
$elementModel->beforeSave($row);
// Unlink linked elements
if ($input->get('unlink') == 'on') {
$data['parent_id'] = 0;
}
$dateNow = new JDate();
if ($row->id != 0) {
$data['modified'] = $dateNow->toSql();
$data['modified_by'] = $this->user->get('id');
} else {
$data['created'] = $dateNow->toSql();
$data['created_by'] = $this->user->get('id');
$data['created_by_alias'] = $this->user->get('username');
}
/**
* $$$ hugh
* This insane chunk of code is needed because the validation rule params are not in sequential,
* completely indexed arrays. What we have is single item arrays, with specific numeric
* keys, like foo-something[0], bar-otherthing[2], etc. And if you json_encode an array with incomplete
* or out of sequence numeric indexes, it encodes it as an object instead of an array. Which means the first
* validation plugin will encode as an array, as it's params are single [0] index, and the rest as objects.
* This foobars things, as we then don't know if validation params are arrays or objects!
*
* One option would be to modify every validation, and test every param we use, and if necessary convert it,
* but that would be a major pain in the ass.
*
* So ... we need to fill in the blanks in the arrays, and ksort them. But, we need to know the param names
* for each validation. But as they are just stuck in with the rest of the element params, there is no easy
* way of knowing which are validation params and which are element params.
*
* So ... we need to load the validation objects, then load the XML file for each one, and iterate through
* the fieldsets! Well, that's the only way I could come up with doing it. Hopefully Rob can come up with
* a quicker and simpler way of doing this!
*/
$validations = FArrayHelper::getValue($params['validations'], 'plugin', array());
$num_validations = count($validations);
$validation_plugins = $this->getValidations($elementModel, $validations);
foreach ($validation_plugins as $plugin) {
$plugin_form = $plugin->getJForm();
JForm::addFormPath(JPATH_SITE . '/plugins/fabrik_validationrule/' . $plugin->get('pluginName'));
$xmlFile = JPATH_SITE . '/plugins/fabrik_validationrule/' . $plugin->get('pluginName') . '/forms/fields.xml';
$xml = $plugin->jform->loadFile($xmlFile, false);
//.........这里部分代码省略.........
示例14: checkboxRows
/**
* Helper function to get an array of data from the checkbox joined db table.
* Used for working out the filter sql and filter dropdown contents
*
* @param string $groupBy field name to key the results on - avoids duplicates
* @param string $condition if supplied then filters the list (must then supply $where and $value)
* @param string $value if supplied then filters the list (must then supply $where and $condtion)
* @param string $where if supplied then filters the list (must then supply $value and $condtion)
* @param int $offset query offset - default 0
* @param int $limit query limit - default 0
*
* @return array rows
*/
protected function checkboxRows($groupBy = null, $condition = null, $value = null, $where = null, $offset = 0, $limit = 0)
{
$params = $this->getParams();
$db = $this->getDb();
$query = $db->getQuery(true);
$join = $this->getJoinModel()->getJoin();
$jointable = $db->quoteName($join->table_join);
$shortName = $db->quoteName($this->getElement()->name);
if (is_null($groupBy)) {
$groupBy = 'value';
}
$to = $params->get('join_db_name');
$key = $db->quoteName($to . '.' . $params->get('join_key_column'));
$label = $db->quoteName($to . '.' . $this->getLabelParamVal());
$v = $jointable . '.' . $shortName;
$query->select($jointable . '.parent_id, ' . $v . ' AS value, ' . $label . ' AS text')->from($jointable)->join('LEFT', $to . ' ON ' . $key . ' = ' . $jointable . '.' . $shortName);
if (!is_null($condition) && !is_null($value)) {
if (is_null($where)) {
$where = $label;
}
$query->where($where . ' ' . $condition . ' ' . $value);
}
$db->setQuery($query, $offset, $limit);
$groupBy = FabrikString::shortColName($groupBy);
$rows = $db->loadObjectList($groupBy);
return $rows;
}
示例15: reorder
/**
* Compacts the ordering sequence of the selected records
*
* @param string $colid column name to order on
* @param string $where additional where query to limit ordering to a particular subset of records
*
* @since 3.0.5
*
* @return bool
*/
public function reorder($colid, $where = '')
{
$elementModel = $this->getFormModel()->getElement($colid, true);
$asfields = array();
$fields = array();
$elementModel->getAsField_html($asfields, $fields);
$col = $asfields[0];
$field = explode("AS", $col);
$field = array_shift($field);
$db = $this->getDb();
$k = $this->getTable()->db_primary_key;
$shortKey = FabrikString::shortColName($k);
$tbl = $this->getTable()->db_table_name;
// Get the primary keys and ordering values for the selection.
$query = $db->getQuery(true);
$query->select($k . ' AS id, ' . $field . ' AS ordering');
$query->from($tbl);
$query->where($field . ' >= 0');
$query->order($field);
// Setup the extra where and ordering clause data.
if ($where) {
$query->where($where);
}
$db->setQuery($query);
$rows = $db->loadObjectList();
// Compact the ordering values.
foreach ($rows as $i => $row) {
// Only update rows that are necessary.
if ($row->ordering != $i + 1) {
// Update the row ordering field.
$query = $db->getQuery(true);
$query->update($tbl);
$query->set($field . ' = ' . ($i + 1));
$query->where($k . ' = ' . $db->quote($row->id));
$db->setQuery($query);
$db->execute();
}
}
return true;
}