/** * Copy an entry and associated data * * @param boolean $deep Copy associated data? * @return boolean True on success, false on error */ public function copy($deep = true) { // Get some old info we may need // - Course ID $c_id = $this->get('id'); // Reset the ID. This will force store() to create a new record. $this->set('id', 0); // We want to distinguish this course from the one we copied from $this->set('title', $this->get('title') . ' (copy)'); $this->set('alias', $this->get('alias') . '_copy'); if (!$this->store()) { return false; } if ($deep) { // Copy pages foreach ($this->pages(array('course_id' => $c_id, 'active' => array(0, 1)), true) as $page) { if (!$page->copy($this->get('course_id'))) { $this->setError($page->getError()); } } // Copy units foreach ($this->offerings(array('course_id' => $c_id), true) as $offering) { if (!$offering->copy($this->get('id'))) { $this->setError($offering->getError()); } } // Copy managers foreach ($this->managers(array('course_id' => $c_id), true) as $manager) { $manager->set('id', 0); $manager->set('course_id', $this->get('id')); if (!$manager->store()) { $this->setError($manager->getError()); } } // Copy logo if ($file = $this->get('logo')) { $src = '/' . trim($this->config('uploadpath', '/site/courses'), '/') . '/' . $c_id . '/' . $file; if (file_exists(PATH_APP . $src)) { $dest = '/' . trim($this->config('uploadpath', '/site/courses'), '/') . '/' . $this->get('id'); if (!is_dir(PATH_APP . $dest)) { if (!Filesystem::makeDirectory(PATH_APP . $dest)) { $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH')); } } $dest .= '/' . $file; if (!Filesystem::copy(PATH_APP . $src, PATH_APP . $dest)) { $this->setError(Lang::txt('Failed to copy course logo.')); } } } // Copy tags $tagger = new Tags($c_id); $this->tag($tagger->render('string', array('admin' => 1)), \User::get('id'), 1); } return true; }
/** * Get a list of courses * Accepts an array of filters to build query from * * @param array $filters Filters to build query from * @return mixed */ public function tags($what = 'cloud', $filters = array(), $clear = false) { $ct = new Tags(); return $ct->render($what, $filters, $clear); }