Пример #1
0
 /**
  * Add a  chapter to the Cim10 database
  *
  * @param array $master_entry  The master entry
  * @param array $chapter_entry The chapter entry
  *
  * @return void
  */
 function addChapter($master_entry, $chapter_entry)
 {
     /* We remove the useless characters in the code */
     $master_entry['code'] = self::cleanCode($master_entry['code']);
     $code = '(' . $master_entry['code'] . ')';
     list($sort) = explode('-', $master_entry['code']);
     $date = CMbDT::format($master_entry['date'], '%Y-%m-%d 00:00:00');
     /* Check if the chapter already exists */
     $query = "SELECT `SID` FROM `master` WHERE `code` LIKE '{$code}' AND `type` = 'C';";
     if (!is_null($this->ds->loadResult($query))) {
         return;
     }
     /* Insert the chapter in the master table*/
     $query = "INSERT INTO `master` (`code`, `sort`, `abbrev`, `level`, `type`, `valid`, `date`, `author`)\n      VALUES ('{$code}', '{$sort}\\'', '{$code}', '1', 'C', 1, '{$date}', '" . $master_entry['origine'] . "');";
     if ($this->ds->exec($query)) {
         $this->added_codes++;
         /* Get the SID of the chapter */
         $sid = $this->ds->insertId();
         /* Update the master entry for setting the id1 */
         $query = "UPDATE `master` SET `id1` = {$sid} WHERE `SID` = {$sid};";
         $this->ds->exec($query);
         /* Insert the label */
         $this->insertLabel($sid, 'S', self::cleanLabel($master_entry['label']), $date, $master_entry['origine']);
         $rom = str_replace('Chapitre ', '', $chapter_entry['code']);
         $dec = CMbString::roman2dec($rom);
         /* Create the chapter in the chapter table */
         $query = "INSERT INTO `chapter` (`chap`, `SID`, `rom`) VALUES ({$dec}, {$sid}, '{$rom}');";
         $this->ds->exec($query);
     }
 }