| Conditions | 3 |
| Paths | 2 |
| Total Lines | 92 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 75 | public function customEditorFileManager(Request $request, Grid $grid, $parentId = 0, CDocumentRepository $repository): Response |
||
| 76 | { |
||
| 77 | $id = $request->get('id'); |
||
| 78 | |||
| 79 | $course = $this->getCourse(); |
||
| 80 | $session = $this->getCourseSession(); |
||
| 81 | $parent = $course->getResourceNode(); |
||
| 82 | |||
| 83 | if (!empty($parentId)) { |
||
| 84 | $parent = $repository->getResourceNodeRepository()->find($parentId); |
||
| 85 | } |
||
| 86 | |||
| 87 | $source = new Entity(CDocument::class); |
||
| 88 | |||
| 89 | $qb = $repository->getResourcesByCourse($course, $session, null, $parent); |
||
| 90 | |||
| 91 | // 3. Set QueryBuilder to the source. |
||
| 92 | $source->initQueryBuilder($qb); |
||
| 93 | $grid->setSource($source); |
||
| 94 | |||
| 95 | $title = $grid->getColumn('title'); |
||
| 96 | $title->setSafe(false); |
||
| 97 | |||
| 98 | //$grid->hideFilters(); |
||
| 99 | $grid->setLimits(20); |
||
| 100 | //$grid->isReadyForRedirect(); |
||
| 101 | //$grid->setMaxResults(1); |
||
| 102 | //$grid->setLimits(2); |
||
| 103 | |||
| 104 | $courseIdentifier = $course->getCode(); |
||
| 105 | |||
| 106 | $routeParams = ['cidReq' => $courseIdentifier, 'id']; |
||
| 107 | |||
| 108 | $grid->getColumn('title')->manipulateRenderCell( |
||
| 109 | function ($value, Row $row, $router) use ($course, $routeParams) { |
||
| 110 | /** @var CDocument $entity */ |
||
| 111 | $entity = $row->getEntity(); |
||
| 112 | $resourceNode = $entity->getResourceNode(); |
||
| 113 | $id = $resourceNode->getId(); |
||
| 114 | |||
| 115 | $myParams = $routeParams; |
||
| 116 | $myParams['id'] = $id; |
||
| 117 | $myParams['parentId'] = $id; |
||
| 118 | |||
| 119 | unset($myParams[0]); |
||
| 120 | |||
| 121 | if ($resourceNode->hasResourceFile()) { |
||
| 122 | $documentParams = [ |
||
| 123 | 'course' => $course->getCode(), |
||
| 124 | 'file' => $resourceNode->getPathForDisplay() |
||
| 125 | ]; |
||
| 126 | $url = $router->generate( |
||
| 127 | 'resources_document_get_file', |
||
| 128 | $documentParams |
||
| 129 | ); |
||
| 130 | return '<a href="'.$url.'" class="select_to_ckeditor">'.$value.'</a>'; |
||
| 131 | } |
||
| 132 | |||
| 133 | $url = $router->generate( |
||
| 134 | 'editor_filemanager', |
||
| 135 | $myParams |
||
| 136 | ); |
||
| 137 | |||
| 138 | return '<a href="'.$url.'">'.$value.'</a>'; |
||
| 139 | } |
||
| 140 | ); |
||
| 141 | |||
| 142 | // Show resource data |
||
| 143 | /*$myRowAction = new RowAction( |
||
| 144 | 'use', |
||
| 145 | 'chamilo_core_resource_show', |
||
| 146 | false, |
||
| 147 | '_self', |
||
| 148 | ['class' => 'btn btn-secondary'] |
||
| 149 | ); |
||
| 150 | $myRowAction->setRouteParameters($routeParams); |
||
| 151 | |||
| 152 | $setNodeParameters = function (RowAction $action, Row $row) use ($routeParams) { |
||
| 153 | $id = $row->getEntity()->getResourceNode()->getId(); |
||
| 154 | $routeParams['id'] = $id; |
||
| 155 | $action->setRouteParameters($routeParams); |
||
| 156 | return $action; |
||
| 157 | }; |
||
| 158 | $myRowAction->addManipulateRender($setNodeParameters); |
||
| 159 | |||
| 160 | $grid->addRowAction($myRowAction);*/ |
||
| 161 | |||
| 162 | //return $this->render('@ChamiloTheme/Editor/custom.html.twig', $params); |
||
| 163 | |||
| 164 | return $grid->getGridResponse( |
||
| 165 | '@ChamiloTheme/Editor/custom.html.twig', |
||
| 166 | ['id' => $id, 'grid' => $grid] |
||
| 167 | ); |
||
| 241 |