Example #1
0
 /**
  * Finds updates by their tags that match the given search query.
  * @param string $term the search term.
  * @param integer $page the current page.
  * @return array found tags.
  */
 public static function searchFor($term, $page = 0)
 {
     if (empty($term)) {
         return [];
     }
     $tagIds = static::getTagIds($term);
     if (0 === count($tagIds)) {
         return [];
     }
     $query = "SELECT u.*," . (CW::$app->user->isLogged() ? "0 < (SELECT count(*) FROM `update_upvoters` WHERE `update_id` = `u`.`id` AND `user_id` = " . CW::$app->user->identity->id . ") " : ' false ') . " `voted` FROM updates u JOIN (SELECT distinct update_id FROM update_tags WHERE tag_id IN (" . ArrayHelper::getArrayToString($tagIds, ',') . ") LIMIT " . static::LOAD_FACTOR . " OFFSET " . static::LOAD_FACTOR * $page . ") ut ON ut.update_id = u.id ORDER BY u.rate DESC, u.created_at DESC";
     $stmt = CW::$app->db->executeQuery($query);
     $updates = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     foreach ($updates as &$update) {
         $update['imgUrl'] = '/images/updates/' . $update['id'] . '/' . Update::IMAGE_MEDIUM_WIDTH . 'xX.jpeg';
         $update['updateUrl'] = Update::getUpdateUrl($update['id']);
         $update['postedAgo'] = BaseModel::getPostedAgoTime($update['created_at']);
         $update['created_at'] = strtotime($update['created_at']);
         $update['voted'] = (bool) $update['voted'];
     }
     if (0 < count($updates)) {
         Update::setUpdateTags($updates);
         Update::setUpdatePostedFrom($updates);
         Image::setUpdateImages($updates);
     }
     return $updates;
 }
Example #2
0
                upvote.setAttribute('style', voted ? 'margin-right: 7px; color: #09f;' : 'margin-right: 7px;');
                upvote.setAttribute('title', voted ? 'unvote' : 'upvote');
            }
        }
    });

    upvote.setAttribute('class', 'fa fa-thumbs-up update-btn');
    upvote.setAttribute('title', voted ? 'unvote' : 'upvote');
    upvote.setAttribute('style', voted ? 'margin-right: 7px; color: #09f;' : 'margin-right: 7px;');
<?php 
    }
    ?>
});

var  updateUrl = <?php 
    echo json_encode(Update::getUpdateUrl($update['id']));
    ?>
;

function share(type) {
    App.share({
        type : type,
        url  : updateUrl,
        text : 'google-plus' === type ? <?php 
    echo json_encode($update['description']);
    ?>
 : ''
    });
}

</script>