/**
  * __construct
  *
  * @param string $options 
  * @return void
  */
 public function __construct(array $options = array())
 {
     $dispatcher = ProjectConfiguration::getActive()->getEventDispatcher();
     $dispatcher->connect('commentable.add_commentable_class', array($this, 'getCommentables'));
     $options['generatePath'] = sfConfig::get('sf_lib_dir') . '/model/doctrine/sfCommentsPlugin';
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
 }
 /**
  * Initialize the template
  * @return void
  */
 public function setUp()
 {
     // TODO: cache compiled options since they do not change frequently
     $options = $this->options;
     // merge in special soft delete options
     if ($this->getInvoker()->getTable()->hasTemplate('SoftDelete')) {
         $options = Doctrine_Lib::arrayDeepMerge($options, $this->optionsWhenSoftDeleteIsEnabled);
     }
     // merge in options defined in the schema
     $options = Doctrine_Lib::arrayDeepMerge($options, $this->_options);
     // merge in default options for credentials
     foreach ($options['credentials'] as $credential => $cOptions) {
         $options['credentials'][$credential] = array_merge($this->credentialOptions, $cOptions);
     }
     // merge in default options for fields
     foreach ($options['fields'] as $fieldName => $fieldOptions) {
         $fieldOptions = array_merge($this->fieldOptions, $fieldOptions);
         if (!is_string($fieldOptions['view']) && !is_null($fieldOptions['view']) && $fieldOptions['view'] !== false) {
             throw new InvalidArgumentException(sprintf('view credential has an invalid type for field %s.', $fieldName));
         }
         if (!is_string($fieldOptions['edit']) && !is_null($fieldOptions['edit']) && $fieldOptions['edit'] !== false) {
             throw new InvalidArgumentException(sprintf('edit credential has an invalid type for field %s.', $fieldName));
         }
         if (!is_string($fieldOptions['create']) && !is_null($fieldOptions['create']) && $fieldOptions['create'] !== false) {
             throw new InvalidArgumentException(sprintf('create credential has an invalid type for field %s.', $fieldName));
         }
         $options['fields'][$fieldName] = $fieldOptions;
     }
     $options['credentials'] = $this->copyRelationsToEachSide($options['credentials']);
     $this->options = $options;
 }
 public function __construct(array $options = array())
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     if (!isset($this->_options['connection'])) {
         $this->_options['connection'] = Doctrine_Manager::connection();
     }
 }
 public function __construct(array $options = array())
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     if (!$this->_options['onlyOwnable']) {
         $this->_plugin = new Doctrine_Guardable($this->_options);
     }
 }
 /**
  * Constructor for Locatable Template
  *
  * @param array $options
  *
  * @return void
  */
 public function __construct(array $options = array())
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     if (!$this->_options['fields']) {
         throw new sfException('The Geolocatable Behavior requires the "fields" option to be set in your schema');
     }
 }
 public function fill($name, $values = array())
 {
     $formValues = Doctrine_Lib::arrayDeepMerge($this->getFormValues($name), $values);
     foreach ($formValues as $key => $value) {
         $this->setDefaultField($key, $value);
     }
     return $this->getObjectToReturn();
 }
Beispiel #7
0
 /** 
  * setOption 
  * sets an option in order to allow flexible listener chaining 
  * 
  * @param mixed $name              the name of the option to set 
  * @param mixed $value              the value of the option 
  */
 public function setOption($name, $value = null)
 {
     if (is_array($name)) {
         $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $name);
     } else {
         $this->_options[$name] = $value;
     }
 }
 /**
  * __construct
  *
  * @param string $array
  * @return null
  */
 public function __construct(array $options = array())
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->getOptions(), $options);
     $this->invokerNamespace = sprintf('%s/%s', __CLASS__, sfCacheTaggingToolkit::generateVersion());
     $versionColumn = $this->getOption('versionColumn');
     if (!is_string($versionColumn) || 0 >= strlen($versionColumn)) {
         throw new sfConfigurationException(sprintf('sfCacheTaggingPlugin: "%s" behaviors "versionColumn" ' . 'should be string and not empty, passed "%s"', sfCacheTaggingToolkit::TEMPLATE_NAME, (string) $versionColumn));
     }
 }
