/**
  * 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()));
 }
 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();
 }
 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));
 }
 /**
  * Update changed documentation pages in database
  */
 protected function updateDatabase($branch)
 {
     $types = dmDb::query('Doc d')->select('d.type')->distinct()->fetchFlat();
     $cultures = sfConfig::get('dm_i18n_cultures');
     $originalCulture = sfDoctrineRecord::getDefaultCulture();
     foreach ($types as $type) {
         foreach ($cultures as $culture) {
             sfDoctrineRecord::setDefaultCulture($culture);
             $dir = dmOs::join($this->repo->getDir(), $type, $culture);
             $files = sfFinder::type('file')->name('/^\\d{2}\\s-\\s.+\\.markdown$/')->in($dir);
             foreach ($files as $file) {
                 $docName = preg_replace('/^\\d{2}\\s-\\s(.+)\\.markdown$/', '$1', basename($file));
                 $docRecord = dmDb::query('DocPage dp')->withI18n()->innerJoin('dp.Doc doc')->innerJoin('doc.Branch branch')->where('branch.number = ?', $branch)->andWhere('doc.type = ?', $type)->andWhere('dpTranslation.name = ?', $docName)->fetchOne();
                 if ($docRecord) {
                     $docText = file_get_contents($file);
                     if ($docRecord->text != $docText) {
                         $docRecord->text = $docText;
                         $docRecord->save();
                     }
                 }
             }
         }
     }
     sfDoctrineRecord::setDefaultCulture($originalCulture);
 }
