<commit_before><?php

namespace com\indigloo\sc\mysql {

    use \com\indigloo\mysql as MySQL;
    use \com\indigloo\Util as Util ;
    use \com\indigloo\Configuration as Config ;
    
    use \com\indigloo\sc\Constants as AppConstants ;
    use \com\indigloo\mysql\PDOWrapper;
    use \com\indigloo\exception\DBException as DBException;

    class Bookmark {

        static function find($subjectId,$objectId,$verb) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($subjectId,"integer");
            settype($objectId,"integer");
            settype($verb,"integer");

            $sql = " select count(id) as count from sc_bookmark " ;
            $sql .= " where subject_id = %d and object_id = %d and verb = %d ";
            $sql = sprintf($sql,$subjectId,$objectId,$verb);

            $row = MySQL\Helper::fetchRow($mysqli, $sql);
            return $row;
        }

        // for historical reasons this method is used to fetch the posts that 
        // have been bookmarked

        static function getLatest($limit,$filters) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($limit,"integer");

            $sql = " select q.* , l.name as user_name from sc_post q, sc_bookmark a, sc_login l " ;

            $q = new MySQL\Query($mysqli);
            $q->setAlias("com\indigloo\sc\model\Bookmark","a");
            $q->addCondition("q.pseudo_id = a.object_id");
            $q->addCondition("q.login_id = l.id");
            $q->filter($filters);
            $sql .= $q->get();

            $sql .= "order by q.id desc LIMIT %d ";
            $sql = sprintf($sql,$limit);