Beispiel #9
0
 /**
  * __construct 
  * 
  * @param array $options 
  * @return void
  */
 public function __construct(array $options)
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     if (!isset($this->_options['analyzer'])) {
         $this->_options['analyzer'] = new Doctrine_Search_Analyzer_Standard();
     }
     if (!isset($this->_options['connection'])) {
         $this->_options['connection'] = Doctrine_Manager::connection();
     }
 }
Beispiel #10
0
 /**
  * __construct 
  * 
  * @param array $options 
  * @return void
  */
 public function __construct(array $options)
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     if (!isset($this->_options['analyzer'])) {
         $this->_options['analyzer'] = 'Doctrine_Search_Analyzer_Standard';
     }
     if (!isset($this->_options['analyzer_options'])) {
         $this->_options['analyzer_options'] = array();
     }
     $this->_options['analyzer'] = new $this->_options['analyzer']($this->_options['analyzer_options']);
 }
 /**
  * @param array $options
  *
  * options can contain:
  *
  *  - string   thumb_dir    The directory to create the thumbnails in (relative to the file's dirname)
  *  - boolean  on_demand    Whether to create or not thumbnails on demand
  *  - boolean  on_save      Whether to create or not thumbnails on save
  *  - boolean  strict       Whether to allow other formats than those in 'formats'
  *  - array    formats      Default formats to create for on_save
  *
  *  the 'formats' array should contain a list of formats per-field:
  *
  *  array(
  *    'media_id'    => array('50x50')
  *    'cover_image' => array('100x50')
  *  )
  */
 public function __construct(array $options = array())
 {
     if (!class_exists('sfThumbnail')) {
         throw new sfException('You need the sfThumbnailPlugin installed to use this template');
     }
     $app_config = array();
     if (isset($options['config_key'])) {
         if (null === ($app_config = sfConfig::get('app_' . $options['config_key'], null))) {
             throw new sfException(sprintf('Could not find configuration in key "%s", maybe you forget a ".plugins" in your app.yml ?', $options['config_key']));
         }
     }
     $this->options = Doctrine_Lib::arrayDeepMerge($this->options, $options, $app_config);
 }
 /**
  * Constructor for Markdown Template
  *
  * @param array $options 
  * @return void
  * @author Brent Shaffer
  */
 public function __construct(array $options = array())
 {
     if (!isset($options['fields'])) {
         throw new sfException("Required parameter 'fields' not set in Doctrine Markdown");
     }
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     // Set markdown field names if they are not set by the user
     foreach ($this->_options['fields'] as $key => $value) {
         if (is_int($key)) {
             unset($this->_options['fields'][$key]);
             $this->_options['fields'][$value . '_html'] = $value;
         }
     }
 }
  public function setRoutingValue(array $values)
  {
    $this->info('setting routing.yml config values');
      
    $path = sfConfig::get('sf_app_dir') . '/config/routing.yml';
        
    $config = Doctrine_Lib::arrayDeepMerge(sfYaml::load($path), $values);

    file_put_contents($path, sfYaml::dump($config));
    
    sfToolkit::clearDirectory(sfConfig::get('sf_cache_dir'));
    
    return $this;
  }
 public function joinForTableProxy(Doctrine_Query $q, array $options = array())
 {
     $options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     $q->getRootAlias();
     // fix for initialize root
     if (empty($options['parentTable'])) {
         $parentTable = $q->getRoot();
         $parentTableAlias = $q->getRootAlias();
     } else {
         $parentTable = Doctrine::getTable($options['parentTable']);
         $parentTableAlias = empty($options['parentTableAlias']) ? $q->getSqlTableAlias(sfInflector::tableize($options['parentTable'])) : $options['parentTableAlias'];
     }
     if (!empty($options['componentAlias'])) {
         $componentAlias = $options['componentAlias'];
     } elseif ($parentTable->hasRelation($this->_table->getComponentName())) {
         $componentAlias = $this->_table->getComponentName();
     } else {
         $componentName = $this->_table->getComponentName();
         $relations = $parentTable->getRelations();
         foreach ($relations as $relation) {
             if ($relation['class'] == $componentName) {
                 $componentAlias = $relation['alias'];
                 break;
             }
         }
     }
     $tableAlias = empty($options['tableAlias']) ? $this->_table->getAlias() : $options['tableAlias'];
     $q->addSqlTableAlias($tableAlias, sfInflector::tableize($this->_table->getComponentName()));
     $q->leftJoin($parentTableAlias . '.' . $componentAlias . ' ' . $tableAlias);
     if ($options['withI18n'] == true && $this->_table->hasTemplate('Doctrine_Template_I18nMod')) {
         $cultures = empty($options['cultures']) ? sfContext::getInstance()->getUser()->getCulture() : $options['cultures'];
         $chunkWith = implode(' AND ', array_fill(0, count($cultures), ' ' . $tableAlias . '_trans.lang = ? '));
         $q->leftJoin($tableAlias . '.Translation ' . $tableAlias . '_trans WITH ' . $chunkWith, $cultures);
     }
     return $q;
 }
