コード例 #1
0
 /**
  * Implementation of filterSet() to call set on Translation relationship to allow
  * access to I18n properties from the main object.
  *
  * @param Doctrine_Record $record
  * @param string $name Name of the property
  * @param string $value Value of the property
  * @return void
  */
 public function filterSet(Doctrine_Record $record, $fieldName, $value)
 {
     $translation = $record->get('Translation');
     $culture = myDoctrineRecord::getDefaultCulture();
     if ($translation->contains($culture)) {
         $i18n = $record->get('Translation')->get($culture);
     } else {
         $i18n = $record->get('Translation')->get($culture);
         /*
          * If translation is new
          * populate it with i18n fallback
          */
         if ($i18n->state() == Doctrine_Record::STATE_TDIRTY) {
             if ($fallback = $record->getI18nFallBack()) {
                 $fallBackData = $fallback->toArray();
                 unset($fallBackData['id'], $fallBackData['lang']);
                 $i18n->fromArray($fallBackData);
             }
         }
     }
     if (!ctype_lower($fieldName) && !$i18n->contains($fieldName)) {
         $underscoredFieldName = dmString::underscore($fieldName);
         if (strpos($underscoredFieldName, '_') !== false && $i18n->contains($underscoredFieldName)) {
             $fieldName = $underscoredFieldName;
         }
     }
     $i18n->set($fieldName, $value);
     return $value;
 }
コード例 #2
0
ファイル: dmForm.php プロジェクト: vjousse/diem
 public function setup()
 {
     parent::setup();
     $this->widgetSchema->setFormFormatterName('dmList');
     $this->key = 'dm_form_' . self::$counter++;
     $this->setName(dmString::underscore(get_class($this)));
 }
コード例 #3
0
ファイル: dmFrontTestFunctional.php プロジェクト: jdart/diem
 public function addWidget(DmZone $zone, $moduleAction)
 {
     list($module, $action) = explode('/', $moduleAction);
     $this->info('Add a ' . $moduleAction . ' widget')->get(sprintf('/index.php/+/dmWidget/add?to_dm_zone=%d&mod=' . $module . '&act=' . $action . '&dm_cpi=%d', $zone->id, $this->getPage()->id))->checks(array('module_action' => 'dmWidget/add', 'method' => 'get'))->has('.dm_widget.' . str_replace('dm_widget_', '', dmString::underscore($module)) . '.' . dmString::underscore($action));
     $zone->refreshRelated('Widgets');
     return $this;
 }
コード例 #4
0
 public function execute(Doctrine_Connection $connection, $arguments = array(), $options = array())
 {
     $adapter = $this->getAdapter($connection);
     $infos = $adapter->getInfos();
     $infos['tag'] = dmString::underscore(dmOs::sanitizeFileName($options['tag']));
     $file = $this->getFile($infos);
     $this->log(sprintf('About to backup %s@%s to %s', $infos['name'], $infos['host'], $file));
     $this->createDir();
     $adapter->execute($file);
     $this->log('Done.');
 }
コード例 #5
0
ファイル: DmPageFrontEditForm.php プロジェクト: theolymp/diem
 public function checkModuleAction($validator, $values)
 {
     if (!empty($values['module']) && !empty($values['action'])) {
         foreach (array('module', 'action') as $key) {
             $values[$key] = dmString::modulize(str_replace('-', '_', dmString::slugify(dmString::underscore($values[$key]))));
         }
         $existingPage = dmDb::query('DmPage p')->where('p.module = ? AND p.action = ? and p.record_id = ? AND p.id != ?', array($values['module'], $values['action'], $this->object->record_id, $this->object->id))->fetchRecord();
         if ($existingPage) {
             $error = new sfValidatorError($validator, $this->getI18n()->__('The page "%1%" uses this module.action', array('%1%' => $existingPage->name)));
             // throw an error bound to the password field
             throw new sfValidatorErrorSchema($validator, array('action' => $error));
         }
     }
     return $values;
 }
