Пример #1
0
$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>
			<input type="text" name="title" class="wiki-title" placeholder="Wiki page title" value="<?php 
echo $asset->get('title');
?>
" />
		</p>

		<label for="content">Content: </label>
		<?php 
$content = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $asset->get('content'));
echo $this->editor('content', $content, 35, 10, 'content');
//, null, null, array('class' => 'minimal no-footer images'));
?>

<?php 
// @TODO: implement asset insertion to wiki body!
?>
Пример #2
0
$config = Component::params('com_courses');
$tool_path = $config->get('tool_path');
?>

<div class="edit-asset">
	<h3>Edit Asset</h3>

	<form action="<?php 
echo Request::base(true);
?>
/api/courses/asset/save" method="POST" class="edit-form">

		<p>
			<label for="title">Title:</label>
			<input type="text" name="title" value="<?php 
echo $asset->get('title');
?>
" placeholder="Asset Title" />
		</p>
		<?php 
if ($asset->get('type') != 'form') {
    ?>
		<p>
			<label for="title">URL:</label>
			<input type="text" name="url" value="<?php 
    echo $asset->get('url');
    ?>
" placeholder="Asset URL" />
		</p>
		<?php 
}
Пример #3
0
 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') {
             $link = '<span class="info">' . $this->escape(stripslashes($a->get('content') ? $a->get('content') : $a->get('title'))) . '</span>';
Пример #4
0
        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')));
        ?>
							</a>
							<span class="details">
								<time datetime="<?php 
 /**
  * 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();
                 }
             }
         }
     }
 }
Пример #6
0
                }
            }
        }
        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 
                    echo Lang::txt('This asset is <strong>unpublished</strong>.');
Пример #7
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);
 }