Beispiel #15
0
 /**
  * _processInheritance
  * 
  * Perform some processing on inheritance.
  * Sets the default type and sets some default values for certain types
  *
  * @param string $array 
  * @return void
  */
 protected function _processInheritance($array)
 {
     // Apply default inheritance configuration
     foreach ($array as $className => $definition) {
         if (!empty($array[$className]['inheritance'])) {
             $this->_validateSchemaElement('inheritance', array_keys($definition['inheritance']), $className . '->inheritance');
             // Default inheritance to concrete inheritance
             if (!isset($array[$className]['inheritance']['type'])) {
                 $array[$className]['inheritance']['type'] = 'concrete';
             }
             // Some magic for setting up the keyField and keyValue column aggregation options
             // Adds keyField to the parent class automatically
             if ($array[$className]['inheritance']['type'] == 'column_aggregation') {
                 // Set the keyField to 'type' by default
                 if (!isset($array[$className]['inheritance']['keyField'])) {
                     $array[$className]['inheritance']['keyField'] = 'type';
                 }
                 // Set the keyValue to the name of the child class if it does not exist
                 if (!isset($array[$className]['inheritance']['keyValue'])) {
                     $array[$className]['inheritance']['keyValue'] = $className;
                 }
                 $parent = $this->_findBaseSuperClass($array, $definition['className']);
                 // Add the keyType column to the parent if a definition does not already exist
                 if (!isset($array[$parent]['columns'][$array[$className]['inheritance']['keyField']])) {
                     $array[$parent]['columns'][$array[$className]['inheritance']['keyField']] = array('name' => $array[$className]['inheritance']['keyField'], 'type' => 'string', 'length' => 255);
                 }
             }
         }
     }
     // Array of the array keys to move to the parent, and the value to default the child definition to
     // after moving it. Will also populate the subclasses array for the inheritance parent
     $moves = array('columns' => array(), 'indexes' => array(), 'attributes' => array(), 'options' => array(), 'checks' => array());
     foreach ($array as $className => $definition) {
         // Move any definitions on the schema to the parent
         if (isset($definition['inheritance']['extends']) && isset($definition['inheritance']['type']) && ($definition['inheritance']['type'] == 'simple' || $definition['inheritance']['type'] == 'column_aggregation')) {
             $parent = $this->_findBaseSuperClass($array, $definition['className']);
             foreach ($moves as $move => $resetValue) {
                 if (isset($array[$parent][$move]) && isset($definition[$move])) {
                     $array[$parent][$move] = Doctrine_Lib::arrayDeepMerge($array[$parent][$move], $definition[$move]);
                     $array[$definition['className']][$move] = $resetValue;
                 }
             }
             // Populate the parents subclasses
             if ($definition['inheritance']['type'] == 'column_aggregation') {
                 // Fix for 2015: loop through superclasses' inheritance to the base-superclass to
                 // make sure we collect all keyFields needed (and not only the first)
                 $inheritanceFields = array($definition['inheritance']['keyField'] => $definition['inheritance']['keyValue']);
                 $superClass = $definition['inheritance']['extends'];
                 $multiInheritanceDef = $array[$superClass];
                 while (count($multiInheritanceDef['inheritance']) > 0 && array_key_exists('extends', $multiInheritanceDef['inheritance']) && $multiInheritanceDef['inheritance']['type'] == 'column_aggregation') {
                     $superClass = $multiInheritanceDef['inheritance']['extends'];
                     // keep original keyField with it's keyValue
                     if (!isset($inheritanceFields[$multiInheritanceDef['inheritance']['keyField']])) {
                         $inheritanceFields[$multiInheritanceDef['inheritance']['keyField']] = $multiInheritanceDef['inheritance']['keyValue'];
                     }
                     $multiInheritanceDef = $array[$superClass];
                 }
                 $array[$parent]['inheritance']['subclasses'][$definition['className']] = $inheritanceFields;
             }
         }
     }
     return $array;
 }
