function addComment() { \SKS\LIB\Session::checkUserPermission(); $db = new DB(); $post = new \SKS\DB\Entity\Post(); $post = $db->findById($post, $_POST["post_id"]); if (isset($_POST["action"])) { $form = new \SKS\LIB\Form(); $form->post("comment")->addRule("required")->addRule("minlength", 5); $errors = $form->validate(); //set the comment $comment = new \SKS\DB\Entity\Comment(); $comment->setComment($_POST["comment"]); $user = $db->findById(Session::getLoggedInUser(), Session::getLoggedInUser()->getId()); $comment->setCommentedBy($user); if (isset($errors)) { $this->view->comment = $comment; $this->view->errors = $errors; } else { //Set the post $post->addComment($comment); $comment->setPost($post); $post = $db->update($post, true); $comment = $db->update($comment, true); $this->view->message = 'Commented Successfully'; } } $this->view->post = $post; $this->view->title = 'Post'; $this->view->render('post/addComment', false); }
public function updateProfile($id) { \SKS\LIB\Session::checkUserPermission(); $this->view->title = 'Update Profile'; //validate the form $form = new \SKS\LIB\Form(); $form->post('first_name')->addRule('minlength', 2)->post('email')->addRule('email')->post('last_name')->addRule('required'); $errors = $form->validate(); $db = new DB(); $user = new \SKS\DB\Entity\User(); $user = $db->findById($user, $id); $user->setFirstName($this->getPostValue("first_name")); $user->setLastName($this->getPostValue("last_name")); $user->setEmail($this->getPostValue("email")); //Set the profile Image $profileImage = new \SKS\DB\Entity\Image(); if (isset($_POST["profile_image_id"])) { $profileImage = $db->findById($profileImage, $_POST["profile_image_id"]); } $user->setProfileImage($profileImage); $this->view->user = $user; //If error occurs if (isset($errors)) { $this->view->errors = $errors; //save user } else { $is_same = $user->getEmail() == \SKS\LIB\Session::getLoggedInUser()->getEmail(); $exists = $is_same ? false : $user->exist(array("email" => $user->getEmail())); if ($exists) { $this->view->errors = array("Email already exits"); } else { // Save the user $db->update($user, true); $this->view->message = "Profile is updated successfully."; } } $this->view->render('user/profile_form', false); }