Exemplo n.º 1
0
 /**
  * PointChannels::Load()
  *
  * @param mixed $userId
  * @param mixed $domainId
  * @return
  */
 function Load($userId, $domainId, $pointType = '', $participationType = '', $siftByResource = false, $rapMonth = false, $rapYear = false)
 {
     //echo "In PointChannels->Load(...)...<br>\n";
     $participationTypeClause = $participationType != '' ? " and pat.ParticipationTypeID = {$participationType} " : '';
     $pointTypeClause = $pointType != '' ? " and ptypes.PointTypeName = '{$pointType}' " : " and not ptypes.PointTypeName = 'Resource' ";
     $resourceSort = $siftByResource ? " rappc.ChannelDescription, " : '';
     $resourceClause = $siftByResource ? " and rap.AssetObjectID = pc.ObjectID\n and rap.AssetChannelID = pc.ChannelID\n and rap.ResourceObjectID = rappc.ObjectID \n " : '';
     $resourceTable = $siftByResource ? ", mdr.t_resourceassetprofiles rap, mdr.t_pointchannels rappc " : '';
     $resourceFields = $siftByResource ? ", rappc.ChannelDescription ResourceDescription, rap.AssetObjectID,  rap.AssetChannelID, rap.ResourceObjectID " : '';
     $rapDateClause = $rapMonth ? " and rap.EffectiveMonth = '{$rapMonth}' and rap.EffectiveYear = '{$rapYear}'" : '';
     //print $rapDateClause;
     $this->p_userId = $userId;
     $this->p_domainId = $domainId;
     $sql = "\n            SELECT DISTINCT\n                pc.*,\n                pn.ReadTimeOffset,\n                pn.ReadInterval,\n                t.TimeZoneID,\n                t.TimeZoneName,\n                t.TimeZoneDescription,\n                t.IsDstActive,\n                t.StdAbbreviation,\n                t.StdDescription,\n                t.StdOffset,\n                t.StdMonth,\n                t.StdWeek,\n                t.StdDay,\n                t.StdHour,\n                t.DstAbbreviation,\n                t.DstDescription,\n                t.DstOffset,\n                t.DstMonth,\n                t.DstWeek,\n                t.DstDay,\n                t.DstHour,\n                zo.ObjectDescription Zone,\n                pat.ParticipationTypeID,\n                pat.ParticipationTypeDescription,\n                pcppp.CommittedReduction,\n                rp.PriceID RealTimePriceID,\n                rp.PriceDescription RealTimePriceDescription,\n                hp.PriceID HourlyPriceID,\n                hp.PriceDescription HourlyPriceDescription {$resourceFields}\n            FROM\n                mdr.t_objectxrefs dgox,\n                mdr.t_objecttypes got,\n                mdr.t_objects go,\n                mdr.t_objectxrefs ugox,\n                mdr.t_actorprivilegexrefs gpx,\n                mdr.t_actorprivilegexrefs dpx,\n                mdr.t_privileges p,\n                mdr.t_privilegetypes pt,\n                mdr.t_points pn,\n                mdr.t_timezones t,\n                mdr.t_objects po,\n                mdr.t_pointchannels pc,\n                mdr.t_objectxrefs pzox,\n                mdr.t_objects zo,\n                mdr.t_zones z,\n                mdr.t_pointchannelprogramparticipationprofiles pcppp,\n                mdr.t_participationtypes pat,\n                mdr.t_pricelocations pl,\n                mdr.t_pricecomponents pco,\n                mdr.t_pricetypes rpt,\n                mdr.t_pricetypes hpt,\n                mdr.t_prices rp,\n                mdr.t_prices hp,\n                mdr.t_pointtypes ptypes {$resourceTable}\n            WHERE\n                got.ObjectTypeName = 'Group' and\n                go.ObjectTypeID = got.ObjectTypeID and\n                dgox.ChildObjectID = go.ObjectID and\n                dgox.ParentObjectID = {$this->p_domainId} and\n                ugox.ParentObjectID = dgox.ChildObjectID and\n                ugox.ChildObjectID = {$this->p_userId}  and\n                gpx.ObjectID = ugox.ParentObjectID and\n                dpx.ObjectID = dgox.ParentObjectID and\n                gpx.PrivilegeID = dpx.PrivilegeID and\n                p.PrivilegeID = gpx.PrivilegeID and\n                pt.PrivilegeTypeID = p.PrivilegeTypeID and\n                pt.PrivilegeTypeName = 'Read' and\n                po.ObjectID = p.ObjectID and\n                pn.ObjectID = po.ObjectID and\n                t.TimeZoneID = pn.TimeZoneID and\n                po.IsInactive = 0 and\n                pn.IsEnabled = 1 and\n                pc.ObjectID = pn.ObjectID and\n                pc.IsEnabled = 1 and\n                pc.IsPlotable = 1 and\n                pzox.ChildObjectID = pn.ObjectID and\n                zo.ObjectID = pzox.ParentObjectID and\n                z.ObjectID = zo.ObjectID and\n                pcppp.PointObjectID = p.ObjectID and\n                pat.ParticipationTypeID = pcppp.ParticipationTypeID and\n                pco.PriceComponentName = 'LBMP' and\n                pl.ZoneObjectID = z.ObjectID and\n                rpt.PriceTypeName = 'RealTimePrice' and\n                rp.PriceTypeID = rpt.PriceTypeID and\n                rp.PriceLocationID = pl.PriceLocationID and\n                rp.PriceComponentID = pco.PriceComponentID and\n                hpt.PriceTypeName = 'HourlyPrice' and\n                hp.PriceTypeID = hpt.PriceTypeID and\n                hp.PriceLocationID = pl.PriceLocationID and\n                hp.PriceComponentID = pco.PriceComponentID and\n                ptypes.PointTypeID = pn.PointTypeID {$participationTypeClause} {$resourceClause} {$pointTypeClause} {$rapDateClause} \n            ORDER BY\n                {$resourceSort}\n                pc.ChannelDescription\n            ";
     //$this->preDebugger($sql);
     $result = mysql_query($sql, $this->sqlConnection());
     //echo mysql_num_rows($result);
     if (mysql_num_rows($result) > 0) {
         while ($row = mysql_fetch_array($result)) {
             //$this->preDebugger($row);
             if ($siftByResource) {
                 $this->p_resources[$row['ResourceObjectID']]['description'] = $row['ResourceDescription'];
                 $this->p_resources[$row['ResourceObjectID']]['assets'][$row["AssetObjectID"] . ':' . $row["AssetChannelID"]]['id'] = $row["ObjectID"];
                 $this->p_resources[$row['ResourceObjectID']]['assets'][$row["AssetObjectID"] . ':' . $row["AssetChannelID"]]['channelId'] = $row["ChannelID"];
                 $this->p_resources[$row['ResourceObjectID']]['assets'][$row["AssetObjectID"] . ':' . $row["AssetChannelID"]]['description'] = $row["ChannelDescription"];
                 $this->p_resources[$row['ResourceObjectID']]['assets'][$row["AssetObjectID"] . ':' . $row["AssetChannelID"]]['programId'] = $row["ParticipationTypeID"];
                 $this->p_resources[$row['ResourceObjectID']]['assets'][$row["AssetObjectID"] . ':' . $row["AssetChannelID"]]['programDescription'] = $row["ParticipationTypeDescription"];
                 $this->p_resources[$row['ResourceObjectID']]['assets'][$row["AssetObjectID"] . ':' . $row["AssetChannelID"]]['assetIdentifier'] = $row["AssetIdentifier"];
             } else {
                 $inx = $this->p_length++;
                 //inx has no meaning in the new context -- just using it to hold things together right now.
                 $uom = new UnitOfMeasure();
                 $uom->Load($row["UnitOfMeasureID"]);
                 $dluom = new UnitOfMeasure();
                 $dluom->Load($row["DrawLimitUnitOfMeasureID"]);
                 $pointChannel = new PointChannel($row["ObjectID"], $row["ChannelID"], $row["ChannelName"], $row["ChannelDescription"], $uom, $row["PulseConversionFactor"], $row["DrawLimit"], $dluom, $row["IsGenerator"], $row["AssetIdentifier"]);
                 $this->p_pointChannel[$inx] = clone $pointChannel;
                 $this->p_pcMap[$pointChannel->objectId()][$pointChannel->channelId()] = $inx;
                 //$this->preDebugger($pointChannel);
                 /*
                             print '<pre style="color: red;">';
                             echo "pointChannel='" . $this->p_pointChannel[$inx]->objectId() . "', '" . $this->p_pointChannel[$inx]->channelId() . "'<br>\n";
                             echo "index='" . $this->p_pcMap[$pointChannel->objectId()][$pointChannel->channelId()] . "'<br>\n";
                             print '</pre>';
                 */
                 if (!isset($this->p_meterPoint[$pointChannel->objectId()])) {
                     $this->p_meterPoint[$pointChannel->objectId()] = new MeterPoint();
                     $this->p_meterPoint[$pointChannel->objectId()]->id($pointChannel->objectId());
                     $this->p_meterPoint[$pointChannel->objectId()]->readTimeOffset($row["ReadTimeOffset"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->readInterval($row["ReadInterval"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->zone($row["Zone"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->committedReduction($row["CommittedReduction"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->participationTypeID($row["ParticipationTypeID"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->participationTypeDescription($row["ParticipationTypeDescription"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->displayPriceId($row["RealTimePriceID"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->displayPriceDescription($row["RealTimePriceDescription"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->settlementPriceId($row["HourlyPriceID"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->settlementPriceDescription($row["HourlyPriceDescription"]);
                     $this->p_participationTypeList[$row["ParticipationTypeID"]] = $row["ParticipationTypeDescription"];
                     $timeZone = new TimeZone();
                     $timeZone->id($row["TimeZoneID"]);
                     $timeZone->name($row["TimeZoneName"]);
                     $timeZone->description($row["TimeZoneDescription"]);
                     $timeZone->isDstActive($row["IsDstActive"]);
                     $timeZone->stdAbbreviation($row["StdAbbreviation"]);
                     $timeZone->stdDescription($row["StdDescription"]);
                     $timeZone->stdOffset($row["StdOffset"]);
                     $timeZone->stdMonth($row["StdMonth"]);
                     $timeZone->stdWeek($row["StdWeek"]);
                     $timeZone->stdDay($row["StdDay"]);
                     $timeZone->stdHour($row["StdHour"]);
                     $timeZone->dstAbbreviation($row["DstAbbreviation"]);
                     $timeZone->dstDescription($row["DstDescription"]);
                     $timeZone->dstOffset($row["DstOffset"]);
                     $timeZone->dstMonth($row["DstMonth"]);
                     $timeZone->dstWeek($row["DstWeek"]);
                     $timeZone->dstDay($row["DstDay"]);
                     $timeZone->dstHour($row["DstHour"]);
                     $this->p_meterPoint[$pointChannel->objectId()]->timeZone($timeZone);
                 }
                 $this->p_pointChannel[$inx]->meterPoint($this->p_meterPoint[$pointChannel->objectId()]);
             }
             //print_r($this->p_resource);
         }
         // end while
     } else {
         $this->p_resources = false;
     }
     //end if
 }