本文整理汇总了PHP中dmDb::table方法的典型用法代码示例。如果您正苦于以下问题:PHP dmDb::table方法的具体用法?PHP dmDb::table怎么用?PHP dmDb::table使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dmDb
的用法示例。
在下文中一共展示了dmDb::table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLayout
public function getLayout()
{
if (!($layout = $this->_get('Layout'))) {
$this->set('Layout', dmDb::table('DmLayout')->findFirstOrCreate())->save();
}
return $layout;
}
示例2: executeNewMultipleFile
/**
* Allows the upload of multiple files
*
* @param sfWebRequest $request
*/
public function executeNewMultipleFile(dmWebRequest $request)
{
// Retrived the folder by folder_id or by object in case of usage in dmMedia/gallery module
if ($request->hasParameter('folder_id')) {
$folderId = $request->getParameter('folder_id');
} else {
$objectModel = $request->getParameter('model');
$objectPk = $request->getParameter('pk');
$object = dmDb::table($objectModel)->find($objectPk);
$folderId = $object->getDmMediaFolder()->getId();
}
$this->forward404Unless($folder = dmDb::table('DmMediaFolder')->find($folderId));
if (!$folder->isWritable()) {
$this->getUser()->logAlert($this->getI18n()->__('Folder %1% is not writable', array('%1%' => $folder->fullPath)));
}
$form = new dmMediaUploadifyForm();
$form->setDefault('dm_media_folder_id', $folder->id);
if ($request->isMethod('post') && $form->bindAndValid($request)) {
$media = $form->save();
if (isset($object)) {
$object->addMedia($media);
// In dmMedia/gallery usage, we also need to associate with the object
}
return $this->renderText('success');
}
$action = '+/dmMediaUploadifyerAdmin/newMultipleFile?' . (isset($object) ? "&model={$objectModel}&pk={$objectPk}" : 'folder_id=' . $folder->id);
return $this->renderAsync(array('html' => $form->render('.dm_form.list.little action="' . $action . '"'), 'css' => $form->getStylesheets(), 'js' => $form->getJavascripts()));
}
示例3: createPageTranslations
protected function createPageTranslations($pageId)
{
$cultures = $this->getOption('cultures');
$translationTable = dmDb::table('DmPageTranslation');
$existingCultures = $translationTable->createQuery('t')->where('t.id = ? ', $pageId)->andWhereIn('t.lang', $cultures)->select('t.lang')->fetchFlat();
// can not generate translations from nothing
if (empty($existingCultures)) {
return;
}
// calculate missing cultures for this page
$missingCultures = array_diff($cultures, $existingCultures);
// all translations exist
if (empty($missingCultures)) {
return;
}
if (in_array(sfConfig::get('sf_default_culture'), $existingCultures)) {
$mainCulture = sfConfig::get('sf_default_culture');
} elseif (in_array(myDoctrineRecord::getDefaultCulture(), $existingCultures)) {
$mainCulture = myDoctrineRecord::getDefaultCulture();
} else {
$mainCulture = dmArray::first($existingCultures);
}
$mainTranslationArray = $translationTable->createQuery('t')->select('t.slug, t.name, t.title, t.h1, t.description, t.keywords, t.is_active')->where('t.id = ?', $pageId)->andWhere('t.lang = ?', $mainCulture)->limit(1)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
$missingTranslations = new myDoctrineCollection(dmDb::table('DmPageTranslation'));
if ($this->getOption('activate_new_translations')) {
$isActive = $mainTranslationArray['is_active'];
} else {
$isActive = false;
}
foreach ($missingCultures as $culture) {
$missingTranslations->add($translationTable->create(array_merge($mainTranslationArray, array('lang' => $culture, 'is_active' => $isActive))));
}
$missingTranslations->save();
}
示例4: copyModel
protected function copyModel($model)
{
$table = dmDb::table($model);
$tableName = $table->getTableName();
$vars = array();
$placeholders = array();
foreach ($table->getColumns() as $columnName => $column) {
$fields[] = $columnName;
$placeholders[] = ':' . $columnName;
}
$conn = Doctrine_Manager::connection();
$stmt = $conn->prepare(sprintf('INSERT INTO %s (%s) VALUES (%s)', $tableName, implode(',', $fields), implode(',', $placeholders)))->getStatement();
$conn->beginTransaction();
try {
foreach ($this->oldDb->getData($tableName) as $array) {
$values = array();
foreach ($fields as $field) {
$values[':' . $field] = isset($array[$field]) ? $array[$field] : '';
}
$stmt->execute($values);
}
} catch (Exception $e) {
dmDebug::show($model, $array);
throw $e;
}
$conn->commit();
}
示例5: getDmMediaFolder
/**
* @return DmMediaFolder the DmMediaFolder used to store this table's record's medias
*/
public function getDmMediaFolder()
{
if ($this->hasCache('dm_media_folder')) {
return $this->getCache('dm_media_folder');
}
return $this->setCache('dm_media_folder', dmDb::table('DmMediaFolder')->findOneByRelPathOrCreate($this->getDmModule()->getUnderscore()));
}
示例6: getPage
public function getPage()
{
if (null === $this->page) {
$this->page = dmDb::table('DmPage')->findOneByIdWithI18n($this->pageId);
}
return $this->page;
}
示例7: getQuery
/**
* Get the query for the pager.
*
* @return Doctrine_Query
*/
public function getQuery()
{
if (dmDb::table($this->class)->hasI18n()) {
return parent::getQuery()->withI18n();
}
return parent::getQuery();
}
示例8: executeImportSentences
public function executeImportSentences(dmWebRequest $request)
{
$catalogue = $this->getObjectOrForward404($request);
$form = new DmCatalogueImportForm();
sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
if ($request->isMethod('post') && $form->bindAndValid($request)) {
$file = $form->getValue('file');
$override = $form->getValue('override');
$dataFile = $file->getTempName();
$table = dmDb::table('DmTransUnit');
$existQuery = $table->createQuery('t')->select('t.id, t.source, t.target, t.created_at, t.updated_at')->where('t.dm_catalogue_id = ? AND t.source = ?');
$catalogueId = $catalogue->get('id');
$nbAdded = 0;
$nbUpdated = 0;
try {
if (!is_array($data = sfYaml::load(file_get_contents($dataFile)))) {
$this->getUser()->logError($this->getI18n()->__('Could not load file: %file%', array('%file%' => $file->getOriginalName())));
return $this->renderPartial('dmInterface/flash');
}
} catch (Exception $e) {
$this->getUser()->logError($this->getI18n()->__('Unable to parse file: %file%', array('%file%' => $file->getOriginalName())));
return $this->renderPartial('dmInterface/flash');
}
$addedTranslations = new Doctrine_Collection($table);
$line = 0;
foreach ($data as $source => $target) {
++$line;
if (!is_string($source) || !is_string($target)) {
$this->getUser()->logError($this->getI18n()->__('Error line %line%: %file%', array('%line%' => $line, '%file%' => $file->getOriginalName())));
return $this->renderPartial('dmInterface/flash');
} else {
$existing = $existQuery->fetchOneArray(array($catalogueId, $source));
if (!empty($existing) && $existing['source'] === $source) {
if ($existing['target'] !== $target) {
if ($override || $existing['created_at'] === $existing['updated_at']) {
$table->createQuery()->update('DmTransUnit')->set('target', '?', array($target))->where('id = ?', $existing['id'])->execute();
++$nbUpdated;
}
}
} elseif (empty($existing)) {
$addedTranslations->add(dmDb::create('DmTransUnit', array('dm_catalogue_id' => $catalogue->get('id'), 'source' => $source, 'target' => $target)));
++$nbAdded;
}
}
}
$addedTranslations->save();
if ($nbAdded) {
$this->getUser()->logInfo($this->getI18n()->__('%catalogue%: added %count% translation(s)', array('%catalogue%' => $catalogue->get('name'), '%count%' => $nbAdded)));
}
if ($nbUpdated) {
$this->getUser()->logInfo($this->getI18n()->__('%catalogue%: updated %count% translation(s)', array('%catalogue%' => $catalogue->get('name'), '%count%' => $nbUpdated)));
}
if (!$nbAdded && !$nbUpdated) {
$this->getUser()->logInfo($this->getI18n()->__('%catalogue%: nothing to add and update', array('%catalogue%' => $catalogue->get('name'))));
}
return $this->renderText(url_for1($this->getRouteArrayForAction('index')));
}
$action = url_for1($this->getRouteArrayForAction('importSentences', $catalogue));
return $this->renderText($form->render('.dm_form.list.little action="' . $action . '"'));
}
示例9: executeRate
public function executeRate(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod('POST'));
list($class, $id) = dmString::decode($request->getParameter('hash'));
$this->forward404Unless($table = dmDb::table($class));
$this->forward404Unless($record = $table->find($id));
$this->forward404Unless($table->hasTemplate('DmRatable'));
$template = $table->getTemplate('DmRatable');
$options = $template->getOptions();
$value = (int) $request->getParameter('value');
$this->forward404Unless($value >= 0 && $value <= $options['max_rate']);
$rate = array('rate' => $value);
if ($options['user']) {
$this->forward404Unless($this->getUser()->isAuthenticated());
$rate['dm_user_id'] = $this->getUser()->getUserId();
} else {
$rate['session_id'] = session_id();
}
if ($value) {
$record->addRate($rate);
$message = $this->getService('i18n')->__('Rating saved (%rate%)', array('%rate%' => $value));
} else {
$record->cancelRate($rate);
$message = $this->getService('i18n')->__('Rating removed');
}
return $this->renderComponent('dmRatable', 'rating', array('record' => $record, 'message' => $message));
}
示例10: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
throw new dmException('deprecated');
$this->withDatabase();
$page = dmDb::table('DmPage')->findOneByIdWithI18n($arguments['id'], $arguments['culture']);
if (!$page instanceof DmPage) {
throw new dmException('No page with id = ' . $arguments['id']);
}
$this->getContext()->setPage($page);
$area = dmDb::query('DmArea a, a.Zones z, z.Widgets w')->select('a.id, z.id, w.module, w.action, w.value')->where('a.type = ? AND a.dm_page_view_id = ?', array('content', $page->get('PageView')->get('id')))->orderBy('z.position asc, w.position asc')->fetchArray();
$widgetTypeManager = $dmContext->get('widget_type_manager');
$html = '';
foreach ($area[0]['Zones'] as $zone) {
foreach ($zone['Widgets'] as $widget) {
if (!in_array($widget['module'] . '.' . $widget['action'], self::$skipWidgets)) {
$widget['css_class'] = null;
$widgetViewClass = $widgetTypeManager->getWidgetType($widget['module'], $widget['action'])->getViewClass();
$widgetView = new $widgetViewClass($widget);
try {
$html .= $widgetView->toIndexableString();
} catch (Exception $e) {
$this->log($e->getMessage());
}
}
}
}
$indexableText = dmSearchIndex::cleanText($html);
die($indexableText);
}
示例11: getPages
protected function getPages($includeCurrent = true)
{
$treeObject = dmDb::table('DmPage')->getTree();
$baseQuery = dmDb::table('DmPage')->createQuery('p')->withI18n();
if (!isset($this->compiledVars['includeInactivePages']) || !$this->compiledVars['includeInactivePages']) {
$baseQuery->where('pTranslation.is_active = ?', true);
}
$treeObject->setBaseQuery($baseQuery);
if (!($currentPage = $this->context->getPage())) {
throw new dmException('No current page');
}
$ancestors = $currentPage->getNode()->getAncestors();
$ancestors = $ancestors ? $ancestors : array();
$treeObject->resetBaseQuery();
if ($includeCurrent) {
$ancestors[] = $currentPage;
}
$pages = array();
foreach ($ancestors as $page) {
$pages[$page->get('module') . '/' . $page->get('action') . '/' . $page->getRecordId()] = $page;
}
/*
* Allow listeners of dm.bread_crumb.filter_pages event
* to filter and modify the pages list
*/
return $this->context->getEventDispatcher()->filter(new sfEvent($this, 'dm.bread_crumb.filter_pages', array('page' => $this->context->getPage())), $pages)->getReturnValue();
}
示例12: fetchRecord
protected function fetchRecord($model, $id)
{
$key = $model . ':' . $id;
if (!isset(self::$recordsCache[$key])) {
self::$recordsCache[$key] = dmDb::table($model)->createQuery('r')->where('r.id = ?', $id)->fetchRecord();
}
return self::$recordsCache[$key];
}
示例13: checkSearchPage
/**
* Check that search page exist
* and, if doesn't, will create it
*/
public function checkSearchPage()
{
if (!$this->createQuery('p')->where('p.module = ? AND p.action = ?', array('main', 'search'))->exists()) {
$searchResultsPage = $this->create(array('name' => $this->tryToTranslate('Search results'), 'title' => $this->tryToTranslate('Search results'), 'module' => 'main', 'action' => 'search', 'slug' => 'search'));
$searchResultsPage->getNode()->insertAsLastChildOf($this->getTree()->fetchRoot());
dmDb::table('DmWidget')->createInZone($searchResultsPage->PageView->Area->Zones[0], 'dmWidgetSearch/results')->save();
}
}
示例14: setTemplate
/**
* Set a template to the mail
*
* @param mixed $templateName the template name, or a DmMailTemplateInstance
* @return dmMail $this
*/
public function setTemplate($templateName)
{
if ($templateName instanceof DmMailTemplate) {
$this->template = $templateName;
} elseif (!($this->template = dmDb::query('DmMailTemplate t')->where('t.name = ?', $templateName)->fetchRecord())) {
$this->template = dmDb::table('DmMailTemplate')->createDefault($templateName);
}
return $this;
}
示例15: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$this->withDatabase();
$snippetPage = dmDb::table('DmPage')->findOneByModuleAndAction('snippet', 'list');
if ($snippetPage->Node->getParent()->isModuleAction('main', 'root')) {
$communityPage = dmDb::table('DmPage')->findOneByModuleAndAction('main', 'community');
$snippetPage->Node->moveAsFirstChildOf($communityPage);
}
}