Skip to content

Commit

Permalink
Allow the Author field to be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendan Abbott committed Apr 6, 2011
1 parent f33bad9 commit e296a59
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
25 changes: 10 additions & 15 deletions symphony/lib/toolkit/fields/field.author.php
Expand Up @@ -16,6 +16,7 @@
public function __construct(&$parent){
parent::__construct($parent);
$this->_name = __('Author');
$this->_required = true;
}

public function canToggle(){
Expand Down Expand Up @@ -70,35 +71,29 @@ public function processRawFieldData($data, &$status, $simulate=false, $entry_id=

public function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL){

$value = (isset($data['author_id']) ? $data['author_id'] : NULL);

$callback = Administration::instance()->getPageCallback();
$value = isset($data['author_id']) ? $data['author_id'] : NULL;

if ($this->get('default_to_current_user') == 'yes' && empty($data) && empty($_POST)) {
$value = array(Administration::instance()->Author->get('id'));
}

if (!is_array($value)) {
$value = array($value);
}

$authors = AuthorManager::fetch();
if(!is_array($value)) $value = array($value);

$options = array();

if ($this->get('required') != 'yes') $options[] = array(NULL, false, NULL);

$authors = AuthorManager::fetch();
foreach($authors as $a){
$options[] = array($a->get('id'), in_array($a->get('id'), $value), $a->getFullName());
}

$fieldname = 'fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix;
if($this->get('allow_multiple_selection') == 'yes') $fieldname .= '[]';

$attr = array();

if($this->get('allow_multiple_selection') == 'yes') $attr['multiple'] = 'multiple';

$label = Widget::Label($this->get('label'));
$label->appendChild(Widget::Select($fieldname, $options, $attr));
$label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') == 'yes' ? array('multiple' => 'multiple') : NULL)));

if($flagWithError != NULL) $wrapper->appendChild(Widget::wrapFormElementWithError($label, $flagWithError));
else $wrapper->appendChild($label);
}
Expand Down Expand Up @@ -295,17 +290,17 @@ public function displaySettingsPanel(&$wrapper, $errors = null) {
$label->setValue(__('%s Select current user by default', array($input->generate())));
$div->appendChild($label);

$this->appendRequiredCheckbox($div);
$this->appendShowColumnCheckbox($div);
$wrapper->appendChild($div);

}

public function createTable(){
return Symphony::Database()->query(
"CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') ."` (
`id` int(11) unsigned NOT NULL auto_increment,
`entry_id` int(11) unsigned NOT NULL,
`author_id` int(11) unsigned NOT NULL,
`author_id` int(11) unsigned NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `entry_id` (`entry_id`),
KEY `author_id` (`author_id`)
Expand Down
2 changes: 1 addition & 1 deletion symphony/lib/toolkit/fields/field.select.php
Expand Up @@ -316,7 +316,7 @@ public function checkFields(&$errors, $checkForDuplicates=true){
public function findDefaults(&$fields){
if(!isset($fields['allow_multiple_selection'])) $fields['allow_multiple_selection'] = 'no';
if(!isset($fields['show_association'])) $fields['show_association'] = 'no';
if(!isset($fields['show_association'])) $fields['sort_options'] = 'no';
if(!isset($fields['sort_options'])) $fields['sort_options'] = 'no';
}

public function displaySettingsPanel(&$wrapper, $errors = null) {
Expand Down
14 changes: 14 additions & 0 deletions update.php
Expand Up @@ -404,6 +404,20 @@ function render($output){
// Remove the 'driver' from the Config
unset($settings['database']['driver']);
writeConfig(DOCROOT . '/manifest', $settings, $settings['file']['write_mode']);

// Remove the NOT NULL from the Author tables
try {
$author = $frontend->Database->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_author`");

foreach($author as $id) {
$table = '`tbl_entries_data_' . $id . '`';

$frontend->Database->query(
'ALTER TABLE ' . $table . ' CHANGE `author_id` `author_id` int(11) unsigned NULL'
);
}
}
catch(Exception $ex) {}
}

$sbl_version = $frontend->Database->fetchVar('version', 0,
Expand Down

0 comments on commit e296a59

Please sign in to comment.