<?php
/*
    Klasa opakowania dla CPT homework
    /wp-content/plugins/schoolpress/classes/class.homework.php
*/
class Homework {
    // Konstruktor może pobrać $post_id
    function __construct( $post_id = NULL ) {
        if ( !empty( $post_id ) )
            $this->getPost( $post_id );
    }

    // Pobranie powiązanych postów i zdefiniowanie właściwości
    function getPost( $post_id ) {
        // Pobranie posta
        $this->post = get_post( $post_id );

        // Zdefiniowanie właściwości zapewniających łatwy dostęp do danych
        if ( !empty( $this->post ) ) {
            $this->id = $this->post->ID;
            $this->post_id = $this->post->ID;
            $this->title = $this->post->post_title;
            $this->teacher_id = $this->post->post_author;
            $this->content = $this->post->post_content;
            $this->required = $this->post->_schoolpress_homework_is_required;
            $this->due_date = $this->post->due_date;
        }

        // Zwrot identyfikatora znalezionego posta, w przeciwnym razie zwracaną wartością jest false
        if ( !empty( $this->id ) )
            return $this->id;
        else
            return false;
        }
    }
?>
