This question has been answered by multiple community members. See the first response.
/** * Connection to TopSecret */ $this->topsecret = $this->modx->topSecret; /** * Connection to Tracker */ $this->tracker = $this->modx->Tracker;
<object class="someObject" table="carts" extends="xPDOSimpleObject"> <field key="userid" dbtype="integer" precision="10" phptype="integer" attributes="unsigned" null="false" default="0" /> <aggregate alias="User" class="modUser" local="userid" foreign="id" cardinality="one" owner="foreign" /> <index name="userid" primary="false" unique="false" type="BTREE"> <column key="userid" length="" collation="A" null="false" /> </index> </object>
<?php
$secret = $modx->TopSecret;
if (is_object($secret) && $secret instanceof TopSecret) {
/// DO STUFF HERE YOU HAVE ACCESS TO THE CURRENT USER
}
<input type="hidden" name="class_key" value="yourUserClass" />
The Register part of the package has code to override fields, but it's difficult to see how it works. I would try something like this in your registration form:
<input name="class_key" value="yourUserClass" type="hidden">
If that doesn't work, you can create a postHook that rewrites the class_key field.
if (!empty($_POST)) {
if (isset($_POST["itemid"]) && isset($_POST["rating"])) {
if(!$modx->addPackage('rate','/<root path>/public_html/core/components/rate/model/','rate_')) {
return 'Problem loading module.';
}
$userid = $modx->user->get('id');
$user = $modx->getObject('extUser', $userid);
$myScore = $user->getOne('USERSCORE',array('Item_ID' => $_POST["itemid"]));
if($myScore) {
$myScore->set('Score',$_POST["rating"]); // this is in case the score already exists
}
else {
$myScore = $modx->newObject('USERSCORE');
$myScore->set('Item_ID',$_POST["itemid"]);
$myScore->set('Score',$_POST["rating"]);
$user->addOne($myScore);
}
$user->save();
return 'Ready.';
}
}
...
<!-- extend the modUser class -->
<object class="extUser" extends="modUser">
<composite alias="USERSCORE" class="USERSCORE" local="id" foreign="User_ID" cardinality="many" owner="local" />
</object>
...
<object class="USERSCORE" table="USER_SCORE" extends="xPDOObject">
<field key="User_ID" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" index="pk" />
<field key="Item_ID" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" index="pk" />
<field key="Score" dbtype="tinyint" precision="1" phptype="integer" null="false" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
<column key="User_ID" length="" collation="A" null="false" />
<column key="Item_ID" length="" collation="A" null="false" />
</index>
<index alias="Item_ID" name="Item_ID" primary="false" unique="false" type="BTREE" >
<column key="Item_ID" length="" collation="A" null="false" />
</index>
<aggregate alias="extUser" class="extUser" local="User_ID" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="USERSCORE" table="carts" extends="xPDOSimpleObject">
$obj = $modx->getObject('USERSCORE', array ('userId'=> $modx->user->getPrimaryKey());
$collection = $modx->getCollection('USERSCORE', array ('userId'=> $modx->user->getPrimaryKey());
<?php
/**
* File eWalletModxService.php
* Created on: April 3, 2013 2:42 PM
* Project shawn_wilkerson
* @package ewallet
* @version
* @category
* @author W. Shawn Wilkerson
* @link http://www.shawnWilkerson.com
* @copyright Copyright (c) 2013, Sanity LLC. All rights reserved.
* @license
*
* Provides site wide access to the class and underlying xPDO Model Package
*/
$modelPath = $modx->getOption('ewallet' . '.core_path', null, $modx->getOption('core_path') . 'components/' . 'ewallet' . '/') . 'model/ewallet/';
$modx->getService('Ewallet', 'ewallet', $modelPath, $params= array ());
<?php
$ew = $modx->Ewallet;
if (is_object($ew) && $ew instanceof Ewallet) {
return $ew->destroyCart();
}
try {
$corePath = $this->modx->getOption('ewallet.core_path', $config, $this->modx->getOption('core_path') . 'components/ewallet/');
$assetsUrl = $this->modx->getOption('ewallet.assets_url', $config, $this->modx->getOption('assets_url') . 'components/ewallet/');
$this->config = array_merge(
array(
'assetsUrl' => $assetsUrl,
'cssUrl' => $assetsUrl . 'css/',
'jsUrl' => $assetsUrl . 'js/',
'imagesUrl' => $assetsUrl . 'images/',
'corePath' => $corePath,
'modelPath' => $corePath . 'model/',
'chunksPath' => $corePath . 'elements/chunks/',
'snippetsPath' => $corePath . 'elements/snippets/',
'processorsPath' => $corePath . 'processors/',
'prefix' => 'ew_',
), $config);
$this->modx->addPackage('ewallet', $this->config['modelPath'], $this->config['prefix']);
} catch (xPDOException $xe) {
$this->sendError('unavailable', array('error_message' => $xe->getMessage()));
} catch (Exception $e) {
$this->sendError('unavailable', array('error_message' => $e->getMessage()));
}
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in <rootdir>/public_html/core/xpdo/om/xpdoobject.class.php on line 1668, referer: http://<mywebsite>/index.php?id=19
$myScore = $user->getOne('USERSCORE',array('Item_ID' => $_POST["itemid"]));
if($myScore) {
$myScore->set('Score',$_POST["rating"]); // this is in case the score already exists
}
else {
$myScore = $modx->newObject('USERSCORE');
$myScore->set('Item_ID',$_POST["itemid"]);
$myScore->set('Score',$_POST["rating"]);
$user->addOne($myScore);
}
$user->save();
return 'Ready.';
$myScore = $user->getOne('USERSCORE',array('Item_ID' => $_POST["itemid"]));
if($myScore) {
$myScore->set('Score',$_POST["rating"]); // this is in case the score already exists
}
else {
$myScore = $modx->newObject('USERSCORE');
$myScore->set('User_ID',$userid);
$myScore->set('Item_ID',$_POST["itemid"]);
$myScore->set('Score',$_POST["rating"]);
}
$myScore->save();
return 'Ready.';