Example #1
0
 public function get_by_user($user_id)
 {
     $user = Model_User::find($user_id);
     $success = false;
     if (!$user) {
         return $this->error(['Cannot find user.']);
     }
     $data = null;
     if ($user->isRoleTeacher()) {
         $data = Model_Subject::find('all', ['user_id' => $user->id]);
     } else {
         if ($user->isRoleStudent()) {
             $data = Model_Subject::find('all', ['related' => ['student_course' => ['where' => ['user_id' => $user->id]]]]);
         }
     }
     if ($data) {
         $success = true;
     }
     return $this->response(['data' => $data, 'success' => $success]);
 }
Example #2
0
 public function action_edit($id = null)
 {
     $where = ['id' => $id];
     if (Model_User::is_current_user('teacher')) {
         $where['subject.user_id'] = Auth::get('id');
     }
     $syllabus = Model_Syllabus::find('first', ['where' => $where, 'related' => ['subject']]);
     if (empty($syllabus)) {
         Session::set_flash('error', 'Syllabus does not exist.');
         Response::redirect('site/syllabuses');
     }
     $val = Model_Syllabus::validate('edit');
     if ($val->run()) {
         $syllabus->title = Input::post('title');
         $syllabus->file_url = Input::post('file_url');
         $syllabus->subject_id = Input::post('subject_id');
         if ($syllabus->save()) {
             Session::set_flash('success', e('Updated syllabus #' . $id));
             Response::redirect('site/syllabuses');
         } else {
             Session::set_flash('error', e('Could not update syllabus #' . $id));
         }
     } else {
         if (Input::method() == 'POST') {
             $syllabus->title = $val->validated('title');
             $syllabus->file_url = $val->validated('file_url');
             $syllabus->subject_id = $val->validated('subject_id');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('syllabus', $syllabus, false);
     }
     $subjects = Model_Subject::getSubjectOptions();
     $this->template->set_global('subjects', $subjects, false);
     $this->template->title = "Syllabuses";
     $this->template->content = View::forge('site/syllabuses/edit');
 }
Example #3
0
 			<div class="panel panel-default">
 			 	<div class="panel-heading">All Courses</div>
			    <div class="panel-body">
			    	<h1 class="text-muted text-center"><?php 
echo Model_Course::all_courses();
?>
</h1>
			    </div>
			</div>
 		</div>
 		<div class="col-md-4">
 			<div class="panel panel-default">
 			 	<div class="panel-heading">All Subjects</div>
			    <div class="panel-body">
			    	<h1 class="text-muted text-center"><?php 
echo Model_Subject::all_subjects();
?>
</h1>
			    </div>
			</div>
 		</div>
 		<div class="col-md-4">
 			<div class="panel panel-default">
 			 	<div class="panel-heading">All Teachers</div>
			    <div class="panel-body">
			    	<h1 class="text-muted text-center"><?php 
echo Model_User::all_teachers();
?>
</h1>
			    </div>
			</div>
Example #4
0
File: view.php Project: xXLXx/ddc
	<?php 
echo Date::forge($activity->date)->format("%b %d, %Y %H:%M %p", true);
?>
</p>

<h5><strong>Activity Until:</strong></h5>
</p>
	<?php 
echo Date::forge($activity->end_date)->format("%b %d, %Y %H:%M %p", true);
?>
</p>

<h5><strong>Subject:</strong></h5>
<p>
	<?php 
echo Model_Subject::getSubjectName($activity->subject_id) ?: Config::get('no_subject')[$activity->subject_id];
?>
</p>

<h5><strong>Activity:</strong></h5>
<p>
	<?php 
echo $activity->activity_content;
?>
</p>

<br/><br/>
<div class="text-center">
	<?php 
echo Html::anchor('site/activities/edit/' . $activity->id, 'Edit', array('class' => 'btn btn-primary'));
?>
Example #5
0
File: book.php Project: xXLXx/ddc
 public function action_edit($id = null)
 {
     $where = ['id' => $id];
     if (Model_User::is_current_user('teacher')) {
         $where['subject.user_id'] = Auth::get('id');
     }
     $book = Model_Book::find('first', ['where' => $where, 'related' => ['subject']]);
     if (empty($book)) {
         Session::set_flash('error', 'Book does not exist.');
         Response::redirect('site/book');
     }
     $val = Model_Book::validate('edit');
     if ($val->run()) {
         $bookUploadConfig = Config::get('upload_book_url');
         $bookUploadConfig['base_path'] = $bookUploadConfig['path'];
         $bookUploadConfig['path'] = $this->getFilePath($bookUploadConfig['path'], Input::post('sub_folder'), Input::post('course_id'));
         $isReuploaded = false;
         $book->book_name = Input::post('book_name');
         $book->subject_id = Input::post('subject_id');
         $book->course_id = Input::post('course_id');
         $book->is_institutional = Input::post('is_institutional');
         $book->sub_folder = Input::post('sub_folder');
         Upload::process(Config::get('upload_profile_picture'));
         if (empty(Upload::get_files()) || Upload::is_valid()) {
             if (!empty(Upload::get_files())) {
                 Upload::save();
                 $value = Upload::get_files();
                 foreach ($value as $files) {
                     $book->cover_photo = $value[0]['saved_as'];
                 }
             }
             Upload::process($bookUploadConfig);
             if (Upload::get_files() || empty(Upload::is_valid())) {
                 if (!empty(Upload::get_files())) {
                     Upload::save();
                     $value = Upload::get_files();
                     foreach ($value as $files) {
                         unlink($bookUploadConfig['base_path'] . '/' . $book->book_url);
                         $book->book_url = str_replace($bookUploadConfig['base_path'] . '/', '', $bookUploadConfig['path']) . '/' . $value[0]['saved_as'];
                         $isReuploaded = true;
                     }
                 }
                 $tmpPath = str_replace($bookUploadConfig['base_path'] . '/', '', $bookUploadConfig['path']);
                 if (!$isReuploaded && strpos($book->book_url, $tmpPath) == false) {
                     rename($bookUploadConfig['base_path'] . '/' . $book->book_url, $bookUploadConfig['path'] . '/' . preg_replace('/^.+\\//', '', $book->book_url));
                     $book->book_url = $tmpPath . '/' . preg_replace('/^.+\\//', '', $book->book_url);
                 }
                 if ($book->save()) {
                     Session::set_flash('success', e('Updated book #' . $id));
                     Response::redirect('site/book');
                 } else {
                     Session::set_flash('error', e('Could not update book #' . $id));
                 }
             } else {
                 Session::set_flash('error', 'Uploaded book is invalid.');
                 $this->template->set_global('book', $book, false);
             }
         } else {
             Session::set_flash('error', 'Cover photo is invalid.');
             $this->template->set_global('book', $book, false);
         }
     } else {
         if (Input::method() == 'POST') {
             $book->book_url = $val->validated('book_url');
             $book->book_name = $val->validated('book_name');
             $book->subject_id = $val->validated('subject_id');
             $book->cover_photo = $val->validated('cover_photo');
             $book->course_id = $val->validated('course_id');
             $book->is_institutional = $val->validated('is_institutional');
             $book->sub_folder = $val->validated('sub_folder');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('book', $book, false);
     }
     $subjects = Model_Subject::getSubjectOptions();
     $courses = Model_Course::getCoursesOptions();
     $this->template->set_global('subjects', $subjects, false);
     $this->template->set_global('courses', $courses, false);
     $this->template->title = "Books";
     $this->template->content = View::forge('site/book/edit');
 }
Example #6
0
 public static function all_subjects()
 {
     $subjects = Model_Subject::count();
     return $subjects;
 }
Example #7
0
 function init()
 {
     parent::init();
     $this->join('subject_class_map.subject_id', 'id')->hasOne('Class', 'class_id')->display('hindi');
 }
Example #8
0
 public function action_delete($id = null)
 {
     $where = ['id' => $id];
     if (Model_User::is_current_user('teacher')) {
         $where['user_id'] = Auth::get('id');
     }
     if ($subject = Model_Subject::find('first', ['where' => $where])) {
         $subject->delete();
         Session::set_flash('success', e('Deleted subject #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete subject #' . $id));
     }
     Response::redirect('site/subject');
 }
Example #9
0
File: index.php Project: xXLXx/ddc
	<tbody>
<?php 
    foreach ($activities as $item) {
        ?>
		<tr>

			<td><?php 
        echo $item->getTypeName();
        ?>
</td>
			<td><?php 
        echo Date::forge($item->date)->format("%h %d, %Y %H:%M %p", true);
        ?>
</td>
			<td><?php 
        echo Model_Subject::getSubjectName($item->subject_id) ?: Config::get('no_subject')[$item->subject_id];
        ?>
</td>
			<td><?php 
        echo $item->activity_content;
        ?>
</td>
			<td>
				<?php 
        echo Html::anchor('site/activities/view/' . $item->id, 'View');
        ?>
 |
				<?php 
        echo Html::anchor('site/activities/edit/' . $item->id, 'Edit');
        ?>
 |
Example #10
0
File: book.php Project: xXLXx/ddc
 public function getSubjectDesc()
 {
     $subjects = Model_Subject::find('first', array('where' => array(array('id', $this->subject_id))));
     return $subjects ? $subjects->subject_code : '';
 }
Example #11
0
File: _form.php Project: xXLXx/ddc
		</div>
		<div class="form-group is-institutional">
	        <?php 
echo Form::checkbox('is_institutional', 1, Input::post('is_institutional', isset($activity) ? $activity->is_institutional : ''));
?>
			<?php 
echo Form::label('Is Institutional', 'is_institutional', array('class' => 'control-label'));
?>
		</div>

		<div class="form-group">
			<?php 
echo Form::label('Subject', 'subject_id', array('class' => 'control-label'));
?>
	        <?php 
echo Form::select('subject_id', Input::post('subject_id', isset($activity) ? $activity->subject_id : ''), Model_Subject::getSubjectOptions(), array('class' => 'subject form-control'));
?>
		</div>

		<div class="form-group">
			<?php 
echo Form::label('Activity', 'activity_content', array('class' => 'control-label'));
?>

				<?php 
echo Form::textarea('activity_content', Input::post('activity_content', isset($activity) ? $activity->activity_content : ''), array('class' => 'col-md-8 form-control', 'rows' => 8, 'placeholder' => 'Activity content'));
?>
		</div>

		<div class="form-group text-center">
			<label class='control-label'>&nbsp;</label>