コード例 #6
0
ファイル: dmFormDoctrine.php プロジェクト: jwegner/diem
 /**
  * @return dmFormDoctrine
  */
 protected function setupNestedSet()
 {
     if ($this->object instanceof sfDoctrineRecord && $this->object->getTable() instanceof myDoctrineTable) {
         // unset NestedSet columns not needed as added in the getAutoFieldsToUnset() method
         $this->updateNestedSetWidget($this->object->getTable(), 'nested_set_parent_id', 'Child of');
         // check all relations for NestedSet
         foreach ($this->object->getTable()->getRelationHolder()->getAll() as $relation) {
             if ($relation->getTable() instanceof dmDoctrineTable && $relation->getTable()->isNestedSet()) {
                 // check for many to many
                 $fieldName = $relation->getType() ? dmString::underscore($relation->getAlias()) . '_list' : $relation->getLocalColumnName();
                 $this->updateNestedSetWidget($relation->getTable(), $fieldName);
             }
         }
     }
     return $this;
 }
コード例 #7
0
 /**
  * Returns the default configuration for fields.
  *
  * @return array An array of default configuration for all fields
  */
 public function getDefaultFieldsConfiguration()
 {
     $fields = array();
     $names = array();
     foreach ($this->getColumns() as $name => $column) {
         $names[] = $name;
         if ($localRelation = $this->table->getRelationHolder()->getLocalByColumnName($name)) {
             $label = dmString::humanize($localRelation->getAlias());
         } else {
             $label = dmString::humanize($name);
         }
         $fields[$name] = array_merge(array('is_link' => (bool) $column->isPrimaryKey(), 'is_real' => true, 'is_partial' => false, 'is_component' => false, 'type' => $this->getType($column), 'markdown' => $this->module->getTable()->isMarkdownColumn($name), 'label' => $label), isset($this->config['fields'][$name]) ? $this->config['fields'][$name] : array());
     }
     foreach ($this->getManyToManyTables() as $relation) {
         $name = dmString::underscore($relation->getAlias()) . '_list';
         $names[] = $name;
         $module = $this->moduleManager->getModuleByModel($relation->getClass());
         $fields[$name] = array_merge(array('is_link' => false, 'is_real' => false, 'is_partial' => false, 'is_component' => false, 'type' => 'Text', 'label' => $module ? $module->getPlural() : dmString::humanize($relation->getAlias())), isset($this->config['fields'][$name]) ? $this->config['fields'][$name] : array());
     }
     foreach ($this->table->getRelationHolder()->getForeigns() as $alias => $relation) {
         if ($this->moduleManager->getModuleByModel($relation->getClass())) {
             $name = dmString::underscore($alias) . '_list';
             $names[] = $name;
             $fields[$name] = array_merge(array('is_link' => false, 'is_real' => false, 'is_partial' => false, 'is_component' => false, 'type' => 'Text', 'label' => $this->moduleManager->getModuleByModel($relation->getClass())->getPlural()), isset($this->config['fields'][$name]) ? $this->config['fields'][$name] : array());
         }
     }
     foreach ($this->table->getRelationHolder()->getLocalMedias() as $alias => $relation) {
         $name = $relation->getLocal() . '_form';
         $names[] = $name;
         $fields[$name] = array_merge(array('label' => $alias, 'is_real' => false, 'type' => 'Text'), isset($this->config['fields'][$name]) ? $this->config['fields'][$name] : array());
     }
     if (isset($this->config['fields'])) {
         foreach ($this->config['fields'] as $name => $params) {
             if (in_array($name, $names)) {
                 continue;
             }
             $fields[$name] = array_merge(array('is_link' => false, 'is_real' => false, 'is_partial' => false, 'is_component' => false, 'type' => 'Text'), is_array($params) ? $params : array());
         }
     }
     unset($this->config['fields']);
     return $fields;
 }
