当前位置: 首页>>代码示例>>PHP>>正文


PHP FabrikString::dbFieldName方法代码示例

本文整理汇总了PHP中FabrikString::dbFieldName方法的典型用法代码示例。如果您正苦于以下问题:PHP FabrikString::dbFieldName方法的具体用法?PHP FabrikString::dbFieldName怎么用?PHP FabrikString::dbFieldName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FabrikString的用法示例。


在下文中一共展示了FabrikString::dbFieldName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createDBTable

 /**
  * Create a table to store the forms' data depending upon what groups are assigned to the form
  *
  * @param   string $dbTableName Taken from the table object linked to the form
  * @param   array  $fields      List of default elements to add. (key = element name, value = plugin
  * @param   array  $opts        Additional options, e.g. collation
  *
  * @return mixed false if fail otherwise array of primary keys
  */
 public function createDBTable($dbTableName = null, $fields = array('id' => 'internalid', 'date_time' => 'date'), $opts = array())
 {
     $db = FabrikWorker::getDbo(true);
     $fabrikDb = $this->getDb();
     $formModel = $this->getFormModel();
     if (is_null($dbTableName)) {
         $dbTableName = $this->getTable()->db_table_name;
     }
     $sql = 'CREATE TABLE IF NOT EXISTS ' . $db->qn($dbTableName) . ' (';
     $input = $this->app->input;
     $jForm = $input->get('jform', array(), 'array');
     if ($jForm['id'] == 0 && array_key_exists('current_groups', $jForm)) {
         // Saving a new form
         $groupIds = $jForm['current_groups'];
     } else {
         $query = $db->getQuery(true);
         $formId = (int) $this->get('form.id', $this->getFormModel()->id);
         $query->select('group_id')->from('#__{package}_formgroup')->where('form_id = ' . $formId);
         $db->setQuery($query);
         $groupIds = $db->loadColumn();
     }
     $i = 0;
     foreach ($fields as $name => $plugin) {
         // $$$ hugh - testing corner case where we are called from form model's updateDatabase,
         // and the underlying table has been deleted.  So elements already exist.
         $element = $formModel->getElement($name);
         if ($element === false) {
             // Installation demo data sets 2 group ids
             if (is_string($plugin)) {
                 $plugin = array('plugin' => $plugin, 'group_id' => $groupIds[0]);
             }
             $plugin['ordering'] = $i;
             $element = $this->makeElement($name, $plugin);
             if (!$element) {
                 return false;
             }
         }
         $elementModels[] = clone $element;
         $i++;
     }
     $arAddedObj = array();
     $keys = array();
     $lines = array();
     foreach ($elementModels as $elementModel) {
         $element = $elementModel->getElement();
         // Replace all non alphanumeric characters with _
         $objName = FabrikString::dbFieldName($element->name);
         if ($element->get('primary_key') || $element->get('plugin') === 'internalid') {
             $keys[] = $objName;
         }
         // Any elements that are names the same (eg radio buttons) can not be entered twice into the database
         if (!in_array($objName, $arAddedObj)) {
             $arAddedObj[] = $objName;
             $objType = $elementModel->getFieldDescription();
             if ($objName != '' && !is_null($objType)) {
                 if (JString::stristr($objType, 'not null')) {
                     $lines[] = $fabrikDb->qn($objName) . ' ' . $objType;
                 } else {
                     $lines[] = $fabrikDb->qn($objName) . ' ' . $objType . ' null';
                 }
             }
         }
     }
     $func = create_function('$value', '$db = FabrikWorker::getDbo(true);;return $db->qn($value);');
     $sql .= implode(', ', $lines);
     if (!empty($keys)) {
         $sql .= ', PRIMARY KEY (' . implode(',', array_map($func, $keys)) . '))';
     } else {
         $sql .= ')';
     }
     foreach ($opts as $k => $v) {
         if ($v != '') {
             $sql .= ' ' . $k . ' ' . $v;
         }
     }
     $sql .= ' ENGINE = MYISAM ';
     $fabrikDb->setQuery($sql);
     $fabrikDb->execute();
     return $keys;
 }
开发者ID:jfquestiaux,项目名称:fabrik,代码行数:89,代码来源:list.php

