当前位置: 首页>>代码示例>>PHP>>正文


PHP data_update_instance函数代码示例

本文整理汇总了PHP中data_update_instance函数的典型用法代码示例。如果您正苦于以下问题:PHP data_update_instance函数的具体用法?PHP data_update_instance怎么用?PHP data_update_instance使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了data_update_instance函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import

 function import()
 {
     global $CFG;
     list($settings, $newfields, $currentfields) = $this->get_settings();
     $preservedfields = array();
     $overwritesettings = optional_param('overwritesettings', 0, PARAM_BOOL);
     /* Maps fields and makes new ones */
     if (!empty($newfields)) {
         /* We require an injective mapping, and need to know what to protect */
         foreach ($newfields as $nid => $newfield) {
             $cid = optional_param("field_{$nid}", -1, PARAM_INT);
             if ($cid == -1) {
                 continue;
             }
             if (array_key_exists($cid, $preservedfields)) {
                 error("Not an injective map");
             } else {
                 $preservedfields[$cid] = true;
             }
         }
         foreach ($newfields as $nid => $newfield) {
             $cid = optional_param("field_{$nid}", -1, PARAM_INT);
             /* A mapping. Just need to change field params. Data kept. */
             if ($cid != -1 and isset($currentfields[$cid])) {
                 $fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->data);
                 foreach ($newfield as $param => $value) {
                     if ($param != "id") {
                         $fieldobject->field->{$param} = $value;
                     }
                 }
                 unset($fieldobject->field->similarfield);
                 $fieldobject->update_field();
                 unset($fieldobject);
             } else {
                 include_once "field/{$newfield->type}/field.class.php";
                 if (!isset($newfield->description)) {
                     $newfield->description = '';
                 }
                 $classname = 'data_field_' . $newfield->type;
                 $fieldclass = new $classname($newfield, $this->data);
                 $fieldclass->insert_field();
                 unset($fieldclass);
             }
         }
     }
     /* Get rid of all old unused data */
     if (!empty($preservedfields)) {
         foreach ($currentfields as $cid => $currentfield) {
             if (!array_key_exists($cid, $preservedfields)) {
                 /* Data not used anymore so wipe! */
                 print "Deleting field {$currentfield->name}<br />";
                 $id = $currentfield->id;
                 //Why delete existing data records and related comments/ratings??
                 /*
                                     if ($content = get_records('data_content', 'fieldid', $id)) {
                                         foreach ($content as $item) {
                                             delete_records('data_ratings', 'recordid', $item->recordid);
                                             delete_records('data_comments', 'recordid', $item->recordid);
                                             delete_records('data_records', 'id', $item->recordid);
                                         }
                                     }*/
                 delete_records('data_content', 'fieldid', $id);
                 delete_records('data_fields', 'id', $id);
             }
         }
     }
     // handle special settings here
     if (!empty($settings->defaultsort)) {
         if (is_numeric($settings->defaultsort)) {
             // old broken value
             $settings->defaultsort = 0;
         } else {
             $settings->defaultsort = (int) get_field('data_fields', 'id', 'dataid', $this->data->id, 'name', addslashes($settings->defaultsort));
         }
     } else {
         $settings->defaultsort = 0;
     }
     // do we want to overwrite all current database settings?
     if ($overwritesettings) {
         // all supported settings
         $overwrite = array_keys((array) $settings);
     } else {
         // only templates and sorting
         $overwrite = array('singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter', 'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate', 'asearchtemplate', 'defaultsortdir', 'defaultsort');
     }
     // now overwrite current data settings
     foreach ($this->data as $prop => $unused) {
         if (in_array($prop, $overwrite)) {
             $this->data->{$prop} = $settings->{$prop};
         }
     }
     data_update_instance(addslashes_object($this->data));
     if (strstr($this->folder, '/temp/')) {
         // Removes the temporary files
         clean_preset($this->folder);
     }
     return true;
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:98,代码来源:lib.php

示例2: import