Beispiel #16
0
 /**
  * _processInheritance
  * 
  * Perform some processing on inheritance.
  * Sets the default type and sets some default values for certain types
  *
  * @param string $array 
  * @return void
  */
 protected function _processInheritance($array)
 {
     // Apply default inheritance configuration
     foreach ($array as $className => $definition) {
         if (!empty($array[$className]['inheritance'])) {
             $this->_validateSchemaElement('inheritance', array_keys($definition['inheritance']));
             // Default inheritance to concrete inheritance
             if (!isset($array[$className]['inheritance']['type'])) {
                 $array[$className]['inheritance']['type'] = 'concrete';
             }
             // Some magic for setting up the keyField and keyValue column aggregation options
             // Adds keyField to the parent class automatically
             if ($array[$className]['inheritance']['type'] == 'column_aggregation') {
                 // Set the keyField to 'type' by default
                 if (!isset($array[$className]['inheritance']['keyField'])) {
                     $array[$className]['inheritance']['keyField'] = 'type';
                 }
                 // Set the keyValue to the name of the child class if it does not exist
                 if (!isset($array[$className]['inheritance']['keyValue'])) {
                     $array[$className]['inheritance']['keyValue'] = $className;
                 }
                 // Add the keyType column to the parent if a definition does not already exist
                 if (!isset($array[$array[$className]['inheritance']['extends']]['columns']['type'])) {
                     $array[$definition['inheritance']['extends']]['columns'][$array[$className]['inheritance']['keyField']] = array('name' => $array[$className]['inheritance']['keyField'], 'type' => 'string', 'length' => 255);
                 }
             }
         }
     }
     // Array of the array keys to move to the parent, and the value to default the child definition to
     // after moving it. Will also populate the subclasses array for the inheritance parent
     $moves = array('columns' => array());
     foreach ($array as $className => $definition) {
         // Move any definitions on the schema to the parent
         if (isset($definition['inheritance']['extends']) && isset($definition['inheritance']['type']) && ($definition['inheritance']['type'] == 'simple' || $definition['inheritance']['type'] == 'column_aggregation')) {
             $extends = $definition['inheritance']['extends'];
             foreach ($moves as $move => $resetValue) {
                 $array[$extends][$move] = Doctrine_Lib::arrayDeepMerge($array[$extends][$move], $definition[$move]);
                 $array[$definition['className']][$move] = $resetValue;
             }
             // Populate the parents subclasses
             if ($definition['inheritance']['type'] == 'column_aggregation') {
                 $array[$extends]['inheritance']['subclasses'][$definition['className']] = array($definition['inheritance']['keyField'] => $definition['inheritance']['keyValue']);
             }
         }
     }
     return $array;
 }