コード例 #8
0
 protected function fixModuleConfig($moduleKey, $moduleConfig, $isInContent)
 {
     /*
      * Extract plural from name
      * name | plural
      */
     if (!empty($moduleConfig['name'])) {
         if (strpos($moduleConfig['name'], '|')) {
             list($moduleConfig['name'], $moduleConfig['plural']) = explode('|', $moduleConfig['name']);
         }
     } else {
         $moduleConfig['name'] = dmString::humanize($moduleKey);
     }
     if (empty($moduleConfig['model'])) {
         $candidateModel = dmString::camelize($moduleKey);
         $model = class_exists('Base' . $candidateModel, true) ? Doctrine_Core::isValidModelClass($candidateModel) ? $candidateModel : false : false;
     } else {
         $model = $moduleConfig['model'];
     }
     // BC "actions" deprecated keyword becomes "components"
     if (isset($moduleConfig['actions'])) {
         $moduleConfig['components'] = $moduleConfig['actions'];
         unset($moduleConfig['actions']);
     }
     //security features
     $securityConfig = $this->fixSecurityConfig($moduleKey, $moduleConfig);
     $moduleOptions = array('name' => (string) trim($moduleConfig['name']), 'plural' => (string) trim(empty($moduleConfig['plural']) ? $model ? dmString::pluralize($moduleConfig['name']) : $moduleConfig['name'] : $moduleConfig['plural']), 'model' => $model, 'credentials' => isset($moduleConfig['credentials']) ? is_string($moduleConfig['credentials']) ? trim($moduleConfig['credentials']) : (is_array($moduleConfig['credentials']) ? $moduleConfig['credentials'] : '') : ((bool) $isInContent ? 'content' : null), 'underscore' => (string) dmString::underscore($moduleKey), 'is_project' => (bool) $isInContent || dmArray::get($moduleConfig, 'page', false) || count(dmArray::get($moduleConfig, 'components', array())), 'plugin' => $moduleConfig['plugin'], 'overridden' => dmArray::get($moduleConfig, 'overridden', false), 'has_admin' => (bool) dmArray::get($moduleConfig, 'admin', $model || !$isInContent), 'has_front' => (bool) dmArray::get($moduleConfig, 'front', true), 'components' => dmArray::get($moduleConfig, 'components', array()), 'has_security' => is_array($securityConfig), 'security' => $securityConfig, 'i18n_catalogue' => isset($moduleConfig['i18n_catalogue']) ? $moduleConfig['i18n_catalogue'] : sfConfig::get('dm_i18n_catalogue'));
     if ($moduleOptions['is_project']) {
         $moduleOptions = array_merge($moduleOptions, array('parent_key' => dmArray::get($moduleConfig, 'parent') ? dmString::modulize(trim(dmArray::get($moduleConfig, 'parent'))) : null, 'has_page' => (bool) dmArray::get($moduleConfig, 'page', false)));
     }
     // fix non array action filters
     foreach ($moduleOptions['components'] as $componentKey => $componentConfig) {
         if (is_array($componentConfig) && array_key_exists('filters', $componentConfig) && !is_array($componentConfig['filters'])) {
             $moduleOptions['components'][$componentKey]['filters'] = array($componentConfig['filters']);
         }
     }
     return $moduleOptions;
 }
