MODx Revo Gallery: How to set tags by choosing from list and filter albums by them in resourses - gallery

I need to get albums from gallery for 'Closes' which has categoties 'dress, skirts...' and collections (each element from subcategory can relate to different collections) and I need get closes elements filtering by categories, collections, and other parameters. But it's difficult to input the same tags in each Gallery item when creating it. How can I make such a catalog with Gallery?
And even more – each gallery item (element) have multiple images of the same item, so now i create Albums -> Subalbums -> Items.
I'm not sure can I do this with Gallery extra? May be use MIGx somehow... and code Gallery.

Im not sure entirely what your after but I would be tempted to create my own PHP snippet that searches the ModX database its self. Eg:
//TEMP VAR SEARCH
$sql = 'SELECT * FROM `modx_site_tmplvar_contentvalues` WHERE `value` LIKE "%WHAT EVER TAGS YOU HAVE%"';
$tvqresult = mysql_query($sql);
$num_rowstvq = mysql_num_rows($tvqresult);
while ($rowtvq = mysql_fetch_array($tvqresult)) {
$contid = $rowtvq['contentid'];
//MAIN QUERY
$mainsql = 'SELECT * FROM `modx_site_content` WHERE `id` = ' . $rowtvq['contentid'] . ' AND `template` = 12 AND `published` = 1 AND `deleted` = 0';
$resultmain = mysql_query($mainsql);
while ($row = mysql_fetch_array($resultmain)) {
echo "[[Ditto? &parents=`134` &documents=" . $row['id'] . " &tpl=`tempchunk`]]";
}//END MAIN LOOP
}
NOTE: This is just normal SQL - with Revo I believe you will had to make some slight adjustments to have it work with PDO.

Related

How can I replace WITH inside a CREATE TRIGGER in SQLite?

I have the following piece of code that creates a trigger that pulls some info from any other row in the same table with the same hash as the newly added row:
CREATE TRIGGER if not exists tr
after insert ON images
BEGIN
WITH a AS ( SELECT * FROM images WHERE hash = new.hash )
update images set
categories = a.categories,
quality = a.quality,
ide = a.ide,
drawing = a.drawing,
ide_commentary = a.ide_commentary,
priority = a.priority
where rowid = new.rowid;
END
However, for some reason SQLite doesn't support doing this. The only way I can see of doing what I want seems to be making a separate select for each value that needs to be updated, like this:
categories = ( SELECT categories FROM images WHERE hash = new.hash ),
quality = ( SELECT quality FROM images WHERE hash = new.hash ),
etc.
but this is just terrible on every level. Is there any better way to do this?

Want to create a dynamic page to list content by letter

