/**
  * Parses the json in to a channel object
  *
  * @param string $json
  * @return \Swiftriver\Core\ObjectModel\Channel
  */
 public function ParseJSONToChannel($json)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Calling json_decode]", \PEAR_LOG_DEBUG);
     $data = json_decode($json);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Extracting data from the JSON objects]", \PEAR_LOG_DEBUG);
     if (!isset($data) || !$data) {
         $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [ERROR: No objects present at data[0], returning null]", \PEAR_LOG_DEBUG);
         return null;
     }
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Extracting values from the data]", \PEAR_LOG_DEBUG);
     $type = $data->type;
     $updatePeriod = $data->updatePeriod;
     $active = $data->active;
     $parameters = $data->parameters;
     if (!isset($type) || !isset($updatePeriod) || !isset($parameters) || !is_array($parameters)) {
         $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [ERROR: either the 'type', 'updatePeriod' or 'parameters array' could not be found, returning null]", \PEAR_LOG_DEBUG);
         return null;
     }
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Constructing Channel object]", \PEAR_LOG_DEBUG);
     $formattedParams = array();
     foreach ($parameters as $params) {
         $formattedParams[$params->key] = $params->value;
     }
     $channel = new \Swiftriver\Core\ObjectModel\Channel();
     $channel->SetType($type);
     $channel->SetUpdatePeriod($updatePeriod);
     $channel->SetActive($active);
     $channel->SetParameters($formattedParams);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Method finished]", \PEAR_LOG_INFO);
     return $channel;
 }
 /**
  * Lists all the current Channel Processing Jobs in the core
  * @return \Swiftriver\Core\ObjectModel\Channel[]
  */
 public static function ListAllChannelProcessingJobs()
 {
     $query = "SELECT * FROM channelprocessingjobs ORDER BY nextrun;";
     $result = self::RunQuery($query);
     if (!$result) {
         return null;
     }
     $channels = array();
     while ($row = mysql_fetch_array($result, \MYSQL_ASSOC)) {
         $type = $row["type"];
         $parameters = $row["parameters"];
         $updatePeriod = $row["updateperiod"];
         $nextrun = strtotime($row["nextrun"]);
         $lastrun = strtotime($row["lastrun"]);
         $lastsucess = strtotime($row["lastsucess"]);
         $timesrun = $row["timesrun"];
         $active = $row["active"];
         $channel = new \Swiftriver\Core\ObjectModel\Channel();
         $channel->SetType($type);
         $channel->SetUpdatePeriod($updatePeriod);
         $channel->SetActive(!isset($active) || $active != 0);
         $params = array();
         foreach (explode("|", $parameters) as $parameter) {
             $pair = explode(",", $parameter);
             $key = urldecode($pair[0]);
             $value = urldecode($pair[1]);
             $params[$key] = $value;
         }
         $channel->SetParameters($params);
         $channels[] = $channel;
     }
     return $channels;
 }