General developer forum

Course Category Add New File Upload Field

 
Picture of hitesh prajapati
Course Category Add New File Upload Field
 

HI everyone,

i need to add new file field to upload  image using filepicker function.

i added the field using below code in editcategory_form.php file.

$mform->addElement('filepicker', 'catimagefile', get_string('categoryimage'), null,$imageoptions);

But, i can't able to add and update this field into `mdl_files` table.

i follow the method for upload badges image, but still there is some issue.

can you help me with the code solution for above issue?

Thanks.





 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Course Category Add New File Upload Field
 
Average of ratings: -
Picture of hitesh prajapati
Re: Course Category Add New File Upload Field
 

Yes, i already check for this link,
But i need save the file/images into mdl_files Table.
i follow the file upload code of upload badges. but it's not working.

can  you please help me in coding flow  with course category coding files to add/edit files field.
Thanks for your reply!
 

 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Course Category Add New File Upload Field
Plugin developersTesters

What are the errors showing up on the screen. Can you please make sure debugging is turned on on the site and see if you encounter any errors .



 
Average of ratings: -
Picture of hitesh prajapati
Re: Course Category Add New File Upload Field
 
Hi,
Yes, i already enabled the developer debug mode. and it's shows the error when i update the category.

i added the code for display image upload field on 

course/classes/editcategory_form.php

call the function in below file 
course/editcategory.php

and add the function in below file 

lib/coursecatlib.php


see the below images of my code added into above files





 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Course Category Add New File Upload Field
Plugin developersTesters

Well the problem seems to be that $coursecat is not obviously not set in the else bit so you cant use these: 


$coursecat->category_process_cat_image() ;
$coursecat->category_process_banner_image() ;

You probably need to put those two lines after this : 


$category = coursecat::create($data, $mform->get_description_editor_options());
and then use the $category variable and do this  : 

$category->category_process_cat_image() ;
$category->category_process_banner_image() ;

 
Average of ratings: -
Picture of hitesh prajapati
Re: Course Category Add New File Upload Field
 

Hi Hittesh Ahuja,

I follow your instruction and add the code in else part after create category.

But still having same error, even i update the code error display for old function.

i already Purge all caches. Is there any thing that i need to do to remove cache ?

also what about the function to update image fields ?

where should i add code to update file field ?

see below images.

 





 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Course Category Add New File Upload Field
Plugin developersTesters

It looks like your code is still cached somehow .. there is no $coursecat on line 122 so this is wrong. 


Hittesh

 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Course Category Add New File Upload Field
Plugin developersTesters

could you zip me the changes so i can try it on my end. 

 
Average of ratings: -
Picture of hitesh prajapati
Re: Course Category Add New File Upload Field
 

yes sure.

here is the core (moodle 3.2) files that i was changed.

see below zip file.

Also can you please help me how to display custom block to student and admin login.

i created on custom block to display course categories only. it's display on admin login my/ section but not display on student login.

i checked the blog permission to view blog and student is added to view this block.

Picture of hitesh prajapati
Re: Course Category Add New File Upload Field
 

Hi Hittesh Ahuja,

Did you find any solution from above zip?

 
Average of ratings: -