//.........这里部分代码省略.........
        global $DB, $CFG;

        $params = $this->get_preset_settings();
        $settings = $params->settings;
        $newfields = $params->importfields;
        $currentfields = $params->currentfields;
        $preservedfields = array();

        /* Maps fields and makes new ones */
        if (!empty($newfields)) {
            /* We require an injective mapping, and need to know what to protect */
            foreach ($newfields as $nid => $newfield) {
                $cid = optional_param("field_$nid", -1, PARAM_INT);
                if ($cid == -1) {
                    continue;
                }
                if (array_key_exists($cid, $preservedfields)){
                    print_error('notinjectivemap', 'data');
                }
                else $preservedfields[$cid] = true;
            }

            foreach ($newfields as $nid => $newfield) {
                $cid = optional_param("field_$nid", -1, PARAM_INT);

                /* A mapping. Just need to change field params. Data kept. */
                if ($cid != -1 and isset($currentfields[$cid])) {
                    $fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->module);
                    foreach ($newfield as $param => $value) {
                        if ($param != "id") {
                            $fieldobject->field->$param = $value;
                        }
                    }
                    unset($fieldobject->field->similarfield);
                    $fieldobject->update_field();
                    unset($fieldobject);
                } else {
                    /* Make a new field */
                    include_once("field/$newfield->type/field.class.php");

                    if (!isset($newfield->description)) {
                        $newfield->description = '';
                    }
                    $classname = 'data_field_'.$newfield->type;
                    $fieldclass = new $classname($newfield, $this->module);
                    $fieldclass->insert_field();
                    unset($fieldclass);
                }
            }
        }

        /* Get rid of all old unused data */
        if (!empty($preservedfields)) {
            foreach ($currentfields as $cid => $currentfield) {
                if (!array_key_exists($cid, $preservedfields)) {
                    /* Data not used anymore so wipe! */
                    print "Deleting field $currentfield->name<br />";

                    $id = $currentfield->id;
                    //Why delete existing data records and related comments/ratings??
                    $DB->delete_records('data_content', array('fieldid'=>$id));
                    $DB->delete_records('data_fields', array('id'=>$id));
                }
            }
        }

        // handle special settings here
        if (!empty($settings->defaultsort)) {
            if (is_numeric($settings->defaultsort)) {
                // old broken value
                $settings->defaultsort = 0;
            } else {
                $settings->defaultsort = (int)$DB->get_field('data_fields', 'id', array('dataid'=>$this->module->id, 'name'=>$settings->defaultsort));
            }
        } else {
            $settings->defaultsort = 0;
        }

        // do we want to overwrite all current database settings?
        if ($overwritesettings) {
            // all supported settings
            $overwrite = array_keys((array)$settings);
        } else {
            // only templates and sorting
            $overwrite = array('singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
                               'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate',
                               'asearchtemplate', 'defaultsortdir', 'defaultsort');
        }

        // now overwrite current data settings
        foreach ($this->module as $prop=>$unused) {
            if (in_array($prop, $overwrite)) {
                $this->module->$prop = $settings->$prop;
            }
        }

        data_update_instance($this->module);

        return $this->cleanup();
    }
开发者ID:nottmoo,项目名称:moodle,代码行数:101,代码来源:lib.php

示例3: import

 /**
  * import()
  * TODO document
  */
 function import()
 {
     global $CFG;
     list($settings, $newfields, $currentfields) = $this->load_from_file();
     $preservedfields = array();
     /* Maps fields and makes new ones */
     if (!empty($newfields)) {
         /* We require an injective mapping, and need to know what to protect */
         foreach ($newfields as $nid => $newfield) {
             $cid = optional_param("field_{$nid}", -1, PARAM_INT);
             if ($cid == -1) {
                 continue;
             }
             if (array_key_exists($cid, $preservedfields)) {
                 print_error('notinjectivemap', 'data');
             } else {
                 $preservedfields[$cid] = true;
             }
         }
         foreach ($newfields as $nid => $newfield) {
             $cid = optional_param("field_{$nid}", -1, PARAM_INT);
             /* A mapping. Just need to change field params. Data kept. */
             if ($cid != -1 and isset($currentfelds[$cid])) {
                 $fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->data);
                 foreach ($newfield as $param => $value) {
                     if ($param != "id") {
                         $fieldobject->field->{$param} = $value;
                     }
                 }
                 unset($fieldobject->field->similarfield);
                 $fieldobject->update_field();
                 unset($fieldobject);
             } else {
                 include_once "field/{$newfield->type}/field.class.php";
                 if (!isset($newfield->description)) {
                     $newfield->description = '';
                 }
                 $classname = 'data_field_' . $newfield->type;
                 $fieldclass = new $classname($newfield, $this->data);
                 $fieldclass->insert_field();
                 unset($fieldclass);
             }
         }
     }
     /* Get rid of all old unused data */
     if (!empty($preservedfields)) {
         foreach ($currentfields as $cid => $currentfield) {
             if (!array_key_exists($cid, $preservedfields)) {
                 /* Data not used anymore so wipe! */
                 print "Deleting field {$currentfield->name}<br />";
                 $id = $currentfield->id;
                 // Why delete existing data records and related comments/ratings ??
                 /*
                 if ($content = get_records('data_content', 'fieldid', $id)) {
                     foreach ($content as $item) {
                         delete_records('data_ratings', 'recordid', $item->recordid);
                         delete_records('data_comments', 'recordid', $item->recordid);
                         delete_records('data_records', 'id', $item->recordid);
                     }
                 }
                 */
                 delete_records('data_content', 'fieldid', $id);
                 delete_records('data_fields', 'id', $id);
             }
         }
     }
     data_update_instance(addslashes_object($settings));
     if (strstr($this->directory, '/temp/')) {
         clean_preset($this->directory);
     }
     /* Removes the temporary files */
     return true;
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:77,代码来源:preset_class.php


注:本文中的data_update_instance函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。