Q: Is Vodes supposed to remember previously viewed content and not charge twice?

15 years 3 months ago - 15 years 3 months ago #4813 by producerman1
Sorry if it is a stupid question sorry.

Thanks Saka for helping with the mod that got me this far!

<?php
defined('_JEXEC') or die('Restricted access');

$user = & JFactory::getUser();
$path = JPATH_SITE.DS.'components'.DS.'com_vodes'.DS.'models'.DS.'credits.php';
require_once($path);
$credits =& new VodesModelCredits();
$credits->_user = $user;
$credits->decrease(1);

if ($credits->balance()<=0) {
   // redirect
   global $mainframe;
   $mainframe->redirect('index.php?option=com_vodes', 'Buy credits!');
}
if else (USER HAS VIEWED ITEM PREVIOUSLY DO NOT DEDUCT CREDIT?) {

} else {
   // continue to show content
}
?>

NOTE: I was getting alternating credit deductions when testing the above code. Meaning that one time it would deduct 1 then 2 then 1 even if I had the emmeded code set to "blank". However it seems that setting the credits.php decrease amount to "0" and allowing the embedded code to set the amount has worked best.

Thanks again!

Best wishes,

PM1

Please Log in or Create an account to join the conversation.

15 years 3 months ago #4814 by Saka
Included plugin deducts the credits each time. It doesn't remember which pages user already purchased. To support something like that you would need to write a new plugin or extend the existing one and add a database table to store the info.

Emir Sakic
www.sakic.net

Please Log in or Create an account to join the conversation.

15 years 3 months ago - 15 years 3 months ago #4815 by producerman1
Thanks for the insight Saka.

As I am using JEvents I would imagine I would need to get the info from the "eventid" from the following. (?)

The following is from the JEvents config.php file.:

$sql = <<<SQL
CREATE TABLE IF NOT EXISTS #__jevents_rrule (
rr_id int(12) NOT NULL auto_increment,
eventid int(12) NOT NULL default 1, <---I am thinking of using this.
freq varchar(30) NOT NULL default "",
until int(12) NOT NULL default 1,
untilraw varchar(30) NOT NULL default "",
count int(6) NOT NULL default 1,
rinterval int(6) NOT NULL default 1,
bysecond  varchar(50) NOT NULL default "",
byminute  varchar(50) NOT NULL default "",
byhour  varchar(50) NOT NULL default "",
byday  varchar(50) NOT NULL default "",
bymonthday  varchar(50) NOT NULL default "",
byyearday  varchar(50) NOT NULL default "",
byweekno  varchar(50) NOT NULL default "",
bymonth  varchar(50) NOT NULL default "",
bysetpos  varchar(50) NOT NULL default "",
wkst  varchar(50) NOT NULL default "",
PRIMARY KEY  (rr_id),
INDEX (eventid)
) TYPE=MyISAM $charset;
SQL;
$db->setQuery($sql);
$db->query();
echo $db->getErrorMsg();

$sql = "ALTER TABLE `#__jevents_rrule` ADD INDEX eventid (eventid)";
$db->setQuery( $sql );
@$db->query();

End code Jevents config.php

NOW...

I created a field on the table on the DB jos_vodes_credits below.

-- phpMyAdmin SQL Dump
-- version 2.10.0.2
-- www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Aug 01, 2009 at 01:52 PM
-- Server version: 5.0.37
-- PHP Version: 5.2.1

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `mysql_jos_xxxxxxxxxxx`
--

--

--
-- Table structure for table `jos_vodes_credits`
--

CREATE TABLE `jos_vodes_credits` (
 `id` int(11) NOT NULL auto_increment,
 `userid` int(11) NOT NULL default '0',
 `credit` int(11) NOT NULL default '0',                        
`vod_itemids` varchar(150) NOT NULL default '1' COMMENT 'this checks content itemids',  ** New Field.<-- not sure about the null thing or if it will  store the ids.
 PRIMARY KEY  (`id`),
 KEY `userid` (`userid`),
 KEY `vod_itemids` (`vod_itemids`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `jos_vodes_credits`
--

INSERT INTO `jos_vodes_credits` VALUES (1, 62, 100, '1');
INSERT INTO `jos_vodes_credits` VALUES (2, 63, 97, '1');

End My DB field entry.

Now my thought was to add... look for "**"


<?php
defined('_JEXEC') or die('Restricted access');

$user = & JFactory::getUser();
$path = JPATH_SITE.DS.'components'.DS.'com_vodes'.DS.'models'.DS.'credits.php';
require_once($path);
$credits =& new VodesModelCredits();
$credits->_user = $user;
$credits->decrease(3);

if ($credits->itemmatches()=ANY) { **<-- what should go where ANY is? It should check and see a match.
returns true;
}else{
if ($credits->balance()<=0) {
   // redirect
   global $mainframe;
   $mainframe->redirect('index.php?option=com_vodes', 'Buy credits!');
} else {
   // continue to show content
}
?>

Below added to Vodes' credit.php... look for **

/**
* Method to match itemids
*
* @access public
 * @return boolean True on success
*/
function itemmatch()
{
$query = 'SELECT credit FROM #__vodes_credits WHERE vod_itemids'.$this->?; **<
What should go there "?" ?[/color]
$this->_db->setQuery( $query );
if ($this->_db->query()) {
return true;
} else {
$query = 'SELECT * FROM #__vodes_credits WHERE userid='.$this->_user->id;
$this->_db->setQuery( $query );
if ($row = $this->_db->loadObject()) {
$credit = $row->credit - $credit;
if ($credit >= 0) {
$query = 'UPDATE #__vodes_credits SET
credit = '.$this->_db->Quote($credit).'
WHERE id = '.$this->_db->Quote($row->id);
$this->_db->setQuery($query);
if ($this->_db->query()) {
return true;
} else {
$this->setError($this->_db->getErrorMsg());
}
}
}
return false;
}
End code mod of credits.php.

Now of course I have absolutely NO IDEA what I am doing. But I figured if I can get it in the ball park via common sense, then I could help others as well as learn. As well as help Saka add a new feature.  ;D

Come to think of it, I am starting to think of how to ADD the special content itemids into the data base. I would need to have a "check if exists if else add to the database" thing going on. Unfortunately this damn comp doesn't have the Bluetooth to my brain and just do what I think feature. ;)

But boy if it were a guitar.... :D

Best wishes,

PM1

Please Log in or Create an account to join the conversation.

15 years 3 months ago #4816 by Saka
Unfortunately this goes beyond my support for this component. It is provided for free as it is, any modifications are only provided for a fee.

Of course you are welcome to share your code with other users here.

Emir Sakic
www.sakic.net

Please Log in or Create an account to join the conversation.

15 years 3 months ago #4818 by producerman1
Thanks for the reply Saka. I kind of understand.

But as spending the credits is just as important as distributing them... I am sure the importance of not double charging an end users clients would be a priority.

It could cause a lot of grief for a webmaster/site owner if a person has already been credited for an item that is viewable only online.

I find it hard to believe the subject hasn't arisen sooner. Perhaps it has... not looking to start a big hooplah, just trying to get this thing to not kill my clients. I really like the idea of Vodes and would like not to have to start over with another component.

But thanks none the less.

That being said, anyone else have any input?

Best wishes,

PM1

Please Log in or Create an account to join the conversation.

About us

We provide high quality Joomla components created by a co-founder and original core developer of Joomla. For over a decade, our products have been used by more than 20.000 webmasters around the world.

Stay in touch