Ejemplo n.º 1
0
defined('_HZEXEC_') or die;
$results = null;
$notes = $this->model->notes($this->filters);
if ($notes) {
    foreach ($notes as $note) {
        $ky = $note->get('scope_id');
        if (!isset($results[$ky])) {
            $results[$ky] = array();
        }
        $results[$ky][] = $note;
    }
}
$base = $this->offering->link();
if ($results) {
    foreach ($results as $id => $notes) {
        $lecture = new \Components\Courses\Models\Assetgroup($id);
        $unit = \Components\Courses\Models\Unit::getInstance($lecture->get('unit_id'));
        echo $this->escape(stripslashes($lecture->get('title'))) . "\n";
        echo '--------------------------------------------------' . "\n";
        foreach ($notes as $note) {
            echo '#' . $note->get('id');
            if ($note->get('timestamp') != '00:00:00') {
                echo ' video time: ' . $this->escape($note->get('timestamp'));
            }
            echo "\n";
            echo $this->escape(stripslashes($note->get('content')));
            echo "\n\n";
        }
        echo "\n";
    }
}
Ejemplo n.º 2
0
 /**
  * Reorder a plugin
  *
  * @param      integer $access Access level to set
  * @return     void
  */
 public function orderTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $id = Request::getVar('id', array(0), 'post', 'array');
     \Hubzero\Utility\Arr::toInteger($id, array(0));
     $uid = $id[0];
     $inc = $this->_task == 'orderup' ? -1 : 1;
     $row = new Tables\Assetgroup($this->database);
     $row->load($uid);
     $row->move($inc, 'unit_id=' . $this->database->Quote($row->unit_id) . ' AND parent=' . $this->database->Quote($row->parent));
     $row->reorder('unit_id=' . $this->database->Quote($row->unit_id) . ' AND parent=' . $this->database->Quote($row->parent));
     //$unit = \Components\Courses\Models\Unit::getInstance(Request::getInt('unit', 0));
     //$ags = $unit->assetgroups(null, array('parent' => $row->parent));
     if ($ags = $row->find(array('w' => array('parent' => $row->parent, 'unit_id' => $row->unit_id)))) {
         foreach ($ags as $ag) {
             $a = new \Components\Courses\Models\Assetgroup($ag);
             $a->store();
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&unit=' . Request::getInt('unit', 0), false));
 }
Ejemplo n.º 3
0
				<input type="submit" class="filter-submit" value="<?php 
    echo Lang::txt('PLG_COURSES_NOTES_GO');
    ?>
" />
			</p>
		</div><!-- / .filters-inner -->
	</fieldset>
</form>

<div class="notes-wrap">
<?php 
    if ($results) {
        ?>
	<?php 
        foreach ($results as $id => $notes) {
            $lecture = new \Components\Courses\Models\Assetgroup($id);
            $unit = \Components\Courses\Models\Unit::getInstance($lecture->get('unit_id'));
            ?>
	<div class="section">
		<h3><?php 
            echo $this->escape(stripslashes($lecture->get('title')));
            ?>
</h3>
		<?php 
            foreach ($notes as $note) {
                ?>
		<div class="jSticky-medium static<?php 
                if ($note->get('access')) {
                    echo ' annotation';
                }
                ?>
Ejemplo n.º 4
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;
$ag = new \Components\Courses\Models\Assetgroup($this->scope_id);
?>

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

		<p>
			<label for="title">Title:</label>
			<input type="text" name="title" value="<?php 
echo $ag->get('title');
?>
" placeholder="Asset Group Title" />
		</p>
Ejemplo n.º 5
0
 /**
  * Saves data to the database
  *
  * @param     $redirect boolean Redirect after saving?
  * @return    void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $fields = Request::getVar('fields', array(), 'post');
     // Instantiate a Course object
     $model = \Components\Courses\Models\Unit::getInstance($fields['id']);
     if (!$model->bind($fields)) {
         $this->setError($model->getError());
         $this->editTask($model);
         return;
     }
     if (!$model->store(true)) {
         $this->setError($model->getError());
         $this->editTask($model);
         return;
     }
     if ($model->get('id') && $model->assetgroups()->total() <= 0) {
         $asset_groups = explode(',', $this->config->get('default_asset_groups', 'Lectures, Homework, Exam'));
         array_map('trim', $asset_groups);
         foreach ($asset_groups as $key) {
             // Get our asset group object
             $assetGroup = new \Components\Courses\Models\Assetgroup(null);
             $assetGroup->set('title', $key);
             $assetGroup->set('unit_id', $model->get('id'));
             $assetGroup->set('parent', 0);
             // Save the asset group
             if (!$assetGroup->store(true)) {
                 $this->setError($model->getError());
             }
         }
     }
     if ($this->_task == 'apply') {
         return $this->editTask($model);
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&offering=' . Request::getInt('offering', 0), false), Lang::txt('COM_COURSES_ITEM_SAVED'));
 }
Ejemplo n.º 6
0
 /**
  * Create method for this handler
  *
  * @return array of assets created
  **/
 public function create()
 {
     // Include needed files
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'asset.association.php';
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'asset.php';
     require_once dirname(__DIR__) . DS . 'asset.php';
     // Get the file
     if (isset($_FILES['files'])) {
         $file = $_FILES['files']['name'][0];
         $size = (int) $_FILES['files']['size'];
         // Get the file extension
         $pathinfo = pathinfo($file);
         $filename = $pathinfo['filename'];
         $ext = $pathinfo['extension'];
     } else {
         return array('error' => 'No files provided');
     }
     // @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 = (int) $config->get('upload_maxsize');
     $sizeLimit = $sizeLimit * 1024 * 1024;
     // 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}");
     }
     // get request vars
     $course_id = Request::getInt('course_id', 0);
     $offering_alias = Request::getCmd('offering', '');
     $scope = Request::getCmd('scope', 'asset_group');
     $scope_id = Request::getInt('scope_id', 0);
     // get all assets in group
     $assetGroup = new \Components\Courses\Models\Assetgroup($scope_id);
     $assets = $assetGroup->assets();
     // check to see if any of our assets are html5?
     $hubpresenter = null;
     foreach ($assets as $asset) {
         if ($asset->get('type') == 'video' && $asset->get('subtype') == 'video' && in_array($asset->get('state'), array(0, 1)) && strpos($asset->get('url'), 'zip')) {
             $hubpresenter = $asset;
             break;
         }
     }
     // make sure we have asset
     if ($hubpresenter === null) {
         return array('error' => 'Unable to locate html5 video or hubpresenter asset to attach subtitle file to.');
     }
     // build path to asset
     $pathToAsset = $hubpresenter->path($course_id);
     $pathToAssetFolder = trim(dirname($pathToAsset), DS);
     // build target path
     $target_path = PATH_APP . DS . $pathToAssetFolder . DS . $filename . '.' . $ext;
     // Move the file to the site folder
     set_time_limit(60);
     // Scan for viruses
     if (!Filesystem::isSafe($_FILES['files']['tmp_name'][0])) {
         // Scan failed, return an error
         return array('error' => 'File rejected because the anti-virus scan failed.');
     }
     // move file
     if (!($move = move_uploaded_file($_FILES['files']['tmp_name'][0], $target_path))) {
         // Move failed, delete asset and association and return an error
         return array('error' => 'Move file failed');
     }
     // get json file
     $jsonFile = $pathToAssetFolder . DS . 'presentation.json';
     // get manifest
     $manifest = file_get_contents(PATH_APP . DS . $jsonFile);
     $manifest = json_decode($manifest);
     // make sure we have a subtitles section
     $currentSubtitles = array();
     if (!isset($manifest->presentation->subtitles)) {
         $manifest->presentation->subtitles = array();
     } else {
         foreach ($manifest->presentation->subtitles as $subtitle) {
             $currentSubtitles[] = $subtitle->source;
         }
     }
     // create subtitle details based on filename
     $info = pathinfo($file);
     $name = str_replace('-auto', '', $info['filename']);
     $autoplay = strstr($info['filename'], '-auto') ? 1 : 0;
     $source = $file;
     // use only the last segment from name (ex. ThisIsATest.English => English)
     $nameParts = explode('.', $name);
     $name = array_pop($nameParts);
     // add subtitle
     $subtitle = new stdClass();
     $subtitle->type = 'SRT';
     $subtitle->name = ucfirst($name);
     $subtitle->source = $source;
     $subtitle->autoplay = $autoplay;
     // only add sub if we dont already have it
     if (!in_array($subtitle->source, $currentSubtitles)) {
         $manifest->presentation->subtitles[] = $subtitle;
     }
     // update json file
     file_put_contents(PATH_APP . DS . $jsonFile, json_encode($manifest, JSON_PRETTY_PRINT));
     //parse subtitle file
     $lines = self::_parseSubtitleFile($target_path);
     // make transcript file
     $transcript = '';
     foreach ($lines as $line) {
         $transcript .= ' ' . trim($line->text);
     }
     // trim transcript and replace add slide markers
     $transcript = str_replace(array("\r\n", "\n"), array('', ''), $transcript);
     $transcript = preg_replace("/\\[([^\\]]*)\\]/ux", "\n\n[\$1]", $transcript);
     // add title to transcript
     $transcript = $manifest->presentation->title . PHP_EOL . str_repeat('==', 20) . PHP_EOL . ltrim($transcript, PHP_EOL);
     // Create our asset table object
     $assetObj = new Tables\Asset($this->db);
     $this->asset['title'] = 'Video Transcript';
     $this->asset['type'] = 'file';
     $this->asset['subtype'] = 'file';
     $this->asset['url'] = $info['filename'] . '.txt';
     $this->asset['created'] = Date::toSql();
     $this->asset['created_by'] = App::get('authn')['user_id'];
     $this->asset['course_id'] = $course_id;
     // Save the asset
     if (!$assetObj->save($this->asset)) {
         return array('error' => 'Asset save failed');
     }
     // Create asset assoc object
     $assocObj = new Tables\AssetAssociation($this->db);
     $this->assoc['asset_id'] = $assetObj->get('id');
     $this->assoc['scope'] = $scope;
     $this->assoc['scope_id'] = $scope_id;
     // Save the asset association
     if (!$assocObj->save($this->assoc)) {
         return array('error' => 'Asset association save failed');
     }
     // Get courses config
     $cconfig = Component::params('com_courses');
     // Build the upload path if it doesn't exist
     $uploadDirectory = PATH_APP . DS . trim($cconfig->get('uploadpath', '/site/courses'), DS) . DS . $this->asset['course_id'] . DS . $this->assoc['asset_id'] . DS;
     // 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
     $transcript_target_path = $uploadDirectory . $this->asset['url'];
     // make transcript file
     file_put_contents($transcript_target_path, $transcript);
     // 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);
     $url = Route::url('index.php?option=com_courses&controller=offering&gid=' . $course->get('alias') . '&offering=' . $offering_alias . '&asset=' . $assetObj->get('id'));
     // build return info
     $return_info = array('asset_id' => $this->assoc['asset_id'], 'asset_title' => $this->asset['title'], 'asset_type' => $this->asset['type'], 'asset_subtype' => $this->asset['subtype'], 'asset_url' => $url, 'course_id' => $this->asset['course_id'], 'offering_alias' => Request::getCmd('offering', ''), 'scope_id' => $this->assoc['scope_id'], 'asset_ext' => 'txt', 'upload_path' => $uploadDirectory, 'target_path' => $transcript_target_path);
     // Return info
     return array('assets' => $return_info);
 }