/** * Read file and returns an array filled up with its' content. * * @return array of objects */ protected function read() { $result = array(); $path = $this->path; if (!is_readable($path)) { return array(); } $items = \Import::csv_reader($path); foreach ($items as $item) { $item = (object) $item; $title = isset($item->title) ? trim($item->title) : ''; $content = isset($item->content) ? trim($item->content) : ''; $type = isset($item->type) ? trim($item->type) : ''; $title = \Security::remove_XSS($title); $content = \Security::remove_XSS($content); $type = \Security::remove_XSS($type); $is_blank_line = empty($title) && empty($content) && empty($type); if ($is_blank_line) { continue; } $type = CourseDescriptionType::repository()->find_one_by_name($type); $type_id = $type ? $type->id : 0; $description = CourseDescription::create(); $description->title = $title; $description->content = $content; $description->description_type = $type_id; $result[] = $description; } return $result; }
/** * * @param array $descriptions */ public function add($descriptions) { $this->objects_imported = 0; $this->objects_skipped = 0; foreach ($descriptions as $description) { $title = $description->title; $content = $description->content; $type = $description->type; if (empty($type)) { $type = CourseDescriptionType::repository()->find_one_by_name('general'); $description->description_type = $type->id; } if (empty($title) || empty($content)) { $this->objects_skipped++; continue; } // $description = $this->find_by_title($title); // if ($description && $this->update_existing_entries == false) { // $this->objects_skipped++; // continue; // } $description->c_id = $this->course->c_id; $description->session_id = $this->course->session_id; $repo = CourseDescription::repository(); $success = $repo->save($description); if ($success) { $this->objects_imported++; } else { $this->objects_skipped++; } } }
/** * Returns an array of objects of type CourseDescription corresponding to * a specific course, without session ids (session id = 0) * * @param int $course_id * * @return array Array of CourseDescriptions */ public static function get_descriptions($course_id) { // Get course code $course_info = api_get_course_info_by_id($course_id); if (!empty($course_info)) { $course_id = $course_info['real_id']; } else { return array(); } $t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION); $sql = "SELECT * FROM {$t_course_desc}\n WHERE c_id = {$course_id} AND session_id = '0'"; $sql_result = Database::query($sql); $results = array(); while ($row = Database::fetch_array($sql_result)) { $desc_tmp = new CourseDescription(); $desc_tmp->set_id($row['id']); $desc_tmp->set_title($row['title']); $desc_tmp->set_content($row['content']); $desc_tmp->set_session_id($row['session_id']); $desc_tmp->set_description_type($row['description_type']); $desc_tmp->set_progress($row['progress']); $results[] = $desc_tmp; } return $results; }
/** * Import PDFs * @param string Filename * @param string The subdirectory in which to put the files in each course */ function import_pdfs($file, $subDir = '/') { $baseDir = api_get_path(SYS_ARCHIVE_PATH); $uploadPath = 'pdfimport/'; $errors = array(); if (!is_dir($baseDir . $uploadPath)) { @mkdir($baseDir . $uploadPath); } if (!unzip_uploaded_file($_FILES['import_file'], $uploadPath, $baseDir, 1024 * 1024 * 1024)) { error_log('Could not unzip uploaded file in ' . __FILE__ . ', line ' . __LINE__); return $errors; } $list = scandir($baseDir . $uploadPath); $i = 0; foreach ($list as $file) { if (substr($file, 0, 1) == '.' or !is_file($baseDir . $uploadPath . $file)) { continue; } $parts = preg_split('/_/', $file); $course = api_get_course_info($parts[0]); if (count($course) > 0) { // Build file info because handle_uploaded_document() needs it (name, type, size, tmp_name) $fileSize = filesize($baseDir . $uploadPath . $file); $docId = add_document($course, $subDir . '/' . $file, 'file', $fileSize, $parts[1] . ' ' . substr($parts[2], 0, -4)); if ($docId > 0) { if (!is_file($baseDir . $uploadPath . $file)) { error_log($baseDir . $uploadPath . $file . ' does not exists in ' . __FILE__); } if (is_file(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file)) { error_log(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file . ' exists at destination in ' . __FILE__); } if (!is_writeable(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir)) { error_log('Destination ' . api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . ' is NOT writeable in ' . __FILE__); } // Place each file in its folder in each course $move = rename($baseDir . $uploadPath . $file, api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file); api_item_property_update($course, TOOL_DOCUMENT, $docId, 'DocumentAdded', api_get_user_id()); // Redo visibility api_set_default_visibility($docId, TOOL_DOCUMENT); $errors[] = array('Line' => 0, 'Code' => $course['code'], 'Title' => $course['title']); // Now add a link to the file from the Course description tool $link = '<p>Sílabo de la asignatura <a href="' . api_get_path(WEB_CODE_PATH) . 'document/document.php?cidReq=' . $course['code'] . '&id_session=0&gidReq=0&action=download&id=' . $docId . '" target="_blank"><img src="' . api_get_path(WEB_IMG_PATH) . 'icons/32/pdf.png"></a></p>'; $course_description = new CourseDescription(); $session_id = api_get_session_id(); $course_description->set_course_id($course['real_id']); $course_description->set_session_id($session_id); $course_description->set_title('Presentación de la asignatura'); $course_description->set_content($link); $course_description->set_description_type(1); $course_description->insert(); } } else { error_log($parts[0] . ' is not a course, apparently'); $errors[] = array('Line' => 0, 'Code' => $parts[0], 'Title' => $parts[0] . ' - ' . get_lang('CodeDoesNotExists')); } $i++; //found at least one entry that is not a dir or a . } if ($i == 0) { $errors[] = array('Line' => 0, 'Code' => '.', 'Title' => get_lang('NoPDFFoundAtRoot')); } return $errors; }
/** * It's used for destroy a course description, * render to listing view * @param int $id description type */ public function destroy($id) { $course_description = new CourseDescription(); $session_id = api_get_session_id(); $course_description->set_session_id($session_id); if (!empty($id)) { $course_description->set_id($id); $course_description->delete(); Display::addFlash(Display::return_message(get_lang('CourseDescriptionDeleted'))); } $this->listing(false); }
/** * Edit course description * * @param string API secret key * @param string Course id field name * @param string Course id value * @param int Category id from course description * @param string Description title * @param string Course description content */ public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { $verifKey = $this->verifyKey($secret_key); if($verifKey instanceof WSError) { $this->handleError($verifKey); } else { $course_id = $this->getCourseId($course_id_field_name, $course_id_value); if($course_id instanceof WSError) { return $course_id; } else { // Create the new course description $cd = new CourseDescription(); $cd->set_description_type($course_desc_id); $cd->set_title($course_desc_title); $cd->set_content($course_desc_content); $cd->set_session_id(0); // Get course info $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id)); // Check if this course description exists $descriptions = CourseDescription::get_descriptions($course_id); $exists = false; foreach($descriptions as $description) { if($description->get_description_type() == $course_desc_id) { $exists = true; } } if (!$exists) { $cd->set_progress(0); $cd->insert($course_info['db_name']); } else { $cd->update($course_info['db_name']); } } } }
/** * Create a new course description object. * * @return \CourseDescription */ public function create() { $result = new CourseDescription(); $result->set_description_type($this->get_id()); return $result; }
if (isset($_REQUEST['descId']) && is_numeric($_REQUEST['descId'])) { $descId = (int) $_REQUEST['descId']; } else { $descId = null; } if (isset($_REQUEST['category']) && $_REQUEST['category'] >= 0) { $category = $_REQUEST['category']; } else { $category = -1; } /* * init other vars */ $dialogBox = new DialogBox(); if ($is_allowedToEdit && !empty($cmd)) { $description = new CourseDescription(); if (!empty($descId)) { $description->load($descId); } if ($cmd == 'exEdit') { if (isset($_REQUEST['descTitle'])) { $description->setTitle($_REQUEST['descTitle']); } if (isset($_REQUEST['descContent'])) { $description->setContent($_REQUEST['descContent']); } if (isset($_REQUEST['descCategory'])) { $description->setCategory($_REQUEST['descCategory']); } if ($description->validate()) { // Update description
/** * It's used for destroy a course description, * render to listing view * @param int description type */ public function destroy($id) { $course_description = new CourseDescription(); $session_id = api_get_session_id(); $course_description->set_session_id($session_id); if (!empty($id)) { $course_description->set_id($id); $affected_rows = $course_description->delete(); } if ($affected_rows) { $message['destroy'] = true; } $this->listing(false, $message); }
<?php /* For licensing terms, see /license.txt */ /** * View (MVC patter) for editing a course description * @author Christian Fasanando <*****@*****.**> * @package chamilo.course_description */ // protect a course script api_protect_course_script(true); if (empty($id)) { $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : ''; if (empty($id)) { // If the ID was not provided, find the first matching description item given the item type $course_description = new CourseDescription(); $description = $course_description->get_data_by_description_type($description_type); if (count($description) > 0) { $id = $description['id']; } // If no corresponding description is found, edit a new one unset($course_description); } } $original_id = $id; if (empty($error)) { $token = Security::get_token(); } // display categories $categories = array(); foreach ($default_description_titles as $id => $title) { $categories[$id] = $title;
/** * Exclude object from result * * @param CourseDescription $courseDescription Object to remove from the list of results * * @return CourseDescriptionQuery The current query, for fluid interface */ public function prune($courseDescription = null) { if ($courseDescription) { $this->addUsingAlias(CourseDescriptionPeer::ID, $courseDescription->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param CourseDescription $value A CourseDescription object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(CourseDescription $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }