Exemplo n.º 1
0
 /**
  * Update the Water Mark to indicate the last data edit
  * @param int $dataSetId The Data Set ID to Update
  */
 private function UpdateWatermark($dataSetId)
 {
     if ($dataSetId == 0 || $dataSetId == '') {
         return $this->SetError(25001, __('Missing dataSetId'));
     }
     if (!$this->updateWatermark) {
         return;
     }
     Debug::LogEntry('audit', sprintf('Updating water mark on DataSetId: %d', $dataSetId), 'DataSetData', 'UpdateWatermark');
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('UPDATE `dataset` SET LastDataEdit = :last_data_edit WHERE DataSetID = :dataset_id');
         $sth->execute(array('last_data_edit' => time(), 'dataset_id' => $dataSetId));
         // Get affected Campaigns
         Kit::ClassLoader('dataset');
         $dataSet = new DataSet($this->db);
         $campaigns = $dataSet->GetCampaignsForDataSet($dataSetId);
         Kit::ClassLoader('display');
         $display = new Display($this->db);
         foreach ($campaigns as $campaignId) {
             // Assess all displays
             $campaigns = $display->NotifyDisplays($campaignId);
         }
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * Sets the Layout Xml and writes it back to the database
  * @return
  * @param $layoutid Object
  * @param $xml Object
  */
 public function SetLayoutXml($layoutid, $xml)
 {
     Debug::LogEntry('audit', 'IN', 'Layout', 'SetLayoutXml');
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('UPDATE layout SET xml = :xml, modifieddt = NOW() WHERE layoutID = :layoutid');
         $sth->execute(array('layoutid' => $layoutid, 'xml' => $xml));
         // Get the Campaign ID
         $campaign = new Campaign($this->db);
         $campaignId = $campaign->GetCampaignId($layoutid);
         // Notify (dont error)
         if (!$this->delayFinalise) {
             $displayObject = new Display($this->db);
             $displayObject->NotifyDisplays($campaignId);
         }
         Debug::LogEntry('audit', 'OUT', 'Layout', 'SetLayoutXml');
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25007, 'Unable to Update Layout.');
         }
         return false;
     }
 }
