protected function getOptionsForSelect($value, $choices)
 {
     $choices = dmArray::valueToKey($value ? $value : $choices);
     $html = parent::getOptionsForSelect($choices, $choices);
     // fcbkcomplete wants a class selected
     $html = str_replace('selected="selected"', 'class="selected"', $html);
     return $html;
 }
 protected function getFormDisplay()
 {
     $fields = dmArray::valueToKey(array_diff($this->table->getAllColumnNames(), array_unique(array_merge($this->getFormExcludedFields(), $this->table->getPrimaryKeys(), array_keys((array) $this->table->getOption('inheritanceMap'))))));
     /*
      * Remove media fields not to see them in foreigns fields
      */
     foreach ($this->table->getRelationHolder()->getLocalMedias() as $alias => $relation) {
         if (in_array($relation['local'], $fields)) {
             unset($fields[$relation['local']]);
         }
     }
     $sets = array();
     $sets['NONE'] = array();
     if (in_array($this->table->getIdentifierColumnName(), $fields)) {
         if ('embed' != sfConfig::get('dm_i18n_form') || !$this->table->hasI18n() || !$this->table->isI18nColumn($field)) {
             $sets['NONE'][] = $this->table->getIdentifierColumnName();
         }
         unset($fields[$this->table->getIdentifierColumnName()]);
     }
     foreach ($this->getBooleanFields($fields) as $field) {
         if (in_array($field, $fields)) {
             $sets['NONE'][] = $field;
             unset($fields[$field]);
         }
     }
     foreach ($this->table->getRelationHolder()->getLocals() as $alias => $relation) {
         if ($relation->getClass() == 'DmMedia') {
             $sets[dmString::humanize($relation['local'])] = array($relation['local'] . '_form', $relation['local'] . '_view');
         } else {
             $sets['NONE'][] = $relation->getLocalColumnName();
             unset($fields[$relation->getLocalColumnName()]);
         }
     }
     foreach ($this->getTextFields($fields) as $field) {
         if (in_array($field, $fields)) {
             if ('embed' != sfConfig::get('dm_i18n_form') || !$this->table->hasI18n() || !$this->table->isI18nColumn($field)) {
                 $sets[dmString::humanize($field)][] = $field;
             }
             unset($fields[$field]);
         }
     }
     foreach (array_merge($this->table->getRelationHolder()->getAssociations(), $this->table->getRelationHolder()->getForeigns()) as $alias => $relation) {
         if ($this->table->hasTemplate('DmGallery') && 'DmMedia' === $relation->getClass()) {
             continue;
         }
         if ($relation->getType() !== Doctrine_Relation::ONE && ($relationModule = $this->module->getManager()->getModuleByModel($relation->getClass()))) {
             $label = $relationModule->getPlural();
         } else {
             continue;
         }
         $sets[$label][] = dmString::underscore($alias) . '_list';
     }
     if ($this->table->hasTemplate('DmGallery')) {
         $sets['Gallery'][] = 'dm_gallery';
     }
     if ('embed' == sfConfig::get('dm_i18n_form') && $this->table->hasI18n()) {
         $sets['Lang'] = array();
         foreach (sfConfig::get('dm_i18n_cultures') as $culture) {
             $sets['Lang'][] = $culture;
         }
     }
     $sets['Others'] = array();
     foreach ($fields as $field) {
         if ('embed' != sfConfig::get('dm_i18n_form') || !$this->table->hasI18n() || !$this->table->isI18nColumn($field)) {
             $sets['Others'][] = $field;
         }
         unset($fields[$field]);
     }
     return $this->removeEmptyValues($sets);
 }
Beispiel #3
0
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::firsts($array, 2), array('alpha', 'beta'), 'first values');
$t->diag('get');
$t->is_deeply(dmArray::get('alpha', null, 'test'), 'test', 'first parameter is not an array');
$t->is_deeply(dmArray::get(array('alpha'), 0, 'test'), 'alpha', 'key exists');
$t->is_deeply(dmArray::get(array('alpha'), 1, 'test'), 'test', 'key not exists');
$t->is_deeply(dmArray::get(array(''), 0, 'test', false), '', 'empty value without default if empty');
$t->is_deeply(dmArray::get(array(''), 0, 'test', true), 'test', 'empty value with default if empty');
$t->is_deeply(dmArray::get(array('alpha'), 0, 'test', true), 'alpha', 'key exists with default if empty');
$t->diag('last');
$t->is_deeply(dmArray::last('alpha'), 'alpha', 'first parameter is not an array');
$t->is_deeply(dmArray::last(array()), null, 'empty source array');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::last($array), 'delta', 'last value');
$t->diag('toHtmlCssClasses');
$classes = array('class1', '', ' class2', ' ', '  class3  ');
$cleanClasses = 'class1 class2 class3';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$classes = array('class1');
$cleanClasses = 'class1';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$classes = array('  class1 class2 class3  ');
$cleanClasses = 'class1 class2 class3';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$t->diag('unsetEmpty');
$array = array(1 => '', 2 => 'delta', 3 => '', 'alpha' => 'gamma', 'gamma' => '', 'delta' => '');
$t->is_deeply(dmArray::unsetEmpty($array, array(3, 'gamma')), array('1' => '', '2' => 'delta', 'alpha' => 'gamma', 'delta' => ''), 'check');
$t->diag('valueToKey');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::valueToKey($array), array('alpha' => 'alpha', 'beta' => 'beta', 'gamma' => 'gamma', 'delta' => 'delta'), 'check');
 protected function getTagNames()
 {
     return dmArray::valueToKey(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div'));
 }
 protected function getFields()
 {
     return dmArray::valueToKey($this->table->getAllColumnNames());
 }