示例#1
0
 /**
  * Create an item entry
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     $id = $id ?: Request::getInt('id', 0);
     include_once Component::path('com_courses') . DS . 'models' . DS . 'courses.php';
     $course = null;
     if (!$id) {
         $course = \Components\Courses\Models\Course::getInstance(Request::getVar('gid', ''));
         $id = $course->get('id');
     }
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     if (!$course) {
         $course = new \Components\Courses\Models\Course($id);
     }
     if (!$course->exists()) {
         $this->setError(Lang::txt('Course not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $course->get('id'))->set('created', $course->get('created'))->set('created_by', $course->get('created_by'))->set('title', $course->get('title'))->set('description', String::truncate($course->get('blurb'), 200))->set('url', Route::url($course->link()));
     if (!$this->store()) {
         return false;
     }
     return true;
 }