I want to create a dynamic page in WP theme so that when I pass a letter from 'A-Z' it will display all the posts with the title starting from that letter.
Can you please tell me how to proceed?
If you are using themes and getting the index key via a query parameter then you can create a new custom theme file and add the following code to get the list of posts.
$thePostIdArray = null;
$indexkey = $_GET['indexkey'];
if ($indexkey!=null){
$querystr = "
SELECT wposts.ID
FROM $wpdb->posts wposts
WHERE UPPER(wposts.post_title) like '".$indexkey."%'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
ORDER BY wposts.post_title ASC
";
$thePostArray = $wpdb->get_results($querystr);
$i = 0;
foreach ($thePostArray as $currentPost){
$thePostIdArray[$i] = $currentPost->ID;
$i++;
}
After that just just a matter of going through the post array and displaying them.

Drupal CCK field select option names, where are they?

I have a custom content type which has a field called "location" which is a long select list (100 or so items). I want to get an array of all locations which have a piece of content associated with them. The numeric value of this field is stored in content_type_[my_content_type], but I can't find anywhere in the database where the name of the values are stored. I hope that's not too confusing - just to be clear, I want to do something like this:
SELECT DISTINCT(field_location_value) FROM content_type_[my_content_type]
and then
SELECT field_location_name_or_something FROM where_on_earth_are_the_names_stored
and then do something with the two arrays to find the names I want.
Can anyone help?
Thanks a lot. Drupal 6, by the way.
If you mean select list field of CCK:
Get all location associated with current node (piece of content?):
$node = node_load('YOUR content ID');
print_r($node->field_location); // $node->field_location - this will array of values.
Get all values of that field (defined in "Allowed values"):
$content_field = content_fields('field_location');
$allowed_values = content_allowed_values($content_field); // array of values
I found this, after much trial and tribulation, in the database table content_node_field_instance, under the field's widget settings field.
This Drupal 6 code snipped will retrieve your cck field value options and put them in the $allowed_values variable as an array. Replace 'YOUR_CCK_FIELD_NAME' with your cck field name (name, not label)
$cck_field_name = 'YOUR_CCK_FIELD_NAME';
$cck_field = db_fetch_object(db_query("SELECT global_settings FROM {content_node_field} WHERE field_name = '%s'", $cck_field_name));
$cck_field_global_settings = unserialize($cck_field->global_settings);
$allowed_values = explode("\r\n", trim($cck_field_global_settings['allowed_values'], "\r\n"));
In Drupal 7 if you have a field of type List (text) then I have written the following function to return an array of options:
function get_drupal_select_options($field_name) {
$options = unserialize(db_query("SELECT c.data
FROM field_config_instance i
INNER JOIN field_config c ON c.id = i.field_id
WHERE i.field_name = :fieldname", array(':fieldname'=>$field_name))->fetchField());
return $options['settings']['allowed_values'];
}

Wordpress wpdb select from multipe tables

I have a three tables for my wordpress plugin.
videos = id, name
playlists = id, name
video_playlist = id, video_id, playlist_id
how do I get multiple results for multiple tables.
ie, I am busy editing a playlist and would like to display all videos in the playlist.
so the ID for the playlist you are viewing is passed and that is referenced against the video_playlist table to obtain all the video IDs.
Now to take it one step further I would like to also display the names for the Videos.
Here is what I currently have.
<?php if(isset($update)) {
$rows = $wpdb->get_results("SELECT * FROM $table_play_vid WHERE playlist_id = $update->id");
foreach($rows as $row){
echo $row->video_id;
}} ?>
Try something like this.
?php if(isset($update)) {
$rows = $wpdb->get_results("SELECT vp.video_id, v.name FROM $table_play_vid vp, videos v WHERE vp.playlist_id = $update->id and vp.video_id=v.id");
foreach($rows as $row){
echo $row->video_id." ".$row->name;
}} ?>
I think it's a common MySQL query.
SELECT thistable.column, thattable.column FROM thistable,thattable WHERE thistable.something = thattable.something

Drupal exposed date filter: remove "-Year" from select

Just what the title says, I can't figure out why "-Year" is being added to the top of my exposed filter select box. What do I need to do to make it go away?
Select a year in the "Absolute value" dropdown when configuring your Date filter. That year will then be displayed instead of -Year. I doubt though you can actually remove -Year from the exposed select box unless you make some source code changes/additions.
Found a solution to this, and it's pretty stupid.
I ended up putting this in a custom module, and ended up both removing the label and also setting the number of years displayed based on the data that's in the database:
function modulename_form_views_exposed_form_alter(&$form, $form_state) {
if($form['#id'] == 'theformid') {
// Remove the label as the first element from the date select
$form['date_filter']['value']['#date_label_position'] = 'none';
// Find the minimum year from all of the published news nodes
$date = db_fetch_array(
db_query("
SELECT YEAR(MIN(d.field_date_value)) as 'min'
FROM {content_field_date} d
INNER JOIN {node} n
ON n.nid = d.nid
WHERE n.type = 'news' AND n.status = 1")
);
// Set the new year range in the filter
$new_min = date('Y') - $date['min'];
$form['date_filter']['value']['#date_year_range'] = "-$new_min:+0";
}
}

Resources