Beispiel #1
0
            $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 />';
Beispiel #2
0
 /**
  * @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;
 }
Beispiel #3
0
    /**
     * @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;
    }