/** * Редактирование записи * * @param array $params * @return \ActionResponse */ public function actionUpdate($params = array()) { $errors = array(); $model = $this->mapper()->findById($params['id']); if (!empty($_POST)) { $attr = $_POST; unset($attr['Cover']); unset($attr['File']); $model->import($attr); if (!empty($_FILES['Cover']['name'])) { $model->setCover(\Toolkit::i()->fileStorage->bucket('images')->saveUploadedFile($model, 'Cover')); } if (!empty($_POST['Cover_delete'])) { \Toolkit::i()->fileStorage->bucket('images')->removeFile($model->getCover()); $model->setCover(''); } if (!empty($_FILES['File']['name'])) { $model->setFile(\Toolkit::i()->fileStorage->bucket('files')->saveUploadedFile($model, 'File')); } if (!empty($_POST['File_delete'])) { \Toolkit::i()->fileStorage->bucket('files')->removeFile($model->getFile()); $model->setFile(''); } if ($model->save()) { $this->redirect(array('index')); } else { $errors = $model->getErrors(); } } return $this->view('Update', array('Model' => $model, 'Errors' => $errors)); }
public function process() { $params = Toolkit::i()->request->getParams(); if (count($params) < 2) { echo "Please specify module and command\n"; } else { $module = $params[0]; $controller = $params[1]; Core::import('Modules.' . $module); $sController = $module . $controller . 'Command'; $sControllerFull = 'ruxon\\modules\\' . $module . '\\commands\\' . $sController; if (class_exists($sControllerFull)) { $oController = new $sControllerFull(); } else { $oController = new $sController(); } unset($params[0]); unset($params[1]); $par = array_values($params); $action_params = array(); if (count($par)) { foreach ($par as $k => $val) { if (substr_count($val, "=") > 0) { $tmp = explode("=", $val); $action_params[$tmp[0]] = trim($tmp[1]); } else { $action_params[] = $val; } } } $oController->run('Execute', $action_params); } }
public function render() { $value = 0; $value_id = 0; $aDataSource = $this->getDataSource(); $aDataSource[2]['Criteria']['ParentId'] = 0; $oDataProvider = new DataProvider($aDataSource); $oData = $oDataProvider->execute(); //echo '<pre>', print_r($oData, true), '</pre>'; die(); $aResult = array(); $aResult[] = array('Name' => $this->getDefaultText(), 'Value' => $this->getDefaultValue()); if ($this->getDefault()) { $aRs = array(); if (preg_match("#:(.*?)#isU", $this->getDefault(), $aRs)) { $value = Toolkit::getInstance()->request->get($aRs[1], Request::C_GET); } } if ($this->getValue()) { $value_id = $this->getValue(); } if ($oData->count() > 0) { $aResult = $this->getChilds($oData, 1, $aResult); } echo FormHelper::selectbox($this->getAlias(), $value_id, $aResult, array('class' => 'selectbox', 'id' => 'field_' . $this->getAlias())); }
public static function getInstance() { if (self::$instance == false) { self::$instance = new Toolkit(); } return self::$instance; }
public function render() { $value = 0; $value_id = 0; $aDataSource = $this->getDataSource(); if ($this->getIsTree()) { $aDataSource[2]['Criteria']['ParentId'] = 0; } $oDataProvider = new DataProvider($aDataSource); $oData = $oDataProvider->execute(); //echo '<pre>', print_r($oData, true), '</pre>'; die(); $aResult = array(); $aResult[] = array('Name' => $this->getDefaultText(), 'Value' => $this->getDefaultValue()); if ($this->getDefault()) { $aRs = array(); if (preg_match("#:(.*?)#isU", $this->getDefault(), $aRs)) { $value = Toolkit::getInstance()->request->get($aRs[1], Request::C_GET); } } if ($this->getValue()) { $value_id = $this->getValue(); } $aResult = $this->createRow($oData, $aResult); if ($this->getOnChange()) { $tmpChange = $this->getOnChange(); echo FormHelper::selectbox($this->getAlias(), $value_id, $aResult, array('class' => 'selectbox ajax_response_list', 'data-field' => $tmpChange[0], 'data-id' => $this->getValue(), 'id' => 'field_' . $this->getAlias())); //$.post('/structure/page_backend/typeParams', {Id: $this->getValue()}, function (data) { /* response */ }); } else { echo FormHelper::selectbox($this->getAlias(), $value_id, $aResult, array('class' => 'selectbox', 'id' => 'field_' . $this->getAlias())); } }
public function render() { $value = 0; $value_id = 0; $oDataProvider = new DataProvider($this->getDataSource()); $oData = $oDataProvider->execute(); //echo '<pre>', print_r($oData, true), '</pre>'; die(); $aResult = array(); /*$aResult[] = array( 'Name' => $this->getDefaultText(), 'Value' => $this->getDefaultValue() ); */ if ($this->getDefault()) { $aRs = array(); if (preg_match("#:(.*?)#isU", $this->getDefault(), $aRs)) { $value = Toolkit::getInstance()->request->get($aRs[1], Request::C_GET); } } //echo 'val:', print_r($this->getValue()->toSimpleArray(), true); if ($this->getValue()) { $value_id = $this->getValue()->toSimpleArray(); } if ($oData->count() > 0) { foreach ($oData as $itm) { $getter = 'get' . $this->getValueField(); $aResultTmp = array('Value' => call_user_func(array($itm, $getter)), 'Name' => $this->getTextFormat()); $aRs = array(); if (preg_match_all("/:(.*):/iU", $aResultTmp['Name'], $aRs)) { foreach ($aRs[1] as $k => $val) { $value = $itm; if (strpos($val, "-") !== false) { $xVal = explode("-", $val); foreach ($xVal as $_val) { $sGetter = 'get' . $_val; $value = call_user_func(array($value, $sGetter)); } } else { $sGetter = 'get' . $val; $value = call_user_func(array($value, $sGetter)); } $aResultTmp['Name'] = str_replace($aRs[0][$k], $value, $aResultTmp['Name']); } } /*if (isset($aContainer['IsTree']) && $aContainer['IsTree'] == true) { $aResultTmp['Name'] = str_repeat(' |-- ', $itm->getTreeLevel() - 1).$aResultTmp['Name']; }*/ $aResult[] = $aResultTmp; } } $sResult = FormHelper::multiselect($this->getAlias() . '[]', $value_id, $aResult, array('class' => 'multiselect', 'id' => 'field_' . $this->getAlias())); if ($this->getExtended()) { $sResult .= '<script>$(document).ready( function() { $(\'#field_' . $this->getAlias() . '\').multiselect({sortable: false, searchable: false}); } );</script>'; } echo $sResult; }
/** * extracts tags from the provided text and connects them to this question. If a tag is deleted it * will be deleted from the relation * * @return void * @author The Young Shepherd **/ public function save(Doctrine_Connection $conn = null) { $currentTags = array(); foreach ($this->Tags as $tag) { $currentTags[] = $tag->name; } $newTags = array_keys(Toolkit::extractTags($this->Best->question . ' ' . $this->Best->answer)); $deleteTags = array_diff($currentTags, $newTags); foreach ($deleteTags as $name) { foreach ($this->Tags as $index => $tag) { if ($tag->name === $name) { unset($this->Tags[$index]); break; // go to next name to delete } } } $addTags = array_diff($newTags, $currentTags); foreach ($addTags as $name) { if (!($tag = Doctrine::getTable('Tag')->findOneByName($name))) { $tag = new Tag(); $tag->name = $name; } $this->Tags[] = $tag; } return parent::save($conn); }
public function run() { $this->start(); $aResult = array(); $aData = array(); $oData = $this->getComponentRequest()->getData(); $buttons = $this->getComponentRequest()->getButtons(); foreach ($this->getComponentRequest()->getFields() as $alias => $header) { $sClassName = $this->sModuleAlias . 'FormView' . $header['Type'] . 'Column'; $aTmpParams2 = array('Module' => $this->sModuleAlias, 'Component' => $this->sComponentAlias, 'Alias' => $alias, 'Type' => $header['Type'], 'Help' => isset($header['Help']) ? $header['Help'] : '', 'Title' => $header['Title'], 'Required' => isset($header['Params']['Required']) ? $header['Params']['Required'] : false); if (isset($header['Field'])) { if (is_object($oData)) { $sGetter = 'get' . $header['Field']; $aTmpParams2['Value'] = call_user_func(array($oData, $sGetter)); } else { if (is_array($oData)) { if (!empty($oData[$header['Field']])) { $aTmpParams2['Value'] = $oData[$header['Field']]; } else { $aTmpParams2['Value'] = ''; } } } } if (isset($header['Params']) && count($header['Params'])) { $aTmpParams2 = \ArrayHelper::merge($aTmpParams2, $header['Params']); } $aData[$alias] = new $sClassName($aTmpParams2); } $backLink = $this->getComponentRequest()->getBackLink(); if ($backLink) { $aRs = array(); if (preg_match_all("#:~(.*?)#isU", $backLink, $aRs)) { foreach ($aRs[0] as $k => $it) { $backLink = str_replace($it, Toolkit::getInstance()->request->get($aRs[1][$k], Request::C_GET), $backLink); } } if (preg_match_all("#:(.*?)#isU", $backLink, $aRs)) { foreach ($aRs[0] as $k => $it) { $sGetter = 'get' . $aRs[1][$k]; $backLink = str_replace($it, call_user_func(array($oData, $sGetter)), $backLink); } } } if (!empty($buttons)) { $aResult['Buttons'] = new \SimpleCollection(); foreach ($buttons as $button) { $aResult['Buttons']->add(new \RuxonFormViewButton($button)); } } $aResult['ElementId'] = is_object($oData) ? $oData->getId() : 0; $aResult['Title'] = $this->getComponentRequest()->getTitle(); $aResult['Errors'] = $this->getComponentRequest()->getErrors(); $aResult['BackLink'] = $backLink; $aResult['Data'] = new \SimpleCollection($aData); $this->end($aResult, true); }
public function run(FilterChain $oFilterChain) { if (Toolkit::getInstance()->auth->checkAdminAccess()) { $oFilterChain->next(); } else { header("Location: " . Toolkit::getInstance()->auth->loginUrl); Core::app()->hardEnd(); } }
public function render() { if ($this->getValue()) { $file = Toolkit::i()->fileStorage->bucket($this->getBucketName())->getImage($this->getValue()); echo '<img src="' . $file->getThumbUrl(100) . '" alt="" />'; echo '<br />'; echo FormHelper::checkbox($this->getAlias() . '_delete', false, ['id' => $this->getAlias() . '_delete']); echo ' ' . FormHelper::labelFor($this->getAlias() . '_delete', 'Удалить'); } echo FormHelper::file($this->getAlias(), $this->getValue(), array('id' => 'field_' . $this->getAlias())); }
public function run(FilterChain $oFilterChain) { if (count($this->getParams())) { foreach ($this->getParams() as $key => $val) { $class_name = $val['class']; unset($val['class']); Toolkit::getInstance()->addToolkit($key, new $class_name($val)); } } $oFilterChain->next(); }
public function render() { if ($this->getValue()) { $file = Toolkit::i()->fileStorage->bucket($this->getBucketName())->getFile($this->getValue()); echo '<a target="_blank" href="' . $file->getFileUrl() . '">' . $this->getValue() . '</a>'; echo '<br />'; echo FormHelper::checkbox($this->getAlias() . '_delete', false, ['id' => $this->getAlias() . '_delete']); echo ' ' . FormHelper::labelFor($this->getAlias() . '_delete', 'Удалить'); } echo FormHelper::file($this->getAlias(), $this->getValue(), array('id' => 'field_' . $this->getAlias())); }
/** * create a new plane instance, optionally prefilled */ public function __construct($name, $db, $r = NULL) { $this->db = $db; if ($r === NULL) { $query = $this->db->prepare("\n SELECT name, first, last FROM planes\n WHERE replace(replace(lower(name), '_', ''), ' ', '') = ?\n LIMIT 1"); $query->execute([Toolkit::normalizeName($name)]); $r = $query->fetch(\PDO::FETCH_ASSOC); $query->closeCursor(); if ($r === False) { throw new Exception('No plane named ' . $name); } } $this->name = $r['name']; $this->first = $r['first']; $this->last = $r['last']; }
public function raise($alias, $recipients, $params = array(), $subject = '') { if (!is_array($recipients)) { $recipients = array($recipients); } Toolkit::i()->mail->ClearAddresses(); Toolkit::i()->mail->From = $this->fromEmail; Toolkit::i()->mail->FromName = $this->fromName; foreach ($recipients as $email) { Toolkit::i()->mail->AddAddress($email); } Toolkit::i()->mail->Subject = $subject; $emailTemplate = new MailTemplate($params); Toolkit::i()->mail->SetHtmlBody($emailTemplate->fetch($alias)); return Toolkit::i()->mail->Send(); }
/** * Recursively removed a directory * @param string $dir */ public static function delTree($dir) { if (is_dir($dir)) { $objects = @scandir($dir); if (is_array($objects)) { foreach ($objects as $object) { if ($object != "." && $object != "..") { if (@filetype($dir . DIRECTORY_SEPARATOR . $object) == "dir") { Toolkit::delTree($dir . DIRECTORY_SEPARATOR . $object); } else { @unlink($dir . DIRECTORY_SEPARATOR . $object); } } } reset($objects); } @rmdir($dir); } }
/** * from 8-character *DTS format to 17-character full date and time * * @param $dtsDateTime * @return bool */ public function dtsToYymmdd($dtsDateTime) { $inputFormat = "*DTS"; // special system format, returned by some APIs. $outputFormat = "*YYMD"; // 17 chars long $outputVarname = 'datetimeOut'; $apiPgm = 'QWCCVTDT'; $apiLib = 'QSYS'; $paramXml = "<parm io='in' comment='1. Input format'>\n <data var='formatIn' type='10A' comment='*DTS is system time stamp format'>{$inputFormat}</data>\n </parm>\n <parm io='in' comment='2. Input variable'>\n <data var='datetimeIn' type='8b' comment='*DTS format is type 8b (binary)'>{$dtsDateTime}</data>\n </parm>\n <parm io='in' comment='3. Output format'>\n <data var='formatOut' type='10A' comment='*YYMD means YYYYMMDDHHMMSSmmm (milliseconds)'>{$outputFormat}</data>\n </parm>\n <parm io='out' comment='4. Output variable'>\n <ds var='{$outputVarname}' comment='Data structure, total of 17 bytes, to split date/time into YYYYMMDD, HHMMSS, and microseconds, as indicated by *YYMD format'>\n <data var='date' type='8a' comment='YYYYMMDD' />\n <data var='time' type='6a' comment='HHMMSS' />\n <data var='microseconds' type='3a' comment='microsecs (3 digits)' />\n </ds>\n </parm>\n" . Toolkit::getErrorDataStructXml(5); // param number 5 // pass param xml directly in. $retPgmArr = $this->ToolkitSrvObj->PgmCall($apiPgm, $apiLib, $paramXml); if ($this->ToolkitSrvObj->getErrorCode()) { return false; } $retArr = $retPgmArr['io_param'][$outputVarname]; return $retArr; }
/** * parse a string of form U+A..U+B,U+C in a Range */ public static function parseRange($str, $db) { $set = []; $junks = preg_split('/\\s*(?:,\\s*)+/', trim($str)); foreach ($junks as $j) { $ranges = preg_split('/\\s*(?:-|\\.\\.|:)\\s*/', $j); switch (count($ranges)) { case 0: break; case 1: $tmp = Toolkit::parseCodepoint($ranges[0]); if (is_int($tmp)) { $set[] = $tmp; } break; case 2: $low = Toolkit::parseCodepoint($ranges[0]); $high = Toolkit::parseCodepoint($ranges[1]); if (is_int($low) && is_int($high)) { $set = array_merge($set, range(min($low, $high), max($high, $low))); } break; default: $max = -1; $min = 0x110000; foreach ($ranges as $r) { $tmp = Toolkit::parseCodepoint($r); if (is_int($tmp) && $tmp > $max) { $max = $tmp; } if (is_int($tmp) && $tmp < $min) { $min = $tmp; } } if ($min < 0x110000 && $max > -1) { $set = array_merge($set, range(min($min, $max), max($max, $min))); } } } return new Range($set, $db); }
public function raise($alias, $recipients, $params = array()) { Loader::import('Modules.Main'); if (!is_array($recipients)) { $recipients = array($recipients); } $event = Manager::getInstance()->getMapper('EmailObjectMapper')->findFirst(array('Criteria' => array('IsActive' => true, 'Alias' => $alias))); if ($event->getId()) { Toolkit::getInstance()->mail->ClearAddresses(); Toolkit::getInstance()->mail->From = Manager::getInstance()->getModule('Main')->config('FromEmail'); Toolkit::getInstance()->mail->FromName = Manager::getInstance()->getModule('Main')->config('FromName'); foreach ($recipients as $email) { Toolkit::getInstance()->mail->AddAddress($email); } Toolkit::getInstance()->mail->Subject = $event->getSubject(); $emailTemplate = new MailTemplate($params); Toolkit::getInstance()->mail->SetHtmlBody($emailTemplate->fetch($event->getAlias())); return Toolkit::getInstance()->mail->Send(); } return false; }
public function init() { if (!$this->merchant_id) { $this->merchant_id = Manager::getInstance()->getModule('Shop')->config('PlatronMerchantId'); } if (!$this->secret_key) { $this->secret_key = Manager::getInstance()->getModule('Shop')->config('PlatronSecretKey'); } if ($this->test_mode === null) { $this->test_mode = Manager::getInstance()->getModule('Shop')->config('PlatronTestMode'); } if (!$this->site_url) { $this->site_url = 'http://' . Toolkit::getInstance()->request->getServerName(); } if (!$this->result_url) { $this->result_url = 'http://' . Toolkit::getInstance()->request->getServerName() . '/shop/payment/result'; } if (!$this->success_url) { $this->success_url = 'http://' . Toolkit::getInstance()->request->getServerName() . '/shop/payment/success'; } if (!$this->failure_url) { $this->failure_url = 'http://' . Toolkit::getInstance()->request->getServerName() . '/shop/payment/failed'; } }
/** * import * * @param int $courseId The id the course to import users into * * @return void */ public function import($courseId = null) { if (!is_null($courseId)) { $course = $this->Course->getAccessibleCourseById($courseId, User::get('id'), User::getCourseFilterPermission()); if (empty($course)) { $this->Session->setFlash(__('Error: That course does not exist.', true)); $this->redirect('/courses'); } $this->breadcrumb->push(array('course' => $course['Course'])); } $courses = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list'); $this->set('courses', $courses); // make sure we know the course we're importing users into if ($courseId == null && !empty($this->data)) { $courseId = $this->data['Course']['Course']; } $this->set('courseId', $courseId); $this->set('breadcrumb', $this->breadcrumb->push(__('Import Students From Text (.txt) or CSV File (.csv)', true))); if (!empty($this->data)) { // check that file upload worked if ($this->FileUpload->success) { $uploadFile = $this->FileUpload->uploadDir . DS . $this->FileUpload->finalFile; } else { $this->Session->setFlash($this->FileUpload->showErrors()); return; } $data = Toolkit::parseCSV($uploadFile); $usernames = array(); // generation password for users who weren't given one foreach ($data as &$user) { if (empty($user[User::IMPORT_PASSWORD])) { $user[User::GENERATED_PASSWORD] = $this->PasswordGenerator->generate(); } else { $user[User::GENERATED_PASSWORD] = ''; } $usernames[] = $user[User::IMPORT_USERNAME]; } if ($this->data['User']['update_class']) { $this->User->removeOldStudents($usernames, $courseId); } // add the users to the database $result = $this->User->addUserByArray($data, true); if (!$result) { $this->Session->setFlash("Error: Unable to import users."); return; } $insertedIds = array(); foreach ($this->User->insertedIds as $new) { $insertedIds[] = $new; } foreach ($result['updated_students'] as $old) { $insertedIds[] = $old['User']['id']; } // enrol the users in the selectec course $this->Course->enrolStudents($insertedIds, $this->data['Course']['Course']); $this->FileUpload->removeFile($uploadFile); $this->set('data', $result); $this->render('userSummary'); } }
/** * getMixEvalDemoData get demo data for mix evaluation preview * * @param mixed $data mix data * * @static * @access public * @return array demo data */ static function getMixEvalDemoData($mixeval, $selfEval = 1) { return array('event' => array('Event' => array('id' => 0, 'title' => 'Preview Event', 'self_eval' => $selfEval, 'due_date' => Toolkit::formatDate(time() + 5 * 24 * 60 * 60), 'release_date_end' => Toolkit::formatDate(time() + 6 * 24 * 60 * 60), 'description' => 'Preview for mix evaluation event.', 'com_req' => true, 'template_id' => 0), 'Group' => array('id' => 0, 'group_name' => 'Demo Group'), 'GroupEvent' => array('id' => 0)), 'groupMembers' => array(array('User' => array('id' => 1, 'first_name' => 'Demo', 'last_name' => 'Student1', 'full_name' => 'Demo Student1')), array('User' => array('id' => 2, 'first_name' => 'Demo', 'last_name' => 'Student2', 'full_name' => 'Demo Student2')), array('User' => array('id' => 3, 'first_name' => 'Demo', 'last_name' => 'Student3', 'full_name' => 'Demo Student3'))), 'mixeval' => array('Mixeval' => $mixeval), 'courseId' => 0, 'userId' => 1, 'evaluateeCount' => 2, 'fullName' => User::get('full_name'), 'members' => 0, 'enrol' => 1, 'self' => null, 'preview' => true); }
/** * Set response * @param string $json JSON response */ public function setResponse($json) { $this->response = Toolkit::arrayToDataContainer(json_decode($json, true)); }
foreach ($this->getErrors() as $error) { ?> <p><?php echo $error; ?> </p> <?php } ?> </div> <?php } ?> <form action="<?php echo Toolkit::i()->getRequest()->getUrl(); ?> " method="post" enctype="multipart/form-data" class="form-horizontal"> <div class="form-group"> <label class="col-sm-2 control-label" for="login_field"><?php echo $this->getModel()->fieldTitle('Login'); ?> </label> <div class="col-sm-10"> <?php echo FormHelper::textbox('Login', $this->getModel()->Login); ?> </div> </div>
/** * Возвращает тулкит * * @return Toolkit */ protected function getToolkit() { return Toolkit::getInstance(); }
public function smsEvent($alias, $to, $params = array()) { return Toolkit::i()->smsEvent->raise($alias, $to, $params); }
static function hexContrastColor($hex) { $rgb = Toolkit::hex2rgb($hex); return Toolkit::rgb2hex(Toolkit::rgbContrastColor($rgb)); }
public function createUrl($path, $params = array()) { return Toolkit::i()->urlManager->createUrl($path, $params); }
public static function getParams() { return Toolkit::i()->urlManager->getParams(); }
/** * import * * @access public * @return void */ function import() { if (!empty($this->data)) { // check that file upload worked if ($this->FileUpload->success) { $uploadFile = $this->FileUpload->uploadDir . DS . $this->FileUpload->finalFile; } else { $this->Session->setFlash($this->FileUpload->showErrors()); return; } $students = Toolkit::parseCSV($uploadFile); $identifiers = Set::extract('/' . Course::IDENTIFIER, $students); $data = $this->data['Course']; $move = $data['action']; $field = $data['identifiers']; $fieldText = $field == 'student_no' ? __('student number', true) : __('username', true); // create a copy of the source survey else grab destSurveys id if (isset($data['sourceSurveys'])) { if ($data['surveyChoices']) { $event = $this->Event->findById($data['sourceSurveys']); $event['Event']['id'] = null; $event['Event']['course_id'] = $data['destCourses']; if (!$this->Event->save($event['Event'])) { $this->Session->setFlash(__('Error: Event was unable to be created.', true)); $this->redirect('import'); return; } $destEventId = $this->Event->getLastInsertID(); } else { $destEventId = $data['destSurveys']; } } $error = array(); $success = array(); $users = array(); if (!empty($identifiers)) { $users = $this->User->find('all', array('conditions' => array('User.' . $field => $identifiers, 'Role.id' => $this->User->USER_TYPE_STUDENT), 'contain' => array('Role'))); } $invalid = array_diff($identifiers, Set::extract('/User/' . $field, $users)); foreach ($invalid as $inv) { $error[$inv] = sprintf(__('No student with %s %s exists.', true), $fieldText, $inv); } $enrolled = $this->UserEnrol->findAllByCourseId($data['sourceCourses']); $enrolled = Set::extract('/UserEnrol/user_id', $enrolled); $destEnrolled = $this->UserEnrol->findAllByCourseId($data['destCourses']); $destEnrolled = Set::extract('/UserEnrol/user_id', $destEnrolled); if ($move) { $event = $this->Event->findAllByCourseId($data['sourceCourses']); $eventIds = Set::extract('/Event/id', $event); $sub = $this->EvaluationSubmission->find('all', array('conditions' => array('grp_event_id !=' => null, 'submitter_id' => $enrolled, 'EvaluationSubmission.event_id' => $eventIds))); $submission = Set::combine($sub, '{n}.EvaluationSubmission.id', '{n}.EvaluationSubmission', '{n}.EvaluationSubmission.submitter_id'); } // enrol student foreach ($users as $user) { $identifier = $user['User'][$field]; // enrol student to destination course if not already enrolled if (!in_array($user['User']['id'], $destEnrolled)) { if (!$this->User->addStudent($user['User']['id'], $data['destCourses'])) { $error[$identifier] = __('The student could not be enrolled to the destination course.', true); continue; } } // move or copy survey submission if (isset($data['sourceSurveys'])) { $sub = $this->EvaluationSubmission->getEvalSubmissionByEventIdSubmitter($data['sourceSurveys'], $user['User']['id']); $destSub = $this->EvaluationSubmission->getEvalSubmissionByEventIdSubmitter($data['destSurveys'], $user['User']['id']); if ($sub && empty($destSub)) { $inputs = $this->SurveyInput->getByEventIdUserId($data['sourceSurveys'], $user['User']['id']); // if choose to copy set id to null if (!$move) { $sub['EvaluationSubmission']['id'] = null; } $sub['EvaluationSubmission']['event_id'] = $destEventId; $sInputs = array(); foreach ($inputs as $input) { $tmp = $input['SurveyInput']; if (!$move) { $tmp['id'] = null; } $tmp['event_id'] = $destEventId; $sInputs[] = $tmp; } if (!($this->EvaluationSubmission->save($sub) && $this->SurveyInput->saveAll($sInputs))) { $error[$identifier] = __("The student's survey submission could not be transferred, however they are enrolled in the destination course.", true); continue; } } } if (!isset($error[$identifier])) { $success[$identifier] = __('Success.', true); } if ($move && in_array($user['User']['id'], $enrolled)) { if (!$this->User->removeStudent($user['User']['id'], $data['sourceCourses'])) { $success[$identifier] .= __(' However they were unsuccessfully unenrolled from the source course.', true); } } else { if (!in_array($user['User']['id'], $enrolled)) { $success[$identifier] .= sprintf(__(' However no student with %s %s was enrolled in the source course.', true), $fieldText, $identifier); } } if ($move && isset($submission[$user['User']['id']])) { $success[$identifier] .= "\n" . __("The student has already submitted a peer evaluation in the source course.", true); } if (isset($data['sourceSurveys']) && !empty($destSub) && $sub) { $success[$identifier] .= "\n" . __("The student has already submitted to the\n destination survey, therefore the survey submission from the source survey was not transferred.", true); } } $this->set('errors', $error); $this->set('success', $success); $this->set('courseId', $data['destCourses']); $this->set('identifier', ucwords($fieldText)); $this->FileUpload->removeFile($uploadFile); $this->render('import_summary'); } $destCourses = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list'); //$sourceEvents = $this->Event->getActiveSurveyEvents(array_keys($destCourses)); //$courseIds = array_unique(Set::extract('/Event/course_id', $sourceEvents)); $courseIds = array_keys($destCourses); $sourceCourses = $this->Course->getCourseList($courseIds); asort($sourceCourses); $this->set('sourceCourses', $sourceCourses); $this->set('sourceSurveys', array()); $this->set('destCourses', $destCourses); $this->set('destSurveys', array()); }
/** * close the list * * @return bool */ public function close() { // call QGYCLST, the "close list" api. $apiPgm = 'QGYCLST'; $apiLib = 'QSYS'; $requestHandle = $this->_requestHandle; $paramXml = "<parm io='in' comment='1. request handle'>\n <data var='requestHandle' comment='Request handle: binary/hex' type='4b'>{$requestHandle}</data>\n </parm>\n" . Toolkit::getErrorDataStructXml(2); // param number 2 // pass param xml directly in. $this->ToolkitSrvObj->PgmCall($apiPgm, $apiLib, $paramXml); // GUI0006 means end of list if ($this->ToolkitSrvObj->getErrorCode()) { return false; } else { return true; } }