Ejemplo n.º 1
0
 /**
  * Update existing note and logs the action
  * @param int $noteid id in table note
  * @param string $title note title
  * @param text $content note body
  * @param string $reference_obj_id refernced object by note. It contains the object type (from $ref_object_types) and object id (id in the corresponding db table), e.g., video_link:5  
  */
 public static function update_note($noteid, $title, $content, $reference_obj_id = NULL){
     global $uid;
     $refobjinfo = References::get_ref_obj_field_values($reference_obj_id);
     Database::get()->query("UPDATE note SET title = ?s, content = ?s, reference_obj_module = ?d, reference_obj_type = ?s, reference_obj_id = ?d, reference_obj_course = ?d WHERE id = ?d", $title, purify($content), $refobjinfo['objmodule'], $refobjinfo['objtype'], $refobjinfo['objid'], $refobjinfo['objcourse'], $noteid);
     Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_NOTE, $noteid);
     Log::record(0, MODULE_ID_NOTES, LOG_MODIFY, array('user_id' => $uid, 'id' => $noteid,
     'title' => $title,
     'content' => ellipsize_html(canonicalize_whitespace(strip_tags($content)), 50, '+')));
 }
Ejemplo n.º 2
0
 /**
  * Update existing event and logs the action
  * @param int $eventid id in table personal_calendar
  * @param string $title event title
  * @param string $start event datetime
  * @param text $content event details
  * @param boolean $recursivelly specifies if the update should be applied to all events of the group of recursive events or to the specific one
  * @param string $reference_obj_id refernced object by note. It contains the object type (from $ref_object_types) and object id (id in the corresponding db table), e.g., video_link:5
  */
 public static function update_event($eventid, $title, $start, $duration, $content, $recursivelly = false, $reference_obj_id = NULL)
 {
     global $uid, $langNotValidInput;
     $refobjinfo = References::get_ref_obj_field_values($reference_obj_id);
     $d1 = DateTime::createFromFormat('Y-m-d H:i', $start);
     $d2 = DateTime::createFromFormat('Y-m-d H:i:s', $start);
     $title = trim($title);
     if (empty($title) || !($d1 && $d1->format('Y-m-d H:i') == $start || $d2 && $d2->format('Y-m-d H:i:s') == $start)) {
         return array('success' => false, 'message' => $langNotValidInput);
     }
     $where_clause = $recursivelly ? "WHERE source_event_id = ?d" : "WHERE id = ?d";
     Database::get()->query("UPDATE personal_calendar SET " . "title = ?s, " . "start = ?t, " . "duration = ?t, " . "content = ?s, " . "reference_obj_module = ?d, " . "reference_obj_type = ?s, " . "reference_obj_id = ?d, " . "reference_obj_course = ?d " . $where_clause, $title, $start, $duration, purify($content), $refobjinfo['objmodule'], $refobjinfo['objtype'], $refobjinfo['objid'], $refobjinfo['objcourse'], $eventid);
     Log::record(0, MODULE_ID_PERSONALCALENDAR, LOG_MODIFY, array('user_id' => $uid, 'id' => $eventid, 'title' => $title, 'content' => ellipsize_html(canonicalize_whitespace(strip_tags($content)), 50, '+')));
     return array('success' => true, 'message' => '', 'event' => $eventid);
 }
Ejemplo n.º 3
0
    /**
     * Update existing event and logs the action
     * @param int $eventid id in table personal_calendar
     * @param string $title event title
     * @param string $start event datetime
     * @param text $content event details
     * @param boolean $recursivelly specifies if the update should be applied to all events of the group of recursive events or to the specific one
     * @param string $reference_obj_id refernced object by note. It contains the object type (from $ref_object_types) and object id (id in the corresponding db table), e.g., video_link:5
     */
    public static function update_event($eventid, $title, $start, $duration, $content, $recursivelly = false, $recursion = NULL, $reference_obj_id = NULL) {
        global $uid, $langNotValidInput;
        
        if($recursivelly && !is_null($recursion)){
            $oldrec = Calendar_Events::get_event_recursion($eventid, 'personal');
            $p = "P".$recursion['repeat'].$recursion['unit'];
            $e = DateTime::createFromFormat('d-m-Y', $recursion['end'])->format('Y-m-d');
            if($oldrec->recursion_period != $p || $oldrec->recursion_end != $e){
                Calendar_Events::delete_recursive_event($eventid, 'personal');
                return Calendar_Events::add_event($title, $content, $start, $duration, $recursion, $reference_obj_id);
            }
        }
        if(!is_null($recursion) && !Calendar_Events::is_recursive($eventid, 'personal')){
            Calendar_Events::delete_event($eventid, 'personal');
            return Calendar_Events::add_event($title, $content, $start, $duration, $recursion, $reference_obj_id);
        }
            
        $refobjinfo = References::get_ref_obj_field_values($reference_obj_id);

        $d1 = DateTime::createFromFormat('d-m-Y H:i', $start);
        $d2 = DateTime::createFromFormat('d-m-Y H:i:s', $start);
        $title = trim($title);
        if (empty($title) || !(($d1 && $d1->format('d-m-Y H:i') == $start) || ($d2 && $d2->format('d-m-Y H:i:s') == $start))) {
            return array('success' => false, 'message' => $langNotValidInput);
        }

        $where_clause = ($recursivelly)? "WHERE source_event_id = ?d":"WHERE id = ?d";
        $startdatetimeformatted = ($recursivelly)? $d1->format('H:i'):$d1->format('Y-m-d H:i');
        $start_date_update_clause = ($recursivelly)? "start = CONCAT(date_format(start, '%Y-%m-%d '),?t), ":"start = ?t, ";
        Database::get()->query("UPDATE personal_calendar SET "
                . "title = ?s, "
                . $start_date_update_clause
                . "duration = ?t, "
                . "content = ?s, "
                . "reference_obj_module = ?d, "
                . "reference_obj_type = ?s, "
                . "reference_obj_id = ?d, "
                . "reference_obj_course = ?d "
                . $where_clause,
                $title, $startdatetimeformatted, $duration, purify($content), $refobjinfo['objmodule'], $refobjinfo['objtype'], $refobjinfo['objid'], $refobjinfo['objcourse'], $eventid);

        Log::record(0, MODULE_ID_PERSONALCALENDAR, LOG_MODIFY, array('user_id' => $uid, 'id' => $eventid,
        'title' => $title,
        'content' => ellipsize_html(canonicalize_whitespace(strip_tags($content)), 50, '+')));
        return array('success' => true, 'message' => '', 'event' => $eventid);
    }