Пример #1
0
 public function share($user_id, $post_id)
 {
     $post_mapper = new Application_Model_PostMapper();
     $user_mapper = new Application_Model_UserMapper();
     $shared_post = $post_mapper->find($post_id);
     $user = $user_mapper->find($shared_post['user_id']);
     $share_elm = $this->findByTwoColumns('user_id', $user_id, 'post_id', $post_id);
     $db = Zend_Registry::get('db');
     if (empty($share_elm)) {
         $sql = "insert into post_share VALUES(" . $user_id . "," . $post_id . ");";
         $db->query($sql);
         $post_model = new Application_Model_Post();
         $username = $user['username'];
         $post_model->_fields['user_id'] = get_user_id();
         $post_model->_fields['content'] = "The Post originally shared by {$username}: \n" . $shared_post['content'];
         $post_model->_fields['comment_number'] = 0;
         $post_model->_fields['is_reported'] = 0;
         $post_model->_fields['updated_at'] = time();
         $new_id = $post_mapper->save($post_model);
         $path = APPLICATION_PATH . "/../public/post_pic/" . "{$post_id}.png";
         $path2 = APPLICATION_PATH . "/../public/post_pic/{$new_id}.png";
         copy($path, $path2);
         return true;
     }
     return false;
 }
Пример #2
0
 public function adminAction()
 {
     $this->view->isAdmin = is_admin();
     $post_mapper = new Application_Model_PostMapper();
     $posts = $post_mapper->findAllByColumn('is_reported', 1);
     $this->view->posts = $posts;
 }
Пример #3
0
 public function shareAction()
 {
     $request = $this->getRequest();
     $post_id = $request->getParam('post_id');
     $user_id = get_user_id();
     $share_mapper = new Application_Model_ShareMapper();
     $is_shared = $share_mapper->share($user_id, $post_id);
     if ($is_shared) {
         $notification_mapper = new Application_Model_NotificationMapper();
         $notification_model = new Application_Model_Notification();
         $post_mapper = new Application_Model_PostMapper();
         $post = $post_mapper->find($post_id);
         $notification_model->_fields['user_id'] = $post['user_id'];
         $notification_model->_fields['is_seen'] = 0;
         $notification_model->_fields['content'] = get_username() . " Likes your post with id = {$post_id}";
         $notification_mapper->save($notification_model);
     }
     $this->_redirect('/post/home');
 }