/**
 * Dwoo {survey_name} function plugin
 *
 * Type:     function<br>
 * Name:     survey_title<br>
 * Date:     June 22, 2006<br>
 * Purpose:  Get the survey title from XML
 * @author   Gregor Anzelj
 * @version  1.0
 * @return Survey title instead of survey filename
 */
function Dwoo_Plugin_survey_title(Dwoo $dwoo, $survey, $lang = null)
{
    safe_require('artefact', 'survey');
    $return = ArtefactTypeSurvey::get_survey_title_from_xml($survey);
    if ($lang != null) {
        $return .= ' (' . substr($lang, 0, 2) . ')';
    }
    return $return;
}
Пример #2
0
function get_accessible_surveys()
{
    // Get names of all the survey responses (from other users) that are accessible to our user...
    global $USER;
    $results = get_records_sql_array("SELECT\ta.title\n\t\tFROM {artefact} a\n\t\tLEFT JOIN {artefact_access_usr} aau ON (aau.artefact = a.id)\n\t\tWHERE aau.usr = ?", array($USER->get('id')));
    // Prepare our accessible surveys array so we can use it as options in drop-down select box...
    $survey_types = array('empty' => get_string('selectsurvey', 'artefact.survey'));
    if ($results) {
        // There can be (and often will be) duplicates of survey names:
        // two/more users can complete the same survey, but the responses will appear as different artefacts.
        //
        // We use/simulate mathematical concept of Set, which can contain only one instance of the same thing (survey in our case).
        //
        // We achieve that by checking if the current survey name is already contained in our accessible surveys array.
        // If not, we add the name of taht survey to our accessible surveys array
        $accessible_surveys = array();
        foreach ($results as $result) {
            if (!in_array($result->title, $accessible_surveys)) {
                $accessible_surveys[] = $result->title;
            }
        }
        foreach ($accessible_surveys as $filename) {
            $LANGUAGE = ArtefactTypeSurvey::get_default_lang($filename);
            $xmlDoc = new DOMDocument('1.0', 'UTF-8');
            $ch = curl_init(get_config('wwwroot') . 'artefact/survey/surveys/' . $filename);
            # Return http response in string
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $loaded = $xmlDoc->loadXML(curl_exec($ch));
            if ($loaded) {
                $surveyname = $xmlDoc->getElementsByTagName('survey')->item(0)->getAttribute('name');
                if (isset($surveyname) && $surveyname == substr($filename, 0, -4)) {
                    $title = $xmlDoc->getElementsByTagName('title')->item(0)->getAttribute($LANGUAGE);
                    $survey_types = array_merge($survey_types, array($filename => $title));
                } else {
                    $message = get_string('surveynameerror', 'artefact.survey', $filename);
                    $_SESSION['messages'][] = array('type' => 'error', 'msg' => $message);
                }
            } else {
                $message = get_string('surveyerror', 'artefact.survey', $filename);
                $_SESSION['messages'][] = array('type' => 'error', 'msg' => $message);
            }
        }
    }
    return $survey_types;
}
Пример #3
0
 public static function instance_config_form($instance)
 {
     safe_require('artefact', 'survey');
     $configdata = $instance->get('configdata');
     return array('artefactid' => self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null), 'showresponses' => array('type' => 'checkbox', 'title' => get_string('showresponses', 'blocktype.survey/survey'), 'defaultvalue' => isset($configdata['showresponses']) ? $configdata['showresponses'] : false), 'showresults' => array('type' => 'checkbox', 'title' => get_string('showresults', 'blocktype.survey/survey'), 'defaultvalue' => isset($configdata['showresults']) ? $configdata['showresults'] : true), 'showchart' => array('type' => 'checkbox', 'title' => get_string('showchart', 'blocktype.survey/survey'), 'defaultvalue' => isset($configdata['showchart']) ? $configdata['showchart'] : true), 'chartoptions' => array('type' => 'fieldset', 'legend' => get_string('chartoptions', 'artefact.survey'), 'collapsible' => true, 'collapsed' => true, 'elements' => ArtefactTypeSurvey::get_chart_options_elements($configdata)));
 }
