| Conditions | 11 |
| Paths | 131 |
| Total Lines | 117 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 14 | public static function convert(string $packagedir, string $outdir, \Chamilo\CourseBundle\Component\CourseCopy\Course $objCourse) |
||
| 15 | { |
||
| 16 | $dir = realpath($packagedir); |
||
| 17 | if (empty($dir)) { |
||
| 18 | throw new InvalidArgumentException('Directory does not exist!'); |
||
| 19 | } |
||
| 20 | $odir = realpath($outdir); |
||
| 21 | if (empty($odir)) { |
||
| 22 | throw new InvalidArgumentException('Directory does not exist!'); |
||
| 23 | } |
||
| 24 | |||
| 25 | if (!empty($objCourse)) { |
||
| 26 | //Initialize the manifest metadata class |
||
| 27 | $meta = new CcMetadataManifest(); |
||
| 28 | |||
| 29 | //Package metadata |
||
| 30 | $metageneral = new CcMetadataGeneral(); |
||
| 31 | $metageneral->setLanguage($objCourse->info['language']); |
||
|
|
|||
| 32 | $metageneral->setTitle($objCourse->info['title'], $objCourse->info['language']); |
||
| 33 | $metageneral->setDescription('', $objCourse->info['language']); |
||
| 34 | $metageneral->setCatalog('category'); |
||
| 35 | $metageneral->setEntry($objCourse->info['categoryName']); |
||
| 36 | $meta->addMetadataGeneral($metageneral); |
||
| 37 | |||
| 38 | // Create the manifest |
||
| 39 | $manifest = new CcManifest(); |
||
| 40 | |||
| 41 | $manifest->addMetadataManifest($meta); |
||
| 42 | |||
| 43 | $organization = null; |
||
| 44 | |||
| 45 | //Get the course structure - this will be transformed into organization |
||
| 46 | //Step 1 - Get the list and order of sections/topics |
||
| 47 | |||
| 48 | $count = 1; |
||
| 49 | $sections = []; |
||
| 50 | $resources = $objCourse->resources; |
||
| 51 | |||
| 52 | // We check the quiz sections |
||
| 53 | if (isset($resources['quiz'])) { |
||
| 54 | $quizSections = self::getItemSections( |
||
| 55 | $resources['quiz'], // array of quiz IDs generated by the course backup process |
||
| 56 | 'quiz', |
||
| 57 | $count, |
||
| 58 | $objCourse->info['code'], |
||
| 59 | $resources[RESOURCE_QUIZQUESTION] // selected question IDs from the course export form |
||
| 60 | ); |
||
| 61 | $sections = array_merge($sections, $quizSections); |
||
| 62 | } |
||
| 63 | |||
| 64 | // We check the document sections |
||
| 65 | if (isset($resources['document'])) { |
||
| 66 | $documentSections = self::getItemSections( |
||
| 67 | $resources['document'], |
||
| 68 | 'document', |
||
| 69 | $count, |
||
| 70 | $objCourse->info['code'] |
||
| 71 | ); |
||
| 72 | $sections = array_merge($sections, $documentSections); |
||
| 73 | } |
||
| 74 | |||
| 75 | // We check the wiki sections |
||
| 76 | if (isset($resources['wiki'])) { |
||
| 77 | $wikiSections = self::getItemSections( |
||
| 78 | $resources['wiki'], |
||
| 79 | 'wiki', |
||
| 80 | $count, |
||
| 81 | $objCourse->info['code'] |
||
| 82 | ); |
||
| 83 | $sections = array_merge($sections, $wikiSections); |
||
| 84 | } |
||
| 85 | |||
| 86 | // We check the forum sections |
||
| 87 | if (isset($resources['forum'])) { |
||
| 88 | $forumSections = self::getItemSections( |
||
| 89 | $resources['forum'], |
||
| 90 | 'forum', |
||
| 91 | $count, |
||
| 92 | $objCourse->info['code'], |
||
| 93 | $resources['Forum_Category'] |
||
| 94 | ); |
||
| 95 | $sections = array_merge($sections, $forumSections); |
||
| 96 | } |
||
| 97 | |||
| 98 | // We check the link sections |
||
| 99 | if (isset($resources['link'])) { |
||
| 100 | $linkSections = self::getItemSections( |
||
| 101 | $resources['link'], |
||
| 102 | 'link', |
||
| 103 | $count, |
||
| 104 | $objCourse->info['code'], |
||
| 105 | $resources['Link_Category'] |
||
| 106 | ); |
||
| 107 | $sections = array_merge($sections, $linkSections); |
||
| 108 | } |
||
| 109 | |||
| 110 | //organization title |
||
| 111 | $organization = new CcOrganization(); |
||
| 112 | foreach ($sections as $sectionid => $values) { |
||
| 113 | $item = new CcItem(); |
||
| 114 | $item->title = $values[0]; |
||
| 115 | self::processSequence($item, $manifest, $values[1], $dir, $odir); |
||
| 116 | $organization->addItem($item); |
||
| 117 | } |
||
| 118 | $manifest->putNodes(); |
||
| 119 | |||
| 120 | if (!empty($organization)) { |
||
| 121 | $manifest->addNewOrganization($organization); |
||
| 122 | } |
||
| 123 | |||
| 124 | $manifestpath = $outdir.DIRECTORY_SEPARATOR.'imsmanifest.xml'; |
||
| 125 | $saved = $manifest->saveTo($manifestpath); |
||
| 126 | |||
| 127 | return $saved; |
||
| 128 | } |
||
| 129 | |||
| 130 | return false; |
||
| 131 | } |
||
| 363 |