            $rows = MySQL\Helper::fetchRows($mysqli, $sql);
            return $rows;
        }

        // for historical reasons this method is used to fetch the posts that 
        // have been bookmarked
        
        static function getPaged($start,$direction,$limit,$filters) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($start,"integer");
            settype($limit,"integer");
            $direction = $mysqli->real_escape_string($direction);

            $sql = " select q.* , l.name as user_name from sc_post q, sc_bookmark a, sc_login l " ;

            $q = new MySQL\Query($mysqli);
            $q->setAlias("com\indigloo\sc\model\Bookmark","a");
            $q->addCondition("q.pseudo_id = a.object_id ");
            $q->addCondition("q.login_id = l.id");
            $q->filter($filters);
            $sql .= $q->get();

            $sql .= $q->getPagination($start,$direction,"q.id",$limit);
            $rows = MySQL\Helper::fetchRows($mysqli, $sql);
            
            //reverse rows for 'before' direction
            if($direction == 'before') {
                $results = array_reverse($rows) ;
                return $results ;
            }

            return $rows;
        }
        
        static function getOnLoginId($subjectId,$verb) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($subjectId,"integer");
            settype($verb,"integer");

            $sql = " select q.* , l.name as user_name " ;
            $sql .= " from sc_post q, sc_bookmark a , sc_login l " ;
            $sql .= " where q.pseudo_id = a.object_id and q.login_id = l.id ";
            $sql .= " and a.subject_id = %d and a.verb = %d limit 20 ";

            $sql = sprintf($sql,$subjectId,$verb);
            $rows = MySQL\Helper::fetchRows($mysqli, $sql);
            return $rows;
        }

        static function getLikeOnItemId($itemId) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($itemId,"integer");
            //@todo change UI if num_likes > 10
            $sql = " select l.id as login_id, l.name as user_name " ;
            $sql .= " from sc_bookmark b , sc_login l " ;
            $sql .= " where  b.subject_id = l.id and b.object_id = %d limit 10 ";
            
            $sql = sprintf($sql,$itemId);
            $rows = MySQL\Helper::fetchRows($mysqli, $sql);
            return $rows;
        }

        static function add(
                $ownerId,
                $subjectId,
                $subject,
                $objectId,
                $objectType,
                $title,
                $verb){


            $dbh = NULL ;
             
            try {
<commit_msg>bug fix: item -fetch likes SQL should use sc_bookmark.verb=1 condition in query<commit_after><?php

namespace com\indigloo\sc\mysql {

    use \com\indigloo\mysql as MySQL;
    use \com\indigloo\Util as Util ;
    use \com\indigloo\Configuration as Config ;
    
    use \com\indigloo\sc\Constants as AppConstants ;
    use \com\indigloo\mysql\PDOWrapper;
    use \com\indigloo\exception\DBException as DBException;

    class Bookmark {

        static function find($subjectId,$objectId,$verb) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($subjectId,"integer");
            settype($objectId,"integer");
            settype($verb,"integer");

            $sql = " select count(id) as count from sc_bookmark " ;
            $sql .= " where subject_id = %d and object_id = %d and verb = %d ";
            $sql = sprintf($sql,$subjectId,$objectId,$verb);

            $row = MySQL\Helper::fetchRow($mysqli, $sql);
            return $row;
        }

        // for historical reasons this method is used to fetch the posts that 
        // have been bookmarked

        static function getLatest($limit,$filters) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($limit,"integer");

            $sql = " select q.* , l.name as user_name from sc_post q, sc_bookmark a, sc_login l " ;

            $q = new MySQL\Query($mysqli);
            $q->setAlias("com\indigloo\sc\model\Bookmark","a");
            $q->addCondition("q.pseudo_id = a.object_id");
            $q->addCondition("q.login_id = l.id");
            $q->filter($filters);
            $sql .= $q->get();

            $sql .= "order by q.id desc LIMIT %d ";
            $sql = sprintf($sql,$limit);

            $rows = MySQL\Helper::fetchRows($mysqli, $sql);
            return $rows;
        }

        // for historical reasons this method is used to fetch the posts that 
        // have been bookmarked
        
        static function getPaged($start,$direction,$limit,$filters) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($start,"integer");
            settype($limit,"integer");
            $direction = $mysqli->real_escape_string($direction);

            $sql = " select q.* , l.name as user_name from sc_post q, sc_bookmark a, sc_login l " ;

            $q = new MySQL\Query($mysqli);
            $q->setAlias("com\indigloo\sc\model\Bookmark","a");
            $q->addCondition("q.pseudo_id = a.object_id ");
            $q->addCondition("q.login_id = l.id");
            $q->filter($filters);
            $sql .= $q->get();

            $sql .= $q->getPagination($start,$direction,"q.id",$limit);
            $rows = MySQL\Helper::fetchRows($mysqli, $sql);
            
            //reverse rows for 'before' direction
            if($direction == 'before') {
                $results = array_reverse($rows) ;
                return $results ;
            }

            return $rows;
        }
        
        static function getOnLoginId($subjectId,$verb) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($subjectId,"integer");
            settype($verb,"integer");

            $sql = " select q.* , l.name as user_name " ;
            $sql .= " from sc_post q, sc_bookmark a , sc_login l " ;
            $sql .= " where q.pseudo_id = a.object_id and q.login_id = l.id ";
            $sql .= " and a.subject_id = %d and a.verb = %d limit 20 ";

            $sql = sprintf($sql,$subjectId,$verb);
            $rows = MySQL\Helper::fetchRows($mysqli, $sql);
            return $rows;
        }

        static function getLikeOnItemId($itemId) {
            $mysqli = MySQL\Connection::getInstance()->getHandle();

            //sanitize input
            settype($itemId,"integer");
            //@todo change UI if num_likes > 10
            $sql = " select l.id as login_id, l.name as user_name " ;
            $sql .= " from sc_bookmark b , sc_login l " ;
            $sql .= " where  b.subject_id = l.id and b.verb = 1 and b.object_id = %d limit 10 ";
            
            $sql = sprintf($sql,$itemId);
            $rows = MySQL\Helper::fetchRows($mysqli, $sql);
            return $rows;
        }

        static function add(
                $ownerId,
                $subjectId,
                $subject,
                $objectId,
                $objectType,
                $title,
                $verb){


            $dbh = NULL ;
             
            try {

{'fraction_non_alphanumeric': 0.13707840798178073, 'fraction_numerical': 0.0015182735061273181, 'mean_word_length': 1.714748307329997, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '5201728', 'n_tokens_mistral': 2738, 'n_tokens_neox': 2624, 'n_words': 600}