Пример #1
0
 function rate($data)
 {
     $row =& $this->getTable('phocagalleryvotes', 'Table');
     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 = 'catid = ' . (int) $row->catid;
         $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
     phocagalleryimport('phocagallery.rate.ratecategory');
     if (!PhocaGalleryRateCategory::updateVoteStatistics($data['catid'])) {
         return false;
     }
     return true;
 }
Пример #2
0
 function delete($cid = array())
 {
     if (count($cid)) {
         JArrayHelper::toInteger($cid);
         $cids = implode(',', $cid);
         //Select affected catids
         $query = 'SELECT v.catid AS catid' . ' FROM #__phocagallery_votes AS v' . ' WHERE v.id IN ( ' . $cids . ' )';
         $catids = $this->_getList($query);
         //Delete it from DB
         $query = 'DELETE FROM #__phocagallery_votes' . ' WHERE id IN ( ' . $cids . ' )';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         phocagalleryimport('phocagallery.rate.ratecategory');
         foreach ($catids as $valueCatid) {
             $updated = PhocaGalleryRateCategory::updateVoteStatistics($valueCatid->catid);
             if (!$updated) {
                 return false;
             }
         }
     }
     return true;
 }