Exemplo n.º 3
0
 /**
  * Add
  * @return 
  * @param $displayGroupIDs Object
  * @param $fromDT Object
  * @param $toDT Object
  * @param $layoutID Object
  * @param $recType Object
  * @param $recDetail Object
  * @param $recToDT Object
  * @param $isPriority Object
  * @param $userID Object
  * @param $displayOrder Object
  */
 public function Add($displayGroupIDs, $fromDT, $toDT, $campaignId, $recType, $recDetail, $recToDT, $isPriority, $userID, $displayOrder = 0)
 {
     Debug::LogEntry('audit', 'IN', 'Schedule', 'Add');
     try {
         $dbh = PDOConnect::init();
         // Validation
         if (count($displayGroupIDs) == 0) {
             return $this->SetError(25001, __('No display groups selected'));
         }
         if ($userID == 0) {
             return $this->SetError(25001, __('No User Id Present'));
         }
         // Cant have a 0 increment as it creates a loop
         if ($recDetail == 0) {
             $recDetail = 1;
         }
         // make the displayid_list from the selected displays.
         $displayGroupIDList = implode(",", $displayGroupIDs);
         // Parameters for the query
         $params = array('campaignid' => $campaignId, 'displaygroupids' => $displayGroupIDList, 'userid' => $userID, 'is_priority' => $isPriority, 'fromdt' => $fromDT, 'todt' => $toDT);
         $SQL = "";
         $SQL .= "INSERT INTO `schedule` (CampaignId, DisplayGroupIDs, userID, is_priority, FromDT, ToDT ";
         // Columns for Recurrence
         if ($recType != '' && $recType != 'null') {
             $SQL .= ", recurrence_type, recurrence_detail, recurrence_range ";
         }
         $SQL .= ") ";
         $SQL .= " VALUES ( :campaignid, :displaygroupids, :userid, :is_priority, :fromdt, :todt ";
         // Values for Recurrence
         if ($recType != '' && $recType != 'null') {
             $SQL .= ", :recurrence_type, :recurrence_detail, :recurrence_range ";
             $params['recurrence_type'] = $recType;
             $params['recurrence_detail'] = $recDetail;
             $params['recurrence_range'] = $recToDT;
         }
         $SQL .= ")";
         $sth = $dbh->prepare($SQL);
         $sth->execute($params);
         // Get the event id
         $eventID = $dbh->lastInsertId();
         // Make sure we dont just have one...
         if (!is_array($displayGroupIDs)) {
             $displayGroupIDs = array($displayGroupIDs);
         }
         // Create a detail record for each display group
         foreach ($displayGroupIDs as $displayGroupID) {
             // Add the parent detail record for this event
             if (!$this->AddDetail($displayGroupID, $campaignId, $fromDT, $toDT, $userID, $isPriority, $eventID, $displayOrder)) {
                 throw new Exception("Error Processing Request", 1);
             }
             // Is there any recurrance to take care of?
             if ($recType != '' && $recType != 'null') {
                 // Set the temp starts
                 $t_start_temp = $fromDT;
                 $t_end_temp = $toDT;
                 Debug::LogEntry('audit', sprintf('Recurrence detected until %d. Recurrence period is %s and interval is %s.', $recToDT, $recDetail, $recType), 'Schedule', 'Add');
                 //loop until we have added the recurring events for the schedule
                 while ($t_start_temp < $recToDT) {
                     // add the appropriate time to the start and end
                     switch ($recType) {
                         case 'Hour':
                             $t_start_temp = mktime(date("H", $t_start_temp) + $recDetail, date("i", $t_start_temp), date("s", $t_start_temp), date("m", $t_start_temp), date("d", $t_start_temp), date("Y", $t_start_temp));
                             $t_end_temp = mktime(date("H", $t_end_temp) + $recDetail, date("i", $t_end_temp), date("s", $t_end_temp), date("m", $t_end_temp), date("d", $t_end_temp), date("Y", $t_end_temp));
                             break;
                         case 'Day':
                             $t_start_temp = mktime(date("H", $t_start_temp), date("i", $t_start_temp), date("s", $t_start_temp), date("m", $t_start_temp), date("d", $t_start_temp) + $recDetail, date("Y", $t_start_temp));
                             $t_end_temp = mktime(date("H", $t_end_temp), date("i", $t_end_temp), date("s", $t_end_temp), date("m", $t_end_temp), date("d", $t_end_temp) + $recDetail, date("Y", $t_end_temp));
                             break;
                         case 'Week':
                             $t_start_temp = mktime(date("H", $t_start_temp), date("i", $t_start_temp), date("s", $t_start_temp), date("m", $t_start_temp), date("d", $t_start_temp) + $recDetail * 7, date("Y", $t_start_temp));
                             $t_end_temp = mktime(date("H", $t_end_temp), date("i", $t_end_temp), date("s", $t_end_temp), date("m", $t_end_temp), date("d", $t_end_temp) + $recDetail * 7, date("Y", $t_end_temp));
                             break;
                         case 'Month':
                             $t_start_temp = mktime(date("H", $t_start_temp), date("i", $t_start_temp), date("s", $t_start_temp), date("m", $t_start_temp) + $recDetail, date("d", $t_start_temp), date("Y", $t_start_temp));
                             $t_end_temp = mktime(date("H", $t_end_temp), date("i", $t_end_temp), date("s", $t_end_temp), date("m", $t_end_temp) + $recDetail, date("d", $t_end_temp), date("Y", $t_end_temp));
                             break;
                         case 'Year':
                             $t_start_temp = mktime(date("H", $t_start_temp), date("i", $t_start_temp), date("s", $t_start_temp), date("m", $t_start_temp), date("d", $t_start_temp), date("Y", $t_start_temp) + $recDetail);
                             $t_end_temp = mktime(date("H", $t_end_temp), date("i", $t_end_temp), date("s", $t_end_temp), date("m", $t_end_temp), date("d", $t_end_temp), date("Y", $t_end_temp) + $recDetail);
                             break;
                     }
                     // after we have added the appropriate amount, are we still valid
                     if ($t_start_temp > $recToDT) {
                         break;
                     }
                     if (!$this->AddDetail($displayGroupID, $campaignId, $t_start_temp, $t_end_temp, $userID, $isPriority, $eventID, $displayOrder)) {
                         throw new Exception("Error Processing Request", 1);
                     }
                 }
             }
         }
         // Notify (dont error)
         Kit::ClassLoader('Display');
         $displayObject = new Display($this->db);
         $displayObject->NotifyDisplays($campaignId);
         Debug::LogEntry('audit', 'OUT', 'Schedule', 'Add');
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25001, __('Could not INSERT a new Schedule'));
         }
         return false;
     }
 }