Beispiel #1
0
 /**
  * Updates data in a table.
  *
  * @param   $table      JaxpMySqlTable
  *          Affected table.
  *          
  * @param   $row        JaxpMySqlRow
  *          Modified records.
  *          
  * @param   $conditions JaxpMySqlConditions
  *          Matches for original records. If null, it'll overwrite all data.
  *          
  * @return  int
  *          Number of affected rows.
  *          
  * @uses    JaxpMySqlTable, JaxpMySqlRow, JaxpMySqlConditions
  * @access  public
  * @since   1.1
  *
  * @internal    2010.01.03 -- fixed error with partial row updates.
  */
 function Update(JaxpMySqlTable $table, JaxpMySqlRow $row, JaxpMySqlConditions $conditions = null)
 {
     $sql_query_template = "UPDATE %s SET %s" . ($conditions ? " WHERE %s" : "");
     $destination_table = $table->TableName;
     # Get all fields from table, except auto-incremental ones.
     $fields = $row->GetColumnNames(true);
     # Match values with fields.
     foreach ($fields as $i => $f) {
         if ($row->Columns[$f]->Value) {
             $v = $row->Columns[$f]->HasQuotes() ? "'" . $row->Columns[$f]->Value . "'" : $row->Columns[$f]->Value;
             $update_sentences[] = "{$f} = {$v}";
         }
     }
     $update_list = implode(", ", $update_sentences);
     # If update conditions were specified, place them in the query.
     # Otherwise, build query without conditions.
     $sql_query = $conditions ? sprintf($sql_query_template, $destination_table, $update_list, $conditions->ParseToStringList()) : sprintf($sql_query_template, $destination_table, $update_list);
     # Execute query.
     mysql_query('SET NAMES utf8');
     mysql_query($sql_query);
     #echo $sql_query;
     # Return number of affected rows.
     return mysql_affected_rows();
 }
Beispiel #2
0
 /**
  * Look up all media belonging to this gallery and organize it
  * into the pertinent object collections.
  *
  * @uses    JaxpMySqlHandler
  * @uses    JaxpMySqlConditions
  * @uses    JaxpJournalMediaPhoto
  * @uses    JaxpJournalMediaVideo
  * @uses    JaxpJournalMediaAudio
  *
  * @param   string $source_table_name   Table which contains media data.
  *
  * @access  public
  * @return  void
  * @since   1.0
  */
 function LoadMedia($source_table_name)
 {
     # Shortcut to the database object.
     $db = $this->MySqlHandler->Database;
     # Instantiate the Media table.
     $journal_media = $db->LoadTable($source_table_name);
     # Create a filter to locate media that belongs to this gallery.
     # The filter uses the gallery id as a relation key.
     $media_match = new JaxpMySqlConditions();
     $media_match->AddCondition($journal_media->Columns["gallery_id"], $this->ElementId, JAXP_MYSQL_MATCH_EQUAL);
     # Execute the filter.
     $gallery_media = $this->MySqlHandler->Filter($journal_media, $media_match);
     # If there are any media contents found...
     if (count($gallery_media->Rows)) {
         # ...iterate through them...
         foreach ($gallery_media->Rows as $r) {
             # ...get current media's id...
             $rId = $r->Columns["id"]->Value;
             # ...determine the media type...
             switch ($r->Columns["media_type"]->Value) {
                 # Is it a photo?
                 case JAXP_MEDIA_TYPE_PHOTO:
                     # Add it to the Photo collection.
                     $this->Photo[$rId] = new JaxpMediaPhoto($rId, $r->Columns["title"]->Value, $r->Columns["description"]->Value, $r->Columns["source_file_name"]->Value, $this->ElementId);
                     break;
                     # Is it a video?
                 # Is it a video?
                 case JAXP_MEDIA_TYPE_VIDEO:
                     # Add it to the Video collection.
                     $this->Video[$rId] = new JaxpMediaVideo($rId, $r->Columns["title"]->Value, $r->Columns["description"]->Value, $r->Columns["source_file_name"]->Value, $this->ElementId);
                     break;
                     # Is it audio?
                 # Is it audio?
                 case JAXP_MEDIA_TYPE_AUDIO:
                     # Add it to the Audio collection.
                     $this->Audio[$rId] = new JaxpMediaAudio($rId, $r->Columns["title"]->Value, $r->Columns["description"]->Value, $r->Columns["source_file_name"]->Value, $this->ElementId);
                     break;
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Locates a note using permalink data.
  *
  * @uses    JaxpDate
  * @uses    JaxpMySqlHandler
  * @uses    JaxpMySqlConditions
  *
  * @access  public
  * @return  JaxpJournalNote     An object representing the note.
  * @since   1.2.1
  */
 function GetNoteFromPermalink()
 {
     # Parse the URL address and take the last two parts
     # (i.e. from "/uri/a/b/c/", take 'b' and 'c', unslashed.
     list($date, $title) = array_slice(explode("/", $_SERVER["REQUEST_URI"]), 2, 2);
     # Convert date string to an usable object.
     $datePosted = new JaxpDate(JAXP_DATE_FROM_STRING, $date);
     # Reformat the title passed by GET.
     # Punctuation characters mutate to wildcards for LIKE-comparison.
     $title = str_replace("-", " ", $title);
     $title = str_replace("_", "%", $title);
     # Instantiate the Notes table.
     $journal_notes = $this->MySqlHandler->Database->Tables["journal_notes"];
     # Create a dual-condition filter, to locate by title and by date.
     $filter = new JaxpMySqlConditions();
     $filter->AddCondition($journal_notes->Columns["title"], $title, JAXP_MYSQL_MATCH_CONTAINS);
     $filter->AddCondition($journal_notes->Columns["date_posted"], $datePosted->ToTimestamp(), JAXP_MYSQL_MATCH_GREATER_OR_EQUAL_THAN);
     # Apply the filter.
     $note = $this->MySqlHandler->Select("SELECT * FROM journal_notes WHERE " . $filter->ParseToStringList());
     # Since the filter ensures only one entry will be retrieved,
     # return the first element of the resulting array.
     return $this->Notes[$note->Rows[0]->Columns["id"]->Value];
 }