示例#1
0
 /**
  * @param $originalWork
  *
  * @return string
  *
  * @throws UnknownWorkTypeException
  */
 protected static function checkValid($originalWork)
 {
     if (is_array($originalWork)) {
         $type = Utility::array_get($originalWork, 'type', null);
     } else {
         $type = $originalWork->type;
     }
     $className = __NAMESPACE__ . '\\' . ucfirst(strtolower($type));
     if (!class_exists($className)) {
         throw new UnknownWorkTypeException("Unknown type {$type}.");
     }
     return $className;
 }
示例#2
0
 /**
  * Format the translator names (APA)
  *
  * @param array $translators
  *
  * @return string
  */
 function formatTranslators($translators)
 {
     return '';
     $count = count($translators);
     //Count the number of authors in the array
     $numAuthors = 0;
     //Count the number of translators in the array
     $numTranslators = 0;
     foreach ($translators as $contributor) {
         if (Utility::array_get($contributor, 'cselect') == 'author') {
             $numAuthors++;
         } elseif (Utility::array_get($contributor, 'cselect') == 'translator') {
             $numTranslators++;
         }
     }
     $ret = '';
     //Translator iterative counter
     $t = 0;
     for ($i = 0; $i < $count; $i++) {
         if ($translators[$i]['cselect'] == 'translator') {
             //If this contributor is an translator
             if ($t == 0) {
                 //First time through the loop
                 if ($numTranslators > 1) {
                     //There is more than one translator
                     $ret .= '(';
                     $ret .= substr(ucwords($translators[$i]['fname']), 0, 1) . '. ';
                     if ($translators[$i]['mi']) {
                         $ret .= ucwords($translators[$i]['mi']) . '. ';
                     }
                     $ret .= ucwords($translators[$i]['lname']);
                     if ($numTranslators > 2) {
                         //There are more than two translators
                         $ret .= ',';
                     }
                 } else {
                     //There is only one translator
                     if ($translators[$i]['lname'] != 'Anonymous' || !$translators[$i]['lname'] && !$translators[$i]['fname'] && !$translators[$i]['mi']) {
                         //The translator is not Anonymous or blank
                         $ret .= '(';
                         $ret .= substr(ucwords($translators[$i]['fname']), 0, 1) . '. ';
                         if ($translators[$i]['mi']) {
                             $ret .= ucwords($translators[$i]['mi']) . '. ';
                         }
                         $ret .= ucwords($translators[$i]['lname']);
                     }
                 }
             } elseif ($t + 1 == $numTranslators) {
                 //Last time through the loop
                 if ($numTranslators > 1) {
                     //There is more than one translator
                     $ret .= ' & ' . substr(ucwords($translators[$i]['fname']), 0, 1) . '. ';
                     if ($translators[$i]['mi']) {
                         $ret .= ucwords($translators[$i]['mi']) . '. ';
                     }
                     $ret .= ucwords($translators[$i]['lname']);
                 } else {
                     //There is only one translator
                     if ($translators[$i]['lname'] != 'Anonymous' || !$translators[$i]['lname'] && !$translators[$i]['fname'] && !$translators[$i]['mi']) {
                         //The translator is not Anonymous or blank
                         $ret .= '(';
                         $ret .= substr(ucwords($translators[$i]['fname']), 0, 1) . '. ';
                         if ($translators[$i]['mi']) {
                             $ret .= ucwords($translators[$i]['mi']) . '. ';
                         }
                         $ret .= ucwords($translators[$i]['lname']);
                     }
                 }
             } elseif ($t + 2 == $numTranslators) {
                 //Second to last time through the loop
                 $ret .= ' ' . substr(ucwords($translators[$i]['fname']), 0, 1) . '. ';
                 if ($translators[$i]['mi']) {
                     $ret .= ucwords($translators[$i]['mi']) . '. ';
                 }
                 $ret .= ucwords($translators[$i]['lname']);
             } else {
                 $ret .= ' ' . substr(ucwords($translators[$i]['fname']), 0, 1) . '. ';
                 if ($translators[$i]['mi']) {
                     $ret .= ucwords($translators[$i]['mi']) . '. ';
                 }
                 $ret .= ucwords($translators[$i]['lname']) . ',';
             }
             $t++;
         }
     }
     if ($numTranslators > 0) {
         $ret .= ', Trans.).';
     }
     return $ret;
 }