예제 #1
0
 /**
  * getStats 
  * 
  * @param int $userid 
  * 
  * @return void
  */
 function getStats($userid)
 {
     $data = array();
     $postsCount = getPostsById($userid, 'array');
     $photosCount = getPhotosById($userid, 'array');
     $commentsCount = getCommentsById($userid, 'array');
     $calendarsCount = getCalendarEntriesById($userid, 'array');
     $data['posts'] = '
                 <div class="stat" data-percent="' . $postsCount['percent'] . '">
                     <div class="label">' . T_('Posts') . '</div>
                     <span class="inner" title="' . $postsCount['percent'] . '%">' . $postsCount['count'] . '</span>
                 </div>';
     $data['photos'] = '
                 <div class="stat" data-percent="' . $photosCount['percent'] . '">
                     <div class="label">' . T_('Photos') . '</div>
                     <span class="inner" title="' . $photosCount['percent'] . '%">' . $photosCount['count'] . '</span>
                 </div>';
     $data['comments'] = '
                 <div class="stat" data-percent="' . $commentsCount['percent'] . '">
                     <div class="label">' . T_('Comments') . '</div>
                     <span class="inner" title="' . $commentsCount['percent'] . '%">' . $commentsCount['count'] . '</span>
                 </div>';
     $data['events'] = '
                 <div class="stat" data-percent="' . $calendarsCount['percent'] . '">
                     <div class="label">' . T_('Dates') . '</div>
                     <span class="inner" title="' . $calendarsCount['percent'] . '%">' . $calendarsCount['count'] . '</span>
                 </div>';
     if (usingFamilyNews()) {
         $newsCount = getFamilyNewsById($userid, 'array');
         $data['news'] = '
                 <div class="stat" data-percent="' . $newsCount['percent'] . '">
                     <div class="label">' . T_('Family News') . '</div>
                     <span class="inner" title="' . $newsCount['percent'] . '%">' . $newsCount['count'] . '</span>
                 </div>';
     }
     if (usingRecipes()) {
         $recipesCount = getRecipesById($userid, 'array');
         $data['recipes'] = '
                 <div class="stat" data-percent="' . $recipesCount['percent'] . '">
                     <div class="label">' . T_('Recipes') . '</div>
                     <span class="inner" title="' . $recipesCount['percent'] . '%">' . $recipesCount['count'] . '</span>
                 </div>';
     }
     if (usingDocuments()) {
         $documentsCount = getDocumentsById($userid, 'array');
         $data['documents'] = '
                 <div class="stat" data-percent="' . $documentsCount['percent'] . '">
                     <div class="label">' . T_('Documents') . '</div>
                     <span class="inner" title="' . $documentsCount['percent'] . '%">' . $documentsCount['count'] . '</span>
                 </div>';
     }
     if (usingPrayers()) {
         $prayersCount = getPrayersById($userid, 'array');
         $data['prayers'] = '
                 <div class="stat" data-percent="' . $prayersCount['percent'] . '">
                     <div class="label">' . T_('Prayer Concerns') . '</div>
                     <span class="inner" title="' . $prayersCount['percent'] . '%">' . $prayersCount['count'] . '</span>
                 </div>';
     }
     return $data;
 }
예제 #2
0
파일: utils.php 프로젝트: lmcro/fcms
/**
 * getWhatsNewData 
 * 
 * Get the latest information in the site, including any external data.
 * Defaults to the last 30 days.
 * 
 * Types of data:
 * 
 *  ADDRESSADD      Add address of non-member
 *  ADDRESSEDIT     Edit own address
 *  AVATAR          Change avatar
 *  BOARD           Message board post
 *  CALENDAR        Add date to calendar
 *  DOCS            Added document
 *  GALCATCOM       Commented on category of photos
 *  GALCOM          Commented on photo
 *  GALLERY         Added photo
 *  JOINED          Joined the site (became active)
 *  NEWS            Added family news
 *  NEWSCOM         Commented on family news
 *  POLL            Added poll
 *  POLLCOM         Commented on poll
 *  PRAYERS         Added prayer concern
 *  RECIPES         Added recipe
 *  RECIPECOM       Commented on recipe
 *  STATUS          Added status update
 *  VIDEO           Added video
 *  VIDEOCOM        Commented on video
 *  WHEREISEVERYONE Checked in on foursquare
 * 
 * @param int $days 
 * 
 * @return mixed - array on success or false on failure
 */