示例2: createDBTable

 /**
  * Create a table to store the forms' data depending upon what groups are assigned to the form
  *
  * @param   string  $dbTableName  taken from the table oject linked to the form
  * @param   array   $fields       list of default elements to add. (key = element name, value = plugin
  *
  * @return mixed false if fail otherwise array of primary keys
  */
 public function createDBTable($dbTableName = null, $fields = array('id' => 'internalid', 'date_time' => 'date'))
 {
     $db = FabrikWorker::getDbo(true);
     $fabrikDb = $this->getDb();
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     $formModel = $this->getFormModel();
     if (is_null($dbTableName)) {
         $dbTableName = $this->getTable()->db_table_name;
     }
     $sql = 'CREATE TABLE IF NOT EXISTS ' . $db->quoteName($dbTableName) . ' (';
     $post = JRequest::get('post');
     if (array_key_exists('jform', $post) && ($post['jform']['id'] == 0 && array_key_exists('current_groups', $post['jform']))) {
         // Saving a new form
         $groupIds = $post['jform']['current_groups'];
     } else {
         $query = $db->getQuery(true);
         $formid = (int) $this->get('form.id', $this->getFormModel()->id);
         $query->select('group_id')->from('#__{package}_formgroup')->where('form_id = ' . $formid);
         $db->setQuery($query);
         $groupIds = $db->loadResultArray();
     }
     $i = 0;
     foreach ($fields as $name => $plugin) {
         // $$$ hugh - testing corner case where we are called from form model's updateDatabase,
         // and the underlying table has been deleted.  So elements already exist.
         $element = $formModel->getElement($name);
         if ($element === false) {
             // Installation demo data sets 2 groud ids
             if (is_string($plugin)) {
                 $plugin = array('plugin' => $plugin, 'group_id' => $groupIds[0]);
             }
             $plugin['ordering'] = $i;
             $element = $this->makeElement($name, $plugin);
             if (!$element) {
                 return false;
             }
         }
         $elementModels[] = clone $element;
         $i++;
     }
     $arAddedObj = array();
     $keys = array();
     $lines = array();
     foreach ($elementModels as $elementModel) {
         $element = $elementModel->getElement();
         // Replace all non alphanumeric characters with _
         $objname = FabrikString::dbFieldName($element->name);
         //preg_replace("/[^A-Za-z0-9]/", "_", $element->name);
         if ($element->primary_key) {
             $keys[] = $objname;
         }
         // Any elements that are names the same (eg radio buttons) can not be entered twice into the database
         if (!in_array($objname, $arAddedObj)) {
             $arAddedObj[] = $objname;
             $objtype = $elementModel->getFieldDescription();
             if ($objname != "" && !is_null($objtype)) {
                 if (JString::stristr($objtype, 'not null')) {
                     $lines[] = $fabrikDb->quoteName($objname) . " {$objtype}";
                 } else {
                     $lines[] = $fabrikDb->quoteName($objname) . " {$objtype} null";
                 }
             }
         }
     }
     $func = create_function('$value', '$db = FabrikWorker::getDbo(true);;return $db->quoteName($value);');
     $sql .= implode(', ', $lines);
     if (!empty($keys)) {
         $sql .= ', PRIMARY KEY (' . implode(',', array_map($func, $keys)) . '))';
     } else {
         $sql .= ')';
     }
     $sql .= ' ENGINE = MYISAM ';
     $fabrikDb->setQuery($sql);
     if (!$fabrikDb->query()) {
         JError::raiseError(500, $fabrikDb->getErrorMsg());
         return false;
     }
     return $keys;
 }
开发者ID:rogeriocc,项目名称:fabrik,代码行数:88,代码来源:list.php

