public static function handleTagItemsRequest(Tag $Tag)
 {
     $conditions = array('TagID' => $Tag->ID);
     if (!empty($_REQUEST['Class']) && Validators::className($_REQUEST['Class'])) {
         $conditions['ContextClass'] = $_REQUEST['Class'];
     }
     return static::respond('tagItems', array('success' => true, 'data' => TagItem::getAllByWhere($conditions)));
 }
 public static function handleCollectionsRequest()
 {
     $tags = DB::allRecords('SELECT Tag.*, (SELECT COUNT(*) FROM `%2$s` AS TagItem WHERE Tag.`%3$s` = TagItem.`%4$s` AND TagItem.`%6$s` = "Media") AS itemsCount FROM `%1$s` AS Tag ORDER BY itemsCount', array(Tag::$tableName, TagItem::$tableName, Tag::getColumnName('ID'), TagItem::getColumnName('TagID'), Tag::getColumnName('Title'), TagItem::getColumnName('ContextClass')));
     $allMediaCollection = array('Title' => 'All Media', 'itemsCount' => DB::oneValue('SELECT COUNT(*) FROM `%s`', Media::$tableName), 'nodeType' => 'allMedia');
     $tagsCollection = array('Title' => 'Tagged Media', 'itemsCount' => array_sum(array_map(function ($tag) {
         return $tag['itemsCount'];
     }, $tags)), 'nodeType' => 'tags', 'children' => array_map(function ($tag) {
         $tag['nodeType'] = 'tag';
         return $tag;
     }, $tags));
     return static::respond('collections', array($allMediaCollection, $tagsCollection));
 }
Esempio n. 3
0
 public static function getTagsSummary($options = array())
 {
     $options = array_merge(array('tagConditions' => array(), 'itemConditions' => array(), 'Class' => false, 'classConditions' => array(), 'overlayTag' => false, 'order' => 'itemsCount DESC', 'excludeEmpty' => true, 'limit' => false), $options);
     // initialize conditions
     $options['tagConditions'] = Tag::mapConditions($options['tagConditions']);
     if (!empty($options['Class'])) {
         $options['classConditions'] = $options['Class']::mapConditions($options['classConditions']);
     }
     $options['itemConditions'] = TagItem::mapConditions($options['itemConditions']);
     // build query
     if (!empty($options['classConditions'])) {
         $classSubquery = 'SELECT `%s` FROM `%s` WHERE (%s)';
         $classParams = array($options['Class']::getColumnName('ID'), $options['Class']::$tableName, join(') AND (', $options['classConditions']));
     }
     $itemsCountQuery = 'SELECT COUNT(*) FROM `%s` TagItem WHERE TagItem.`%s` = Tag.`%s` AND (%s)';
     $itemsCountParams = array(TagItem::$tableName, TagItem::getColumnName('TagID'), Tag::getColumnName('ID'), count($options['itemConditions']) ? join(') AND (', $options['itemConditions']) : '1');
     if (!empty($options['overlayTag'])) {
         if (!is_object($OverlayTag = $options['overlayTag']) && !($OverlayTag = Tag::getByHandle($options['overlayTag']))) {
             throw new Excoption('Overlay tag not found');
         }
         $itemsCountQuery .= sprintf(' AND (TagItem.`%s`,TagItem.`%s`) IN (SELECT OverlayTagItem.`%s`, OverlayTagItem.`%s` FROM `%s` OverlayTagItem WHERE OverlayTagItem.`%s` = %u)', TagItem::getColumnName('ContextClass'), TagItem::getColumnName('ContextID'), TagItem::getColumnName('ContextClass'), TagItem::getColumnName('ContextID'), TagItem::$tableName, TagItem::getColumnName('TagID'), $OverlayTag->ID);
     }
     if (isset($classSubquery)) {
         $itemsCountQuery .= sprintf(' AND TagItem.`%s` = "%s" AND TagItem.`%s` IN (%s)', TagItem::getColumnName('ContextClass'), $options['Class']::getStaticRootClass(), TagItem::getColumnName('ContextID'), DB::prepareQuery($classSubquery, $classParams));
     }
     $tagSummaryQuery = 'SELECT Tag.*, (%s) AS itemsCount FROM `%s` Tag WHERE (%s)';
     $tagSummaryParams = array(DB::prepareQuery($itemsCountQuery, $itemsCountParams), Tag::$tableName, count($options['tagConditions']) ? join(') AND (', $options['tagConditions']) : '1');
     // exclude empty
     if ($options['excludeEmpty']) {
         $tagSummaryQuery .= ' HAVING itemsCount > 0';
     }
     // add order options
     if ($options['order']) {
         $tagSummaryQuery .= ' ORDER BY ' . join(',', static::_mapFieldOrder($options['order']));
     }
     // add limit options
     if ($options['limit']) {
         $tagSummaryQuery .= sprintf(' LIMIT %u,%u', $options['offset'], $options['limit']);
     }
     try {
         // return indexed table or list
         if ($options['indexField']) {
             return DB::table(Tag::getColumnName($options['indexField']), $tagSummaryQuery, $tagSummaryParams);
         } else {
             return DB::allRecords($tagSummaryQuery, $tagSummaryParams);
         }
     } catch (TableNotFoundException $e) {
         return array();
     }
 }