function getWhatsNewData($days = 30)
{
    $fcmsError = FCMS_Error::getInstance();
    $fcmsDatabase = Database::getInstance($fcmsError);
    $fcmsUser = User::getInstance($fcmsError, $fcmsDatabase);
    $whatsNewData = array();
    $sql = "SELECT p.`id`, `date`, `subject` AS title, p.`post` AS details, u.`id` AS userid, `thread` AS id2, 0 AS id3, 'BOARD' AS type\n            FROM `fcms_board_posts` AS p, `fcms_board_threads` AS t, fcms_users AS u \n            WHERE p.`thread` = t.`id` \n            AND p.`user` = u.`id` \n            AND `date` >= DATE_SUB(CURDATE(),INTERVAL {$days} DAY) \n\n            UNION SELECT a.`id`, c.`created` AS date, c.`column` AS title, '' AS details, a.`user` AS userid, a.`updated_id` AS id2, u.`sex` AS id3, 'ADDRESSEDIT' AS type\n            FROM `fcms_changelog` AS c\n            LEFT JOIN `fcms_users` AS u ON c.`user` = u.`id`\n            LEFT JOIN `fcms_address` AS a ON u.`id` = a.`user`\n            WHERE c.`created` >= DATE_SUB(CURDATE(),INTERVAL {$days} DAY) \n            AND c.`column` != 'avatar'\n\n            UNION SELECT a.id, a.updated AS date, 0 AS title, '' AS details, a.user AS userid, a.`created_id` AS id2, u.joindate AS id3, 'ADDRESSADD' AS type\n            FROM fcms_address AS a, fcms_users AS u\n            WHERE a.user = u.id\n            AND u.`phpass` = 'NONMEMBER' \n            AND u.`activated` < 1 \n            AND a.updated >= DATE_SUB(CURDATE(),INTERVAL {$days} DAY) \n\n            UNION SELECT `id`, `joindate` AS date, 0 AS title, '' AS details, `id` AS userid, 0 AS id2, 0 AS id3, 'JOINED' AS type \n            FROM `fcms_users` \n            WHERE `phpass` != 'NONMEMBER' \n            AND `joindate` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n            AND `activated` > 0 ";
    if (usingFamilyNews()) {
        $sql .= "UNION SELECT n.`id` AS id, n.`updated` AS date, `title`, n.`news` AS details, u.`id` AS userid, u.`sex` AS id2, 0 AS id3, 'NEWS' AS type \n                 FROM `fcms_users` AS u, `fcms_news` AS n \n                 WHERE u.`id` = n.`user` \n                 AND n.`updated` >= DATE_SUB(CURDATE(),INTERVAL {$days} DAY) \n                 AND `username` != 'SITENEWS' \n                 AND `phpass` != 'SITENEWS'\n\n                 UNION SELECT n.`id` AS 'id', nc.`date`, `title`, nc.`comment` AS details, nc.`user` AS userid, 0 AS id2, 0 AS id3, 'NEWSCOM' AS type \n                 FROM `fcms_news_comments` AS nc, `fcms_news` AS n, `fcms_users` AS u \n                 WHERE nc.`date` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n                 AND nc.`user` = u.`id` \n                 AND n.`id` = nc.`news` ";
    }
    if (usingPrayers()) {
        $sql .= "UNION SELECT 0 AS id, `date`, `for` AS title, `desc` AS details, `user` AS userid, 0 AS id2, 0 AS id3, 'PRAYERS' AS type \n                 FROM `fcms_prayers` \n                 WHERE `date` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) ";
    }
    if (usingRecipes()) {
        $sql .= "UNION SELECT `id` AS id, `date`, `name` AS title, '' AS details, `user` AS userid, `category` AS id2, 0 AS id3, 'RECIPES' AS type \n                 FROM `fcms_recipes` \n                 WHERE `date` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n\n                 UNION SELECT r.`id`, rc.`date`, r.`name` AS title, rc.`comment` AS details, rc.`user` AS userid, r.`category` AS id2, 0 AS id3, 'RECIPECOM' AS type\n                 FROM `fcms_recipe_comment` AS rc, `fcms_recipes` AS r\n                 WHERE rc.`date` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY)\n                 AND rc.`recipe` = r.`id` ";
    }
    if (usingdocuments()) {
        $sql .= "UNION SELECT d.`id` AS 'id', d.`date`, `name` AS title, d.`description` AS details, d.`user` AS userid, 0 AS id2, 0 AS id3, 'DOCS' AS type \n                 FROM `fcms_documents` AS d, `fcms_users` AS u \n                 WHERE d.`date` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n                 AND d.`user` = u.`id` ";
    }
    $sql .= "UNION SELECT DISTINCT p.`category` AS id, p.`date`, `name` AS title, '' AS details, p.`user` AS userid, COUNT(*) AS id2, DAYOFYEAR(p.`date`) AS id3, 'GALLERY' AS type \n             FROM `fcms_gallery_photos` AS p, `fcms_users` AS u, `fcms_category` AS c \n             WHERE p.`user` = u.`id` \n             AND p.`category` = c.`id` \n             AND p.`date` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n             GROUP BY userid, title, id3\n\n             UNION SELECT p.`id`, gc.`date`, gc.`comment` AS title, gc.`comment` AS details, gc.`user` AS userid, p.`user` AS id2, `filename` AS id3, 'GALCOM' AS type \n             FROM `fcms_gallery_photo_comment` AS gc, `fcms_users` AS u, `fcms_gallery_photos` AS p \n             WHERE gc.`date` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n             AND gc.`user` = u.`id` \n             AND gc.`photo` = p.`id` \n\n             UNION SELECT g.`id`, g.`created`, c.`name` AS title, g.`comment` AS details, g.`created_id` AS userid, c.`user` AS id2, c.`id` AS id3, 'GALCATCOM' AS type \n             FROM `fcms_gallery_category_comment` AS g\n             LEFT JOIN `fcms_users` AS u    ON g.`created_id`  = u.`id`\n             LEFT JOIN `fcms_category` AS c ON g.`category_id` = c.`id`\n             WHERE g.`created` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n\n             UNION SELECT c.`id`, c.`date_added` AS date, `title`, c.`desc` AS details, `created_by` AS userid, `date` AS id2, `category` AS id3, 'CALENDAR' AS type \n             FROM `fcms_calendar` AS c, `fcms_users` AS u \n             WHERE c.`date_added` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n             AND c.`created_by` = u.`id` AND `private` < 1 \n\n             UNION SELECT `id`, `started` AS date, `question` AS title, '' AS details, '0' AS userid, 'na' AS id2, 'na' AS id3, 'POLL' AS type \n             FROM `fcms_polls` \n             WHERE `started` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n\n             UNION SELECT p.`id`, c.`created` AS date, p.`question` AS title, c.`comment` AS details, c.`created_id` AS userid, 'na' AS id2, 'na' AS id3, 'POLLCOM' AS type \n             FROM `fcms_poll_comment` AS c\n             LEFT JOIN `fcms_polls` AS p ON c.`poll_id` = p.`id`\n             WHERE `created` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n\n             UNION SELECT `id`, `updated` AS date, `status` AS title, '' AS details, `user` AS userid, `parent` AS id2, `created` AS id3, 'STATUS' AS type \n             FROM `fcms_status` \n             WHERE `updated` >= DATE_SUB(CURDATE(), INTERVAL {$days} DAY) \n\n             UNION SELECT 0 as id, c.`created` AS date, 0 AS title, '' AS details, c.`user` AS userid, 0 AS id2, u.`sex` AS id3, 'AVATAR' AS type\n             FROM `fcms_changelog` AS c\n             LEFT JOIN `fcms_users` AS u ON c.`user` = u.`id`\n             WHERE `created` >= DATE_SUB(CURDATE(),INTERVAL {$days} DAY) \n             AND `column` = 'avatar'\n\n             UNION SELECT `id`, `created` AS date, `title`, `description` AS details, `created_id` AS userid, `source_id` AS id2, `source` AS id3, 'VIDEO' AS type\n             FROM `fcms_video`\n             WHERE `created` >= DATE_SUB(CURDATE(),INTERVAL {$days} DAY) \n             AND `active` = '1'\n\n             UNION SELECT `video_id` AS 'id', c.`created` AS date, `comment`, '' AS details, c.`created_id` AS userid, `source_id` AS id2, `source` AS id3, 'VIDEOCOM' AS type\n             FROM `fcms_video_comment` AS c\n             LEFT JOIN `fcms_video` AS v ON c.`video_id` = v.`id`\n             WHERE c.`created` >= DATE_SUB(CURDATE(),INTERVAL {$days} DAY) \n             AND v.`active` = '1'\n\n             ORDER BY date DESC LIMIT 0, 35";
    $whatsNewData = $fcmsDatabase->getRows($sql);
    if ($whatsNewData === false) {
        $fcmsError->setMessage(T_('Could not get What\'s New data.'));
        return false;
    }
    // Get additional data
    $whatsNewData = getAdditionalWhatsNewData($whatsNewData);
    if ($whatsNewData === false) {
        $fcmsError->setMessage(T_('Could not get additional What\'s New data.'));
        return false;
    }
    // Add external foursquare data
    if (usingWhereIsEveryone()) {
        $whatsNewData = getFoursquareWhatsNewData($whatsNewData);
        if ($whatsNewData === false) {
            $fcmsError->setMessage(T_('Could not get Foursquare What\'s New data.'));
            return false;
        }
    }
    // Now lets group events together
    $groupedData = array();
    foreach ($whatsNewData as $data) {
        // Build a lookup for the data for each new item
        $lkup = array();
        switch ($data['type']) {
            case 'THREAD':
            case 'BOARD':
                $lkup = array('type' => 'thread_', 'parent' => 'THREAD', 'child' => 'BOARD', 'parentId' => 'id2', 'childId' => 'id2');
                break;
            case 'GALLERY':
            case 'GALCATCOM':
                $lkup = array('type' => 'gallery_', 'parent' => 'GALLERY', 'child' => 'GALCATCOM', 'parentId' => 'id', 'childId' => 'id3');
                break;
            case 'NEWS':
            case 'NEWSCOM':
                $lkup = array('type' => 'news_', 'parent' => 'NEWS', 'child' => 'NEWSCOM', 'parentId' => 'id', 'childId' => 'id');
                break;
            case 'POLL':
            case 'POLLCOM':
                $lkup = array('type' => 'poll_', 'parent' => 'POLL', 'child' => 'POLLCOM', 'parentId' => 'id', 'childId' => 'id');
                break;
            case 'RECIPES':
            case 'RECIPECOM':
                $lkup = array('type' => 'recipe_', 'parent' => 'RECIPES', 'child' => 'RECIPECOM', 'parentId' => 'id', 'childId' => 'id');
                break;
            case 'STATUS':
            case 'STATUSCOM':
                $lkup = array('type' => 'status_', 'parent' => 'STATUS', 'child' => 'STATUSCOM', 'parentId' => 'id', 'childId' => 'id2');
                break;
            case 'VIDEO':
            case 'VIDEOCOM':
                $lkup = array('type' => 'video_', 'parent' => 'VIDEO', 'child' => 'VIDEOCOM', 'parentId' => 'id', 'childId' => 'id');
                break;
        }
        // Group things together
        if (count($lkup) > 0) {
            $id = $data['type'] == $lkup['parent'] ? $data[$lkup['parentId']] : $data[$lkup['childId']];
            if (isset($groupedData[$lkup['type'] . $id])) {
                if ($data['type'] == $lkup['parent']) {
                    // put it at the top of the group
                    array_unshift($groupedData[$lkup['type'] . $id], $data);
                } else {
                    // put it at the end of the group
                    $groupedData[$lkup['type'] . $id][] = $data;
                }
            } else {
                // start a new group
                $groupedData[$lkup['type'] . $id] = array($data);
            }
        } else {
            $groupedData[] = array($data);
        }
    }
    return $groupedData;
}