コード例 #9
0
 /**
  * Utility function
  * Renders the form for the behavior edit
  * @param dmBehaviorBaseForm $form
  * @param dmBehaviorsManager $behaviorsManager
  * @param boolean $withCopyActions
  * @return rendered form
  */
 protected function renderEdit(dmBehaviorBaseForm $form, $behaviorsManager, $withCopyActions = true)
 {
     $helper = $this->getHelper();
     $copyActions = '';
     if ($withCopyActions && $this->getUser()->can('behavior_add')) {
         $copyActions .= $helper->tag('div.dm_cut_copy_actions.none', ($this->getUser()->can('behavior_delete') ? $helper->link('+/dmBehaviors/cut')->param('dm_behavior_id', $form->getDmBehavior()->get('id'))->text('')->title($this->getI18n()->__('Cut'))->set('.s16block.s16_cut.dm_behavior_cut') : '') . $helper->link('+/dmBehaviors/copy')->param('dm_behavior_id', $form->getDmBehavior()->get('id'))->text('')->title($this->getI18n()->__('Copy'))->set('.s16block.s16_copy.dm_behavior_copy'));
     }
     return $helper->tag('div.dm.dm_behavior_edit.dm_behavior_edit_form.' . dmString::underscore($form->getDmBehavior()->get('dm_behavior_key')) . '_form', array('json' => array('form_class' => $behaviorsManager->getBehaviorFormClass($form->getDmBehavior()->get('dm_behavior_key')), 'form_name' => $form->getName())), $form->render('.dm_form.list.little') . $copyActions);
 }
コード例 #10
0
 protected function renderEdit(dmWidgetBaseForm $form, dmWidgetType $widgetType, $withCopyActions = true)
 {
     $helper = $this->getHelper();
     $devActions = '';
     if ($this->getUser()->can('code_editor') && $form instanceof dmWidgetProjectForm) {
         $templateDir = dmOs::join(sfConfig::get('sf_app_module_dir'), $form->getDmModule()->getKey(), 'templates', '_' . $form->getDmComponent()->getKey() . '.php');
         if (file_exists($templateDir)) {
             $devActions .= '<a href="#' . dmProject::unRootify($templateDir) . '" class="code_editor s16 s16_code_editor block">' . $this->getI18n()->__('Edit template code') . '</a>';
         }
         $componentDir = dmOs::join(sfConfig::get('sf_app_module_dir'), $form->getDmModule()->getKey(), 'actions/components.class.php');
         if (file_exists($componentDir)) {
             $devActions .= '<a href="#' . dmProject::unRootify($componentDir) . '" class="code_editor s16 s16_code_editor block">' . $this->getI18n()->__('Edit component code') . '</a>';
         }
     }
     if ($devActions) {
         $devActions = '<div class="code_editor_links">' . $devActions . '</div>';
     }
     $copyActions = '';
     if ($withCopyActions && $this->getUser()->can('widget_add')) {
         $copyActions = $helper->tag('div.dm_cut_copy_actions.none', $helper->link('+/dmWidget/cut')->param('widget_id', $form->getDmWidget()->get('id'))->text('')->title($this->getI18n()->__('Cut'))->set('.s16block.s16_cut.dm_widget_cut') . $helper->link('+/dmWidget/copy')->param('widget_id', $form->getDmWidget()->get('id'))->text('')->title($this->getI18n()->__('Copy'))->set('.s16block.s16_copy.dm_widget_copy'));
     }
     return $helper->tag('div.dm.dm_widget_edit.' . dmString::underscore($widgetType->getFullKey()) . '_form', array('json' => array('form_class' => $widgetType->getFullKey() . 'Form', 'form_name' => $form->getName())), $form->render('.dm_form.list.little') . $devActions . $copyActions);
 }
コード例 #11
0
ファイル: installer.php プロジェクト: jdart/diem
 */
$settings = array();
if ('Doctrine' != $this->options['orm']) {
    throw new Exception('We are sorry, but Diem ' . DIEM_VERSION . ' supports only Doctrine for ORM.');
}
$projectKey = dmProject::getKey();
/*
 * QUESTIONS
 */
