Commit efa9047a authored by Stacey Walker's avatar Stacey Walker Committed by Richard Mansfield
Browse files

added my plans blocktype for view displays

parent 14726cb2
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-plans
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$string['title'] = 'Your Plans';
$string['description'] = 'Display your plans list';
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-plans
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
class PluginBlocktypePlans extends PluginBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.plans/plans');
}
public static function get_description() {
return get_string('description', 'blocktype.plans/plans');
}
public static function get_categories() {
return array('general');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
require_once(get_config('docroot') . 'artefact/lib.php');
safe_require('artefact','plans');
$view = get_record('view','id', $instance->get('view'));
$smarty = smarty_core();
// Get data about the resume fields the user has
$return = array();
if ($records = get_records_sql_array('
SELECT a.id, a.owner
FROM {artefact} a
WHERE a.owner = ? AND a.artefacttype = \'plans\'', array($view->owner))) {
foreach ($records as $record) {
$artefact = new ArtefactTypePlans($record->id);
$artefactid = $artefact->get('id');
$return[$artefactid]->title = $artefact->get('title');
$return[$artefactid]->description = $artefact->get('description');
$return[$artefactid]->completiondate = $artefact->get('completiondate');
$return[$artefactid]->completed = $artefact->get('completed');
}
$smarty->assign('rows', $return);
}
return $smarty->fetch('blocktype:plans:content.tpl');
}
// Yes, we do have instance config. People are allowed to specify the title
// of the block, nothing else at this time. So in the next two methods we
// say yes and return no fields, so the title will be configurable.
public static function has_instance_config() {
return true;
}
public static function instance_config_form() {
return array();
}
public static function artefactchooser_element($default=null) {
}
/**
* Subscribe to the blockinstancecommit event to make sure all artefacts
* that should be in the blockinstance are
*/
public static function get_event_subscriptions() {
return array(
(object)array(
'event' => 'blockinstancecommit',
'callfunction' => 'ensure_plans_artefacts_in_blockinstance',
),
);
}
/**
* Hook for making sure that all plans artefacts are associated with a
* blockinstance at blockinstance commit time
*/
public static function ensure_plans_artefacts_in_blockinstance($event, $blockinstance) {
if ($blockinstance->get('blocktype') == 'plans') {
safe_require('artefact', 'plans');
// Get all artefacts that are plans and belong to the correct owner
$artefacts = get_records_sql_array('
SELECT id
FROM {artefact}
WHERE artefacttype = \'plans\'
AND owner = (
SELECT owner
FROM {view}
WHERE id = ?
)', array($blockinstance->get('view')));
if ($artefacts) {
// Make sure they're registered as being in this view
foreach ($artefacts as $artefact) {
$record = (object)array(
'view' => $blockinstance->get('view'),
'artefact' => $artefact->id,
'block' => $blockinstance->get('id'),
);
ensure_record_exists('view_artefact', $record, $record);
}
}
}
}
public static function default_copy_type() {
return 'shallow';
}
/**
* My Plans blocktype is only allowed in personal views
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
}
}
?>
{auto_escape off}
{if $rows}
<table id="planslist" class="tablerenderer">
<colgroup width="50%" span="2"></colgroup>
<thead>
<tr>
<th class="plansdate">{str tag='completiondate' section='artefact.plans'}</th>
<th>{str tag='title' section='artefact.plans'}</th>
<th>{str tag='completed' section='artefact.plans'}</th>
</tr>
</thead>
<tbody>
{foreach from=$rows item=row}
<tr class="{cycle values='r0,r1'}">
<td>{$row->completiondate|escape}</td>
<td>{$row->title|escape}<div>{$row->description|escape}</div></td>
{if $row->completed == 1}<td><div class="completed"><img src="/artefact/plans/theme/raw/static/images/success.gif" alt="" /></div></td>{else}<td></td>{/if}
</tr>
{/foreach}
</tbody>
</table>
{/if}
{/auto_escape}
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-plans
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010051700;
$config->release = '1.0.0';
?>
......@@ -62,6 +62,12 @@ class ArtefactTypePlans extends ArtefactType {
public function __construct($id = 0, $data = null) {
parent::__construct($id, $data);
if ($artefact = get_record('artefact_plans_plan', 'artefact', $id)) {
foreach ($fields = $this->get_plan_fields() as $field) {
$this->$field = $artefact->$field;
}
}
}
public static function is_singular() {
......@@ -76,6 +82,15 @@ class ArtefactTypePlans extends ArtefactType {
// @todo Catalyst IT Ltd
}
public function get_plan_fields() {
return array(
'title',
'description',
'completiondate',
'completed',
);
}
public function commit() {
// Return whether or not the commit worked
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment