<?php
$focus = $modx->getService('focus','Focus',$modx->getOption('core_path').'components/focus/model/focus/',$scriptProperties);
$user = $focus->getUserObj($focus->userID);
$location = $modx->newObject('Location', $hook->getValues());
$user->addMany($location);
if($user->save()) {
return true;
} else {
$hook->addError('error_message','Could not save data');
return false;
}
.
[[!FormIt? &hooks=`[[++crt.core_path]]elements/snippets/snippet.addName.php`]]
<form action="[[~[[*id]]]]" method="post" class="form">
<label for="name">
Name: <input type="text" name="name" id="name" value="[[!+fi.name]]" />
</label>
<input type="submit" value="Add" />
</form><?php
/* Activate the class */
$x = $modx->getService('crt','Crt',$modx->getOption('crt.core_path',null,$modx->getOption('core_path').'components/crt/').'model/crt/',$scriptProperties);
/* Check if the class is instanced */
if (!($x instanceof Crt)) return 'Unable to load service.';
$userId = $modx->getObject('extUser', $modx->user->get('id'));
$location = $modx->newObject('Location', array(
'name' => $hook->getValue('name')
));
$userId->addMany($location);
if($userId->save()) {
return true;
} else {
return false;
}[[!include? &file=`[[++crt.core_path]]elements/snippets/snippet.crt.php`]]
<?php
/* Activate the class */
$x = $modx->getService('crt','Crt',$modx->getOption('crt.core_path',null,$modx->getOption('core_path').'components/crt/').'model/crt/',$scriptProperties);
/* Check if the class is instanced */
if (!($x instanceof Crt)) return 'Unable to load service.';$x = $modx->getService('crt','Crt',$modx->getOption('crt.core_path',null,$modx->getOption('core_path').'components/crt/').'model/crt/',$scriptProperties);<?php
if (!class_exists('Crt')) {
class Crt
{
/* Setting up global parameters */
public $modx;
public $config = array();
function __construct(modX &$modx,array $config = array()) {
/* Import modx as a reference */
$this->modx =& $modx;
/* Define base & assets path */
$basePath = $this->modx->getOption('crt.core_path',$config,$this->modx->getOption('core_path').'components/crt/');
$assetsUrl = $this->modx->getOption('crt.assets_url',$config,$this->modx->getOption('assets_url').'components/crt/');
/* Establish the environment */
$this->config = array_merge(array(
'basePath' => $basePath,
'corePath' => $basePath,
'modelPath' => $basePath.'model/',
'processorsPath' => $basePath.'processors/',
'chunksPath' => $basePath.'elements/chunks/',
'jsUrl' => $assetsUrl.'js/',
'cssUrl' => $assetsUrl.'css/',
'assetsUrl' => $assetsUrl,
'connectorUrl' => $assetsUrl.'connector.php',
'userID' => $this->modx->user->get('id'),
),$config);
/* Call the crt package */
$this->modx->addPackage('crt',$this->config['modelPath']);
/* Define the user */
$this->userObj = $this->setUser($this->config['userID']);
$this->userID = $this->userObj->get('id');
}
function __destruct() {
unset ($this->userObj, $this->userID, $this->config);
}
public function getUserObj($userID) {
return $this->modx->getObject('extUser', $userID);
}
public function setUser($userID){
return $this->getUserObj($userID);
}
public function getChunk($name,$properties = array()) {
$chunk = null;
if (!isset($this->chunks[$name])) {
$chunk = $this->_getTplChunk($name);
if (empty($chunk)) {
$chunk = $this->modx->getObject('modChunk',array('name' => $name));
if ($chunk == false) return false;
}
$this->chunks[$name] = $chunk->getContent();
} else {
$o = $this->chunks[$name];
$chunk = $this->modx->newObject('modChunk');
$chunk->setContent($o);
}
$chunk->setCacheable(false);
return $chunk->process($properties);
}
private function _getTplChunk($name,$postfix = '.chunk.tpl') {
$chunk = false;
$f = $this->config['chunksPath'].strtolower($name).$postfix;
if (file_exists($f)) {
$o = file_get_contents($f);
$chunk = $this->modx->newObject('modChunk');
$chunk->set('name',$name);
$chunk->setContent($o);
}
return $chunk;
}
}
}$userId->addMany(array($location));