I working on some module and want to have ability to update table with image sizes - there already two columns in table (width, height). Its my first approach to joomla module develop. All code works except last foreach with update. Where I'm wrong?
And how to trigger this function in module or in backend module settings to button or link? Code in helper.php:
public static function updateSize( $params )
{
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
JHtml::_('behavior.framework', true);
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName(array('a.imgfilename', 'b.catpath')))
->from($db->quoteName('#__imagestable', 'a'))
->where(($db->quoteName('height').'=') && ($db->quoteName('width').'='))
->join('INNER', $db->quoteName('#__imagestable_cat', 'b') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('b.cid') . ')')
->order('RAND() LIMIT 5');
$db->setQuery($query);
$size = $db->loadObjectList();
return $size;
foreach($size as $imageSize){
$imgpath = $path.$imageSize->catpath.'/'.$imageSize->imgfilename;
$imgfilename = $imageSize->imgfilename;
list($width, $height) = getimagesize($imgpath);
$validImgs[] = $imageSize;
foreach ( $validImgs as $row ) {
$query = $db->getQuery(true)
->update($db->quoteName('#__imagestable'))
->where ($db->quoteName('imgfilename').'='.$imgfilename)
->set(array($db->quoteName('height') . '=' . $height, $db->quoteName('width') . '=' .$width));
$db->setQuery($query);
$imgSize = $db->execute();
}
}
}
Is it possible to attach this function to backend XML - maybe to button "Update image sizes"?