Example #1
0
 /**
  * 笔记列表
  */
 function noteAction()
 {
     $noteModel = new NoteModel();
     $noteList = $noteModel->getSectionNote($this->sectionId);
     if ($this->isMobile) {
         $this->displayJson(Common_Error::ERROR_SUCCESS, $noteList);
     }
     $this->assign('section', $this->section);
     $this->assign('chapter', $this->chapter);
     $this->assign('course', $this->course);
     $this->assign('teacher', $this->teacher);
     $this->assign("note_list", $noteList);
 }
 /**
  * This method controls what happens when you move to /note/delete(/XX) in your app.
  * Deletes a note. In a real application a deletion via GET/URL is not recommended, but for demo purposes it's
  * totally okay.
  * @param int $note_id id of the note
  */
 public function delete($note_id)
 {
     NoteModel::deleteNote($note_id);
     Redirect::to('note');
 }
Example #3
0
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
require_once "Libs/autoload.php";
$config = new Config();
$webPage = new PJSWebPage($config->getTitle() . ' - Delete Note');
$act = Tools::Param('act');
if ("Delete Note" === $act) {
    $noteModel = new NoteModel();
    $noteModel->populateFromForm();
    if (!$noteModel->validateForDelete()) {
        $noteView = new NoteFormView('Delete Note', $noteModel);
        $body = "<h2>Invalid data</h2>\n" . $noteView->getForm();
    } else {
        $noteController = new NoteController();
        $noteController->delete($noteModel);
        $body = "Deleted note # " . $noteModel->getId() . "<br />\n";
    }
} else {
    $noteController = new NoteController();
    $noteModel = $noteController->get(Tools::param('id'));
    $noteView = new NoteFormView('Delete Note', $noteModel);
    $body = $noteView->getForm();
}
Example #4
0
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
require_once "Libs/autoload.php";
$config = new Config();
$webPage = new PJSWebPage($config->getTitle() . "Notes - Add Note");
$body = '';
$act = Tools::Param('act');
if ("Add Note" === $act) {
    $model = new NoteModel();
    $model->populateFromForm();
    if (!$model->validateForAdd()) {
        $view = new NoteFormView('Add Note', $model);
        $body = "<h2>Invalid data</h2>\n" . $view->getForm();
    } else {
        $noteController = new NoteController();
        $newId = $noteController->add($model);
        if ($newId > 0) {
            $body = "Added note # " . $newId . "<br />\n";
        }
    }
} else {
    $body = "";
    $noteModel = new NoteModel();
    $noteModel->setAppliesToTable(Tools::param('appliesToTable'));
    $noteModel->setAppliesToId(Tools::param('appliesToId'));
    $view = new NoteFormView("Add Note", $noteModel);
    $body = $view->getForm();
}
$webPage->setBody($body);
$webPage->displayPage();
Example #5
0
 public function notes()
 {
     $this->View->renderWithoutHeaderAndFooter('api/index', array('data' => NoteModel::getAllNotes()));
 }