Esempio n. 4
0
if ($currentMeetup) {
    $currentMeetup['checkins'] = Laddr\MemberCheckin::getAllForMeetupByProject($currentMeetup['id']);
}
$pageData['currentMeetup'] = $currentMeetup;
$pageData['nextMeetup'] = $nextMeetup;
$pageData['futureMeetups'] = $meetups;
// projects
$pageData['projectsTotal'] = Laddr\Project::getCount();
$pageData['projectsTags']['byTech'] = TagItem::getTagsSummary(array('tagConditions' => array('Handle LIKE "tech.%"'), 'itemConditions' => array('ContextClass' => Laddr\Project::getStaticRootClass())));
$pageData['projectsTags']['byTopic'] = TagItem::getTagsSummary(array('tagConditions' => array('Handle LIKE "topic.%"'), 'itemConditions' => array('ContextClass' => Laddr\Project::getStaticRootClass())));
$pageData['projectsTags']['byEvent'] = TagItem::getTagsSummary(array('tagConditions' => array('Handle LIKE "event.%"'), 'itemConditions' => array('ContextClass' => Laddr\Project::getStaticRootClass())));
$pageData['projectsStages'] = Laddr\Project::getStagesSummary();
// members
$pageData['membersTotal'] = Emergence\People\Person::getCount();
$pageData['membersTags']['byTech'] = TagItem::getTagsSummary(array('tagConditions' => array('Handle LIKE "tech.%"'), 'itemConditions' => array('ContextClass' => Emergence\People\Person::getStaticRootClass())));
$pageData['membersTags']['byTopic'] = TagItem::getTagsSummary(array('tagConditions' => array('Handle LIKE "topic.%"'), 'itemConditions' => array('ContextClass' => Emergence\People\Person::getStaticRootClass())));
// build activity stream
if (!($pageData['activity'] = Cache::fetch('home-activity'))) {
    $existingTables = \DB::allValues('table_name', 'SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA = SCHEMA()');
    $activityQueries = [];
    if (in_array(Emergence\CMS\AbstractContent::$tableName, $existingTables)) {
        $activityQueries[] = sprintf('SELECT' . '  ID, Class, Published AS Timestamp' . ' FROM `%s`' . ' WHERE' . '  Class = "%s" AND' . '  Visibility = "Public" AND' . '  Status = "Published" AND' . '  (Published IS NULL OR Published <= CURRENT_TIMESTAMP)', Emergence\CMS\AbstractContent::$tableName, DB::escape(Emergence\CMS\BlogPost::class));
    }
    if (in_array(Laddr\ProjectUpdate::$tableName, $existingTables)) {
        $activityQueries[] = sprintf('SELECT ID, Class, Created AS Timestamp FROM `%s`', Laddr\ProjectUpdate::$tableName);
    }
    if (in_array(Laddr\ProjectBuzz::$tableName, $existingTables)) {
        $activityQueries[] = sprintf('SELECT ID, Class, Published AS Timestamp FROM `%s`', Laddr\ProjectBuzz::$tableName);
    }
    if (count($activityQueries)) {
        $pageData['activity'] = array_map(function ($result) {
 public static function handlePostRequest()
 {
     $data = static::getRequestData();
     // create Content object
     $Content = new CMS_BlogPost();
     $Content->Title = $data['Title'];
     $Content->save();
     // create text ContentItem object
     $ContentItem = new CMS_RichTextContent();
     $ContentItem->ContentID = $Content->ID;
     $ContentItem->Data = $data['Data'];
     $ContentItem->save();
     // create CategoryItem object foreach
     if (is_array($data['Categories']) && count($data['Categories'])) {
         foreach ($data['Categories'] as $cat) {
             $Category = Category::getByID($cat);
             $CategoryItem = new CategoryItem();
             $CategoryItem->ContextClass = 'CMS_BlogPost';
             $CategoryItem->ContextID = $Content->ID;
             $CategoryItem->CategoryID = $Category->ID;
             $CategoryItem->save();
         }
     }
     // create TagItem object foreach. if Tag object doesn't exist, create as well
     if (is_array($data['Tags']) && count($data['Tags'])) {
         foreach ($data['Tags'] as $word) {
             $Tag = Tag::getFromHandle($word, true);
             // second boolean is telling method to make the Tag object for us if it doesn't exist
             $TagItem = new TagItem();
             $TagItem->ContextClass = 'CMS_BlogPost';
             $TagItem->ContextID = $Content->ID;
             $TagItem->TagID = $Tag->ID;
             $TagItem->save();
         }
     }
     return static::respondCRUD($Content, 'singular', 'created');
 }
Esempio n. 6
0
 public function getItemsByClass($class, $options = array())
 {
     // apply defaults
     $options = array_merge(array('conditions' => false, 'order' => false, 'limit' => is_numeric($options) ? $options : false, 'offset' => 0, 'overlayTag' => false, 'calcFoundRows' => false), $options);
     // build TagItem query
     $tagWhere = array();
     $tagWhere[] = sprintf('`%s` = %u', TagItem::getColumnName('TagID'), $this->ID);
     $tagWhere[] = sprintf('`%s` = "%s"', TagItem::getColumnName('ContextClass'), DB::escape($class::getStaticRootClass()));
     $tagQuery = sprintf('SELECT ContextID FROM `%s` TagItem WHERE (%s)', TagItem::$tableName, count($tagWhere) ? join(') AND (', $tagWhere) : '1', $options['limit'] ? sprintf('LIMIT %u', $options['limit']) : '');
     if (!empty($options['overlayTag'])) {
         if (!is_object($OverlayTag = $options['overlayTag']) && !($OverlayTag = Tag::getByHandle($options['overlayTag']))) {
             throw new Exception('Overlay tag not found');
         }
         $tagQuery .= sprintf(' AND (TagItem.`%s`,TagItem.`%s`) IN (SELECT OverlayTagItem.`%s`, OverlayTagItem.`%s` FROM `%s` OverlayTagItem WHERE OverlayTagItem.`%s` = %u)', TagItem::getColumnName('ContextClass'), TagItem::getColumnName('ContextID'), TagItem::getColumnName('ContextClass'), TagItem::getColumnName('ContextID'), TagItem::$tableName, TagItem::getColumnName('TagID'), $OverlayTag->ID);
     }
     // built class table query
     if ($options['conditions']) {
         if (!is_array($options['conditions'])) {
             $options['conditions'] = array($options['conditions']);
         }
         $classWhere = $class::_mapConditions($options['conditions']);
     } else {
         $classWhere = array();
     }
     // return objects
     $classQuery = sprintf('SELECT %s' . ' Content.*' . ' FROM (%s) TagItem' . ' JOIN `%s` Content ON (Content.ID = TagItem.ContextID)' . ' WHERE (%s)', $options['calcFoundRows'] ? 'SQL_CALC_FOUND_ROWS' : '', $tagQuery, $class::$tableName, count($classWhere) ? join(') AND (', $classWhere) : '1');
     if ($options['order']) {
         $classQuery .= ' ORDER BY ' . join(',', $class::_mapFieldOrder($options['order']));
     }
     if ($options['limit']) {
         $classQuery .= sprintf(' LIMIT %u,%u', $options['offset'], $options['limit']);
     }
     return $class::instantiateRecords(DB::allRecords($classQuery));
 }