function rate($data) { $row = $this->getTable('phocagalleryimgvotes'); if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } $row->date = gmdate('Y-m-d H:i:s'); $row->published = 1; if (!$row->id) { $where = 'imgid = ' . (int) $row->imgid; $row->ordering = $row->getNextOrder($where); } if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Update the Vote Statistics if (!PhocaGalleryRateImage::updateVoteStatistics($data['imgid'])) { return false; } return true; }
function delete($cid = array()) { if (count($cid)) { JArrayHelper::toInteger($cid); $cids = implode(',', $cid); //Select affected catids $query = 'SELECT v.imgid AS imgid' . ' FROM #__phocagallery_img_votes AS v' . ' WHERE v.id IN ( ' . $cids . ' )'; $images = $this->_getList($query); //Delete it from DB $query = 'DELETE FROM #__phocagallery_img_votes' . ' WHERE id IN ( ' . $cids . ' )'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } phocagalleryimport('phocagallery.rate.rateimage'); foreach ($images as $valueImgId) { $updated = PhocaGalleryRateImage::updateVoteStatistics($valueImgId->imgid); if (!$updated) { return false; } } } return true; }