<?php
/**
* @package doodles
* @subpackage processors
*/
class DoodleCreateProcessor extends modObjectCreateProcessor {
public $classKey = 'Doodle';
public $languageTopics = array('doodles:default');
public $objectType = 'doodles.doodle';
public function beforeSave() {
$name = $this->getProperty('name');
$mail = $this->getProperty('mail');
if (empty($name)) {
$this->addFieldError('name',$this->modx->lexicon('doodles.doodle_err_ns_name'));
} else if ($this->doesAlreadyExist(array('name' => $name))) {
$this->addFieldError('name',$this->modx->lexicon('doodles.doodle_err_ae'));
}
if (empty($mail)) {
$this->addFieldError('mail',$this->modx->lexicon('doodles.doodle_err_ns_name'));
} else if ($this->doesAlreadyExist(array('mail' => $mail))) {
$this->addFieldError('mail',$this->modx->lexicon('doodles.doodle_err_ae'));
}
return parent::beforeSave();
}
}
return 'DoodleCreateProcessor';
//check for duplication
$count = $modx->getCount('Doodle', array('name' => 'NAME'));
if($count <= 0){
$persone = $modx->newObject('Doodle');
$persone->set('name', 'NAME');
$persone->set('mail', 'MAIL');
if($persone->save()){
echo "true";
}else{
echo "false";
}
}else{
echo "false";
}This question has been answered by wiegers. See the first response.
//array parameters
$processorProps = array(
'name' => 'test11',
'mail' => 'test11',
);
// array options for runProcessor
$otherProps = array(
// where processors
'processors_path' => $modx->getOption('core_path') . 'components/doodles/processors/'
);
$response = $modx->runProcessor('mgr/doodle/create', $processorProps, $otherProps);
if ($response->isError()) {
$errors = $modx->error->failure($response->getMessage());
// echo errors mesages
/*foreach($errors['errors'] as $error){
echo $error['msg'];
}*/
return $modx->error->failure($response->getMessage());
}
//echo id
return $response->response['object']['id'];