Source for file CourseSection.class.php

Documentation is available at CourseSection.class.php

  1. <?php
  2.  
  3. require_once(OKI2."/osid/coursemanagement/CourseSection.php");
  4. /**
  5. * CourseSection is associated with a CourseOffering and is has a separate
  6. * roster and possibly a separate SectionType from any other Sections of the
  7. * Offering. CanonicalCourse contains general information about a course.
  8. * This is in contrast to the CourseOffering which contains information about
  9. * a concrete offering of this course in a specific term and with identified
  10. * people and roles. The section includes information about the location of
  11. * the class as well as the roster of students. CanonicalCourses can contain
  12. * other CanonicalCourses and may be organized hierarchically, in schools,
  13. * departments, for majors, and so on. For each CanonicalCourse, there are
  14. * zero or more offerings and for each offering, zero or more sections. All
  15. * three levels have separate data for Title, Number, Description, and Id.
  16. * This information can be the same or different as implementations choose and
  17. * applications require.
  18. *
  19. * <p>
  20. * OSID Version: 2.0
  21. * </p>
  22. *
  23. * @package harmoni.osid_v2.coursemanagement
  24. *
  25. * @copyright Copyright &copy; 2005, Middlebury College
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  27. *
  28. * @version $Id: CourseSection.class.php,v 1.26 2007/09/04 20:25:39 adamfranco Exp $
  29. */
  30. class HarmoniCourseSection
  31. extends CourseSection
  32. {
  33. /**
  34. * @variable object $_node the node in the hierarchy.
  35. * @access private
  36. * @variable object $_id the unique id for the course section.
  37. * @access private
  38. * @variable object $_table the course section table.
  39. * @access private
  40. * @variable object Id $_canonicalCoursesId the hierarchy
  41. * @access private
  42. ***/
  43. var $_node;
  44. var $_id;
  45. var $_table;
  46. var $_hierarchy;
  47. /**
  48. * The constructor.
  49. *
  50. * @param object Id $id
  51. * @param object Node $node
  52. *
  53. * @access public
  54. * @return void
  55. */
  56. function HarmoniCourseSection($id, $node)
  57. {
  58. $this->_id =$id;
  59. $this->_node =$node;
  60. $this->_table = 'cm_section';
  61. $cm = Services::getService("CourseManagement");
  62. $this->_hierarchy =$cm->_hierarchy;
  63. }
  64. /**
  65. * Update the title for this CourseSection.
  66. *
  67. * @param string $title
  68. *
  69. * @throws object CourseManagementException An exception
  70. * with one of the following messages defined in
  71. * org.osid.coursemanagement.CourseManagementException may be
  72. * thrown: {@link }
  73. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  74. * OPERATION_FAILED}, {@link }
  75. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  76. * PERMISSION_DENIED}, {@link }
  77. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  78. * CONFIGURATION_ERROR}, {@link }
  79. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  80. * UNIMPLEMENTED}, {@link }
  81. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  82. * NULL_ARGUMENT}
  83. *
  84. * @access public
  85. */
  86. function updateTitle ( $title ) {
  87. $this->_setField('title',$title);
  88. }
  89.  
  90. /**
  91. * Update the number for this CourseSection.
  92. *
  93. * @param string $number
  94. *
  95. * @throws object CourseManagementException An exception
  96. * with one of the following messages defined in
  97. * org.osid.coursemanagement.CourseManagementException may be
  98. * thrown: {@link }
  99. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  100. * OPERATION_FAILED}, {@link }
  101. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  102. * PERMISSION_DENIED}, {@link }
  103. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  104. * CONFIGURATION_ERROR}, {@link }
  105. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  106. * UNIMPLEMENTED}, {@link }
  107. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  108. * NULL_ARGUMENT}
  109. *
  110. * @access public
  111. */
  112. function updateNumber ( $number ) {
  113. $this->_setField('number',$number);
  114. }
  115.  
  116. /**
  117. * Update the description for this CourseSection.
  118. *
  119. * @param string $description
  120. *
  121. * @throws object CourseManagementException An exception
  122. * with one of the following messages defined in
  123. * org.osid.coursemanagement.CourseManagementException may be
  124. * thrown: {@link }
  125. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  126. * OPERATION_FAILED}, {@link }
  127. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  128. * PERMISSION_DENIED}, {@link }
  129. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  130. * CONFIGURATION_ERROR}, {@link }
  131. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  132. * UNIMPLEMENTED}, {@link }
  133. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  134. * NULL_ARGUMENT}
  135. *
  136. * @access public
  137. */
  138. function updateDescription ( $description ) {
  139. $this->_node->updateDescription($description );
  140. }
  141.  
  142. /**
  143. * Update the display name for this CourseSection.
  144. *
  145. * @param string $displayName
  146. *
  147. * @throws object CourseManagementException An exception
  148. * with one of the following messages defined in
  149. * org.osid.coursemanagement.CourseManagementException may be
  150. * thrown: {@link }
  151. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  152. * OPERATION_FAILED}, {@link }
  153. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  154. * PERMISSION_DENIED}, {@link }
  155. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  156. * CONFIGURATION_ERROR}, {@link }
  157. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  158. * UNIMPLEMENTED}, {@link }
  159. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  160. * NULL_ARGUMENT}
  161. *
  162. * @access public
  163. */
  164. function updateDisplayName ( $displayName ) {
  165. $this->_node->updateDisplayName($displayName );
  166. }
  167.  
  168. /**
  169. * Update the location may be a room address, a map, or any other object.
  170. *
  171. * @param object mixed $location (original type: java.io.Serializable)
  172. *
  173. * @throws object CourseManagementException An exception
  174. * with one of the following messages defined in
  175. * org.osid.coursemanagement.CourseManagementException may be
  176. * thrown: {@link }
  177. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  178. * OPERATION_FAILED}, {@link }
  179. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  180. * PERMISSION_DENIED}, {@link }
  181. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  182. * CONFIGURATION_ERROR}, {@link }
  183. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  184. * UNIMPLEMENTED}, {@link }
  185. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  186. * NULL_ARGUMENT}
  187. *
  188. * @access public
  189. */
  190. function updateLocation ( $location ) {
  191. $this->_setField('location',$location);
  192. }
  193.  
  194. /**
  195. * Get the title for this CourseSection.
  196. *
  197. * @return string
  198. *
  199. * @throws object CourseManagementException An exception
  200. * with one of the following messages defined in
  201. * org.osid.coursemanagement.CourseManagementException may be
  202. * thrown: {@link }
  203. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  204. * OPERATION_FAILED}, {@link }
  205. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  206. * PERMISSION_DENIED}, {@link }
  207. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  208. * CONFIGURATION_ERROR}, {@link }
  209. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  210. * UNIMPLEMENTED}
  211. *
  212. * @access public
  213. */
  214. function getTitle () {
  215. return $this->_getField('title');
  216. }
  217.  
  218. /**
  219. * Get the number for this CourseSection.
  220. *
  221. * @return string
  222. *
  223. * @throws object CourseManagementException An exception
  224. * with one of the following messages defined in
  225. * org.osid.coursemanagement.CourseManagementException may be
  226. * thrown: {@link }
  227. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  228. * OPERATION_FAILED}, {@link }
  229. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  230. * PERMISSION_DENIED}, {@link }
  231. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  232. * CONFIGURATION_ERROR}, {@link }
  233. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  234. * UNIMPLEMENTED}
  235. *
  236. * @access public
  237. */
  238. function getNumber () {
  239. return $this->_getField('number');
  240. }
  241.  
  242. /**
  243. * Get the description for this CourseSection.
  244. *
  245. * @return string
  246. *
  247. * @throws object CourseManagementException An exception
  248. * with one of the following messages defined in
  249. * org.osid.coursemanagement.CourseManagementException may be
  250. * thrown: {@link }
  251. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  252. * OPERATION_FAILED}, {@link }
  253. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  254. * PERMISSION_DENIED}, {@link }
  255. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  256. * CONFIGURATION_ERROR}, {@link }
  257. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  258. * UNIMPLEMENTED}
  259. *
  260. * @access public
  261. */
  262. function getDescription () {
  263. return $this->_node->getDescription();
  264. }
  265.  
  266. /**
  267. * Get the display name for this CourseSection.
  268. *
  269. * @return string
  270. *
  271. * @throws object CourseManagementException An exception
  272. * with one of the following messages defined in
  273. * org.osid.coursemanagement.CourseManagementException may be
  274. * thrown: {@link }
  275. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  276. * OPERATION_FAILED}, {@link }
  277. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  278. * PERMISSION_DENIED}, {@link }
  279. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  280. * CONFIGURATION_ERROR}, {@link }
  281. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  282. * UNIMPLEMENTED}
  283. *
  284. * @access public
  285. */
  286. function getDisplayName () {
  287. return $this->_node->getDisplayName();
  288. }
  289.  
  290. /**
  291. * Get the unique Id for this CourseSection.
  292. *
  293. * @return object Id
  294. *
  295. * @throws object CourseManagementException An exception
  296. * with one of the following messages defined in
  297. * org.osid.coursemanagement.CourseManagementException may be
  298. * thrown: {@link }
  299. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  300. * OPERATION_FAILED}, {@link }
  301. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  302. * PERMISSION_DENIED}, {@link }
  303. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  304. * CONFIGURATION_ERROR}, {@link }
  305. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  306. * UNIMPLEMENTED}
  307. *
  308. * @access public
  309. */
  310. function getId () {
  311. return $this->_id;
  312. }
  313.  
  314. /**
  315. * Get the Section Type for this CourseSection. This Type is meaningful to
  316. * the implementation and applications and are not specified by the OSID.
  317. *
  318. * @return object Type
  319. *
  320. * @throws object CourseManagementException An exception
  321. * with one of the following messages defined in
  322. * org.osid.coursemanagement.CourseManagementException may be
  323. * thrown: {@link }
  324. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  325. * OPERATION_FAILED}, {@link }
  326. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  327. * PERMISSION_DENIED}, {@link }
  328. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  329. * CONFIGURATION_ERROR}, {@link }
  330. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  331. * UNIMPLEMENTED}
  332. *
  333. * @access public
  334. */
  335. function getSectionType () {
  336. return $this->_getType('section');
  337. }
  338.  
  339. /**
  340. * Get the Schedule for this Section. Schedules are defined in scheduling
  341. * OSID. ScheduleItems are returned in chronological order by increasing
  342. * start date.
  343. *
  344. * @return object ScheduleItemIterator
  345. *
  346. * @throws object CourseManagementException An exception
  347. * with one of the following messages defined in
  348. * org.osid.coursemanagement.CourseManagementException may be
  349. * thrown: {@link }
  350. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  351. * OPERATION_FAILED}, {@link }
  352. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  353. * PERMISSION_DENIED}, {@link }
  354. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  355. * CONFIGURATION_ERROR}, {@link }
  356. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  357. * UNIMPLEMENTED}
  358. *
  359. * @access public
  360. */
  361. function getSchedule () {
  362. $dbManager = Services::getService("DatabaseManager");
  363. $query= new SelectQuery;
  364. $query->addTable('cm_schedule');
  365. $query->addTable('sc_item',INNER_JOIN,'cm_schedule.fk_sc_item = sc_item.id');
  366. $query->addColumn('cm_schedule.fk_sc_item');
  367. $query->addWhere("cm_schedule.fk_id='".addslashes($this->_id->getIdString())."'");
  368. $query->addOrderBy('sc_item.start');
  369. $res=$dbManager->query($query);
  370. $array=array();
  371. $sm = Services::getService("SchedulingManager");
  372. $idManager = Services::getService("IdManager");
  373. while($res->hasMoreRows()){
  374. $row = $res->getCurrentRow();
  375. $res->advanceRow();
  376. $id =$idManager->getId($row['fk_sc_item']);
  377. $si =$sm->getScheduleItem($id);
  378. $array[] =$si;
  379. }
  380. $ret = new HarmoniScheduleItemIterator($array);
  381. return $ret;
  382. }
  383.  
  384. /**
  385. * Get the location may be a room address, a map, or any other object.
  386. *
  387. * @return object mixed (original type: java.io.Serializable)
  388. *
  389. * @throws object CourseManagementException An exception
  390. * with one of the following messages defined in
  391. * org.osid.coursemanagement.CourseManagementException may be
  392. * thrown: {@link }
  393. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  394. * OPERATION_FAILED}, {@link }
  395. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  396. * PERMISSION_DENIED}, {@link }
  397. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  398. * CONFIGURATION_ERROR}, {@link }
  399. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  400. * UNIMPLEMENTED}
  401. *
  402. * @access public
  403. */
  404.  
  405. function getLocation () {
  406. $location = $this->_getField('location');
  407. return $location;
  408. }
  409.  
  410. /**
  411. * Get the Status for this CourseSection.
  412. *
  413. * @return object Type
  414. *
  415. * @throws object CourseManagementException An exception
  416. * with one of the following messages defined in
  417. * org.osid.coursemanagement.CourseManagementException may be
  418. * thrown: {@link }
  419. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  420. * OPERATION_FAILED}, {@link }
  421. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  422. * PERMISSION_DENIED}, {@link }
  423. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  424. * CONFIGURATION_ERROR}, {@link }
  425. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  426. * UNIMPLEMENTED}
  427. *
  428. * @access public
  429. */
  430. function getStatus () {
  431. return $this->_getType('section_stat');
  432. }
  433.  
  434. /**
  435. * Get all the Property Types for CourseSection.
  436. *
  437. * @return object TypeIterator
  438. *
  439. * @throws object CourseManagementException An exception
  440. * with one of the following messages defined in
  441. * org.osid.coursemanagement.CourseManagementException may be
  442. * thrown: {@link }
  443. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  444. * OPERATION_FAILED}, {@link }
  445. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  446. * PERMISSION_DENIED}, {@link }
  447. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  448. * CONFIGURATION_ERROR}, {@link }
  449. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  450. * UNIMPLEMENTED}
  451. *
  452. * @access public
  453. */
  454. function getPropertyTypes () {
  455. $courseType =$this->getSectionType();
  456. $propType = new Type("PropertiesType", $courseType->getAuthority(), "properties");
  457. $array = array($propType);
  458. $typeIterator = new HarmoniTypeIterator($array);
  459. return $typeIterator;
  460. }
  461.  
  462. /**
  463. * Get the Properties associated with this CourseSection.
  464. *
  465. * @return object PropertiesIterator
  466. *
  467. * @throws object CourseManagementException An exception
  468. * with one of the following messages defined in
  469. * org.osid.coursemanagement.CourseManagementException may be
  470. * thrown: {@link }
  471. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  472. * OPERATION_FAILED}, {@link }
  473. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  474. * PERMISSION_DENIED}, {@link }
  475. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  476. * CONFIGURATION_ERROR}, {@link }
  477. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  478. * UNIMPLEMENTED}
  479. *
  480. * @access public
  481. */
  482. function getProperties () {
  483. $array = array($this->_getProperties());
  484. $ret = new HarmoniPropertiesIterator($array);
  485. return $ret;//return the iterator
  486. }
  487.  
  488. /**
  489. * Get the CourseOffering that contains this CourseSection.
  490. *
  491. * @return object CourseOffering
  492. *
  493. * @throws object CourseManagementException An exception
  494. * with one of the following messages defined in
  495. * org.osid.coursemanagement.CourseManagementException may be
  496. * thrown: {@link }
  497. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  498. * OPERATION_FAILED}, {@link }
  499. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  500. * PERMISSION_DENIED}, {@link }
  501. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  502. * CONFIGURATION_ERROR}, {@link }
  503. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  504. * UNIMPLEMENTED}
  505. *
  506. * @access public
  507. */
  508. function getCourseOffering () {
  509. $nodeIterator =$this->_node->getParents();
  510. if(!$nodeIterator->hasNextNode()){
  511. print "<b>Warning!</b> Course Section ".$this->getDisplayName()." has no Course Offering Parent.";
  512. return null;
  513. }
  514. $parentNode =$nodeIterator->nextNode();
  515. $cm = Services::getService("CourseManagement");
  516. return $cm -> getCourseOffering($parentNode->getID());
  517. }
  518.  
  519. /**
  520. * Add an Asset for this CourseSection. Does nothing if the course has a
  521. * single copy of the asset and prints a warning if there is more than one
  522. * copy of that asset in one course.
  523. *
  524. * @param object Id $assetId
  525. *
  526. * @throws object CourseManagementException An exception
  527. * with one of the following messages defined in
  528. * org.osid.coursemanagement.CourseManagementException may be
  529. * thrown: {@link }
  530. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  531. * OPERATION_FAILED}, {@link }
  532. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  533. * PERMISSION_DENIED}, {@link }
  534. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  535. * CONFIGURATION_ERROR}, {@link }
  536. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  537. * UNIMPLEMENTED}, {@link }
  538. * org.osid.coursemanagement.CourseManagementException#ALREADY_ADDED
  539. * ALREADY_ADDED}
  540. *
  541. * @access public
  542. */
  543. function addAsset ( $assetId ) {
  544. $dbManager = Services::getService("DatabaseManager");
  545. $query= new SelectQuery;
  546. $query->addTable('cm_assets');
  547. $query->addWhere("fk_course_id='".$this->_id->getIdString()."'");
  548. $query->addWhere("fk_asset_id='".addslashes($assetId->getIdString())."'");
  549. $query->addColumn('fk_course_id');//@TODO We don't need fk_course_id here--we only want to check to see if that asset is already there.
  550. $res=$dbManager->query($query);
  551.  
  552.  
  553.  
  554. if($res->getNumberOfRows()==0){
  555. $query= new InsertQuery;
  556. $query->setTable('cm_assets');
  557. $values[]="'".addslashes($this->_id->getIdString())."'";
  558. $values[]="'".addslashes($assetId->getIdString())."'";
  559. $query->setColumns(array('fk_course_id','fk_asset_id'));
  560. $query->addRowOfValues($values);
  561. $result =$dbManager->query($query);
  562. }elseif($res->getNumberOfRows()==1){
  563. //do nothing
  564. }else{
  565. print "\n<b>Warning!<\b> The asset with course ".$this->getDisplayName()." and id ".$assetId->getIdString()." is not unique--there are ".$res->getNumberOfRows()." copies.\n";
  566.  
  567. }
  568. }
  569.  
  570. /**
  571. * Remove an Asset for this CourseSection.
  572. *
  573. * @param object Id $assetId
  574. *
  575. * @throws object CourseManagementException An exception
  576. * with one of the following messages defined in
  577. * org.osid.coursemanagement.CourseManagementException may be
  578. * thrown: {@link }
  579. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  580. * OPERATION_FAILED}, {@link }
  581. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  582. * PERMISSION_DENIED}, {@link }
  583. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  584. * CONFIGURATION_ERROR}, {@link }
  585. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  586. * UNIMPLEMENTED}, {@link }
  587. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  588. * NULL_ARGUMENT}, {@link }
  589. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  590. * UNKNOWN_ID}
  591. *
  592. * @access public
  593. */
  594. function removeAsset ( $assetId ) {
  595. $dbManager = Services::getService("DatabaseManager");
  596. $query= new DeleteQuery;
  597. $query->setTable('cm_assets');
  598. $query->addWhere("fk_course_id='".$this->_id->getIdString()."'");
  599. $query->addWhere("fk_asset_id='".addslashes($assetId->getIdString())."'");
  600. $dbManager->query($query);
  601. }
  602.  
  603. /**
  604. * Get the Assets associated with this CourseSection.
  605. *
  606. * @return object IdIterator
  607. *
  608. * @throws object CourseManagementException An exception
  609. * with one of the following messages defined in
  610. * org.osid.coursemanagement.CourseManagementException may be
  611. * thrown: {@link }
  612. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  613. * OPERATION_FAILED}, {@link }
  614. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  615. * PERMISSION_DENIED}, {@link }
  616. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  617. * CONFIGURATION_ERROR}, {@link }
  618. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  619. * UNIMPLEMENTED}
  620. *
  621. * @access public
  622. */
  623. function getAssets () {
  624. $dbManager = Services::getService("DatabaseManager");
  625. $query= new SelectQuery;
  626. $query->addTable('cm_assets');
  627. $query->addWhere("fk_course_id='".$this->_id->getIdString()."'");
  628. $query->addColumn('fk_asset_id');
  629. $res=$dbManager->query($query);
  630. $array=array();
  631. $idManager = Services::getService("Id");
  632. while($res->hasMoreRows()){
  633. $row = $res->getCurrentRow();
  634. $res->advanceRow();
  635. $array[]=$idManager->getId($row['fk_asset_id']);
  636. }
  637. $ret = new HarmoniIdIterator($array);
  638. return $ret;
  639. }
  640.  
  641. /**
  642. * Update the Schedule for this Section. Schedules are defined in
  643. * scheduling OSID.
  644. *
  645. * @param object ScheduleItem[] $scheduleItems
  646. *
  647. * @throws object CourseManagementException An exception
  648. * with one of the following messages defined in
  649. * org.osid.coursemanagement.CourseManagementException may be
  650. * thrown: {@link }
  651. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  652. * OPERATION_FAILED}, {@link }
  653. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  654. * PERMISSION_DENIED}, {@link }
  655. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  656. * CONFIGURATION_ERROR}, {@link }
  657. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  658. * UNIMPLEMENTED}, {@link }
  659. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  660. * NULL_ARGUMENT}
  661. *
  662. * @access public
  663. */
  664. function updateSchedule ( $scheduleItems ) {
  665. $dbManager = Services::getService("DatabaseManager");
  666. $query= new DeleteQuery;
  667. $query->setTable('cm_schedule');
  668. $query->addWhere('fk_id='.addslashes($this->_id->getIdString()));
  669. $dbManager->query($query);
  670. /*
  671. $query= new InsertQuery;
  672. $query->setTable('cm_schedule');
  673. $query->setColumns(array('fk_id','fk_sc_item'));
  674. $idString = "'".addslashes($id->getIdString())."'";
  675.  
  676.  
  677. //iterate through array
  678. foreach($schedule as $scheduleItem){
  679. $values = array();
  680. $values[]= $idString;
  681. $scheduleId =$scheduleItem->getId();
  682. $values[]="'".addslashes($scheduleId->getIdString())."'";
  683. $query->addRowOfValues($values);
  684.  
  685. }
  686. $dbManager->query($query);
  687. */
  688. //query
  689. $query= new InsertQuery;
  690. $query->setTable('cm_schedule');
  691. $query->setColumns(array('fk_id','fk_sc_item'));
  692. $idString = "'".addslashes($this->_id->getIdString())."'";
  693. //iterate through array
  694. foreach($scheduleItems as $scheduleItem){
  695. $values = array();
  696. $values[]= $idString;
  697. $id =$scheduleItem->getId();
  698. $values[]="'".addslashes($id->getIdString())."'";
  699. $query->addRowOfValues($values);
  700. }
  701. $dbManager->query($query);
  702. }
  703.  
  704. /**
  705. * Add a student to the roster and assign the specified Enrollment Status
  706. * Type.
  707. *
  708. * @param object Id $agentId
  709. * @param object Type $enrollmentStatusType
  710. *
  711. * @throws object CourseManagementException An exception
  712. * with one of the following messages defined in
  713. * org.osid.coursemanagement.CourseManagementException may be
  714. * thrown: {@link }
  715. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  716. * OPERATION_FAILED}, {@link }
  717. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  718. * PERMISSION_DENIED}, {@link }
  719. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  720. * CONFIGURATION_ERROR}, {@link }
  721. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  722. * UNIMPLEMENTED}, {@link }
  723. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  724. * NULL_ARGUMENT}, {@link }
  725. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  726. * UNKNOWN_TYPE}, {@link }
  727. * org.osid.coursemanagement.CourseManagementException#ALREADY_ADDED
  728. * ALREADY_ADDED}
  729. *
  730. * @access public
  731. */
  732. function addStudent ( $agentId, $enrollmentStatusType ) {
  733.  
  734. $dbManager = Services::getService("DatabaseManager");
  735. $query= new SelectQuery;
  736. $query->addTable('cm_enroll');
  737. $query->addWhere("fk_cm_section='".addslashes($this->_id->getIdString())."'");
  738. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  739. //I don't need Id, but I need to select something for the query to work
  740. $query->addColumn('id');
  741. $res=$dbManager->query($query);
  742. if($res->getNumberOfRows()==0){
  743. $typeIndex = $this->_typeToIndex('enroll_stat',$enrollmentStatusType);
  744. $query= new InsertQuery;
  745. $query->setTable('cm_enroll');
  746. $values[]="'".addslashes($agentId->getIdString())."'";
  747. $values[]="'".addslashes($typeIndex)."'";
  748. $values[]="'".addslashes($this->_id->getIdString())."'";
  749. $query->setColumns(array('fk_student_id','fk_cm_enroll_stat_type','fk_cm_section'));
  750. $query->addRowOfValues($values);
  751. $query->setAutoIncrementColumn('id','id_sequence');
  752. $dbManager->query($query);
  753. }else{
  754. print "<b>Warning!</b> Student with id ".$agentId->getIdString()." is already enrolled in section ".$this->getDisplayName().".";
  755. }
  756.  
  757. }
  758.  
  759. /**
  760. * Change the Enrollment Status Type for the student on the roster.
  761. *
  762. * @param object Id $agentId
  763. * @param object Type $enrollmentStatusType
  764. *
  765. * @throws object CourseManagementException An exception
  766. * with one of the following messages defined in
  767. * org.osid.coursemanagement.CourseManagementException may be
  768. * thrown: {@link }
  769. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  770. * OPERATION_FAILED}, {@link }
  771. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  772. * PERMISSION_DENIED}, {@link }
  773. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  774. * CONFIGURATION_ERROR}, {@link }
  775. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  776. * UNIMPLEMENTED}, {@link }
  777. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  778. * NULL_ARGUMENT}, {@link }
  779. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  780. * UNKNOWN_TYPE}
  781. *
  782. * @access public
  783. */
  784. function changeStudent ( $agentId, $enrollmentStatusType ) {
  785. $dbManager = Services::getService("DatabaseManager");
  786. $query= new SelectQuery;
  787. $query->addTable('cm_enroll');
  788. $query->addWhere("fk_cm_section='".addslashes($this->_id->getIdString())."'");
  789. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  790. //I don't need Id, but I need to select something for the query to work
  791. $query->addColumn('id');
  792. $res=$dbManager->query($query);
  793. if($res->getNumberOfRows()==0){
  794. throwError(new Error("Cannot change status of student [".$agentId->getIDString()."] because that student in not enrolled in the course[".$this->_id->getIdString()."]", "CourseManagement", true));
  795. }else if($res->getNumberOfRows()>1){
  796. print "<b>Warning!</b> Student with id ".$agentId->getIdString()." is already enrolled in section ".$this->getDisplayName()." twice.";
  797. }
  798. $typeIndex = $this->_typeToIndex('enroll_stat',$enrollmentStatusType);
  799. $query= new UpdateQuery;
  800. $query->setTable('cm_enroll');
  801.  
  802. $query->addWhere("fk_cm_section='".addslashes($this->_id->getIdString())."'");
  803. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  804.  
  805. $query->setColumns(array('fk_cm_enroll_stat_type'));
  806. $query->setValues(array("'".addslashes($typeIndex)."'"));
  807.  
  808. $dbManager->query($query);
  809.  
  810. }
  811.  
  812. /**
  813. * Remove a student from the roster.
  814. *
  815. * @param object Id $agentId
  816. *
  817. * @throws object CourseManagementException An exception
  818. * with one of the following messages defined in
  819. * org.osid.coursemanagement.CourseManagementException may be
  820. * thrown: {@link }
  821. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  822. * OPERATION_FAILED}, {@link }
  823. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  824. * PERMISSION_DENIED}, {@link }
  825. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  826. * CONFIGURATION_ERROR}, {@link }
  827. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  828. * UNIMPLEMENTED}, {@link }
  829. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  830. * NULL_ARGUMENT}, {@link }
  831. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  832. * UNKNOWN_ID}
  833. *
  834. * @access public
  835. */
  836. function removeStudent ( $agentId ) {
  837.  
  838. $dbManager = Services::getService("DatabaseManager");
  839. $query= new DeleteQuery;
  840.  
  841.  
  842. $query->setTable('cm_enroll');
  843.  
  844. $query->addWhere("fk_cm_section='".addslashes($this->_id->getIdString())."'");
  845. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  846. $dbManager->query($query);
  847. }
  848.  
  849. /**
  850. * Get the student roster.
  851. *
  852. * @return object EnrollmentRecordIterator
  853. *
  854. * @throws object CourseManagementException An exception
  855. * with one of the following messages defined in
  856. * org.osid.coursemanagement.CourseManagementException may be
  857. * thrown: {@link }
  858. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  859. * OPERATION_FAILED}, {@link }
  860. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  861. * PERMISSION_DENIED}, {@link }
  862. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  863. * CONFIGURATION_ERROR}, {@link }
  864. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  865. * UNIMPLEMENTED}
  866. *
  867. * @access public
  868. */
  869. function getRoster () {
  870.  
  871. $dbManager = Services::getService("DatabaseManager");
  872.  
  873. $array=array();
  874.  
  875.  
  876. $query= new SelectQuery;
  877. $query->addTable('cm_enroll');
  878. //$query->addColumn('fk_student_id');
  879. $query->addColumn('id');
  880. $query->addWhere("fk_cm_section='".addslashes($this->_id->getIdString())."'");
  881.  
  882.  
  883. $res=$dbManager->query($query);
  884. $idManager = Services::getService('IdManager');
  885. while($res->hasMoreRows()){
  886. $row = $res->getCurrentRow();
  887. $res->advanceRow();
  888. $array[] = new HarmoniEnrollmentRecord($idManager->getId($row['id']));
  889. }
  890. $ret = new HarmoniEnrollmentRecordIterator($array);
  891. return $ret;
  892. }
  893.  
  894. /**
  895. * Get the student roster. Include only students with the specified
  896. * Enrollment Status Type.
  897. *
  898. * @param object Type $enrollmentStatusType
  899. *
  900. * @return object EnrollmentRecordIterator
  901. *
  902. * @throws object CourseManagementException An exception
  903. * with one of the following messages defined in
  904. * org.osid.coursemanagement.CourseManagementException may be
  905. * thrown: {@link }
  906. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  907. * OPERATION_FAILED}, {@link }
  908. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  909. * PERMISSION_DENIED}, {@link }
  910. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  911. * CONFIGURATION_ERROR}, {@link }
  912. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  913. * UNIMPLEMENTED}, {@link }
  914. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  915. * NULL_ARGUMENT}, {@link }
  916. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  917. * UNKNOWN_TYPE}
  918. *
  919. * @access public
  920. */
  921. function getRosterByType ( $enrollmentStatusType ) {
  922. $dbManager = Services::getService("DatabaseManager");
  923. $typeIndex = $this->_typeToIndex('enroll_stat',$enrollmentStatusType);
  924.  
  925. $array=array();
  926.  
  927.  
  928. $query= new SelectQuery;
  929. $query->addTable('cm_enroll');
  930. //$query->addColumn('fk_student_id');
  931. $query->addColumn('id');
  932. //$query->addWhere("fk_cm_section='".addslashes($this->_id)."'");
  933. $query->addWhere("fk_cm_section='".addslashes($this->_id->getIdString())."' AND fk_cm_enroll_stat_type='".addslashes($typeIndex)."'");
  934.  
  935. $res=$dbManager->query($query);
  936. $idManager = Services::getService('IdManager');
  937. while($res->hasMoreRows()){
  938. $row = $res->getCurrentRow();
  939. $res->advanceRow();
  940. $array[] = new HarmoniEnrollmentRecord($idManager->getId($row['id']));
  941. }
  942. $ret = new HarmoniEnrollmentRecordIterator($array);
  943. return $ret;
  944. }
  945.  
  946. /**
  947. * Update the Status for this CourseSection.
  948. *
  949. * @param object Type $statusType
  950. *
  951. * @throws object CourseManagementException An exception
  952. * with one of the following messages defined in
  953. * org.osid.coursemanagement.CourseManagementException may be
  954. * thrown: {@link }
  955. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  956. * OPERATION_FAILED}, {@link }
  957. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  958. * PERMISSION_DENIED}, {@link }
  959. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  960. * CONFIGURATION_ERROR}, {@link }
  961. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  962. * UNIMPLEMENTED}, {@link }
  963. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  964. * NULL_ARGUMENT}, {@link }
  965. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  966. * UNKNOWN_TYPE}
  967. *
  968. * @access public
  969. */
  970. function updateStatus ( $statusType ) {
  971. $this->_setField('fk_cm_section_stat_type',$this->_typeToIndex('section_stat',$statusType));
  972. }
  973.  
  974. /**
  975. * Get the Properties of this Type associated with this CourseSection.
  976. *
  977. * @param object Type $propertiesType
  978. *
  979. * @return object Properties
  980. *
  981. * @throws object CourseManagementException An exception
  982. * with one of the following messages defined in
  983. * org.osid.coursemanagement.CourseManagementException may be
  984. * thrown: {@link }
  985. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  986. * OPERATION_FAILED}, {@link }
  987. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  988. * PERMISSION_DENIED}, {@link }
  989. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  990. * CONFIGURATION_ERROR}, {@link }
  991. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  992. * UNIMPLEMENTED}, {@link }
  993. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  994. * NULL_ARGUMENT}, {@link }
  995. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  996. * UNKNOWN_TYPE}
  997. *
  998. * @access public
  999. */
  1000. function getPropertiesByType ( $propertiesType ) {
  1001. $courseType =$this->getSectionType();
  1002. $propertiesType = new Type("PropertiesType", $courseType->getAuthority(), "properties");
  1003. if($propertiesType->isEqualTo($propertiesType)){
  1004. return $this->_getProperties();
  1005. }
  1006. return null;
  1007. }
  1008. function _getProperties(){
  1009. $dbManager = Services::getService("DatabaseManager");
  1010. //get the record
  1011. $query = new SelectQuery;
  1012. $query->addTable('cm_section');
  1013. $query->addColumn("*");
  1014. $query->addWhere("id='".addslashes($this->_id->getIdString())."'");
  1015. $res=$dbManager->query($query);
  1016. //make sure we can find that course
  1017. if(!$res->hasMoreRows()){
  1018. print "<b>Warning!</b> Can't get Properties of Course with id ".$this->_id." since that id wasn't found in the database.";
  1019. return null;
  1020. }
  1021. $row = $res->getCurrentRow();//grab (hopefully) the only row
  1022. //make a type
  1023. $courseType =$this->getSectionType();
  1024. $propertiesType = new Type("PropertiesType", $courseType->getAuthority(), "properties");
  1025. //create a custom Properties object
  1026. $idManager = Services::getService("Id");
  1027. $property = new HarmoniProperties($propertiesType);
  1028. $displayName = $this->_node->getDisplayName();
  1029. $property->addProperty('display_name', $displayName);
  1030. $property->addProperty('title', $row['title']);
  1031. $description = $this->_node->getDescription();
  1032. $property->addProperty('description',$description);
  1033. $property->addProperty('id', $idManager->getId($row['id']));
  1034. $property->addProperty('number', $row['number']);
  1035. $property->addProperty('type', $courseType);
  1036. $statusType =$this->getStatus();
  1037. $property->addProperty('status_type', $statusType);
  1038. $property->addProperty('location', $row['location']);
  1039.  
  1040. $res->free();
  1041. return $property;
  1042. }
  1043. function _typeToIndex($typename, $type)
  1044. {
  1045. $cm=Services::getService("CourseManagement");
  1046. return $cm->_typeToIndex($typename, $type);
  1047. }
  1048.  
  1049. function _getTypes($typename)
  1050. {
  1051. $cm=Services::getService("CourseManagement");
  1052. return $cm->_getTypes($typename);
  1053. }
  1054.  
  1055. function _getField($key)
  1056. {
  1057. $cm=Services::getService("CourseManagement");
  1058. return $cm->_getField($this->_id, $this->_table, $key);
  1059. }
  1060.  
  1061.  
  1062. function _getType($typename){
  1063. $cm=Services::getService("CourseManagement");
  1064. return $cm->_getType($this->_id,$this->_table,$typename);
  1065. }
  1066.  
  1067. function _setField($key, $value)
  1068. {
  1069. $cm=Services::getService("CourseManagement");
  1070. return $cm->_setField($this->_id,$this->_table,$key, $value);
  1071. }
  1072.  
  1073.  
  1074. }
  1075.  
  1076. ?>

Documentation generated on Wed, 19 Sep 2007 10:22:22 -0400 by phpDocumentor 1.3.0RC3