Browse Source

Merge pull request #190 from willtp87/6.x

some code style fixes
pull/192/merge
Jonathan Green 12 years ago
parent
commit
e30760fd87
  1. 102
      fedora_repository.module

102
fedora_repository.module

@ -120,7 +120,7 @@ function fedora_repository_ingest_object($collection_pid, $collection_label = NU
* @param array $form_state * @param array $form_state
*/ */
function fedora_repository_ingest_form_submit(array $form, array &$form_state) { function fedora_repository_ingest_form_submit(array $form, array &$form_state) {
// Only validate the form if the submit button was pressed (other buttons may be used for AHAH. // Only validate if the submit button was pressed, AHAH may use other buttons.
if (array_key_exists('ahah_submission', $form_state) && $form_state['ahah_submission']) { if (array_key_exists('ahah_submission', $form_state) && $form_state['ahah_submission']) {
$form_state['submitted'] = FALSE; $form_state['submitted'] = FALSE;
return; return;
@ -181,7 +181,7 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) {
* @return type * @return type
*/ */
function fedora_repository_ingest_form_validate($form, &$form_state) { function fedora_repository_ingest_form_validate($form, &$form_state) {
// Only validate the form if the submit button was pressed (other buttons may be used for AHAH. // Only validate if the submit button was pressed, AHAH may use other buttons.
$is_ahah_submission = (array_key_exists('ahah_submission', $form_state) && $form_state['ahah_submission']); $is_ahah_submission = (array_key_exists('ahah_submission', $form_state) && $form_state['ahah_submission']);
if ($is_ahah_submission) { if ($is_ahah_submission) {
$form_state['submitted'] = FALSE; $form_state['submitted'] = FALSE;
@ -205,18 +205,18 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
$validators = array(); $validators = array();
$ifl = 'ingest-file-location'; $ifl = 'ingest-file-location';
$fileObject = NULL; $file_object = NULL;
// Check if it's already there; this is what upload_element provides. // Check if it's already there; this is what upload_element provides.
if (is_a($form_state['values'][$ifl], 'stdClass') && property_exists($form_state['values'][$ifl], '')) { if (is_a($form_state['values'][$ifl], 'stdClass') && property_exists($form_state['values'][$ifl], '')) {
$fileObject = $form_state['values'][$ifl]; $file_object = $form_state['values'][$ifl];
} }
elseif (!empty($_FILES['files']['name'][$ifl])) { elseif (!empty($_FILES['files']['name'][$ifl])) {
$fileObject = file_save_upload($ifl, $validators); $file_object = file_save_upload($ifl, $validators);
} }
if ($fileObject !== NULL && property_exists($fileObject, 'filepath')) { if ($file_object !== NULL && property_exists($file_object, 'filepath')) {
file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); file_move($file_object->filepath, 0, 'FILE_EXISTS_RENAME');
$form_state['values'][$ifl] = $fileObject->filepath; $form_state['values'][$ifl] = $file_object->filepath;
} }
if (isset($form_state['values'][$ifl]) && file_exists($form_state['values'][$ifl])) { if (isset($form_state['values'][$ifl]) && file_exists($form_state['values'][$ifl])) {
@ -237,7 +237,7 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
if (!empty($file)) { if (!empty($file)) {
if (!in_array($dformat, $allowedMimeTypes)) { if (!in_array($dformat, $allowedMimeTypes)) {
form_set_error($ifl, form_set_error($ifl,
t('The uploaded file\'s mimetype (@mime) is not associated with this Content Model. The allowed types are: @allowed', array( t("The uploaded file's mimetype (@mime) is not associated with this Content Model. The allowed types are: @allowed", array(
'@mime' => $dformat, '@mime' => $dformat,
'@allowed' => implode(', ', $allowedMimeTypes), '@allowed' => implode(', ', $allowedMimeTypes),
))); )));
@ -271,7 +271,8 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
*/ */
function fedora_repository_ingest_form(&$form_state, $collection_pid, $collection_label = NULL, $content_model = NULL) { function fedora_repository_ingest_form(&$form_state, $collection_pid, $collection_label = NULL, $content_model = NULL) {
module_load_include('inc', 'fedora_repository', 'formClass'); module_load_include('inc', 'fedora_repository', 'formClass');
// For the sake of easily maintaining the module in different core versions create our own form_values variable. // For the sake of easily maintaining the module in different core versions
// create our own form_values variable.
if (empty($form_state['storage']['step'])) { if (empty($form_state['storage']['step'])) {
$form_state['storage']['step'] = 1; $form_state['storage']['step'] = 1;
} }
@ -378,7 +379,8 @@ function add_stream_form_submit($form, &$form_state) {
$pid = $form_state['values']['pid']; $pid = $form_state['values']['pid'];
$dsid = $form_state['values']['stream_id']; $dsid = $form_state['values']['stream_id'];
$dsLabel = $form_state['values']['stream_label'] . substr($form_state['storage']['stream_url'], strrpos($form_state['storage']['stream_url'], '.')); // Add the file extention to the end of the label.; // Add the file extention to the end of the label.
$dsLabel = $form_state['values']['stream_label'] . substr($form_state['storage']['stream_url'], strrpos($form_state['storage']['stream_url'], '.'));
try { try {
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
@ -394,7 +396,8 @@ function add_stream_form_submit($form, &$form_state) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
return; return;
} }
unset($form_state['storage']); //Using storage; need to unset it for forms to work properly... // Using storage; need to unset it for forms to work properly...
unset($form_state['storage']);
$form_state['rebuild'] = TRUE; $form_state['rebuild'] = TRUE;
} }
@ -873,12 +876,14 @@ function fedora_repository_edit_qdc_form_validate($form, &$form_state) {
} }
/** /**
* Check if there is a custom edit metadata function defined in the content model. If so, * Check if there is a custom edit metadata function defined in the
* call it, if not do the submit action for the standard QDC metadata. Custom forms will * content model. If so, call it, if not do the submit action for the
* need to implement their own equivalent to the FormClass->updateMetaData function * standard QDC metadata. Custom forms willneed to implement their own
* equivalent to the FormClass->updateMetaData function
* *
* @param array $form * @param array $form
* @param array $form_state * @param array $form_state
*
* @return * @return
*/ */
function fedora_repository_edit_qdc_form_submit($form, &$form_state) { function fedora_repository_edit_qdc_form_submit($form, &$form_state) {
@ -972,7 +977,7 @@ function makeObject($pid, $dsID) {
} }
/** /**
* Implementation of hook_islandora_tabs(). * Implements hook_islandora_tabs().
* *
* @param $content_models array * @param $content_models array
* An array of ContentModel objects to which the current Fedora Object * An array of ContentModel objects to which the current Fedora Object
@ -991,8 +996,8 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) {
foreach ($content_models as $content_model) { foreach ($content_models as $content_model) {
$content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number); $content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number);
// Each content model may return either a tabpage array or plain HTML. If // Each content model may return either a tabpage array or plain HTML.
// it is HTML, stick it in a tabpage. // If it is HTML, stick it in a tabpage.
if (is_array($content_model_fieldset)) { if (is_array($content_model_fieldset)) {
$cmodels_tabs = array_merge($cmodels_tabs, $content_model_fieldset); $cmodels_tabs = array_merge($cmodels_tabs, $content_model_fieldset);
} }
@ -1005,7 +1010,7 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) {
} }
} }
//can disable showing the object details tab in admin UI // Can disable showing the object details tab in admin UI.
if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { if (variable_get('fedora_repository_show_object_details_tab', TRUE)) {
// Add a 'manage object' tab for all objects, where detailed list of content is shown. // Add a 'manage object' tab for all objects, where detailed list of content is shown.
// XXX: Perhaps this should be extracted into its own object? // XXX: Perhaps this should be extracted into its own object?
@ -1020,7 +1025,7 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) {
} }
/** /**
* Implementation of hook_islandora_tabs_alter(). * Implements hook_islandora_tabs_alter().
* *
* @param &$tabs array * @param &$tabs array
* The array of tabs/tabset to alter. * The array of tabs/tabset to alter.
@ -1030,7 +1035,7 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) {
* @see fedora_repository_get_items() * @see fedora_repository_get_items()
*/ */
function fedora_repository_islandora_tabs_alter(&$tabs, $params) { function fedora_repository_islandora_tabs_alter(&$tabs, $params) {
//Deselect all other tabs if the fedora_object_details tab is supposed // Deselect all other tabs if the fedora_object_details tab is supposed
// to be selected. // to be selected.
$object_details_key = 'fedora_object_details'; $object_details_key = 'fedora_object_details';
if ($tabs[$object_details_key]['#selected']) { if ($tabs[$object_details_key]['#selected']) {
@ -1049,18 +1054,21 @@ function fedora_repository_islandora_tabs_alter(&$tabs, $params) {
* datastream via the makeObject() function; otherwise, call out to the PIDs' * datastream via the makeObject() function; otherwise, call out to the PIDs'
* ContentModels and all Drupal modules for Islandora tabs. * ContentModels and all Drupal modules for Islandora tabs.
* *
* @global $user stdObject * @global stdObject $user
* @param $pid string *
* An optional string containing the PID of an object. (defaults to islandora:root) * @param string $pid
* @param $dsId string * An optional string containing the PID of an object.
* (defaults to islandora:root)
* @param string $dsId
* An optional string containing the dsid of an object. ("-" will be ignored * An optional string containing the dsid of an object. ("-" will be ignored
* to allow later parameters without including one). * to allow later parameters without including one).
* @param $collection string * @param string $collection
* The collection name... Deprecated. * The collection name... Deprecated.
* @param $page_number string/integer(?) * @param string/integer(?) $page_number
* A page number to start on... Seems to be going towards deprecation? * A page number to start on... Seems to be going towards deprecation?
* @param $limit string/integer(?) * @param string/integer(?) $limit
* Used to limit the number of results returned? Deprecated? * Used to limit the number of results returned? Deprecated?
*
* @return string * @return string
* A string containing markup for the rendered tabs. * A string containing markup for the rendered tabs.
*/ */
@ -1118,8 +1126,10 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU
exit; exit;
return ' '; return ' ';
} }
if ($dsId != NULL && $dsId != '-') { //if we have a dsID return the stream otherwise query for a collection of objects // If we have a dsID return the stream
//probably should check pid as well here. // otherwise query for a collection of objects.
if ($dsId != NULL && $dsId != '-') {
// Probably should check pid as well here.
return makeObject($pid, $dsId); return makeObject($pid, $dsId);
} }
@ -1198,8 +1208,8 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) {
* @return type * @return type
*/ */
function repository_page($pid = NULL, $dsId = NULL, $collection = NULL, $pageNumber = NULL) { function repository_page($pid = NULL, $dsId = NULL, $collection = NULL, $pageNumber = NULL) {
//do security check at fedora_repository_get_items function as it has to be called there in case // Do security check at fedora_repository_get_items function as
//someone trys to come in a back door. // it has to be called there in case someone trys to come in a back door.
return fedora_repository_get_items($pid, $dsId, $collection, $pageNumber); return fedora_repository_get_items($pid, $dsId, $collection, $pageNumber);
} }
@ -1220,7 +1230,6 @@ function repository_service($pid = NULL, $servicePid = NULL, $serviceMethod = NU
global $user; global $user;
if (!fedora_repository_check_perm(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { if (!fedora_repository_check_perm(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) {
//drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied"), 'error');
drupal_access_denied(); drupal_access_denied();
if (user_access('access administration pages')) { if (user_access('access administration pages')) {
drupal_set_message(t("PIDs may be added to allowed namespaces, or all namespace restrictions removed @here", array('@here' => l('here', 'admin/settings/fedora_repository'))), 'error'); drupal_set_message(t("PIDs may be added to allowed namespaces, or all namespace restrictions removed @here", array('@here' => l('here', 'admin/settings/fedora_repository'))), 'error');
@ -1247,14 +1256,16 @@ function repository_service($pid = NULL, $servicePid = NULL, $serviceMethod = NU
} }
/** /**
* fedora repository theme * Implements hook_theme().
* @return type *
* @return array
* The themes for the fedora_repository module.
*/ */
function fedora_repository_theme() { function fedora_repository_theme() {
return array( return array(
'fedora_repository_time' => array( 'fedora_repository_time' => array(
'arguments' => array( 'arguments' => array(
'element' => NULL 'element' => NULL,
), ),
'fedora_repository_solution_packs_list' => array( 'fedora_repository_solution_packs_list' => array(
'arguments' => array( 'arguments' => array(
@ -1269,7 +1280,12 @@ function fedora_repository_theme() {
* fedora repository required fedora objects * fedora repository required fedora objects
* *
* @return array * @return array
* array( 'path-to-foxml-file', 'pid', 'dsid', 'path-to-datastream-file', int dsversion, boolean required) * array( 'path-to-foxml-file',
* 'pid',
* 'dsid',
* 'path-to-datastream-file',
* int dsversion,
* boolean required)
*/ */
function fedora_repository_required_fedora_objects() { function fedora_repository_required_fedora_objects() {
@ -1322,12 +1338,14 @@ function fedora_repository_elements() {
/** /**
* fedora repository expand time * fedora repository expand time
*
* @param type $element * @param type $element
*
* @return string * @return string
*/ */
function fedora_repository_expand_time($element) { function fedora_repository_expand_time($element) {
// Default to current time, check default_value but set value so that if // Default to current time, check default_value but set value so that if
// default value is present it will override value // default value is present it will override value.
if (empty($element['#default_value'])) { if (empty($element['#default_value'])) {
$element['#value'] = array( $element['#value'] = array(
'hour' => intval(format_date(time(), 'custom', 'h')), 'hour' => intval(format_date(time(), 'custom', 'h')),
@ -1365,7 +1383,9 @@ function fedora_repository_expand_time($element) {
/** /**
* fedora repository time * fedora repository time
*
* @param type $element * @param type $element
*
* @return type * @return type
*/ */
function fedora_repository_time($element) { function fedora_repository_time($element) {
@ -1375,7 +1395,9 @@ function fedora_repository_time($element) {
/** /**
* theme fedora repository time * theme fedora repository time
*
* @param type $element * @param type $element
*
* @return type * @return type
*/ */
function theme_fedora_repository_time($element) { function theme_fedora_repository_time($element) {
@ -1544,7 +1566,7 @@ function theme_fedora_repository_solution_packs_list($solution_packs) {
} }
/** /**
* Implements hook_forms() * Implements hook_forms().
* *
* @param string $form_id * @param string $form_id
* *

Loading…
Cancel
Save