Example #6
0
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
require_once "Libs/autoload.php";
$config = new Config();
$webPage = new PJSWebPage($config->getTitle() . ' - Edit Note');
$act = Tools::Param('act');
if ("Edit Note" === $act) {
    $noteModel = new NoteModel();
    $noteModel->populateFromForm();
    if (!$noteModel->validateForUpdate()) {
        $view = new NoteFormView('Edit Note', $noteModel);
        $body = "<h2>Invalid data</h2>\n" . $view->getForm();
    } else {
        $noteController = new NoteController();
        $newId = $noteController->update($noteModel);
        if ($newId > 0) {
            $body = "Edited note # " . $newId . "<br />\n";
        }
    }
} else {
    $noteController = new NoteController();
    $noteModel = $noteController->get(Tools::param('id'));
    $view = new NoteFormView('Edit Note', $noteModel);
Example #7
0
 /**
  * android版课程章节列表
  */
 function infoForAndroidAction()
 {
     $courseId = (int) $this->get('course_id', 0);
     if (!$courseId) {
         $this->displayJson(Common_Error::ERROR_PARAM);
     }
     $practiseModel = new PractiseModel();
     $courseModel = new CourseModel();
     $noteModel = new NoteModel();
     $course = $courseModel->getCourse($courseId);
     if (!$course) {
         $this->displayJson(Common_Error::ERROR_PARAM);
     }
     $chapterList = $courseModel->getChapterList($course['id']);
     $sectionList = $courseModel->getSectionList($course['id']);
     if ($this->uid) {
         //用户已学节
         $uSecList = $courseModel->getUserCourseSection($this->uid, $courseId);
         $uPracList = $courseModel->hasCoursePractiseFinished($this->uid, $courseId);
         $userSpendTime = 0;
         if ($uSecList) {
             $uSectionIds = array_keys($uSecList);
             //sectionList是一个1:N的章节关系
             foreach ($sectionList as &$chapter) {
                 foreach ($chapter as &$section) {
                     //各章节的状态
                     $section['type'] = 2;
                     $section['practise_num'] = $practiseModel->getSectionPractiseNum($section['id']);
                     $section['note_num'] = $noteModel->getSectionNoteNum($section['id']);
                     $section['finished'] = isset($uSecList[$section['id']]) ? 1 : 0;
                     $section['practise_finished'] = isset($uPracList[$section['id']]) ? 1 : 0;
                     $section['last'] = $section['id'] == @$uSectionIds[0] ? 1 : 0;
                     $userSpendTime += isset($uSecList[$section['id']]) ? $section['duration'] : 0;
                 }
             }
             unset($chapter);
             unset($section);
         }
         //用户习题
         $course['user_practise_num'] = $courseModel->getUserCoursePractiseNum($this->uid, $course['id']);
         //学习时长
         $course['user_spend_time'] = $userSpendTime;
     }
     //章节合并
     $data = array();
     foreach ($chapterList as $chapter) {
         $chapter['practise_num'] = $practiseModel->getSectionPractiseNum($chapter['id']);
         $chapter['practise_finished'] = isset($uPracList[$chapter['id']]) ? 1 : 0;
         $chapter['type'] = 1;
         $data[] = $chapter;
         foreach ($sectionList[$chapter['id']] as &$sec) {
             $sec['open_time_remain'] = $chapter['open_time_remain'];
         }
         unset($sec);
         $data = array_merge($data, $sectionList[$chapter['id']]);
     }
     if ($this->isMobile) {
         $this->displayJson(Common_Error::ERROR_SUCCESS, $data);
     }
 }
Example #8
0
    /**
     * @param NoteModel $model
     * @see ControllerBase::update()
     */
    public function update($model)
    {
        if ($model->validateForUpdate()) {
            try {
                $query = <<<SQL
UPDATE note
   SET appliesToTable = ?
     , appliesToId = ?
     , noteText = ?
 WHERE id = ?
SQL;
                $id = $model->getId();
                $appliesToTable = $model->getAppliesToTable();
                $appliesToId = $model->getAppliesToId();
                $noteText = htmlspecialchars($model->getNoteText());
                $stmt = $this->_dbh->prepare($query);
                if (!$stmt) {
                    throw new ControllerException('Prepared statement failed for ' . $query);
                }
                if (!$stmt->bind_param('sisi', $appliesToTable, $appliesToId, $noteText, $id)) {
                    throw new ControllerException('Binding parameters for prepared statement failed.');
                }
                if (!$stmt->execute()) {
                    throw new ControllerException('Failed to execute UPDATE statement. (' . $this->_dbh->error . ')');
                }
                /**
                 * @SuppressWarnings checkAliases
                 */
                if (!$stmt->close()) {
                    throw new ControllerException('Something broke while trying to close the prepared statement.');
                }
                return $id;
            } catch (Exception $e) {
                throw new ControllerException($e->getMessage());
            }
        } else {
            throw new ControllerException("Invalid data.");
        }
    }