<commit_before><?php
/**
 * @title          Wall Model
 *
 * @author         <NAME> <<EMAIL>>
 * @copyright      (c) 2012-2018, <NAME>. All Rights Reserved.
 * @license        GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
 * @package        PH7/ App / System / Module / User / Model
 * @version        0.2
 */

namespace PH7;

use PH7\Framework\Mvc\Model\Engine\Db;
use PH7\Framework\Mvc\Model\Engine\Model;

class WallModel extends Model
{
    /**
     * @param int $iProfileId
     * @param string $sPost
     * @param string $sCreatedDate
     *
     * @return bool
     */
    public function add($iProfileId, $sPost, $sCreatedDate)
    {
        $rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersWall') . '(profileId, post, createdDate) VALUES (:profileId, :post, :createdDate)');
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
        $rStmt->bindValue(':post', $sPost, \PDO::PARAM_STR);
        $rStmt->bindValue(':dateTime', $sCreatedDate, \PDO::PARAM_STR);

        return $rStmt->execute();
    }

    /**
     * @param int $iProfileId
     * @param string $sPost
     * @param string $sUpdatedDate
     *
     * @return bool
     */
    public function edit($iProfileId, $sPost, $sUpdatedDate)
    {
        $rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix('MembersWall') . 'SET post = :post, updatedDate = :updatedDate WHERE profileId = :profileId');
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
        $rStmt->bindValue(':post', $sPost, \PDO::PARAM_STR);
        $rStmt->bindValue(':updatedDate', $sUpdatedDate, \PDO::PARAM_STR);

        return $rStmt->execute();
    }

    /**
     * @param int $iProfileId
     * @param int $iWallId
     *
     * @return bool
     */
    public function delete($iProfileId, $iWallId)
    {
        $rStmt = Db::getInstance()->prepare('DELETE FROM' . Db::prefix('MembersWall') . 'WHERE :profileId=:profileId AND wallId=:wallId');
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
        $rStmt->bindValue(':wallId', $iWallId, \PDO::PARAM_INT);

        return $rStmt->execute();
    }

    public function get($iProfileId, $iWallId = null, $iOffset, $iLimit)
    {
        $iOffset = (int)$iOffset;
        $iLimit = (int)$iLimit;

        $sSqlWallId = (!empty($iWallId)) ? ' AND wallId=:wallId ' : '';

        $rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix('MembersWall') . ' AS w LEFT JOIN' . Db::prefix('Members') . 'AS m ON w.profileId = m.profileId WHERE :profileId=:profileId ' . $sSqlWallId . ' ORDER BY dateTime DESC LIMIT :offset, :limit');
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
        if (!empty($iWallId)) $rStmt->bindValue(':wallId', $iWallId, \PDO::PARAM_INT);<commit_msg>Improve readability; Store SQL query into a variable, etc.<commit_after><?php
/**
 * @title          Wall Model
 *
 * @author         <NAME> <<EMAIL>>
 * @copyright      (c) 2012-2018, <NAME>. All Rights Reserved.
 * @license        GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
 * @package        PH7/ App / System / Module / User / Model
 * @version        0.2
 */

namespace PH7;

use PH7\Framework\Mvc\Model\Engine\Db;
use PH7\Framework\Mvc\Model\Engine\Model;

class WallModel extends Model
{
    /**
     * @param int $iProfileId
     * @param string $sPost
     * @param string $sCreatedDate
     *
     * @return bool
     */
    public function add($iProfileId, $sPost, $sCreatedDate)
    {
        $rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersWall') . '(profileId, post, createdDate) VALUES (:profileId, :post, :createdDate)');
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
        $rStmt->bindValue(':post', $sPost, \PDO::PARAM_STR);
        $rStmt->bindValue(':dateTime', $sCreatedDate, \PDO::PARAM_STR);

        return $rStmt->execute();
    }

    /**
     * @param int $iProfileId
     * @param string $sPost
     * @param string $sUpdatedDate
     *
     * @return bool
     */
    public function edit($iProfileId, $sPost, $sUpdatedDate)
    {
        $rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix('MembersWall') . 'SET post = :post, updatedDate = :updatedDate WHERE profileId = :profileId');
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
        $rStmt->bindValue(':post', $sPost, \PDO::PARAM_STR);
        $rStmt->bindValue(':updatedDate', $sUpdatedDate, \PDO::PARAM_STR);

        return $rStmt->execute();
    }

    /**
     * @param int $iProfileId
     * @param int $iWallId
     *
     * @return bool
     */
    public function delete($iProfileId, $iWallId)
    {
        $rStmt = Db::getInstance()->prepare('DELETE FROM' . Db::prefix('MembersWall') . 'WHERE :profileId=:profileId AND wallId=:wallId');
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
        $rStmt->bindValue(':wallId', $iWallId, \PDO::PARAM_INT);

        return $rStmt->execute();
    }

    /**
     * @param int $iProfileId
     * @param int|null $iWallId
     * @param int $iOffset
     * @param int $iLimit
     *
     * @return array
     */
    public function get($iProfileId, $iWallId = null, $iOffset, $iLimit)
    {
        $iOffset = (int)$iOffset;
        $iLimit = (int)$iLimit;

        $sSqlWallId = !empty($iWallId) ? ' AND wallId=:wallId ' : '';
        $sSqlQuery = 'SELECT * FROM' . Db::prefix('MembersWall') . ' AS w LEFT JOIN' .
            Db::prefix('Members') . 'AS m ON w.profileId = m.profileId WHERE :profileId=:profileId ' .
            $sSqlWallId . ' ORDER BY dateTime DESC LIMIT :offset, :limit';

        $rStmt = Db::getInstance()->prepare($sSqlQuery);
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
        if (!empty($iWallId)) {
            $rStmt->bindValue(':wallId', $iWallId, \PDO::PARAM_INT);
        }
{'fraction_non_alphanumeric': 0.16909914443885254, 'fraction_numerical': 0.00536822680758262, 'mean_word_length': 2.866407263294423, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '823507', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1995, 'n_words': 417}