Пример #4
0
$is_survey = get_field('artefact', 'artefacttype', 'id', $id) == 'survey' ? true : false;
$user_is_owner = $USER->get('id') == get_field('artefact', 'owner', 'id', $id) ? true : false;
$user_has_access = record_exists('artefact_access_usr', 'usr', $USER->get('id'), 'artefact', $id);
if (!$is_survey) {
    throw new ArtefactNotFoundException(get_string('artefactnotsurvey', 'artefact.survey'));
}
if (!$user_is_owner && !$user_has_access) {
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$survey = null;
try {
    $survey = artefact_instance_from_id($id);
} catch (Exception $e) {
}
define('TITLE', $survey->get_survey_title_from_xml());
// Get survey filename and return empty responses
$filename = $survey->get('title');
$responses = unserialize($survey->get('description'));
if (!$responses) {
    throw new NotFoundException(get_string('responsesnotfound', 'artefact.survey', ArtefactTypeSurvey::get_survey_title_from_xml($filename)));
}
$html = ArtefactTypeSurvey::build_user_responses_summary_html($filename, $responses);
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('RESULTS', $survey->survey_returns_results($filename));
$smarty->assign('RESULTSHEADNIG', get_string('results', 'artefact.survey'));
$smarty->assign('CHART', $survey->survey_returns_chart($filename));
$smarty->assign('CHARTHEADNIG', get_string('chart', 'artefact.survey'));
$smarty->assign('id', $id);
$smarty->assign('html', $html);
$smarty->display('artefact:survey:results.tpl');
Пример #5
0
define('MENUITEM', 'content/surveys');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'survey');
define('SECTION_PAGE', 'generate');
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php';
define('TITLE', get_string('surveyanalysis', 'artefact.survey'));
require_once 'pieforms/pieform.php';
safe_require('artefact', 'survey');
global $SESSION;
global $USER;
$survey = $SESSION->get('survey');
log_debug($survey);
if ($survey != '') {
    //$analysis1 = ArtefactTypeSurvey::get_empty_responses_from_survey($survey);
    //log_debug($analysis1);
    $analysis = ArtefactTypeSurvey::get_empty_analysis_from_survey($survey);
    //log_debug($analysis);
    $answers = array('V_a01' => 13, 'R_a05' => 1);
    foreach ($answers as $akey => $avalue) {
        foreach ($analysis as $qkey => $qvalue) {
            if (array_key_exists($akey, $qvalue['responses'])) {
                //$analysis[$qkey]['responses'][$akey]['count'] += $avalue;
                $analysis[$qkey]['responses'][$akey]['count']++;
            }
        }
    }
    /*
    log_debug($analysis);
    $analysis[0]['responses']['V_a01']['count']++;
    */
    log_debug($analysis);
Пример #6
0
} catch (Exception $e) {
}
// Get survey filename and return empty responses
$filename = $survey->get('title');
$responses = unserialize($survey->get('description'));
$CONFIG = ArtefactTypeSurvey::get_chart_config($filename);
$CONFIG['ctime'] = strftime(get_string('strfdaymonthyearshort'), $survey->get('ctime'));
// Created
$CONFIG['mtime'] = strftime(get_string('strfdaymonthyearshort'), $survey->get('mtime'));
// Modified
// If language survey, add the language abbreviation at the end of survey title...
if ($survey->get('note') != null) {
    $CONFIG['title'] = $CONFIG['title'] . ' (' . substr($survey->get('note'), 0, -5) . ')';
}
//log_debug($CONFIG);
$DATA = ArtefactTypeSurvey::get_chart_data_from_responses($filename, $responses);
//log_debug($DATA);
if (is_null($CONFIG['charttype'])) {
    $message = get_string('surveyerror', 'artefact.survey', $filename);
    $_SESSION['messages'][] = array('type' => 'error', 'msg' => $message);
}
switch (strtolower($CONFIG['charttype'])) {
    case 'bar':
        draw_bar_chart($WIDTH, $HEIGHT, $DATA, $CONFIG, $LEGEND, $FONT, $PALETTE);
        break;
    case 'stacked':
        draw_stacked_chart($WIDTH, $HEIGHT, $DATA, $CONFIG, $LEGEND, $FONT, $PALETTE);
        break;
    case 'area':
    case 'line':
    case 'plot':
Пример #7
0
function editsurvey_submit(Pieform $form, $values)
{
    global $SESSION, $USER;
    $userid = $USER->get('id');
    $errors = false;
    $artefactid = $values['id'];
    $recipients = $values['recipients'];
    try {
        if ($artefactid == 0) {
            $survey = new ArtefactTypeSurvey();
            $survey->set('owner', $userid);
        } else {
            $survey = new ArtefactTypeSurvey($artefactid);
        }
        $survey->set('title', $values['title']);
        $survey->set('note', $values['language']);
        $survey->commit();
        //if (!empty($recipients)) {
        db_begin();
        execute_sql("DELETE FROM {artefact_access_usr} WHERE artefact = ?", array($survey->get('id')));
        foreach ($recipients as $recipient) {
            execute_sql("INSERT INTO {artefact_access_usr} (usr, artefact) VALUES (?,?)", array($recipient, $survey->get('id')));
        }
        db_commit();
        //}
    } catch (Exception $e) {
        $errors = true;
    }
    if (!$errors) {
        $SESSION->add_ok_msg(get_string('surveysaved', 'artefact.survey'));
    }
    if ($artefactid == 0) {
        $redirecturl = '/artefact/survey/edit.php?id=' . $survey->get('id');
    } else {
        $redirecturl = '/artefact/survey/';
    }
    redirect($redirecturl);
}
Пример #8
0
 public static function instance_config_form($instance)
 {
     global $USER;
     safe_require('artefact', 'survey');
     $configdata = $instance->get('configdata');
     log_debug($configdata);
     $options = getoptions_available_surveys();
     return array('userid' => array('type' => 'hidden', 'value' => $USER->get('id')), 'survey' => array('type' => $options ? 'select' : 'html', 'labelhtml' => get_string('surveytitle', 'artefact.survey'), 'defaultvalue' => isset($configdata['survey']) ? $configdata['survey'] : null, 'value' => $options ? null : '<div id="artefactchooser-body"><p class="noartefacts">' . get_string('noartefactstochoosefrom', 'view') . '</p></div>', 'options' => $options), 'steps' => array('type' => 'select', 'labelhtml' => get_string('surveyhistorysteps', 'blocktype.survey/surveyhistory'), 'defaultvalue' => isset($configdata['steps']) ? $configdata['steps'] : 5, 'options' => array(2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9)), 'showchart' => array('type' => 'checkbox', 'title' => get_string('showchart', 'blocktype.survey/surveyhistory'), 'defaultvalue' => isset($configdata['showchart']) ? $configdata['showchart'] : true), 'chartoptions' => array('type' => 'fieldset', 'legend' => get_string('chartoptions', 'artefact.survey'), 'collapsible' => true, 'collapsed' => true, 'elements' => ArtefactTypeSurvey::get_chart_options_elements($configdata)));
 }
Пример #9
0
$id = param_integer('id', 0);
$is_survey = get_field('artefact', 'artefacttype', 'id', $id) == 'survey' ? true : false;
/*
$user_is_owner   = ($USER->get('id') == get_field('artefact', 'owner', 'id', $id) ? true : false);
$user_has_access = record_exists('artefact_access_usr', 'usr', $USER->get('id'), 'artefact', $id);
*/
if (!$is_survey) {
    throw new ArtefactNotFoundException(get_string('artefactnotsurvey', 'artefact.survey'));
}
/*
if (!$user_is_owner && !$user_has_access) {
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
*/
$survey = null;
try {
    $survey = artefact_instance_from_id($id);
} catch (Exception $e) {
}
define('TITLE', $survey->get_survey_title_from_xml());
// Get survey filename and return empty responses
$filename = $survey->get('title');
$responses = unserialize($survey->get('description'));
$html = ArtefactTypeSurvey::build_user_responses_output_html($filename, $responses);
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
//$smarty->assign('RESPONSES', $survey->survey_returns_responses($filename));
$smarty->assign('RESPONSES', true);
$smarty->assign('id', $id);
$smarty->assign('html', $html);
$smarty->display('artefact:survey:responses.tpl');
Пример #10
0
 public function get_chart_labels_from_responses($filename, $responses)
 {
     $responses = ArtefactTypeSurvey::get_user_responses_from_survey($filename, $responses);
     foreach ($responses as $key => $value) {
         $data = explode('_', $key);
         if (!empty($data[0]) && !empty($data[1])) {
             $sections[$data[0]][$data[1]] = $value;
         }
     }
     // Prepare results summary table...
     $results_summary = array();
     $results_values = array();
     // only the values!
     foreach ($sections as $key => $section) {
         $results_summary = array_merge($results_summary, array($key => array_sum($section) . '|' . array_sum($section) / count($section) * 100));
         array_push($results_values, array_sum($section));
     }
     $return_array = array();
     foreach ($results_summary as $key => $value) {
         array_push($return_array, $key);
     }
     return $return_array;
 }
Пример #11
0
$WIDTH = param_integer('width', 400);
$HEIGHT = param_integer('height', 250);
$PALETTE = param_alpha('palette', 'default');
$FONT['type'] = param_alpha('fonttype', 'sans');
// possible values are 'sans' and 'serif'
$FONT['size'] = param_integer('fontsize', 10);
$OWNER = param_integer('id');
$DATA = PluginBlocktypeCompetencesKadis::prepare_chart_data($OWNER);
//log_debug($DATA);
$CONFIG = PluginBlocktypeCompetencesKadis::prepare_chart_config();
/* Include all the pChart 2.0 classes */
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pDraw.class';
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pImage.class';
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pData.class';
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pRadar.class';
$COLORS = ArtefactTypeSurvey::get_palette_colors($PALETTE);
/* Create your dataset object */
$myData = new pData();
/* Add data in your dataset */
$POINTS = array();
$LABELS = array();
foreach ($DATA as $value) {
    $POINTS[] = $value['value'];
    $LABELS[] = $value['key'];
}
$myData->addPoints($POINTS, $CONFIG['title']);
$myData->setAxisUnit(0, '');
/* Labels definition */
$myData->addPoints($LABELS, 'Legend');
$myData->setSerieDescription('Legend', '');
$myData->setAbscissa('Legend');
Пример #12
0
require_once get_config('docroot') . 'artefact/lib.php';
safe_require('artefact', 'survey');
// Unset SESSION values
// So when we call htdocs/artefact/survey/analysis/index.php script, it would not automatically generate CSV export file
$SESSION->set('survey', '');
// Delete selected survey...
if ($delete = param_integer('delete', 0)) {
    $survey = artefact_instance_from_id($delete);
    $survey->delete();
    $SESSION->add_ok_msg(get_string('surveydeleted', 'artefact.survey'));
}
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
list($count, $data) = ArtefactTypeSurvey::get_survey_list($limit, $offset);
foreach ($data as $survey) {
    $survey->title = ArtefactTypeSurvey::get_survey_title_from_xml($survey->title);
    $flagicons = getlanguageportfolio_languages();
    $flagicon = $survey->note;
    if (isset($flagicon) && !empty($flagicon)) {
        $survey->flagicon = $flagicons[$survey->note]['style'];
    } else {
        $survey->flagicon = 'background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAHElEQVQ4jWP8//8/AyWAiSLdowaMGjBqwCAyAABjmgMdtjw0ugAAAABJRU5ErkJggiANCg==) no-repeat left center; padding-left: 20px;';
    }
}
// Function for comparing, used by usort...
function cmp($a, $b)
{
    return strcmp($a->title, $b->title);
}
usort($data, 'cmp');
// Web browser supports base64 images?
Пример #13
0
function draw_3dpie_chart($WIDTH, $HEIGHT, $DATA, $CONFIG, $LEGEND, $FONT, $PALETTE = 'default')
{
    /* Include all the pChart 2.0 classes */
    include '../lib/pchart2/class/pDraw.class';
    include '../lib/pchart2/class/pImage.class';
    include '../lib/pchart2/class/pData.class';
    include '../lib/pchart2/class/pPie.class';
    $COLORS = ArtefactTypeSurvey::get_palette_colors($PALETTE);
    /* Create your dataset object */
    $myData = new pData();
    /* Add data in your dataset */
    if ($CONFIG['type'] == 'percent') {
        foreach ($DATA[0] as $value) {
            if ($value['percent'] != 0) {
                $POINTS[] = $value['percent'];
                if ($LEGEND == 'key') {
                    $LABELS[] = $value['key'];
                }
                if ($LEGEND == 'label') {
                    $LABELS[] = $value['label'];
                }
            }
        }
        $myData->addPoints($POINTS, $CONFIG['title']);
        $myData->setAxisUnit(0, '%');
    } else {
        foreach ($DATA[0] as $value) {
            if ($value['value'] != 0) {
                $POINTS[] = $value['value'];
                if ($LEGEND == 'key') {
                    $LABELS[] = $value['key'];
                }
                if ($LEGEND == 'label') {
                    $LABELS[] = $value['label'];
                }
            }
        }
        $myData->addPoints($POINTS, $CONFIG['title']);
        $myData->setAxisUnit(0, '');
    }
    /* Labels definition */
    /*
    $myData->addPoints($LABELS,'Legend');
    $myData->setSerieDescription('Legend','');
    $myData->setAbscissa('Legend');
    */
    /* Will replace the whole color scheme by the selected palette */
    $myData->loadPalette('lib/pchart2/palettes/' . $PALETTE . '.color', TRUE);
    /* Create a pChart object and associate your dataset */
    $myPicture = new pImage($WIDTH, $HEIGHT, $myData);
    /* Draw border around the chart */
    $myPicture->drawRectangle(0, 0, $WIDTH - 1, $HEIGHT - 1, array("R" => 0, "G" => 0, "B" => 0));
    /* Draw chart background */
    //$myPicture->drawFilledRectangle(0,0,$WIDTH,$HEIGHT,array("R"=>$COLORS[1]['R'],"G"=>$COLORS[1]['G'],"B"=>$COLORS[1]['B'],"Alpha"=>10));
    /* Define the boundaries of the graph area */
    //$myPicture->setGraphArea(20,20,$WIDTH-20,$HEIGHT-40);
    /* Choose a nice font */
    switch ($FONT['type']) {
        case 'serif':
            $fontname = 'lib/pchart2/fonts/LiberationSerif-Regular.ttf';
            break;
        case 'sans':
            $fontname = 'lib/pchart2/fonts/LiberationSans-Regular.ttf';
            break;
    }
    $myPicture->setFontProperties(array('FontName' => $fontname, 'FontSize' => $FONT['size']));
    /* Create label with survey name */
    //$myPicture->drawText(20,$HEIGHT-30,$CONFIG['title'],array("DrawBox"=>true,"BoxRounded"=>true,"BoxR"=>$COLORS[1]['R'],"BoxG"=>$COLORS[1]['G'],"BoxB"=>$COLORS[1]['B'],"BoxAlpha"=>20,"Align"=>TEXT_ALIGN_MIDDLELEFT));
    /* Create the pPie object */
    $PieChart = new pPie($myPicture, $myData);
    /* Draw a simple pie chart */
    $PIE_WIDTH = $WIDTH - 40;
    // 20px margin on left and right
    $PIE_HEIGHT = $HEIGHT - 60;
    // 20px margin on top and 40px on bottom (space for legend)
    if ($PIE_WIDTH >= $PIE_HEIGHT) {
        // Landscape orientation of the graph...
        $PieRadius = round($PIE_HEIGHT / 2);
    } else {
        // Portrait orientation of the graph...
        $PieRadius = round($PIE_WIDTH / 2);
    }
    $PieX = round($WIDTH / 2);
    $PieY = round($HEIGHT / 2);
    $PieChart->draw3DPie($PieX, $PieY, array("Radius" => $PieRadius, "SecondPass" => false, "DrawLabels" => false));
    /* Build the PNG file and send it to the web browser */
    $myPicture->Stroke();
}
Пример #14
0
 public static function prepare_chart_data($owner)
 {
     safe_require('artefact', 'survey');
     $surveys = array('competence.kadis.interpersonal.xml', 'competence.kadis.organisational.xml', 'competence.kadis.flexibility.xml', 'competence.kadis.problemsolving.xml', 'competence.kadis.leadership.xml', 'competence.kadis.reliability.xml');
     $surveysdata = array();
     foreach ($surveys as $survey) {
         if (record_exists('artefact', 'title', $survey, 'owner', $owner)) {
             $surveysdata[] = get_records_sql_array("\n\t\t\t\t\tSELECT a.id, a.title, a.description, a.mtime\n\t\t\t\t\tFROM {artefact} a\n\t\t\t\t\tWHERE a.owner = ? AND a.title = ?\n\t\t\t\t\tORDER BY a.ctime DESC, a.mtime DESC\n\t\t\t\t\tLIMIT 1;", array($owner, $survey));
         }
     }
     $DATA = array();
     if (!empty($surveysdata)) {
         foreach ($surveysdata as $surveydata) {
             $filename = $surveydata[0]->title;
             $responses = unserialize($surveydata[0]->description);
             $SINGLE = ArtefactTypeSurvey::get_chart_data_from_responses($filename, $responses);
             $SINGLE[0]['value'] = self::set_achieved_level($SINGLE[0]['value'], $SINGLE[0]['key']);
             $DATA = array_merge($DATA, $SINGLE);
         }
     }
     return $DATA;
 }