本文整理汇总了PHP中hierarchy::get_next_child_sortthread方法的典型用法代码示例。如果您正苦于以下问题:PHP hierarchy::get_next_child_sortthread方法的具体用法?PHP hierarchy::get_next_child_sortthread怎么用?PHP hierarchy::get_next_child_sortthread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hierarchy
的用法示例。
在下文中一共展示了hierarchy::get_next_child_sortthread方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: time
$data->visible = 1;
$data->timecreated = time();
$data->usermodified = $USER->id;
$data->childpermissions = 1;
$hierarche = new hierarchy ();
if ($data->parentid == 0) {
$data->depth = 1;
$data->path = '';
} else {
/* ---parent item must exist--- */
$parent = $DB->get_record('local_school', array('id' => $data->parentid));
$data->depth = $parent->depth + 1;
$data->path = $parent->path;
}
if (!$sortthread = $hierarche->get_next_child_sortthread($data->parentid, 'local_school')) {
return false;
}
$data->sortorder = $sortthread;
$data->id = $DB->insert_record('local_school', $data);
$DB->set_field('local_school', 'path', $data->path . '/' . $data->id, array('id' => $data->id));
$data->id++;
$schoolsnew++;
}
}
$cir->cleanup(true);
echo $OUTPUT->box_start('boxwidthnarrow boxaligncenter generalbox', 'uploadresults');
echo '<p>';
if ($optype != UU_SCHOOL_UPDATE) {
echo get_string('schoolscreated', 'local_collegestructure') . ': ' . $schoolsnew . '<br />';
示例2: array
/**
* @method insert_plan
* @todo Inserts a new record
* @param $plan(array)
* @return Id of the inserted data
* */
function insert_plan($plan) {
global $DB;
$hierarchy = new hierarchy;
if ($plan->parentid == 0) {
$plan->depth = 1;
$plan->path = '';
} else {
// parent item must exist
$parent = $DB->get_record('local_curriculum_plan', array('id' => $plan->parentid));
$plan->depth = $parent->depth + 1;
$plan->path = $parent->path;
}
//get next child item that need to provide
if (!$sortorder = $hierarchy->get_next_child_sortthread($plan->parentid, 'local_curriculum_plan')) {
return false;
}
$plan->sortorder = $sortorder;
//$plan->sortorder = $hierarchy->get_next_child_sortthread($plan->parentid, $table = 'local_curriculum_plan');
$newplan = $DB->insert_record('local_curriculum_plan', $plan);
$DB->set_field('local_curriculum_plan', 'path', $plan->path . '/' . $newplan, array('id' => $newplan));
return $plan->id;
}
示例3: update_school
/**
* @method update_school
* @param object $school
* @param object $newparentid school data
* @retun Updates the school
*
*/
public function update_school($school, $newparentid, $plugin) {
global $DB, $CFG;
$hierarche = new hierarchy ();
if (!is_object($school)) {
return false;
}
if ($school->parentid == 0) {
/* ---create a 'fake' old parent item for items at the top level--- */
$oldparent = new stdClass();
$oldparent->id = 0;
$oldparent->path = '';
$oldparent->depth = 0;
} else {
$oldparent = $DB->get_record($plugin, array('id' => $school->parentid));
}
if ($newparentid == 0) {
$newparent = new stdClass();
$newparent->id = 0;
$newparent->path = '';
$newparent->depth = 0;
} else {
$newparent = $DB->get_record($plugin, array('id' => $newparentid));
if ($this->subschool_of($newparent, $school->id) || empty($newparent)) {
return false;
}
}
if (!$newsortorder = $hierarche->get_next_child_sortthread($newparentid, $plugin)) {
return false;
}
$oldsortorder = $school->sortorder;
/* ---update the sortorder for the all items--- */
$this->update_sortorder($oldsortorder, $newsortorder, $plugin);
/* ---update the depth of the item and its descendants--- */
$depthdiff = ($newparent->depth + 1) - $school->depth;
/* ---update the depth--- */
$params = array('depthdiff' => $depthdiff,
'path' => $school->path,
'pathb' => "$school->path/%");
$sql = "UPDATE $CFG->prefix$plugin
SET depth = depth + :depthdiff
WHERE (path = :path OR
" . $DB->sql_like('path', ':pathb') . ")";
$DB->execute($sql, $params);
$length_sql = $DB->sql_length("'$oldparent->path'");
$substr_sql = $DB->sql_substr('path', "{$length_sql} + 1");
$updatepath = $DB->sql_concat("'{$newparent->path}'", $substr_sql);
$params = array(
'path' => $school->path,
'pathb' => "$school->path/%");
$sql = "UPDATE $CFG->prefix$plugin
SET path = $updatepath
WHERE (path = :path OR
" . $DB->sql_like('path', ':pathb') . ")";
$DB->execute($sql, $params);
$todb = new stdClass();
$todb->id = $school->id;
$todb->parentid = $newparentid;
$DB->update_record($plugin, $todb);
return true;
}