本文整理汇总了PHP中FabrikWorker::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP FabrikWorker::getConnection方法的具体用法?PHP FabrikWorker::getConnection怎么用?PHP FabrikWorker::getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FabrikWorker
的用法示例。
在下文中一共展示了FabrikWorker::getConnection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: installSampleData
/**
* Install sample data
*
* @return void
*/
public function installSampleData()
{
$cnn = FabrikWorker::getConnection();
$defaultDb = $cnn->getDb();
$db = FabrikWorker::getDbo(true);
$group = $this->getTable('Group');
$config = $this->config;
$dbTableName = $config->get('dbprefix') . "fb_contact_sample";
echo "<div style='text-align:left;border:1px dotted #cccccc;padding:10px;'>" . "<h3>Installing data...</h3><ol>";
$group->name = "Contact Details";
$group->label = "Contact Details";
$group->published = 1;
if (!$group->store()) {
return JError::raiseWarning(500, $group->getError());
}
$groupId = $db->insertid();
$defaultDb->dropTable($dbTableName);
echo "<li>Group 'Contact Details' created</li>";
echo "<li>Element 'Email' added to group 'Contact Details'</li>";
$group = $this->getTable('Group');
$group->name = "Your Enquiry";
$group->label = "Your Enquiry";
$group->published = 1;
$group->store();
$group2Id = $db->insertid();
echo "<li>Group 'Your Enquiry' created</li>";
echo "<li>Element 'Message' added to group 'Your Enquiry'</li>";
$form = $this->getTable('Form');
$form->label = "Contact Us";
$form->record_in_database = 1;
$form->intro = "This is a sample contact us form, that is stored in a database table";
$form->submit_button_label = "Submit";
$form->published = 1;
$form->form_template = "default";
$form->view_only_template = "default";
$form->store();
echo "<li>Form 'Contact Us' created</li>";
$formId = $db->insertid();
$query = $db->getQuery(true);
$query->insert('#__{package}_formgroup')->set(array('form_id=' . (int) $formId, 'group_id=' . (int) $groupId, 'ordering=0'));
$db->setQuery($query);
$db->execute();
$query = $db->getQuery(true);
$query->insert('#__{package}_formgroup')->set(array('form_id=' . (int) $formId, 'group_id=' . (int) $group2Id, 'ordering=1'));
$db->setQuery($query);
$db->execute();
echo "<li>Groups added to 'Contact Us' form</li>";
$listModel = JModelLegacy::getInstance('List', 'FabrikAdminModel');
$list = $this->getTable('List');
$list->label = "Contact Us Data";
$list->introduction = "This table stores the data submitted in the contact us form";
$list->form_id = $formId;
$list->connection_id = $cnn->getConnection()->id;
$list->db_table_name = $dbTableName;
// Store without name quotes as that's db specific
$list->db_primary_key = $dbTableName . '.id';
$list->auto_inc = 1;
$list->published = 1;
$list->rows_per_page = 10;
$list->params = $listModel->getDefaultParams();
$list->template = 'default';
$list->store();
echo "<li>Table for 'Contact Us' created</li></div>";
$form->store();
$formModel = JModelLegacy::getInstance('Form', 'FabrikFEModel');
$formModel->setId($form->id);
$formModel->form = $form;
$listModel->setState('list.id', $list->id);
$listModel->getItem();
$elements = array('id' => array('plugin' => 'internalid', 'label' => 'id', 'group_id' => $groupId), 'first_name' => array('plugin' => 'field', 'label' => 'First Name', 'group_id' => $groupId), 'last_name' => array('plugin' => 'field', 'label' => 'Last Name', 'group_id' => $groupId), 'email' => array('plugin' => 'field', 'label' => 'Email', 'group_id' => $groupId), 'message' => array('plugin' => 'textarea', 'group_id' => $group2Id));
return $listModel->createDBTable($list->db_table_name, $elements);
}
示例2:
/**
* Load the database object associated with the list
*
* @since 3.0b
*
* @return object database
*/
public function &getDb()
{
$listId = $this->getState('list.id');
$item = $this->getItem($listId);
return FabrikWorker::getConnection($item)->getDb();
}
示例3: saveFormGroups
/**
* After having saved the form we
* 1) Create a new group if none selected in edit form list
* 2) Delete all old form_group records
* 3) Recreate the form group records
* 4) Make a list view if needed
*
* @param array $data jForm data
*
* @throws Exception
*
* @return bool True if you should display the form list, False if you're
* redirected elsewhere
*/
public function saveFormGroups($data)
{
// These are set in parent::save() and contain the updated form id and if the form is a new form
$formId = (int) $this->getState($this->getName() . '.id');
$isNew = (bool) $this->getState($this->getName() . '.new');
/** @var FabrikAdminModelList $listModel */
$listModel = JModelLegacy::getInstance('List', 'FabrikAdminModel');
$item = $listModel->loadFromFormId($formId);
$listModel->set('form.id', $formId);
$listModel->setState('list.form_id', $formId);
$recordInDatabase = $data['record_in_database'];
$dbTableName = $this->safeTableName($isNew, $data, $item);
$fields = $this->getInsertFields($isNew, $data, $listModel, $dbTableName);
if ($recordInDatabase != '1') {
return;
}
$dbTableExists = $listModel->databaseTableExists($dbTableName);
if (!$dbTableExists) {
$listModel->createDBTable($dbTableName, $fields);
}
if (!$dbTableExists || $isNew) {
$connection = FabrikWorker::getConnection(-1);
$item->set('id', null);
$item->set('label', $data['label']);
$item->set('form_id', $formId);
$item->set('connection_id', $connection->getConnection()->id);
$item->set('db_table_name', $dbTableName);
// Store key without quoteNames as that is db specific which we no longer want
$item->set('db_primary_key', $dbTableName . '.id');
$item->set('auto_inc', 1);
$item->set('published', $data['published']);
$item->set('created', $data['created']);
$item->set('created_by', $data['created_by']);
$item->set('access', 1);
$item->set('params', $listModel->getDefaultParams());
$item->store();
$this->contentTypeModel->finalise($item);
} else {
// Update existing table (seems to need to reload here to ensure that _table is set)
$listModel->loadFromFormId($formId);
$listModel->ammendTable();
$currentGroups = (array) FArrayHelper::getValue($data, 'current_groups');
$this->_makeFormGroups($currentGroups);
}
}
示例4:
/**
* Get the lists connection object
* sets $this->connection to the lists connection
*
* @deprecated since 3.0b use FabrikWorker::getConnection() instead
*
* @return object connection
*/
public function &getConnection()
{
$this->connection = FabrikWorker::getConnection($this->getTable());
return $this->connection;
}
示例5: saveFormGroups
/**
* After having saved the form we
* 1) Create a new group if none selected in edit form list
* 2) Delete all old form_group records
* 3) Recreate the form group records
* 4) Make a table view if needed
*
* @param array $data jform data
*
* @return bool True if you should display the form list, False if you're
* redirected elsewhere
*/
public function saveFormGroups($data)
{
// These are set in parent::save() and contain the updated form id and if the form is a new form
$formid = $this->getState($this->getName() . '.id');
$isnew = $this->getState($this->getName() . '.new');
$db = FabrikWorker::getDbo(true);
$currentGroups = (array) JArrayHelper::getValue($data, 'current_groups');
$record_in_database = $data['record_in_database'];
$createGroup = $data['_createGroup'];
$form = $this->getForm();
$fields = array('id' => 'internalid', 'date_time' => 'date');
// If new and record in db and group selected then we want to get those groups elements to create fields for in the db table
if ($isnew && $record_in_database) {
$groups = JArrayHelper::getValue($data, 'current_groups');
if (!empty($groups)) {
$query = $db->getQuery(true);
$query->select('plugin, name')->from('#__fabrik_elements')->where('group_id IN (' . implode(',', $groups) . ')');
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$fields[$row->name] = $row->plugin;
}
}
}
if ($createGroup) {
$group = FabTable::getInstance('Group', 'FabrikTable');
$group->name = $data['label'];
$group->published = 1;
$group->store();
$currentGroups[] = $db->insertid();
}
$this->_makeFormGroups($data, $currentGroups);
if ($record_in_database == '1') {
$listModel = JModel::getInstance('List', 'FabrikModel');
$item = $listModel->loadFromFormId($formid);
if ($isnew) {
$dbTableName = $data['db_table_name'] !== '' ? $data['db_table_name'] : $data['label'];
// Mysql will force db table names to lower case even if you set the db name to upper case - so use clean()
$dbTableName = FabrikString::clean($dbTableName);
// Otherwise part of the table name is taken for element names
$dbTableName = str_replace('___', '_', $dbTableName);
} else {
$dbTableName = $item->db_table_name == '' ? $data['database_name'] : $item->db_table_name;
}
$dbTableExists = $listModel->databaseTableExists($dbTableName);
if (!$dbTableExists) {
/**
* @TODO - need to sanitize table name (get rid of non alphanumeirc or _),
* just not sure whether to do it here, or above (before we test for existinance)
* $$$ hugh - for now, just do it here, after we test for the 'unsanitized', as
* need to do some more testing on MySQL table name case sensitivity
* BUT ... as we're potentially changing the table name after testing for existance
* we need to test again.
* $$$ rob - was replacing with '_' but if your form name was 'x - y' then this was
* converted to x___y which then blows up element name code due to '___' being presumed to be the element splitter.
*/
$dbTableName = preg_replace('#[^0-9a-zA-Z_]#', '', $dbTableName);
if ($listModel->databaseTableExists($dbTableName)) {
return JError::raiseWarning(500, JText::_("COM_FABRIK_DB_TABLE_ALREADY_EXISTS"));
}
$listModel->set('form.id', $formid);
$listModel->createDBTable($dbTableName, $fields);
}
if (!$dbTableExists || $isnew) {
$connection = FabrikWorker::getConnection(-1);
$item->id = null;
$item->label = $data['label'];
$item->form_id = $formid;
$item->connection_id = $connection->getConnection()->id;
$item->db_table_name = $dbTableName;
// Store key without quoteNames as thats db specific *which we no longer want
$item->db_primary_key = $dbTableName . '.id';
$item->auto_inc = 1;
$item->published = $data['published'];
$item->created = $data['created'];
$item->created_by = $data['created_by'];
$item->access = 1;
$item->params = $listModel->getDefaultParams();
$res = $item->store();
} else {
// Update existing table (seems to need to reload here to ensure that _table is set
$item = $listModel->loadFromFormId($formid);
$listModel->ammendTable();
}
}
}
示例6:
/**
* function get the tables connection object
* sets $this->_oConn to the tables connection
* @deprecated since 3.0b use FabrikWorker::getConnection() instead
* @return object connection
*/
function &getConnection()
{
$this->_oConn = FabrikWorker::getConnection($this->getTable());
return $this->_oConn;
}
示例7:
/**
* Load the database object associated with the list
*
* @since 3.0b
*
* @return object database
*/
public function &getDb()
{
return FabrikWorker::getConnection($this->getItem())->getDb();
}