I have two tables:
1.course
-
lectures
-
course_lectures
I want the values in lectures to be automatically generated based on the input of course, when save button is click in course.
For exam, if course_format is topic and course_format_no is 4, then section_name will be
topic1,
topic2,
topic3,
topic4
then, if course_format is topic and course_format_no is 2, then section_name will be
topic1,
topic2
Also, if course_format is weekly and course_format_no is 3, the start_date will be selected. If start_date is 24th November. then section_name will be something like this:
18 November - 24 November,
25 November - 1 December,
2 December - 8 December.
Please I dont know how to go about it.
course model
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "course".
*
* @property string $course_id
* @property string $course_category_id
* @property string $course_code
* @property string $course_name
* @property string $course_num
* @property string $course_summary
* @property string $course_start_date
* @property string $course_format
* @property integer $course_format_no
* @property integer $show_grade
*/
class Course extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'course';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['course_category_id', 'course_format_no', 'show_grade'], 'integer'],
[['course_code', 'course_name', 'course_start_date', 'course_format'], 'required'],
[['course_summary'], 'string'],
[['course_start_date'], 'safe'],
[['course_code'], 'string', 'max' => 100],
[['course_name'], 'string', 'max' => 255],
[['course_num', 'course_format'], 'string', 'max' => 20],
[['course_code'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'course_id' => 'Course ID',
'course_category_id' => 'Course Category ID',
'course_code' => 'Course Code',
'course_name' => 'Course Name',
'course_num' => 'Course Num',
'course_summary' => 'Course Summary',
'course_start_date' => 'Course Start Date',
'course_format' => 'Course Format',
'course_format_no' => 'Course Format No',
'show_grade' => 'Show Grade',
];
}
}
It will be displayed in listview