Beispiel #5
0
 /**
  * @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()));
 }
Beispiel #6
0
 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 . '"'));
 }
Beispiel #7
0
 public function getFirstMedia()
 {
     if ($this->_invoker->contains($this->_options['mediaAlias'])) {
         return $this->_invoker->reference($this->_options['mediaAlias'])->getFirst();
     }
     return dmDb::query('DmMedia m, m.Folder f, m.' . $this->getGalleryRelClass() . ' rel')->where('rel.dm_record_id = ?', $this->_invoker->get('id'))->orderBy('rel.position ASC')->select('m.*, f.*')->fetchOne();
 }
Beispiel #8
0
 public function getPage()
 {
     if (null === $this->page) {
         $this->page = dmDb::table('DmPage')->findOneByIdWithI18n($this->pageId);
     }
     return $this->page;
 }
 protected function generateLayoutTemplates()
 {
     $this->logSection('diem', 'generate layout templates');
     $filesystem = $this->get('filesystem');
     foreach (dmDb::query('DmLayout l')->fetchRecords() as $layout) {
         $template = $layout->get('template');
         $templateFile = dmProject::rootify('apps/front/modules/dmFront/templates/' . $template . 'Success.php');
         if (!file_exists($templateFile)) {
             if ($filesystem->mkdir(dirname($templateFile))) {
                 $filesystem->copy(dmOs::join(sfConfig::get('dm_front_dir'), 'modules/dmFront/templates/pageSuccess.php'), $templateFile);
                 $filesystem->chmod($templateFile, 0777);
             } else {
                 $this->logBlock('Can NOT create layout template ' . $template, 'ERROR');
             }
         }
     }
     $layoutFile = dmProject::rootify('apps/front/modules/dmFront/templates/layout.php');
     if (!file_exists($layoutFile)) {
         if ($filesystem->mkdir(dirname($layoutFile))) {
             $filesystem->copy(dmOs::join(sfConfig::get('dm_front_dir'), 'modules/dmFront/templates/layout.php'), $layoutFile);
             $filesystem->chmod($layoutFile, 0777);
         } else {
             $this->logBlock('Can NOT create layout ' . $layoutFile, 'ERROR');
         }
     }
 }
Beispiel #10
0
 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();
 }
 /**
  * @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);
 }
Beispiel #12
0
 /**
  * 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();
 }
Beispiel #13
0
 protected function checkMissingAreas()
 {
     foreach (self::getAreaTypes() as $type) {
         if (!$this->getArea($type)) {
             $this->get('Areas')->add(dmDb::create('DmArea', array('dm_layout_id' => $this->get('id'), 'type' => $type))->saveGet());
         }
     }
 }
 /**
  * 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();
     }
 }
 public function executeShow()
 {
     $query = $this->getShowQuery('b');
     $this->branch = $this->getRecord($query);
     $this->tuto = dmDb::query('DocPage p')->withI18n()->leftJoin('p.Doc d')->where('d.type = ?', 'tuto')->orderBy('p.position ASC')->fetchOne();
     $this->howTo = dmDb::query('Doc d')->withI18n()->where('d.type = ?', 'howto')->fetchOne();
     $this->openSourceProjects = dmDb::query('DocPage p')->withI18n()->where('pTranslation.name = ?', 'Open source projects')->fetchOne();
 }
Beispiel #16
0
 public function getUser()
 {
     $userId = $this->get('user_id');
     if (!isset(self::$usersCache[$userId])) {
         self::$usersCache[$userId] = $userId ? dmDb::query('DmUser u')->where('u.id = ?', $userId)->fetchRecord() : null;
     }
     return self::$usersCache[$userId];
 }
 public function getGroupNames()
 {
     $groups = dmDb::query('DmSetting s')->select('s.group_name')->groupBy('s.group_name')->fetchPDO();
     foreach ($groups as $index => $group) {
         $groups[$index] = $group[0];
     }
     return $groups;
 }
 public function executeTest()
 {
     $widget = dmDb::query('DmWidget q')->withI18n()->where('q.id = ?', 272)->fetchOne();
     $widgetValue = $widget->value;
     $widget = $widget->toArray();
     $widget['value'] = $widgetValue;
     $this->html = $this->getService('page_helper')->renderWidget($widget);
 }
Beispiel #19
0
 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];
 }
Beispiel #20
0
 public function getLayout()
 {
     if (!($layout = $this->_get('Layout'))) {
         $layout = dmDb::table('DmLayout')->findFirstOrCreate();
         $this->set('Layout', $layout);
         $this->save();
     }
     return $layout;
 }
 public function findFirstOrCreate()
 {
     if (null === $this->firstLayout || !$this->firstLayout->exists()) {
         if (!($this->firstLayout = $this->createQuery()->fetchRecord())) {
             $this->firstLayout = dmDb::create('DmLayout', array('name' => 'Global'))->saveGet();
         }
     }
     return $this->firstLayout;
 }
Beispiel #22
0
 public function save(Doctrine_Connection $conn = null)
 {
     $wasNew = $this->isNew();
     $return = parent::save($conn);
     if ($wasNew && !$this->get('Zones')->count()) {
         dmDb::create('DmZone', array('dm_area_id' => $this->get('id')))->save();
         $this->refresh(true);
     }
 }
Beispiel #23
0
 /**
  * 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::create('DmMailTemplate', array('name' => $templateName));
     }
     return $this;
 }
Beispiel #24
0
 public function executeCurrentVersion(dmWebRequest $request)
 {
     if ($branch = $request->getParameter('branch')) {
         $version = dmDb::pdo('SELECT v.number FROM version v INNER JOIN branch b ON v.branch_id = b.id AND b.number = ? WHERE v.is_active = ? ORDER BY v.position ASC LIMIT 1', array(str_replace(array('_', '-'), '.', $branch), true))->fetchColumn();
     } else {
         $version = dmDb::pdo('SELECT v.number FROM version v WHERE v.is_active = ? ORDER BY v.position ASC LIMIT 1', array(true))->fetchColumn();
     }
     return $this->renderText($version);
 }
 /**
  * @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);
     }
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->withDatabase();
     foreach ($this->getModelFields() as $model => $implodedFields) {
         $fields = explode(' ', $implodedFields);
         foreach (dmDb::table($model)->findAll() as $record) {
             $this->replace($record, $fields);
         }
     }
 }
 protected function getGalleryRecord(dmWebRequest $request)
 {
     $this->forward404Unless($record = dmDb::table($request->getParameter('model'))->find($request->getParameter('pk')), 'Record not found');
     $this->forward404Unless($module = $record->getDmModule(), 'Module not found');
     $this->forwardSecureUnless($this->getUser()->canAccessToModule($module));
     if (!$record->getTable()->hasTemplate('DmGallery')) {
         throw new dmException($record . ' should act as DmGallery');
     }
     return $record;
 }
Beispiel #28
0
 /**
  * Processes the difference of the last snapshot and the current data
  *
  * an example:
  * Snapshot with the objects 1, 2 and 4
  * Current data with objects 2, 3 and 5
  *
  * The process would remove object 4
  * 
  * Diem alteration :
  * I never want translation records to be deleted.
  * It allows not to load all language translation
  * and to save a record without deleting all other translations
  *
  * @return Doctrine_Collection
  */
 public function processDiff()
 {
     if ($translationPos = strpos($this->_table->getComponentName(), 'Translation')) {
         $baseRecordClass = substr($this->_table->getComponentName(), 0, $translationPos);
         if ($baseTable = dmDb::table($baseRecordClass)) {
             return $this;
         }
     }
     return parent::processDiff();
 }
 public function executeMyAccount()
 {
     if ($this->user = $this->getUser()->getDmUser()) {
         $this->plugins = dmDb::query('Plugin p')->where('p.created_by = ?', $this->user->id)->andWhere('p.is_active = ?', true)->orderByPosition()->fetchRecords();
         $this->preloadPages($this->plugins);
     } else {
         $this->form = $this->forms['DmSigninFront'] = new DmSigninFrontForm();
         unset($this->form['remember_me']);
     }
 }
Beispiel #30
0
 /**
  *
  * @return boolean true if ok, false else
  */
 public function addRate(array $rateData)
 {
     if ($rate = $this->getRatesQuery()->addWhere('dm_user_id = ?', $rateData['dm_user_id'])->fetchOne()) {
         $rate->rate = $rateData['rate'];
     } else {
         $rate = dmDb::create($this->getDmRatable()->getOption('className'), $rateData);
         $rate->id = $this->getInvoker()->id;
     }
     $rate->save();
 }