예제 #1
0
    /**
     * Return data on a resource view (this will be some form of HTML)
     *
     * @param      object  $resource Current resource
     * @param      string  $option    Name of the component
     * @param      array   $areas     Active area(s)
     * @param      string  $rtrn      Data to be returned
     * @return     array
     */
    public function onResources($model, $option, $areas, $rtrn = 'all')
    {
        $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
        // Check if our area is in the array of areas we want to return results for
        if (is_array($areas)) {
            if (!array_intersect($areas, $this->onResourcesAreas($model)) && !array_intersect($areas, array_keys($this->onResourcesAreas($model)))) {
                $rtrn = 'metadata';
            }
        }
        if (!is_null($enabled = $model->type->params->get('plg_classrooms')) && !$enabled) {
            return $arr;
        }
        // Are we returning HTML?
        if ($rtrn == 'all' || $rtrn == 'html') {
            $arr['html'] = array('<div id="no-usage"><p class="warning">' . Lang::txt('PLG_RESOURCES_CLASSROOMS_NO_DATA_FOUND') . '</p></div>');
            if (self::any($model->resource->alias)) {
                \Hubzero\Document\Assets::addPluginStyleSheet($this->_type, $this->_name);
                \Hubzero\Document\Assets::addPluginScript($this->_type, $this->_name);
                \Hubzero\Document\Assets::addSystemScript('d3.v2.js');
                $dbh = App::get('db');
                $tool = $dbh->quote($model->resource->alias);
                $dbh->setQuery('SELECT DISTINCT
					c2.toolname AS tool,
					c2.clustersize AS size,
					YEAR(c2.cluster_start) AS year,
					c2.cluster_start,
					c2.cluster_end,
					c2.first_use,
					SUBSTRING_INDEX(c2.cluster, \'|\', 1) AS semester,
					CONCAT(SUBSTRING_INDEX(c2.cluster, \'|\', 1), \'|\', SUBSTRING_INDEX(c2.cluster, \'|\', -2)) AS cluster,
					SHA1(CONCAT(c2.uidNumber, ' . $dbh->quote(uniqid()) . ')) AS uid
					FROM
					(SELECT DISTINCT cluster FROM #__resource_stats_clusters WHERE toolname = ' . $tool . ') AS ct,
					#__resource_stats_clusters AS c2
					WHERE ct.cluster = c2.cluster');
                $nodes = array();
                foreach ($dbh->loadAssocList() as $row) {
                    if (!isset($nodes[$row['semester']])) {
                        $nodes[$row['semester']] = array();
                    }
                    foreach (array('cluster_start', 'cluster_end', 'first_use') as $dateCol) {
                        $row[$dateCol] = date('r', strtotime($row[$dateCol]));
                    }
                    $nodes[$row['semester']][] = $row;
                }
                $arr['html'][] = '<span id="cluster-data" data-tool="' . str_replace('"', '&quot;', $model->resource->alias) . '" data-seed="' . str_replace('"', '&quot;', json_encode(array_values($nodes))) . '"></span>';
            }
            $arr['html'] = implode("\n", $arr['html']);
        }
        return $arr;
    }