Example #1
0
 /**
  *
  * @param <type> $metadata 
  */
 public function set_metadata($metadata)
 {
     self::validate_content($metadata, DBDataType::DATATYPE_TEXT);
     try
     {
         $metadata = $this->db->escape_string($metadata);
         $this->db->quick_query(
                 "UPDATE ".self::FCORE_FORUM." SET
                     ".self::METADATA."='$metadata' WHERE
                     ".self::FORUM_ID."=$this->forum_id");
         $this->db->commit();
     }
     catch(Exception $e)
     {
         $this->db->rollback();
         throw new DBForumException($e->getMessage());
     }
 }
Example #2
0
 /**
  *
  * @param <type> $identifier
  * @return <type> 
  */
 private function consume_identifier(&$identifier)
 {
     if (is_null($identifier) || $identifier == "")
     {
         return "";
     }
     if (is_numeric($identifier))
     {
         return " WHERE ".$this->config_map[self::DB_PRI_KEY_NAME]."=".$identifier;
     }
     if (is_string($identifier))
     {
         return " WHERE $identifier";
     }
     if (!is_array($identifier))
     {
         throw new Exception("invalid identifier type");
     }
     ksort($identifier);
     reset($identifier);
     $search = "";
     if (is_numeric(current($identifier)))
     {
         // if the first value is a number, then we can deduce
         // that all of the values are ids of the records this
         // model is manipulating. so, we just get the the
         // id column name for the table and set each one to the
         // value, and or all of them together
         foreach($identifier as $val)
         {
             if (is_numeric($val))
             {
                 if ($search != "")
                 {
                     $search .= " || ";
                 }
                 $search .= $this->config_map[self::DB_PRI_KEY_NAME]."=".$val;
             }
         }
     } 
     else
     {
         // go through each value and build the where clause of the query
         foreach($identifier as $val)
         {
             // check for the type the value is
             if (is_array($val))
             {
                 // check to make sure that all of the required keys are set
                 if (!isset($val[self::ID_KEY]))
                 {
                     throw new Exception(
                             "invalid array identifier: key not set");
                 }
                 if (!isset($val[self::ID_SIGN]))
                 {
                     throw new Exception(
                             "invalid array identifier: sign not set");
                 }
                 if (!isset($val[self::ID_VAL]))
                 {
                     throw new Exception(
                             "invalid array identifier: val not set");
                 }
                 // check to see if 'func' is set... if it isn't, then
                 // we escape the string and wrap it around quotes,
                 // if it is set, then let it string go unaffected
                 $value = "";
                 if (isset($val[self::ID_ESCAPE]))
                 {
                     if ($val[self::ID_ESCAPE])
                     {
                         $value = "'".$this->conn->escape_string(
                                 $val[self::ID_VAL])."'";
                     }
                     else
                     {
                         $value = $val[self::ID_VAL];
                     }
                 }
                 else
                 {
                     $value = "'".$this->conn->escape_string($val[self::ID_VAL])."'";
                 }
                 // include this into the search
                 $search .= $val[self::ID_KEY]." ".$val[self::ID_SIGN]." ".$value;
             }
             else if (is_string($val))
             {
                 $search .= " $val ";
             }
             else
             {
                 throw new Exception("invalid array identifier");
             }
         }
     }
     return " WHERE $search";
 }