$this->logSection($projectKey, 'Please answer a few questions to configure the ' . $projectKey . ' project' . "\n");
$culture = $this->askAndValidate(array('', 'Choose your site\'s main language ( default: en )', ''), new sfValidatorRegex(array('pattern' => '/^[\\w\\d-]+$/', 'max_length' => 2, 'min_length' => 2, 'required' => false), array('invalid' => 'Language must contain two alphanumeric characters')));
$settings['culture'] = empty($culture) ? 'en' : $culture;
$webDirName = $this->askAndValidate(array('', 'Choose a web directory name ( examples: web, html, public_html;  default: web )', ''), new sfValidatorAnd(array(new sfValidatorRegex(array('pattern' => '/^[\\w\\d-]+$/', 'required' => false), array('invalid' => 'Web directory name must contain only alphanumeric characters')), new sfValidatorRegex(array('pattern' => '/^(apps|lib|config|data|cache|log|plugins|test)$/', 'must_match' => false, 'required' => false), array('invalid' => 'This directory name is already used by symfony'))), array('required' => false)), array('required' => false));
$settings['web_dir_name'] = empty($webDirName) ? 'web' : $webDirName;
do {
    $defaultDbName = dmString::underscore(str_replace('-', '_', $projectKey));
    $isDatabaseOk = false;
    $dbm = $this->askAndValidate(array('', 'What kind of database will be used? ( mysql | pgsql | sqlite )', ''), new sfValidatorChoice(array('choices' => array('mysql', 'pgsql', 'sqlite'))));
    if ('sqlite' !== $dbm) {
        $settings['database'] = array('name' => $this->ask(array('', 'What is the database name? ( default: ' . $defaultDbName . ' )', ''), 'QUESTION', $defaultDbName), 'host' => $this->ask(array('', 'What is the database host? ( default: localhost )', ''), 'QUESTION', 'localhost', ''), 'user' => $this->ask(array('', 'What is the database user?', '')), 'password' => $this->ask(array('', 'What is the database password?', '')));
    } else {
        $settings['database'] = array('name' => $defaultDbName, 'user' => null, 'password' => null);
    }
    switch ($dbm) {
        case "mysql":
            $settings['database']['dsn'] = sprintf('mysql:host=%s;dbname=%s;', $settings['database']['host'], $settings['database']['name']);
            break;
        case "pgsql":
            $settings['database']['dsn'] = sprintf('pgsql:host=%s;dbname=%s;', $settings['database']['host'], $settings['database']['name'], $settings['database']['user'], $settings['database']['password']);
            break;
        case "sqlite":
コード例 #12
0
 protected function getFormFields()
 {
     $fields = array();
     /*
      * Add is_link options
      */
     foreach ($this->getStringFields() as $stringField) {
         if ($this->table->isLinkColumn($stringField)) {
             $fields[dmString::underscore($stringField)] = array('is_link' => true, 'help' => 'Drag & drop a page here from the PAGES panel, or write an url');
         }
     }
     return $fields;
 }
コード例 #13
0
ファイル: dmModuleComponent.php プロジェクト: theolymp/diem
 public function getUnderscore()
 {
     return dmString::underscore($this->getKey());
 }
コード例 #14
0
ファイル: dmFrontPageBaseHelper.php プロジェクト: jdart/diem
 protected function getWidgetCssClassFromPattern(array $widget)
 {
     $pattern = $this->getOption('widget_css_class_pattern');
     if (empty($pattern)) {
         return '';
     }
     return strtr($pattern, array('%module%' => str_replace('dm_widget_', '', dmString::underscore($widget['module'])), '%action%' => dmString::underscore($widget['action'])));
 }
コード例 #15
0
ファイル: dmDoctrineRecord.php プロジェクト: jdart/diem
 /**
  * Allow to set values by modulized fieldName
  * ex : _get('cssClass') returns _get('css_class')
  */
 public function _set($fieldName, $value, $load = true)
 {
     if (!ctype_lower($fieldName) && !ctype_upper($fieldName[0]) && !$this->contains($fieldName)) {
         $underscoredFieldName = dmString::underscore($fieldName);
         if (strpos($underscoredFieldName, '_') !== false && $this->contains($underscoredFieldName)) {
             return parent::_set($underscoredFieldName, $value, $load);
         }
     }
     return parent::_set($fieldName, $value, $load);
 }
コード例 #16
0
 public function renderWidget(array $widget, $executeWidgetAction = false)
 {
     if ($executeWidgetAction) {
         $this->executeWidgetAction($widget);
     }
     //it the widget is called programmatically, it has no id and can not be edited
     if (!isset($widget['id'])) {
         $widget['id'] = 'programmatically_' . substr(md5(serialize($widget)), 0, 6);
         // give a unique id
         $is_programmatically = true;
     } else {
         $is_programmatically = false;
     }
     list($widgetWrapClass, $widgetInnerClass) = $this->getWidgetContainerClasses($widget);
     /*
      * Open widget wrap with wrapped user's classes
      */
     $html = '<div class="' . $widgetWrapClass . '" id="dm_widget_' . $widget['id'] . '">';
     if (!$is_programmatically) {
         /*
          * Add edit button if required
          */
         if ($this->user->can('widget_edit')) {
             try {
                 $widgetPublicName = $this->serviceContainer->getService('widget_type_manager')->getWidgetType($widget)->getPublicName();
             } catch (Exception $e) {
                 $widgetPublicName = $widget['module'] . '.' . $widget['action'];
             }
             $title = $this->i18n->__('Edit this %1%', array('%1%' => $this->i18n->__($widgetPublicName)));
             $html .= '<a class="dm dm_widget_edit" title="' . htmlentities($title, ENT_COMPAT, 'UTF-8') . '"></a>';
         }
         /*
          * Add fast record edit button if required
          */
         if ('show' === $widget['action'] && $this->user->can('widget_edit_fast') && $this->user->can('widget_edit_fast_record')) {
             if ($module = $this->moduleManager->getModuleOrNull($widget['module'])) {
                 if ($module->hasModel()) {
                     $html .= sprintf('<a class="dm dm_widget_record_edit" title="%s"></a>', $this->i18n->__('Edit this %1%', array('%1%' => $this->i18n->__($module->getName()))), $widget['id']);
                 }
             }
         } elseif (!$this->user->can('widget_edit') && $this->user->can('widget_edit_fast')) {
             $fastEditPermission = 'widget_edit_fast_' . dmString::underscore(str_replace('dmWidget', '', $widget['module'])) . '_' . $widget['action'];
             if ($this->user->can($fastEditPermission)) {
                 try {
                     $widgetPublicName = $this->serviceContainer->getService('widget_type_manager')->getWidgetType($widget)->getPublicName();
                 } catch (Exception $e) {
                     $widgetPublicName = $widget['module'] . '.' . $widget['action'];
                 }
                 $html .= sprintf('<a class="dm dm_widget_fast_edit" title="%s"></a>', $this->i18n->__('Edit this %1%', array('%1%' => $this->i18n->__(dmString::lcfirst($widgetPublicName)))), $widget['id']);
             }
         }
     }
     /*
      * Open widget inner with user's classes
      */
     $html .= '<div class="' . $widgetInnerClass . '">';
     /*
      * get widget inner content
      */
     $html .= $this->renderWidgetInner($widget);
     /*
      * Close widget inner
      */
     $html .= '</div>';
     /*
      * Close widget wrap
      */
     $html .= '</div>';
     return $html;
 }
コード例 #17
0
ファイル: dmDoctrineRecord.php プロジェクト: theolymp/diem
 /**
  * Allow to set values by modulized fieldName
  * ex : _get('cssClass') returns _get('css_class')
  */
 public function _set($fieldName, $value, $load = true)
 {
     if (!ctype_lower($fieldName) && !ctype_upper($fieldName[0]) && !$this->contains($fieldName)) {
         $underscoredFieldName = dmString::underscore($fieldName);
         if (strpos($underscoredFieldName, '_') !== false && $this->contains($underscoredFieldName)) {
             return parent::_set($underscoredFieldName, $value, $load);
             //why it was not return'ing from here ?
             //calling parent::_set($fieldName, ...) will always causes throwing an error
         }
     }
     parent::_set($fieldName, $value, $load);
     return $this;
 }