CalendarSegment::cloneCalendar PHP Method

cloneCalendar() static public method

Duplicate all segments from a calendar to his clone
static public cloneCalendar ( $oldid, $newid )
$oldid
$newid
    static function cloneCalendar($oldid, $newid)
    {
        global $DB;
        $query = "SELECT *\n                FROM `glpi_calendarsegments`\n                WHERE `calendars_id`='{$oldid}'";
        foreach ($DB->request($query) as $data) {
            $c = new self();
            unset($data['id']);
            $data['calendars_id'] = $newid;
            $data['_no_history'] = true;
            $c->add($data);
        }
    }

Usage Example

 /** Clone a calendar to another entity : name is updated
  *
  * @param $options array of new values to set
  **/
 function duplicate($options = array())
 {
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             if (isset($this->fields[$key])) {
                 $this->fields[$key] = $val;
             }
         }
     }
     $input = $this->fields;
     $oldID = $input['id'];
     unset($input['id']);
     if ($newID = $this->add($input)) {
         Calendar_Holiday::cloneCalendar($oldID, $newID);
         CalendarSegment::cloneCalendar($oldID, $newID);
         $this->updateDurationCache($newID);
         return true;
     }
     return false;
 }
All Usage Examples Of CalendarSegment::cloneCalendar