Jump to content

First Year Course Re Form For Setting Enrollment To School/course


terrancegavan

Recommended Posts

Hello:

Yes a newbie who is on Chapter 7 of Nixon/ have an assignment due

seeking help not the full answer... otherwise this course is

doing me no good at all... :)

here's the deal:

our challenge ... up to now we have been doing graded exercises worth 5% and I have been doing okay 66 to 96 %

but compiling all that 6 weeks of info into a structured exercise is more daunting

our assignment:


  • Using any text editor, create a file to store course name, course code, and maximum enrolment. Fields can be separated by a special character or special sequence of characters. The field separators must be character sequences that will not occur in a course name or a course code. Each line of the file is a separate course. Each course must have a unique name and a unique course code.
    Example: my list i created as txt in CONTEXT editor .. we can't use (not supposed to use ) an IDE although i have netbeans on board,,,
     
    COLLEGE LIST :: COURSE NUMBERS :: COURSE MAX
    Durham :: art history 201 :: 4
    Fleming :: politics 102 :: 4
    Sheridan :: Philosophy 103 :: 3
    The reason for a low maximum enrolment in the example is to make testing easier.

  • Using any text editor, create a file to store student name and student number. Fields can be separated by a special character or special sequence of characters. The field separators must be character sequences that will not occur in a student name or a student number. Each line of the file is one student. Each student must have a unique student number. In real world enrolments, two or more students may have the same name. The application must be tested to handle that case.
    Example: my list
     
    $name :: $student_id
    t_gavan :: 12000,
    s_elliot :: 12001,
    e_powell :: 12003,
    a_goodson :: 12004,
    j_ehinger :: 12005,
    s_baugh :: 12006,
    d_Butkus :: 12007,
    s_nash :: 12008,
    larry_bird :: 12009,

  • Create any other file that may be needed to store data, for example, a file to list all students enrolled in each course. In a real world application, the code that enrols students may not have authorization to modify the student and course databases. Separating data by functionality simplifies code and maintains data integrity.

  • unsure of what to do here??? just an open file of txt??

Operation

  • A visitor's initial access to the application will be through its main page. The main page will be named index.php.
  • The visitor will be allowed to select a course from a list.
  • The visitor will enter a student name and a student number. The visitor must not be shown a list of student names or student numbers.
    • If the student information does not match an existing student record, the visitor must not be told which part of the student information does not match.
    • If the student name and student number match an existing student record and if the course selected has not reached maximum enrolment and if the student has not enrolled in the course already, the student can be enrolled into the course.

    [*]The visitor must be informed of the results of the enrolment attempt and allowed to select from the course list again.

    [*]Terry writes my help needed >>>I think I need to create a form here that is simple.. ie

    [*]enter name <form method "text" "name">

    [*]enter student id <form method "text" "number">

    [*]choose college <form method ???? dropdown college??> does this make sense??

The objective of the assignment is to demonstrate PHP skills. To maintain focus on the server side objective, the client side must be easy to use but should not include any code except for HTML. (terry writes??? not getting this at all) what's best way to set up the index.php file for form entry???

Make no assumptions about which client platform will be used to test and grade the assignment. The application must work equally well with any web browser on any platform. See the design guide at http://www.anybrowser.org/campaign/ and search the W3C web site for information on web accessibility and non-visual user agents. For example, the W3C specification for tables at http://www.w3.org/TR/html4/struct/tables.html makes recommendation for designing tables that can be rendered by non-visual user agents. terry writes wtf?? I am assuming that we do not want this data to be visible in view source?? and should be out of bounds to hacks...

any hints or examp[les ... re help ..help especially with the index page would be appreciated

i an a self-taught client side web designer who came up through html/then css/then xml then html5 and on to wordpress design... i find that i learned best by reverse engineering... thus i spent an awful lot of time back in the 1990's staring at souyrce code from nifty sites..i am guessing that this is my best hope moving forward with php.. books and exercises are one thing.. but working with code ie another form like this is the best way for me to understand what's really "goin' on!"

cheersany help appreciated

gavanterance

Link to comment
Share on other sites

Well, create all required files first. Then using SplFileObject you can retrieve all lines as such:

 

$file = new SplFileInfo('data/course.csv');

$fileObj = $file->openFile('rb+'); // read
$fileObj->setFlags($fileObj::READ_CSV);
$fileObj->setCsvControl(' :: ', '', '');

foreach ($fileObj as $line) {
  print_r($line);
}

 

This should print out all the lines in your files. To write you do the reverse:

 

$file = new SplFileInfo('data/enrollment.csv');

$fileObj = $file->openFile('wb+'); // write
$fileObj->setCsvControl(' :: ', '', '');

foreach ($students as $enrollment) {
  $fileObj->fputcsv($enrollment);
}

 

You may want to wrap this inside a class:

 

class ProprietaryCsvFile {
  const DELIMITER = ' :: ';
  const ENCLOSURE = '';
  const ESCAPE    = '';
  
  private $file;
  private $reader;
  private $writer;

  public function setFile(SplFileInfo $file) {
    if (!$file instanceof SplFileInfo) {
      throw new InvalidArgumentException;
    }
    
    $this->file = $file;
    $this->refresh();
  }
  
  public function refresh() {
    $this->reader = null;
    $this->writer = null;
  }
  
  private function getReader() {
    if (!$this->reader) {
      $obj = $this->file->openFile('rb+');
      $obj->setFlags($obj::READ_CSV | $obj::SKIP_EMPTY | $obj::DROP_NEW_LINE);
      $obj->setCsvControl($this::DELIMITER, $this::ENCLOSURE, $this::ESCAPE);
      $this->reader = $obj;
    }
    return $this->reader;
  }
  
  private function getWriter() {
    if (!$this->writer) {
      $obj = $this->file->openFile('wb+');
      $obj->setCsvControl($this::DELIMITER, $this::ENCLOSURE, $this::ESCAPE);
      $this->writer = $obj;
    }
    return $this->writer;
  }
  
  public function read() {
    return $this->getReader()->fgetcsv();
  }
  
  public function readAll() { 
    $lines = new ArrayObject();
    foreach ($this->getReader() as $line) {
      $lines->append($line);
    }
    return $lines;
  }
  
  public function write(array $line) {
    $this->getWriter()->fputcsv($line);
  }
  
  public function writeAll(array $lines) {
    foreach ($lines as $line) {
      $this->write($line);
    }
  }
}

 

$file = new ProprietaryCsvFile;
$file->setFile(new SplFileInfo('data/students.csv'));
print_r($file->readAll());

 

Returns all students. To check if a the maximum enrollment has not been exceeded and the student isn't already enrolled is just reading out the proper files and running some checks.

 

Make no assumptions about which client platform will be used to test and grade the assignment. The application must work equally well with any web browser on any platform. See the design guide at http://www.anybrowser.org/campaign/ and search the W3C web site for information on web accessibility and non-visual user agents. For example, the W3C specification for tables at http://www.w3.org/TR...uct/tables.html makes recommendation for designing tables that can be rendered by non-visual user agents.

 

What your teach. wrote here was that you should keep it basic <form/> <table/> <input/> stuff and is nothing special so nothing hackable there ;)

Edited by ignace
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.