示例#1
0
 /**
  * Save the given entries in the profile specified by id.
  * @param string $id The id of the layout to query. 0 to add a new layout.
  * @param string $name The new name of the layout.  
  * @param array $entries A numeric array of {@link SloodleLayoutEntry} objects to store
  * @param bool $add (Default: false) If true, then the entries will be added to the layout instead of replacing existing entries
  * @return bool True if successful, or false otherwise
  */
 function save_layout_by_id($id, $name, $entries, $add = false)
 {
     // Attempt to find the relevant layout
     if ($id > 0) {
         /*
                         // Delete all existing entries if necessary
                         // This will happen when we save
                         // TODO: make add-only functionality for backwards compatibility
                         if (!$add) {
                                 delete_records('sloodle_layout_entry', 'layout', $layout->id);
                         }
         */
         $layout = $this->get_layout($id);
         $layout->name = $name;
         $layout->timeupdated = time();
         $layout->entries = $entries;
         $layout->populate_entries_from_active_objects();
         // where the records have objectuuids set, copy their settings
         if (!$layout->update()) {
             return false;
         }
         $this->layout = $layout;
     } else {
         $layout = new SloodleLayout();
         $layout->name = $name;
         $layout->course = $this->course_object->id;
         $layout->timeupdated = time();
         $layout->entries = $entries;
         $layout->populate_entries_from_active_objects();
         $layout->id = $layout->insert();
         #insert_record('sloodle_layout', $layout);
         if (!$layout->id) {
             return false;
         }
         $this->layout = $layout;
     }
     /*
                 // This should have been done by the layout
                 // Insert each new entry
                 $success = true;
                 foreach ($entries as $e) {
                     $rec = new stdClass();
                     $rec->layout = $layout->id;
                     $rec->name = $e->name;
                     $rec->position = $e->position;
                     $rec->rotation = $e->rotation;
     
                     // TODO EDE: If there's an objectuuid for the entry, copy the entries from the active object table to the layout config table
                     if ($objectuuid != '') {
                        $rec->copy_active_object_with_uuid($e->objectuuid);
                     }
                    
                     $entry_id = insert_record('sloodle_layout_entry', $rec);
                    
                 }
     */
     return $layout->id;
 }