public function __construct($data = array()) { $db = JO_Db::getDefaultAdapter(); try { $db->beginTransaction(); $data['user_id'] = isset($data['user_id']) ? $data['user_id'] : JO_Session::get('user[user_id]'); $data['public'] = isset($data['public']) ? (int) $data['public'] : 1; $data['date_added'] = date('Y-m-d H:i:s'); $board_id = Helper_Db::create('boards', $data); if (!$board_id) { return $this; } Helper_Db::insert('users_boards', array('user_id' => isset($data['user_id']) ? (string) $data['user_id'] : JO_Session::get('user[user_id]'), 'board_id' => $board_id, 'is_author' => 1)); if (isset($data['friends'])) { foreach ($data['friends'] as $fr) { Helper_Db::insert('users_boards', array('user_id' => $fr, 'board_id' => $board_id)); } } $config_private_boards = Helper_Config::get('config_private_boards'); Helper_Db::update('users', array('boards' => new JO_Db_Expr("(SELECT COUNT(board_id) FROM boards WHERE user_id = '" . (isset($data['user_id']) ? (string) $data['user_id'] : JO_Session::get('user[user_id]')) . "' " . ($config_private_boards ? ' AND public = 1' : '') . ")")), array('user_id = ?' => isset($data['user_id']) ? (string) $data['user_id'] : JO_Session::get('user[user_id]'))); ////autoseo new Model_Boards_Autoseo($board_id); $this->board_id = $board_id; $db->commit(); } catch (JO_Exception $e) { $db->rollBack(); $this->error = $e->getMessage(); } }
public function __construct($data) { $comment_id = Helper_Db::create('pins_comments', $data); if (!$comment_id) { return $this; } Helper_Db::update('pins', array('comments' => new JO_Db_Expr("(SELECT COUNT(comment_id) FROM pins_comments WHERE pin_id = '" . (string) $data['pin_id'] . "')"), 'latest_comments' => new JO_Db_Expr("(SELECT GROUP_CONCAT(comment_id ORDER BY comment_id ASC) FROM (SELECT comment_id FROM pins_comments WHERE pin_id = '" . (string) $data['pin_id'] . "' ORDER BY comment_id ASC LIMIT 4) AS tmp)")), array('pin_id = ?' => $data['pin_id'])); $this->comment_id = $comment_id; }
public function __construct($pin_id) { $db = JO_Db::getDefaultAdapter(); try { $db->beginTransaction(); $pin_info = new Model_Pins_Pin($pin_id); if (!$pin_info->count()) { return $this; } $pin_info = $pin_info->data; $result = null; if ($pin_info['pin_image']) { $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $pin_info['pin_pin_id'], 'date_added' => $pin_info['pin_date_added'], 'image' => $pin_info['pin_image'], 'store' => $pin_info['pin_store'], 'gallery_id' => 0)); if (!$result) { $result = $res; } } $gallery = new Model_Pins_Gallery($pin_info['pin_pin_id']); if ($gallery->count()) { foreach ($gallery->data as $gal) { $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $gal['pin_id'], 'date_added' => $pin_info['pin_date_added'], 'image' => $gal['image'], 'store' => $gal['store'], 'gallery_id' => $gal['gallery_id'])); if (!$result) { $result = $res; } } } if ($pin_info['pin_comments']) { $comments = Model_Comments::getComments2(array('filter_pin_id' => $pin_id)); foreach ($comments as $comment) { $del = new Model_Pins_DeleteComment($comment['comment_id']); if (!$result) { $result = $del->affected_rows; } } } $res = Helper_Db::delete('pins', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::delete('pins_invert', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } if ($pin_info['pin_likes']) { $res = Helper_Db::delete('pins_likes', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } } $res = Helper_Db::delete('pins_reports', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::delete('pins_views', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::delete('users_history', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::delete('pins_images', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::update('users', array('likes' => new JO_Db_Expr('(' . $db->select()->from('pins_likes', 'COUNT(like_id)')->where('pin_id IN (?)', new JO_Db_Expr('(' . $db->select()->from('pins', 'pin_id')->where('user_id = ?', $pin_info['user_user_id']) . ')'))->limit(1) . ')')), array('user_id=?' => $pin_info['user_user_id'])); if (!$result) { $result = $res; } ///////////////// update latest pins for user and board ///////////////////// new Model_Users_UpdateLatestPins($pin_info['user_user_id']); new Model_Boards_UpdateLatestPins($pin_info['board_board_id']); ///////////////// Extension on delete ////////////////// $extensions = Model_Extensions::getByMethod('pin_ondelete'); if ($extensions) { $front = JO_Front::getInstance(); foreach ($extensions as $id => $ext) { $res = call_user_func(array($front->formatModuleName('model_' . $ext . '_pin'), 'ondelete'), $pin_id); if (!$result) { $result = $res; } } } $this->affected_rows = $result; $db->commit(); } catch (JO_Exception $e) { $db->rollBack(); } }
public function __construct($data) { $db = JO_Db::getDefaultAdapter(); try { $db->beginTransaction(); $date_added = WM_Date::format(time(), 'yy-mm-dd H:i:s'); $data['date_added'] = $date_added; $data['last_login'] = $date_added; $data['status'] = 1; $data['last_action_datetime'] = $date_added; $data['ip_address'] = JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp()); $data['new_email'] = $data['email']; $data['store'] = JO_Registry::get('default_upload_method'); if (!$data['store']) { $data['store'] = 'Model_Upload_Locale'; } /*$avatar = ''; if(isset($data['avatar']) && $data['avatar']) { $avatar = $data['avatar']; $data['avatar'] = ''; }*/ $rows = Helper_Db::describeTable('users'); $insert = array(); $avatar = ''; foreach ($rows as $row => $def) { if (isset($data[$row])) { if (in_array($row, array('password', 'new_password'))) { if ($data[$row]) { if ($data[$row] instanceof JO_Db_Expr) { $insert[$row] = $data[$row]; } else { $insert[$row] = md5($data[$row]); } } else { $insert[$row] = ''; } } elseif ($row == 'avatar') { $avatar = $data[$row]; $data[$row] = ''; } else { $insert[$row] = $data[$row]; } } else { $insert[$row] = $def; } } //create user $user_id = Helper_Db::create('users', $insert); if (!$user_id) { return $this; } //upload avatar if ($avatar) { $method_for_upload = Helper_Config::get('file_upload_method'); if ($method_for_upload) { $image = call_user_func(array($method_for_upload, 'uploadUserAvatar'), $avatar, $user_id); $error = call_user_func(array($method_for_upload, 'getError')); if ($error) { $this->error[] = $error; } if ($image && isset($image['image']) && $image['image']) { Helper_Db::update('users', array('avatar' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width']), array('user_id = ?' => (string) $user_id)); } } } //create user alias new Model_Users_Autoseo($user_id); /*Helper_Db::insert('url_alias', array( 'query' => 'user_id=' . (string)$user_id, 'keyword' => $data['username'], 'path' => $data['username'], 'route' => 'users/profile' ));*/ //add default boards if (is_array(Helper_Config::get('default_boards'))) { foreach (Helper_Config::get('default_boards') as $def) { new Model_Boards_Create(array('category_id' => $def['category_id'], 'title' => $def['title'], 'user_id' => (string) $user_id)); } } //set following $config_private_boards = Helper_Config::get('config_private_boards'); if (isset($data['following_user']) && $data['following_user'] && $data['following_user'] != -1) { Helper_Db::insert('users_following_user', array('user_id' => (string) $user_id, 'following_id' => (string) $data['following_user'])); Helper_Db::insert('users_following_user', array('user_id' => (string) $data['following_user'], 'following_id' => (string) $user_id)); //update following user info Helper_Db::update('users', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'likes' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins_likes WHERE user_id = users.user_id)'), 'following' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT following_id) FROM users_following_user WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) )'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) )')), array('user_id = ?' => (string) $data['following_user'])); } //update user info Helper_Db::update('users', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'likes' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins_likes WHERE user_id = users.user_id)'), 'following' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT following_id) FROM users_following_user WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT following_id) FROM users_following WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) )'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) )')), array('user_id = ?' => (string) $user_id)); $this->user_id = $user_id; $db->commit(); } catch (JO_Exception $e) { $this->error[] = $e->getMessage(); $db->rollBack(); } }
public static function delete($pin_id) { $db = JO_Db::getDefaultAdapter(); $pin_info = self::getPin($pin_id); if (!$pin_info) { return false; } if ($pin_info['image']) { $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $pin_info['pin_id'], 'date_added' => $pin_info['date_added'], 'image' => $pin_info['image'], 'store' => $pin_info['store'])); } $comments = Model_Comments::getComments(array('filter_pin_id' => $pin_id)); if ($comments) { foreach ($comments as $comment) { $db->delete('pins_comments', array('comment_id = ?' => $comment['comment_id'])); $db->delete('pins_reports_comments', array('comment_id = ?' => $comment['comment_id'])); } } $del = $db->delete('pins', array('pin_id = ?' => $pin_id)); if (!$del) { return false; } else { $db->query("INSERT INTO `pins_images_for_delete`(`pin_id`, `gallery_id`, `date_added`, `image`, `store`) SELECT `pin_id`, `gallery_id`, '" . $pin_info['date_added'] . "', `image`, `store` FROM `pins_gallery` WHERE `pin_id` = '" . $pin_id . "'"); $db->delete('pins_invert', array('pin_id = ?' => $pin_id)); $db->delete('pins_likes', array('pin_id = ?' => $pin_id)); $db->delete('pins_reports', array('pin_id = ?' => $pin_id)); $db->delete('pins_views', array('pin_id = ?' => $pin_id)); $db->delete('users_history', array('pin_id = ?' => $pin_id)); $db->delete('pins_gallery', array('pin_id = ?' => $pin_id)); $db->delete('pins_images', array('pin_id = ?' => $pin_id)); $config_private_boards = Helper_Config::get('config_private_boards'); Helper_Db::update('users', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'likes' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins_likes WHERE user_id = users.user_id)'), 'following' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT following_id) FROM users_following_user WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT following_id) FROM users_following WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) )'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE user_id = users.user_id), \',\', 15 ) )')), array('user_id=?' => $pin_info['user_id'])); Helper_Db::update('boards', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE board_id = boards.board_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) - (SELECT COUNT(DISTINCT user_id) FROM users_following_ignore WHERE following_id = boards.user_id AND board_id = boards.board_id AND user_id != boards.user_id LIMIT 1) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE board_id = boards.board_id), \',\', 15 ) )')), array('board_id=?' => $pin_info['board_id'])); self::deleteCache($pin_info); return true; } }