本文整理汇总了PHP中BackendModel::getDB方法的典型用法代码示例。如果您正苦于以下问题:PHP BackendModel::getDB方法的具体用法?PHP BackendModel::getDB怎么用?PHP BackendModel::getDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackendModel
的用法示例。
在下文中一共展示了BackendModel::getDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute the action
*
* @return void
*/
public function execute()
{
// call parent, this will probably add some general CSS/JS or other required files
parent::execute();
// user is god?
$isGod = BackendAuthentication::getUser()->isGod();
// get possible languages
if ($isGod) {
$possibleLanguages = array_unique(array_merge(BL::getWorkingLanguages(), BL::getInterfaceLanguages()));
} else {
$possibleLanguages = BL::getWorkingLanguages();
}
// get parameters
$language = SpoonFilter::getPostValue('language', array_keys($possibleLanguages), null, 'string');
$module = SpoonFilter::getPostValue('module', BackendModel::getModules(false), null, 'string');
$name = SpoonFilter::getPostValue('name', null, null, 'string');
$type = SpoonFilter::getPostValue('type', BackendModel::getDB()->getEnumValues('locale', 'type'), null, 'string');
$application = SpoonFilter::getPostValue('application', array('backend', 'frontend'), null, 'string');
$value = SpoonFilter::getPostValue('value', null, null, 'string');
// validate values
if (trim($value) == '' || $language == '' || $module == '' || $type == '' || $application == '' || $application == 'frontend' && $module != 'core') {
$error = BL::err('InvalidValue');
}
// in case this is a 'act' type, there are special rules concerning possible values
if ($type == 'act' && !isset($error)) {
if (!SpoonFilter::isValidAgainstRegexp('|^([a-z0-9\\-\\_])+$|', $value)) {
$error = BL::err('InvalidActionValue', $this->getModule());
}
}
// no error?
if (!isset($error)) {
// build item
$item['language'] = $language;
$item['module'] = $module;
$item['name'] = $name;
$item['type'] = $type;
$item['application'] = $application;
$item['value'] = $value;
$item['edited_on'] = BackendModel::getUTCDate();
$item['user_id'] = BackendAuthentication::getUser()->getUserId();
// does the translation exist?
if (BackendLocaleModel::existsByName($name, $type, $module, $language, $application)) {
// add the id to the item
$item['id'] = (int) BackendLocaleModel::getByName($name, $type, $module, $language, $application);
// update in db
BackendLocaleModel::update($item);
} else {
// insert in db
BackendLocaleModel::insert($item);
}
// output OK
$this->output(self::OK);
} else {
$this->output(self::ERROR, null, $error);
}
}
示例2: commentsGet
/**
* Get the comments
*
* @param string[optional] $status The type of comments to get. Possible values are: published, moderation, spam.
* @param int[optional] $limit The maximum number of items to retrieve.
* @param int[optional] $offset The offset.
* @return array
*/
public static function commentsGet($status = null, $limit = 30, $offset = 0)
{
// authorize
if (API::authorize() && API::isValidRequestMethod('GET')) {
// redefine
if ($status !== null) {
$status = (string) $status;
}
$limit = (int) $limit;
$offset = (int) $offset;
// validate
if ($limit > 10000) {
API::output(API::ERROR, array('message' => 'Limit can\'t be larger than 10000.'));
}
// get comments
$comments = (array) BackendModel::getDB()->getRecords('SELECT i.id, UNIX_TIMESTAMP(i.created_on) AS created_on, i.author, i.email, i.website, i.text, i.type, i.status,
p.id AS post_id, p.title AS post_title, m.url AS post_url, p.language AS post_language
FROM blog_comments AS i
INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
INNER JOIN meta AS m ON p.meta_id = m.id
WHERE p.status = ?
GROUP BY i.id
LIMIT ?, ?', array('active', $offset, $limit));
$return = array('comments' => null);
// build return array
foreach ($comments as $row) {
// create array
$item['comment'] = array();
// article meta data
$item['comment']['article']['@attributes']['id'] = $row['post_id'];
$item['comment']['article']['@attributes']['lang'] = $row['post_language'];
$item['comment']['article']['title'] = $row['post_title'];
$item['comment']['article']['url'] = SITE_URL . BackendModel::getURLForBlock('blog', 'detail', $row['post_language']) . '/' . $row['post_url'];
// set attributes
$item['comment']['@attributes']['id'] = $row['id'];
$item['comment']['@attributes']['created_on'] = date('c', $row['created_on']);
$item['comment']['@attributes']['status'] = $row['status'];
// set content
$item['comment']['text'] = $row['text'];
$item['comment']['url'] = $item['comment']['article']['url'] . '#comment-' . $row['id'];
// author data
$item['comment']['author']['@attributes']['email'] = $row['email'];
$item['comment']['author']['name'] = $row['author'];
$item['comment']['author']['website'] = $row['website'];
// add
$return['comments'][] = $item;
}
return $return;
}
}
示例3: validateForm
/**
* Validate the form
*/
private function validateForm()
{
// is the form submitted?
if ($this->frm->isSubmitted()) {
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// no errors?
if ($this->frm->isCorrect()) {
// the total amount of subscribers
$subscribersTotal = 0;
// loop all groups
foreach ($this->externalGroups as $group) {
// insert them in our database
$groupID = BackendModel::getDB(true)->insert('mailmotor_groups', array('name' => $group['name'], 'custom_fields' => $group['custom_fields'], 'created_on' => BackendModel::getUTCDate()));
// insert the CM ID
BackendMailmotorCMHelper::insertCampaignMonitorID('list', $group['id'], $groupID);
// continue looping if this group has no subscribers
if (empty($group['subscribers'])) {
continue;
}
// add this groups subscribers amount to the total
$subscribersTotal += $group['subscribers_amount'];
// loop the subscribers for this group, and import them
foreach ($group['subscribers'] as $subscriber) {
// build new subscriber record
$item = array();
$item['email'] = $subscriber['email'];
$item['source'] = 'import';
$item['created_on'] = $subscriber['date'];
// add an additional custom field 'name', if it was set in the subscriber record
if (!empty($subscriber['name'])) {
$subscriber['custom_fields']['Name'] = $subscriber['name'];
}
// save the subscriber in our database, and subscribe it to this group
BackendMailmotorModel::saveAddress($item, $groupID, !empty($subscriber['custom_fields']) ? $subscriber['custom_fields'] : null);
}
}
// at this point, groups are set
BackendModel::setModuleSetting($this->getModule(), 'cm_groups_set', true);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_import_groups');
// redirect to the index
$this->redirect(BackendModel::createURLForAction('index', $this->getModule()) . '&report=groups-imported&var[]=' . count($this->externalGroups) . '&var[]=' . $subscribersTotal);
}
}
}
示例4: update
/**
* Update a tag
* Remark: $tag['id'] should be available.
*
* @param array $item The new data for the tag.
*/
public static function update($item)
{
return BackendModel::getDB(true)->update('tags', $item, 'id = ?', $item['id']);
}
示例5: updateQuestion
/**
* Update a question item
*
* @return int
* @param array $item The updated item.
*/
public static function updateQuestion(array $item)
{
return BackendModel::getDB(true)->update('faq_questions', $item, 'id = ?', array((int) $item['id']));
}
示例6: updateCommentStatuses
/**
* Updates one or more comments' status
*
* @return void
* @param array $ids The id(s) of the comment(s) to change the status for.
* @param string $status The new status.
*/
public static function updateCommentStatuses($ids, $status)
{
// make sure $ids is an array
$ids = (array) $ids;
// loop and cast to integers
foreach ($ids as &$id) {
$id = (int) $id;
}
// create an array with an equal amount of questionmarks as ids provided
$idPlaceHolders = array_fill(0, count($ids), '?');
// get ids
$itemIds = (array) BackendModel::getDB()->getColumn('SELECT i.post_id
FROM blog_comments AS i
WHERE i.id IN (' . implode(', ', $idPlaceHolders) . ')', $ids);
// update record
BackendModel::getDB(true)->execute('UPDATE blog_comments
SET status = ?
WHERE id IN (' . implode(', ', $idPlaceHolders) . ')', array_merge(array((string) $status), $ids));
// recalculate the comment count
if (!empty($itemIds)) {
self::reCalculateCommentCount($itemIds);
}
// invalidate the cache for blog
BackendModel::invalidateFrontendCache('blog', BL::getWorkingLanguage());
}
示例7: update
/**
* Update a locale item.
*
* @return void
* @param array $item The new data.
*/
public static function update(array $item)
{
// update category
$updated = BackendModel::getDB(true)->update('locale', $item, 'id = ?', array($item['id']));
// rebuild the cache
self::buildCache($item['language'], $item['application']);
// return
return $updated;
}
示例8: execute
/**
* Execute the action
*
* @return void
*/
public function execute()
{
// call parent, this will probably add some general CSS/JS or other required files
parent::execute();
// get parameters
$from = $this->getParameter('from');
$to = $this->getParameter('to');
// validate
if ($from == '') {
throw new BackendException('Specify a from-parameter.');
}
if ($to == '') {
throw new BackendException('Specify a to-parameter.');
}
// get db
$db = BackendModel::getDB(true);
// get all old pages
$ids = $db->getColumn('SELECT id
FROM pages AS i
WHERE i.language = ? AND i.status = ?', array($to, 'active'));
// any old pages
if (!empty($ids)) {
// delete existing pages
foreach ($ids as $id) {
// redefine
$id = (int) $id;
// get revision ids
$revisionIDs = (array) $db->getColumn('SELECT i.revision_id
FROM pages AS i
WHERE i.id = ? AND i.language = ?', array($id, $to));
// get meta ids
$metaIDs = (array) $db->getColumn('SELECT i.meta_id
FROM pages AS i
WHERE i.id = ? AND i.language = ?', array($id, $to));
// delete meta records
if (!empty($metaIDs)) {
$db->delete('meta', 'id IN (' . implode(',', $metaIDs) . ')');
}
// delete blocks and their revisions
if (!empty($revisionIDs)) {
$db->delete('pages_blocks', 'revision_id IN (' . implode(',', $revisionIDs) . ')');
}
// delete page and the revisions
if (!empty($revisionIDs)) {
$db->delete('pages', 'revision_id IN (' . implode(',', $revisionIDs) . ')');
}
}
}
// delete search indexes
$db->delete('search_index', 'module = ? AND language = ?', array('pages', $to));
// get all active pages
$ids = BackendModel::getDB()->getColumn('SELECT id
FROM pages AS i
WHERE i.language = ? AND i.status = ?', array($from, 'active'));
// loop
foreach ($ids as $id) {
// get data
$sourceData = BackendPagesModel::get($id, $from);
// get and build meta
$meta = $db->getRecord('SELECT *
FROM meta
WHERE id = ?', $sourceData['meta_id']);
// remove id
unset($meta['id']);
// build page record
$page = array();
$page['id'] = $sourceData['id'];
$page['user_id'] = BackendAuthentication::getUser()->getUserId();
$page['parent_id'] = $sourceData['parent_id'];
$page['template_id'] = $sourceData['template_id'];
$page['meta_id'] = (int) $db->insert('meta', $meta);
$page['language'] = $to;
$page['type'] = $sourceData['type'];
$page['title'] = $sourceData['title'];
$page['navigation_title'] = $sourceData['navigation_title'];
$page['navigation_title_overwrite'] = $sourceData['navigation_title_overwrite'];
$page['hidden'] = $sourceData['hidden'];
$page['status'] = 'active';
$page['publish_on'] = BackendModel::getUTCDate();
$page['created_on'] = BackendModel::getUTCDate();
$page['edited_on'] = BackendModel::getUTCDate();
$page['allow_move'] = $sourceData['allow_move'];
$page['allow_children'] = $sourceData['allow_children'];
$page['allow_edit'] = $sourceData['allow_edit'];
$page['allow_delete'] = $sourceData['allow_delete'];
$page['sequence'] = $sourceData['sequence'];
$page['data'] = $sourceData['data'] !== null ? serialize($sourceData['data']) : null;
// insert page, store the id, we need it when building the blocks
$revisionId = BackendPagesModel::insert($page);
// init var
$blocks = array();
$hasBlock = $sourceData['has_extra'] == 'Y';
// get the blocks
$sourceBlocks = BackendPagesModel::getBlocks($id, $from);
// loop blocks
//.........这里部分代码省略.........
示例9: updateCategory
/**
* Update a certain category
*
* @param array $item
*/
public static function updateCategory(array $item)
{
BackendModel::getDB(true)->update('faq_categories', $item, 'id = ?', array($item['id']));
BackendModel::invalidateFrontendCache('faq', BL::getWorkingLanguage());
}
示例10: getRecentReferrers
/**
* Get the referrers for certain dates
*
* @return array
*/
public static function getRecentReferrers()
{
// set metrics and dimensions
$gaMetrics = 'ga:entrances';
$gaDimensions = array('ga:source', 'ga:referralPath');
// set parameters
$parameters = array();
$parameters['max-results'] = 10;
$parameters['filters'] = 'ga:medium==referral';
$parameters['sort'] = '-ga:entrances';
// get results
$results = self::getGoogleAnalyticsInstance()->getAnalyticsResults($gaMetrics, mktime(0, 0, 0), mktime(23, 59, 59), $gaDimensions, $parameters);
// no results - try the same query but for yesterday
if (empty($results)) {
$results = self::getGoogleAnalyticsInstance()->getAnalyticsResults($gaMetrics, strtotime('-1day', mktime(0, 0, 0)), strtotime('-1day', mktime(23, 59, 59)), $gaDimensions, $parameters);
}
// init vars
$insertArray = array();
// loop referrers
foreach ($results['entries'] as $entry) {
// build insert record
$insertRecord = array();
$insertRecord['referrer'] = $entry['source'] . $entry['referralPath'];
$insertRecord['entrances'] = $entry['entrances'];
$insertRecord['date'] = $results['startDate'] . ' 00:00:00';
// add record to insert array
$insertArray[] = $insertRecord;
}
// there are some records to be inserted
if (!empty($insertArray)) {
// get DB
$db = BackendModel::getDB(true);
// remove old data and insert array into database
$db->truncate('analytics_referrers');
$db->insert('analytics_referrers', $insertArray);
}
}
示例11: updateCommentStatuses
/**
* Updates one or more comments' status
*
* @param array $ids The id(s) of the comment(s) to change the status for.
* @param string $status The new status.
*/
public static function updateCommentStatuses($ids, $status)
{
// make sure $ids is an array
$ids = (array) $ids;
// loop and cast to integers
foreach ($ids as &$id) {
$id = (int) $id;
}
// create an array with an equal amount of questionmarks as ids provided
$idPlaceHolders = array_fill(0, count($ids), '?');
// get the items and their languages
$items = (array) BackendModel::getDB()->getPairs('SELECT i.post_id, i.language
FROM blog_comments AS i
WHERE i.id IN (' . implode(', ', $idPlaceHolders) . ')', $ids, 'post_id');
// only proceed if there are items
if (!empty($items)) {
// get the ids
$itemIds = array_keys($items);
// get the unique languages
$languages = array_unique(array_values($items));
// update records
BackendModel::getDB(true)->execute('UPDATE blog_comments
SET status = ?
WHERE id IN (' . implode(', ', $idPlaceHolders) . ')', array_merge(array((string) $status), $ids));
// recalculate the comment count
self::reCalculateCommentCount($itemIds);
// invalidate the cache for blog
foreach ($languages as $language) {
BackendModel::invalidateFrontendCache('blog', $language);
}
}
}
示例12: updateTemplate
/**
* Update a template
*
* @param array $item The new data for the template.
*/
public static function updateTemplate(array $item)
{
BackendModel::getDB(true)->update('themes_templates', $item, 'id = ?', array((int) $item['id']));
}
示例13: updateProfileGroup
/**
* Update a membership of a profile in a group.
*
* @return int
* @param int $id Membership id.
* @param array $values Membership data.
*/
public static function updateProfileGroup($id, array $values)
{
return (int) BackendModel::getDB(true)->update('profiles_groups_rights', $values, 'id = ?', (int) $id);
}
示例14: execute
/**
* Execute the action
*
* @return void
*/
public function execute()
{
// no timelimit
set_time_limit(0);
// get database
$db = BackendModel::getDB(true);
// create log
$log = new SpoonLog('custom', BACKEND_CACHE_PATH . '/logs/events');
// get process-id
$pid = getmypid();
// store PID
SpoonFile::setContent(BACKEND_CACHE_PATH . '/hooks/pid', $pid);
// loop forever
while (true) {
// get 1 item
$item = $db->getRecord('SELECT *
FROM hooks_queue
WHERE status = ?
LIMIT 1', array('queued'));
// any item?
if (!empty($item)) {
// init var
$processedSuccesfully = true;
// set item as busy
$db->update('hooks_queue', array('status' => 'busy'), 'id = ?', array($item['id']));
// unserialize data
$item['callback'] = unserialize($item['callback']);
$item['data'] = unserialize($item['data']);
// check if the item is callable
if (!is_callable($item['callback'])) {
// in debug mode we want to know if there are errors
if (SPOON_DEBUG) {
throw new BackendException('Invalid callback.');
}
// set to error state
$db->update('hooks_queue', array('status' => 'error'), 'id = ?', $item['id']);
// reset state
$processedSuccesfully = false;
// logging when we are in debugmode
if (SPOON_DEBUG) {
$log->write('Callback (' . serialize($item['callback']) . ') failed.');
}
}
try {
// logging when we are in debugmode
if (SPOON_DEBUG) {
$log->write('Callback (' . serialize($item['callback']) . ') called.');
}
// call the callback
$return = call_user_func($item['callback'], $item['data']);
// failed?
if ($return === false) {
// set to error state
$db->update('hooks_queue', array('status' => 'error'), 'id = ?', $item['id']);
// reset state
$processedSuccesfully = false;
// logging when we are in debugmode
if (SPOON_DEBUG) {
$log->write('Callback (' . serialize($item['callback']) . ') failed.');
}
}
} catch (Exception $e) {
// set to error state
$db->update('hooks_queue', array('status' => 'error'), 'id = ?', $item['id']);
// reset state
$processedSuccesfully = false;
// logging when we are in debugmode
if (SPOON_DEBUG) {
$log->write('Callback (' . serialize($item['callback']) . ') failed.');
}
}
// everything went fine so delete the item
if ($processedSuccesfully) {
$db->delete('hooks_queue', 'id = ?', $item['id']);
}
// logging when we are in debugmode
if (SPOON_DEBUG) {
$log->write('Callback (' . serialize($item['callback']) . ') finished.');
}
} else {
// remove the file
SpoonFile::delete(BACKEND_CACHE_PATH . '/hooks/pid');
// stop the script
exit;
}
}
}
示例15: send
/**
* Send an email
*
* @param int $id The id of the mail to send.
*/
public static function send($id)
{
$id = (int) $id;
$db = BackendModel::getDB(true);
// get record
$emailRecord = (array) $db->getRecord('SELECT *
FROM emails AS e
WHERE e.id = ?', array($id));
// mailer type
$mailerType = BackendModel::getModuleSetting('core', 'mailer_type', 'mail');
// create new SpoonEmail-instance
$email = new SpoonEmail();
$email->setTemplateCompileDirectory(BACKEND_CACHE_PATH . '/compiled_templates');
// send via SMTP
if ($mailerType == 'smtp') {
// get settings
$SMTPServer = BackendModel::getModuleSetting('core', 'smtp_server');
$SMTPPort = BackendModel::getModuleSetting('core', 'smtp_port', 25);
$SMTPUsername = BackendModel::getModuleSetting('core', 'smtp_username');
$SMTPPassword = BackendModel::getModuleSetting('core', 'smtp_password');
// set server and connect with SMTP
$email->setSMTPConnection($SMTPServer, $SMTPPort, 10);
// set authentication if needed
if ($SMTPUsername !== null && $SMTPPassword !== null) {
$email->setSMTPAuth($SMTPUsername, $SMTPPassword);
}
}
// set some properties
$email->setFrom($emailRecord['from_email'], $emailRecord['from_name']);
$email->addRecipient($emailRecord['to_email'], $emailRecord['to_name']);
$email->setReplyTo($emailRecord['reply_to_email']);
$email->setSubject($emailRecord['subject']);
$email->setHTMLContent($emailRecord['html']);
$email->setCharset(SPOON_CHARSET);
$email->setContentTransferEncoding('base64');
if ($emailRecord['plain_text'] != '') {
$email->setPlainContent($emailRecord['plain_text']);
}
// attachments added
if (isset($emailRecord['attachments']) && $emailRecord['attachments'] !== null) {
// unserialize
$attachments = (array) unserialize($emailRecord['attachments']);
// add attachments to email
foreach ($attachments as $attachment) {
$email->addAttachment($attachment);
}
}
// send the email
if ($email->send()) {
// remove the email
$db->delete('emails', 'id = ?', array($id));
// trigger event
BackendModel::triggerEvent('core', 'after_email_sent', array('id' => $id));
}
}