示例3: makeTableFromCSV

 /**
  * Make or update the list from the CSV file
  *
  * @return  null
  */
 public function makeTableFromCSV()
 {
     // Called when creating new elements from csv import into existing list
     $session = JFactory::getSession();
     $app = JFactory::getApplication();
     $input = $app->input;
     $model = $this->getModel('Importcsv', 'FabrikFEModel');
     $model->import();
     $listId = $input->getInt('fabrik_list', $input->get('listid'));
     if ($listId == 0) {
         $plugins = $input->get('plugin', array(), 'array');
         $createElements = $input->get('createElements', array(), 'array');
         $newElements = array();
         $c = 0;
         $dbName = $input->get('db_table_name', '', 'string');
         $model->matchedHeadings = array();
         foreach ($createElements as $elname => $add) {
             if ($add) {
                 $name = FabrikString::dbFieldName($elname);
                 $plugin = $plugins[$c];
                 $newElements[$name] = $plugin;
                 $model->matchedHeadings[$dbName . '.' . $name] = $name;
             }
             $c++;
         }
         // Stop id and date_time being added to the table and instead use $newElements
         $input->set('defaultfields', $newElements);
         // Create db
         $listModel = $this->getModel('list', 'FabrikAdminModel');
         $data = array('id' => 0, '_database_name' => $dbName, 'connection_id' => $input->getInt('connection_id'), 'access' => 0, 'rows_per_page' => 10, 'template' => 'default', 'published' => 1, 'access' => 1, 'label' => $input->getString('label'), 'jform' => array('id' => 0, '_database_name' => $dbName, 'db_table_name' => ''));
         $input->set('jform', $data['jform']);
         $listModel->save($data);
         $model->listModel = null;
         $input->set('listid', $listModel->getItem()->id);
     } else {
         $headings = $session->get('com_fabrik.matchedHeadings');
         $model->matchedHeadings = $this->addElements($model, $headings);
         $model->listModel = null;
         $input->set('listid', $listId);
     }
     $model->insertData();
     $msg = $model->updateMessage();
     $this->setRedirect('index.php?option=com_fabrik&view=lists', $msg);
 }
开发者ID:LGBGit,项目名称:tierno,代码行数:49,代码来源:import.php

示例4: makeTableFromCSV

 /**
  * Make or update the list from the CSV file
  *
  * @return  null
  */
 public function makeTableFromCSV()
 {
     // Called when creating new elements from csv import into existing list
     $session = JFactory::getSession();
     $app = JFactory::getApplication();
     $input = $app->input;
     $jform = $input->get('jform', null, 'array');
     /** @var FabrikFEModelImportcsv $model */
     $model = $this->getModel('Importcsv', 'FabrikFEModel');
     $listId = (int) $input->getInt('fabrik_list', $input->get('listid'));
     if ($listId === 0) {
         $plugins = $input->get('plugin', array(), 'array');
         $createElements = $input->get('createElements', array(), 'array');
         $newElements = array();
         $c = 0;
         $dbName = $input->get('db_table_name', '', 'string');
         $model->matchedHeadings = array();
         foreach ($createElements as $elName => $add) {
             if ($add) {
                 $name = FabrikString::dbFieldName($elName);
                 $plugin = $plugins[$c];
                 $newElements[$name] = $plugin;
                 $model->matchedHeadings[$dbName . '.' . $name] = $name;
             }
             $c++;
         }
         // Stop id and date_time being added to the table and instead use $newElements
         $input->set('defaultfields', $newElements);
         /** @var FabrikAdminModelList $listModel */
         $listModel = $this->getModel('list', 'FabrikAdminModel');
         /**
          * Create db
          *
          * @TODO should probably add an ACL option to the import options, as we now have to set 'access'
          * to something for the elementtype import.  Defaulting to 1 for now.
          */
         $data = array('id' => 0, '_database_name' => $dbName, 'connection_id' => $input->getInt('connection_id'), 'rows_per_page' => 10, 'template' => 'default', 'published' => 1, 'access' => 1, 'label' => $input->getString('label'), 'jform' => array('id' => 0, '_database_name' => $dbName, 'db_table_name' => '', 'contenttype' => null));
         $input->set('jform', $data['jform']);
         $listModel->save($data);
         $model->listModel = null;
         $input->set('listid', $listModel->getItem()->id);
         // Reset back to import CSV jForm data.
         $input->set('jform', $jform);
     } else {
         $headings = $session->get('com_fabrik.matchedHeadings');
         $model->matchedHeadings = $this->addElements($model, $headings);
         $model->listModel = null;
         $input->set('listid', $listId);
     }
     $model->readCSV($model->getCSVFileName());
     $model->insertData();
     $msg = $model->updateMessage();
     $this->setRedirect('index.php?option=com_fabrik&view=lists', $msg);
 }
开发者ID:glauberm,项目名称:cinevi,代码行数:59,代码来源:import.php


注:本文中的FabrikString::dbFieldName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。