registerguard / slotted

Caché DTI ContentPublisher: The <custom:rg:get:stories> RULE (a.k.a tag) returns a %ListOfObjects of dt.cms.schema.Mapping objects from an Area(s) in a Section.
http://www.registerguard.com
Apache License 2.0
0 stars 0 forks source link

Add new RULE to check if Area has slotted stories... #19

Open mhulse opened 11 years ago

mhulse commented 11 years ago
SELECT COUNT(*) 
FROM dt_cms_schema.Mapping m, dt_cms_schema.Slot s 
WHERE m.sectionID IN (
    SELECT ID 
    FROM dt_cms_schema.Section 
    WHERE name = 'outdoors' 
    AND publicationID = 8
) 
AND m.slotReferenceId = s.slotReferenceID 
AND s.areaID->name = 'Stories' 
AND m.version = 1 
ORDER BY m.slotReferenceId

... Or something along those lines.

I'd try to re-use existing query... Maybe make it an SQL ClassMethod and write another ClassMethod to return a count().

Would also need a new RULE to do and if else check.

mhulse commented 11 years ago

Some interesting info here:

class method for number of rows?

Need %ROWCOUNT or something.


Here's from ##class(dt.cms.support.Rules).getIsAreaSlotted(areaName, sectionName, PubId):

/// Returns a boolean (true if stories are slotting in the section/area.
ClassMethod getIsAreaSlotted(
    areaName As %String,
    sectionName As %String,
    publicationId As %Integer,
    debug As %Integer = 0) As %Boolean
{
    set GridId = 0
    &sql(select p.currentGridId into :GridId from dt_cms_schema.Page p, dt_cms_schema."Section" s 
            where p.sectionid = s.id and s.publicationid = :publicationId and s.name = :sectionName)
    if (SQLCODE '= 0) {
                do ..error(debug,"rules.cls - getIsAreaSlotted() - Failed to get grid. SQLCODE: " _ SQLCODE)
                Quit 1
    }
    if (GridId = 0) {
                do ..error(debug,"rules.cls - getIsAreaSlotted() - Failed to get grid. SectionName " _ sectionName _ " appears to be invalid.")
                Quit 1
    }
    &sql(select ID from dt_cms_schema.Area where name = :areaName and gridID = :GridId)
    if (SQLCODE = 100) {
                do ..error(debug,"rules.cls - getIsAreaSlotted() - Failed to get area - " _ areaName _ ". Invalid areaName")
                Quit 1
    }
    set Slots = ##class(dt.cms.schema.Area).GetAreaMappings(areaName, GridId)

            Quit (Slots.Count() > 0)
}

Not sure if that's of any help.

mhulse commented 11 years ago

Trying to start a conversation here... I'm wanting to avoid writing a whole 'nother rule just to check if there's slotted stories!