SSLTrack::populateFrom PHP Method

populateFrom() public method

public populateFrom ( array $fields )
$fields array
    public function populateFrom(array $fields)
    {
        $this->fields = $fields;
        isset($fields['filename']) && ($this->filename = trim($fields['filename']));
        isset($fields['row']) && ($this->row = $fields['row']);
        isset($fields['title']) && ($this->title = trim($fields['title']));
        isset($fields['artist']) && ($this->artist = trim($fields['artist']));
        isset($fields['deck']) && ($this->deck = $fields['deck']);
        isset($fields['starttime']) && ($this->start_time = $fields['starttime']);
        isset($fields['endtime']) && ($this->end_time = $fields['endtime']);
        isset($fields['played']) && ($this->played = (bool) $fields['played']);
        isset($fields['added']) && ($this->added = $fields['added']);
        isset($fields['updatedAt']) && ($this->updated_at = $fields['updatedAt']);
        isset($fields['playtime']) && ($this->playtime = $fields['playtime']);
        isset($fields['length']) && ($this->length = trim($fields['length']));
        isset($fields['album']) && ($this->album = trim($fields['album']));
        isset($fields['fullpath']) && ($this->fullpath = trim($fields['fullpath']));
    }

Usage Example

コード例 #1
0
 /**
  * @return SSLHistoryDom
  */
 protected function readCSV($filename)
 {
     $fp = fopen($filename, 'r');
     if ($fp === false) {
         throw new RuntimeException("Could not open CSV file {$filename}");
     }
     $tracks = array();
     $field_order = array('row', 'deck', 'artist', 'title', 'starttime', 'endtime', 'played', 'added', 'updatedAt', 'playtime', 'length');
     while (false !== ($fs = fgetcsv($fp))) {
         if ($fs) {
             foreach ($field_order as $i => $f_name) {
                 isset($fs[$i]) && ($fields[$f_name] = $fs[$i]);
             }
             $track = new SSLTrack();
             $track->populateFrom($fields);
             $tracks[] = $track;
         }
     }
     if (empty($tracks)) {
         throw new InvalidArgumentException("File {$filename} contained no records");
     }
     fclose($fp);
     return $tracks;
 }