Esempio n. 1
0
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Sam Wilson <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
\Hubzero\Document\Assets::addSystemScript('jquery.fancyselect.min');
\Hubzero\Document\Assets::addSystemStylesheet('jquery.fancyselect.css');
// Get our asset model
$asset = new \Components\Courses\Models\Asset(Request::getInt('asset_id', null));
$asset->set('section_id', $this->course->offering()->section()->get('id'));
// Get the asset groups
$assetgroups = array();
$assets = array();
foreach ($this->course->offering()->units() as $unit) {
    foreach ($unit->assetgroups() as $agt) {
        foreach ($agt->children() as $ag) {
            $assetgroups[] = array('id' => $ag->get('id'), 'title' => $ag->get('title'));
            foreach ($ag->assets() as $a) {
                if ($a->isPublished()) {
                    $a->set('longTitle', $unit->get('title') . ' - ' . $ag->get('title') . ' - ' . $a->get('title'));
                    $assets[] = $a;
                }
            }
        }
Esempio n. 2
0
 $target = '';
 if ($a->get('type') == 'video' && !$hasPrimaryVideo) {
     $hasPrimaryVideo = true;
     $href = Route::url($base . '&active=outline&unit=' . $unit->get('alias') . '&b=' . $ag->get('alias'));
 } else {
     if ($a->get('type') == 'file' || $a->get('type') == 'url') {
         $target = ' target="_blank"';
     }
 }
 $link = '<a class="' . $cls . '" href="' . $href . '"' . $target . '>' . $this->escape(stripslashes($a->get('title'))) . '</a>';
 // Finally, make sure prereqs have been met
 if (!$prerequisites->hasMet('asset', $a->get('id')) && !$isManager) {
     $info = "This item has prerequisites that have not yet been met. Begin by completing: ";
     $items = array();
     foreach ($prerequisites->get('asset', $a->get('id')) as $prereq) {
         $reqAsset = new \Components\Courses\Models\Asset($prereq['scope_id']);
         $items[] = $reqAsset->get('title');
     }
     $info .= implode(", ", $items);
     $link = '<span title="' . $info . '" class="unavailable hasTip">' . $this->escape(stripslashes($a->get('title'))) . '</span>';
 } else {
     if ($a->get('type') == 'form' && !$isManager) {
         $crumb = $a->get('url');
         if ($crumb && strlen($crumb) == \Components\Courses\Models\PdfFormDeployment::CRUMB_LEN) {
             $dep = \Components\Courses\Models\PdfFormDeployment::fromCrumb($crumb, $this->course->offering()->section()->get('id'));
             if ($dep && $dep->getState() == 'pending') {
                 continue;
             }
         }
     } else {
         if ($a->get('type') == 'text' && $a->get('subtype') == 'note') {
Esempio n. 3
0
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Sam Wilson <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
Html::behavior('core');
// Load asset if applicable
$id = Request::getInt('asset_id', null);
$asset = new \Components\Courses\Models\Asset($id);
$asset->set('section_id', $this->course->offering()->section()->get('id'));
$assets = array();
?>

<div class="wiki-edit">
	<h3>Create a wiki page</h3>

	<form action="<?php 
echo Request::base(true);
?>
/api/courses/asset/new" method="POST" class="edit-form">
		<div class="title-error error">Please provide a title first</div>

		<p>
			<label for="title">Title: </label><span class="required">*required</span>
 /**
  * Up
  **/
 public function up()
 {
     // Add folder/path field
     if ($this->db->tableExists('#__courses_assets') && !$this->db->tableHasField('#__courses_assets', 'path')) {
         $query = "ALTER TABLE `#__courses_assets` ADD `path` VARCHAR(255) NOT NULL DEFAULT ''";
         $this->db->setQuery($query);
         $this->db->query();
         // Set path based on asset id
         $query = "UPDATE `#__courses_assets` SET `path` = CONCAT(`course_id`, '/', `id`)";
         $this->db->setQuery($query);
         $this->db->query();
     }
     // Find all assets with >1 associations
     $query = "SELECT `asset_id`, count(asset_id) AS count FROM `#__courses_asset_associations` GROUP BY `asset_id` HAVING count > 1";
     $this->db->setQuery($query);
     $assetIds = $this->db->loadObjectList();
     if ($assetIds && count($assetIds) > 0) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'asset.php';
         foreach ($assetIds as $aa) {
             $query = "SELECT * FROM `#__courses_asset_associations` WHERE `asset_id` = " . (int) $aa->asset_id . " ORDER BY `id` DESC LIMIT " . (int) ($aa->count - 1);
             $this->db->setQuery($query);
             $toChange = $this->db->loadObjectList();
             foreach ($toChange as $a) {
                 $oldAssetId = $a->asset_id;
                 $asset = new \Components\Courses\Models\Asset($oldAssetId);
                 if ($asset->get('id')) {
                     // Get the offering
                     $offering = 0;
                     if ($a->scope == 'asset_group') {
                         $query = "SELECT `offering_id` FROM `#__courses_asset_groups` AS cag";
                         $query .= " LEFT JOIN `#__courses_units` AS cu ON cag.unit_id = cu.id";
                         $query .= " WHERE cag.id = " . $this->db->quote($a->scope_id);
                         $this->db->setQuery($query);
                         $offering = $this->db->loadResult();
                     } else {
                         if ($a->scope == 'offering') {
                             $offering = $a->scope_id;
                         }
                     }
                     $asset->copy(false);
                     $query = "UPDATE `#__courses_asset_associations` SET `asset_id` = " . $this->db->quote($asset->get('id')) . " WHERE `id` = " . $this->db->quote($a->id);
                     $this->db->setQuery($query);
                     $this->db->query();
                     if ($offering) {
                         // Update gradebook entries
                         $query = "UPDATE `#__courses_grade_book` AS g LEFT JOIN `#__courses_members` AS m ON g.member_id = m.id";
                         $query .= " SET `scope_id` = " . (int) $asset->get('id');
                         $query .= " WHERE `scope_id` = " . (int) $oldAssetId;
                         $query .= " AND `scope` = 'asset'";
                         $query .= " AND m.offering_id = " . (int) $offering;
                         $this->db->setQuery($query);
                         $this->db->query();
                         // Update asset_unity
                         $query = "UPDATE `#__courses_asset_unity` AS u LEFT JOIN `#__courses_members` AS m ON u.member_id = m.id";
                         $query .= " SET `asset_id` = " . (int) $asset->get('id');
                         $query .= " WHERE `asset_id` = " . (int) $oldAssetId;
                         $query .= " AND m.offering_id = " . (int) $offering;
                         $this->db->setQuery($query);
                         $this->db->query();
                         // Update asset_views
                         $query = "UPDATE `#__courses_asset_views` AS v LEFT JOIN `#__courses_members` AS m ON v.viewed_by = m.id";
                         $query .= " SET `asset_id` = " . (int) $asset->get('id');
                         $query .= " WHERE `asset_id` = " . (int) $oldAssetId;
                         $query .= " AND m.offering_id = " . (int) $offering;
                         $this->db->setQuery($query);
                         $this->db->query();
                     }
                 } else {
                     $query = "DELETE FROM `#__courses_asset_associations` WHERE `id` = " . $this->db->quote($a->id);
                     $this->db->setQuery($query);
                     $this->db->query();
                 }
             }
         }
     }
 }
Esempio n. 5
0
    ?>
					<ul class="dashboard-timeline">
					<?php 
    foreach ($rows as $i => $row) {
        switch ($row->scope) {
            case 'unit':
                $obj = \Components\Courses\Models\Unit::getInstance($row->scope_id);
                $url = $base . '&active=outline';
                break;
            case 'asset_group':
                $obj = new \Components\Courses\Models\AssetGroup($row->scope_id);
                $unit = \Components\Courses\Models\Unit::getInstance($obj->get('unit_id'));
                $url = $base . '&active=outline&unit=' . $unit->get('alias') . '&b=' . $obj->get('alias');
                break;
            case 'asset':
                $obj = new \Components\Courses\Models\Asset($row->scope_id);
                $url = $base . '&active=outline&unit=&b=&c=';
                break;
        }
        if (!$obj->exists() || !$obj->isPublished() || $row->scope == 'asset_group' && !$obj->get('parent')) {
            // skip containers
            continue;
        }
        ?>
						<li>
							<a href="<?php 
        echo Route::url($url);
        ?>
">
								<?php 
        echo $this->escape(stripslashes($obj->get('title')));
Esempio n. 6
0
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Sam Wilson <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
$asset = new \Components\Courses\Models\Asset($this->asset->id);
$config = array('option' => 'com_courses', 'scope' => $this->course->get('alias') . DS . $this->course->offering()->alias() . DS . 'asset', 'pagename' => $this->asset->id, 'pageid' => '', 'filepath' => $asset->path($this->course->get('id')), 'domain' => $this->course->get('alias'));
$this->model->set('content', stripslashes($this->model->get('content')));
Event::trigger('content.onContentPrepare', array('com_courses.asset.content', &$this->model, &$config));
?>

<header id="content-header">
	<h2><?php 
echo $this->asset->title;
?>
</h2>

	<div id="content-header-extra">
		<p>
			<a class="icon-prev back btn" href="<?php 
echo Route::url($this->course->offering()->link() . '&active=outline');
Esempio n. 7
0
                    $used_asset = $a;
                }
            }
        }
        if ($used) {
            // Check prerequisites
            $member = $this->course->offering()->section()->member(User::get('id'));
            if (is_null($member->get('section_id'))) {
                $member->set('section_id', $this->course->offering()->section()->get('id'));
            }
            $prerequisites = $member->prerequisites($this->course->offering()->gradebook());
            if (!$this->course->offering()->access('manage') && !$prerequisites->hasMet('asset', $used_asset->get('id'))) {
                $prereqs = $prerequisites->get('asset', $used_asset->get('id'));
                $requirements = array();
                foreach ($prereqs as $pre) {
                    $reqAsset = new \Components\Courses\Models\Asset($pre['scope_id']);
                    $requirements[] = $reqAsset->get('title');
                }
                $requirements = implode(', ', $requirements);
                // Redirect back to the course outline
                App::redirect(Route::url($base), Lang::txt('COM_COURSES_ERROR_ASSET_HAS_PREREQ', $requirements), 'warning');
                return;
            }
            echo $used_asset->render($this->course);
            if ($this->course->offering()->access('manage')) {
                ?>
						<?php 
                if (!$used_asset->isPublished()) {
                    ?>
						<div class="asset-status unpublished">
							<span><?php 
Esempio n. 8
0
 /**
  * Unlink an asset from an object
  *
  * @return  void
  */
 public function unlinkTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $asset_id = Request::getInt('asset', 0);
     $tmpl = Request::getVar('tmpl', '');
     $scope = Request::getVar('scope', 'asset_group');
     $scope_id = Request::getInt('scope_id', 0);
     $course_id = Request::getInt('course_id', 0);
     // Load association
     $tbl = new Tables\AssetAssociation($this->database);
     $tbl->loadByAssetScope($asset_id, $scope_id, $scope);
     // Remove association
     if (!$tbl->delete()) {
         $this->setError($tbl->getError());
     }
     $model = new \Components\Courses\Models\Asset($asset_id);
     // Is this asset linked anywhere else?
     if ($model->parents(array('count' => true)) <= 0) {
         // No -- Asset no longer used. Delete it.
         if (!$model->delete()) {
             $this->setError($model->delete());
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&tmpl=' . $tmpl . '&scope=' . $scope . '&scope_id=' . $scope_id . '&course_id=' . $course_id, false), $this->getError() ? $this->getError() : null, $this->getError() ? 'error' : 'message');
 }
Esempio n. 9
0
 /**
  * Save method for this handler
  * // @FIXME: reduce code duplication here
  *
  * @return array of assets created
  **/
 public function save()
 {
     // Include needed files
     require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'asset.php';
     // Create our asset object
     $id = Request::getInt('id', null);
     $asset = new \Components\Courses\Models\Asset($id);
     // Grab the incoming content
     $content = Request::getVar('content', '', 'default', 'none', 2);
     // Get everything ready to store
     // Check if vars are already set (i.e. by a sub class), before setting them here
     $asset->set('title', !empty($this->asset['title']) ? $this->asset['title'] : strip_tags(substr($content, 0, 25)));
     $asset->set('type', !empty($this->asset['type']) ? $this->asset['type'] : 'text');
     $asset->set('subtype', !empty($this->asset['subtype']) ? $this->asset['subtype'] : 'content');
     $asset->set('content', !empty($this->asset['content']) ? $this->asset['content'] : $content);
     // If we have a state coming in as an int
     if ($graded = Request::getInt('graded', false)) {
         $asset->set('graded', $graded);
         // By default, weight asset as a 'homework' type
         $grade_weight = $asset->get('grade_weight');
         if (empty($grade_weight)) {
             $asset->set('grade_weight', 'homework');
         } else {
             $asset->set('grade_weight', $grade_weight);
         }
     } elseif ($graded = Request::getInt('edit_graded', false)) {
         $asset->set('graded', 0);
     }
     // If we're saving progress calculation var
     if ($progress = Request::getInt('progress_factors', false)) {
         $asset->set('progress_factors', array('asset_id' => $asset->get('id'), 'section_id' => Request::getInt('section_id', 0)));
     } elseif (Request::getInt('edit_progress_factors', false)) {
         $asset->set('section_id', Request::getInt('section_id', 0));
         $asset->set('progress_factors', 'delete');
     }
     // Save the asset
     if (!$asset->store()) {
         return array('error' => 'Asset save failed');
     }
     $scope_id = Request::getInt('scope_id', null);
     $original_scope_id = Request::getInt('original_scope_id', null);
     $scope = Request::getCmd('scope', 'asset_group');
     // Only worry about this if scope id is changing
     if (!is_null($scope_id) && !is_null($original_scope_id) && $scope_id != $original_scope_id) {
         // Create asset assoc object
         require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'tables' . DS . 'asset.association.php';
         $assoc = new Tables\AssetAssociation($this->db);
         if (!$assoc->loadByAssetScope($asset->get('id'), $original_scope_id, $scope)) {
             return array('error' => 'Failed to load asset association');
         }
         // Save the asset association
         if (!$assoc->save(array('scope_id' => $scope_id))) {
             return array('error' => 'Asset association save failed');
         }
     }
     // Get the url to return to the page
     $course_id = Request::getInt('course_id', 0);
     $offering_alias = Request::getCmd('offering', '');
     $course = new \Components\Courses\Models\Course($course_id);
     $course->offering($offering_alias);
     $url = Route::url($course->offering()->link() . '&asset=' . $asset->get('id'));
     $url = rtrim(str_replace('/api', '', Request::root()), '/') . '/' . ltrim($url, '/');
     $files = array('asset_id' => $asset->get('id'), 'asset_title' => $asset->get('title'), 'asset_type' => $asset->get('type'), 'asset_subtype' => $asset->get('subtype'), 'asset_url' => $url, 'asset_state' => $asset->get('state'), 'scope_id' => $scope_id);
     $return_info = array('asset_id' => $asset->get('id'), 'asset_title' => $asset->get('title'), 'asset_type' => $asset->get('type'), 'asset_subtype' => $asset->get('subtype'), 'asset_url' => $url, 'course_id' => $asset->get('course_id'), 'offering_alias' => $offering_alias, 'scope_id' => $scope_id, 'files' => array($files));
     // Return info
     return array('assets' => $return_info);
 }
Esempio n. 10
0
 /**
  * Create method for this handler
  *
  * @return array of assets created
  **/
 public function create()
 {
     $this->asset['title'] = Request::getString('title', '');
     $this->asset['type'] = 'text';
     $this->asset['subtype'] = 'wiki';
     if (!Request::getString('title', false)) {
         return array('error' => 'Please provide a title!');
     }
     if (!Request::getInt('id', false)) {
         // Create asset
         $this->asset['course_id'] = Request::getInt('course_id');
         $return = parent::create();
     } else {
         $this->asset['course_id'] = Request::getInt('course_id');
         $this->assoc['asset_id'] = Request::getInt('id');
         $this->assoc['scope_id'] = Request::getInt('scope_id');
         // Save asset
         $return = parent::save();
     }
     // If files are included, save them as well
     // @FIXME: share this with file upload if possible
     if (isset($_FILES['files'])) {
         // @FIXME: should these come from the global settings, or should they be courses specific
         // Get config
         $config = Component::params('com_media');
         // Max upload size
         $sizeLimit = $config->get('upload_maxsize');
         $sizeLimit = $sizeLimit * 1024 * 1024;
         // Get courses config
         $cconfig = Component::params('com_courses');
         // Loop through files and save them (they will potentially be coming in together, in a single request)
         for ($i = 0; $i < count($_FILES['files']['name']); $i++) {
             $file = $_FILES['files']['name'][$i];
             $size = (int) $_FILES['files']['size'][$i];
             // Get the file extension
             $pathinfo = pathinfo($file);
             $filename = $pathinfo['filename'];
             $ext = $pathinfo['extension'];
             // Check to make sure we have a file and its not too big
             if ($size == 0) {
                 return array('error' => 'File is empty');
             }
             if ($size > $sizeLimit) {
                 $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
                 return array('error' => "File is too large. Max file upload size is {$max}");
             }
             // Build the upload path if it doesn't exist
             require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'asset.php';
             $asset = new \Components\Courses\Models\Asset($this->assoc['asset_id']);
             $uploadDirectory = PATH_APP . DS . $asset->path($this->asset['course_id']);
             // Make sure upload directory exists and is writable
             if (!is_dir($uploadDirectory)) {
                 if (!\Filesystem::makeDirectory($uploadDirectory)) {
                     return array('error' => 'Server error. Unable to create upload directory');
                 }
             }
             if (!is_writable($uploadDirectory)) {
                 return array('error' => 'Server error. Upload directory isn\'t writable');
             }
             // Get the final file path
             $target_path = $uploadDirectory . $filename . '.' . $ext;
             // Move the file to the site folder
             set_time_limit(60);
             // Scan for viruses
             if (!\Filesystem::isSafe($_FILES['files']['tmp_name'][$i])) {
                 // Scan failed, return an error
                 return array('error' => 'File rejected because the anti-virus scan failed.');
             }
             if (!($move = move_uploaded_file($_FILES['files']['tmp_name'][$i], $target_path))) {
                 return array('error' => 'Move file failed');
             }
         }
     }
     // Return info
     return $return;
 }