Beispiel #17
0
 public function __construct(array $options = array())
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     $this->_plugin = new Doctrine_Taggable($this->_options);
 }
 /**
  * Add our extended options before continuing with normal processing.
  * 
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $this->_extendedOptions);
     parent::__construct($options);
 }
 function __construct($conversions = array())
 {
     $this->_conversions = Doctrine_Lib::arrayDeepMerge($this->_conversions, $conversions);
 }
  protected function compile($configs)
  {
    $depth = array(1 => array('list', 'filter', 'form', 'edit', 'show', 'new', 'export'), 2 => array('actions', 'fields'));
    $this->table   = Doctrine_Core::getTable($this->getOptionValue('model_class'));
    $configuration = $this->arrayDeepMerge($this->getDefaultConfiguration(), $configs, $depth);

    // Default values for list display
    if ($configuration['list']['display'] === true) {
      $configuration['list']['display'] = array_slice($this->getAllFieldNames(false), 0, 5);
    }

    // Default values for show display
    if ($configuration['show']['display'] === true) {
      $configuration['show']['display'] = $this->getAllFieldNames(false);
    }

    // Default values for export display
    if ($configuration['export']['display'] === true) {
      $configuration['export']['display'] = $this->getAllFieldNames(false);
    }

    // create "sfHadoriField" object from supplied options for all configurations of type "field"
    foreach ($configuration as $context => $config) {
      if (isset($config['display'])) {
        $display = array();
        foreach ($configuration[$context]['display'] as $key => $options) {
          $name = is_string($key) ? $key : (string) $options;

          // Merge in options if the field is defined in "fields"
          $options = isset($configuration['fields'][$name]) ? array_merge($configuration['fields'][$name], (array)$options) : $options;
          $display[$name] = $this->createFieldFromOptions($name, $options);
        }
        $configuration[$context]['display'] = $display;
      }
    }

    // merge in default "actions" configuration
    foreach ($configuration as $context => $config) {
      if (is_array($config)) {
        foreach ($config as $actionType => $value) {
          if (strpos($actionType, 'actions') !== false) {

            // if action names are set as values (i.e. [edit, new, save]) change them to values
            $configuredActions = array();
            foreach ($value as $action => $options) {
              if (is_int($action) && is_string($options)) {
                $configuredActions[(string)$options] = null;
              } else {
                $configuredActions[$action] = $options;
              }
            }

            // Merge in actions for configurations defined in "actions"
            $actions = Doctrine_Lib::arrayDeepMerge(array_intersect_key($configuration['actions'], $configuredActions), $this->filterNullValues($configuredActions));

            // set "label" and "action" if not set in configuration
            foreach ($actions as $actionName => $actionConfig) {
              $actions[$actionName] = $this->getActionsConfig($actionName, $actionConfig);
            }

            // set "credentials" if security.yml is defined and "use_security_yaml_credentials" is true
            if ($this->loadSecurityCredentials()) {
              foreach ($actions as $actionName => $actionConfig) {
                $actions[$actionName] = $this->addSecurityCredentials($actionName, $actionConfig);
              }
            }

            $configuration[$context][$actionType] = $actions;
          }
        }
      }
    }

    $this->configuration = $configuration;

    // unset export if export is disabled
    if (!$this->hasExporting()) {
      unset($this->configuration['list']['actions']['export']);
    }
  }
Beispiel #21
0
 public function __construct(array $options = array())
 {
     $this->_options = array('author_name' => 'author_name', 'author_email' => 'author_email', 'author_url' => 'author_url', 'content' => 'content');
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
 }
Beispiel #22
0
 /**
  * __construct
  *
  * @param string $array
  * @return void
  */
 public function __construct(array $options = array())
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
 }
 /**
  * __construct
  *
  * @param string $array
  * @return void
  */
 public function __construct(array $options = array())
 {
     $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
     $this->_options['owner_table'] = Doctrine::getTable($this->_options['owner_component']);
     $this->_plugin = new Doctrine_Rating($this->_options);
 }