@@ -0,0 +1,91 @@
<?php
/**
* @package Molajo
* @copyright 2012 Amy Stephen. All rights reserved.
* @license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html
*/
namespace Molajo\Extension\Trigger\Rownumber;

use Molajo\Extension\Trigger\Content\ContentTrigger;
use Molajo\Service\Services;

defined('MOLAJO') or die;

/**
* @package Molajo
* @subpackage Trigger
* @since 1.0
*/
class RownumberTrigger extends ContentTrigger
{
/**
* Static instance
*
* @var object
* @since 1.0
*/
protected static $instance;

/**
* getInstance
*
* @static
* @return bool|object
* @since 1.0
*/
public static function getInstance()
{
if (empty(self::$instance)) {
self::$instance = new RownumberTrigger();
}

return self::$instance;
}

/**
* Before the Query results are injected into the View
*
* @return boolean
* @since 1.0
*/
public function onBeforeViewRender()
{
$count = count($this->query_results);

if ((int) $count == 0
|| $this->query_results == false
|| $this->query_results == null) {
return true;
}

$i = 1;
$even_or_odd = 'odd';
foreach ($this->query_results as $item) {

if ($i == 1) {
$item->first_row = 1;
} else {
$item->first_row = 0;
}

if ($i == $count) {
$item->last_row = 1;
} else {
$item->last_row = 0;
}

$item->total_records = $count;

$item->even_or_odd_row = $even_or_odd;
if ($even_or_odd == 'odd') {
$even_or_odd = 'even';
} else {
$even_or_odd = 'odd';
}

$item->row_number = $i++;
}

return true;
}
}
@@ -4,17 +4,10 @@
<author>Amy Stephen</author>
<create_date>June 2012</create_date>
<copyright>Copyright (C) 2012 Amy Stephen. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<license>GNU General Public License version 2 or later http://www.gnu.org/licenses/gpl.html</license>
<author_email>AmyStephen@gmail.com</author_email>
<author_url>http://molajo.org</author_url>
<version>1.0</version>
<description>VIEW_PAGE_ADMIN_DESCRIPTION</description>
<model name="Admin" catalog_type_id="1150">
<customfields>
<customfield name="parameters">
<field name="this_is_how_you_do_it" type="boolean" null="0" default="1"/>
</customfield>
</customfields>
</model>
<model name="Templates"/>
</extension>

@@ -0,0 +1,7 @@
/*
@package Molajo
@copyright Copyright (C) 2012 Amy Stephen. All rights reserved.
@license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html
*/
header.row { margin-bottom:40px; border-bottom: solid 1px #E6E6E6; margin-left: 10px}
footer.row { margin-top: 20px; border-top: solid 1px #E6E6E6; padding-top: 20px; }
@@ -3,6 +3,5 @@
; License GNU General Public License version 2 or later http://www.gnu.org/licenses/gpl.html
; Note : All ini files need to be saved as UTF-8


PAGE_TEMPLATE_DEFAULT_NAME="Default Page Templete"
PAGE_TEMPLATE_DEFAULT_DESCRIPTION="Default Page Template from the Amazium 2.0 Starter Theme set for Molajo."
PAGE_TEMPLATE_ADMIN_NAME="Administrator Page View"
PAGE_TEMPLATE_ADMIN_DESCRIPTION="Administrator Page View for Molajo."
@@ -7,8 +7,20 @@
*/
defined('MOLAJO') or die; ?>
<include:head/>
<include:template name=Adminheader wrap=Header wrap_class=banner-wrap/>
<include:message/>
<include:request/>
<include:template name=Adminfooter wrap=Footer wrap_class=row,footer/>
<include:template name="Adminheader" wrap="header" wrap_class="row"/>
<include:message wrap="div" wrap_class="row"/>
<section class="row">
<nav class="one columns">
<include:template name=Adminnavigationbar/>
</nav>
<section class="seven columns">
<include:request/>
</section>
<nav class="four columns">
&nbsp;
</nav>
</section>
<footer class="row">
<div class="twelve columns"><include:template name=Adminfooter wrap=none/></div>
</footer>
<include:defer/>
@@ -3,6 +3,5 @@
; License GNU General Public License version 2 or later http://www.gnu.org/licenses/gpl.html
; Note : All ini files need to be saved as UTF-8


PAGE_ADMINEDITOR_NAME="Admin Editor Page View"
PAGE_ADMINEDITOR_NAME="Admin Editor Page View for use with Molajo."
@@ -1,4 +1,7 @@
/* these styles should be moved to an external stylesheet */

header.row { margin-bottom:20px; border-bottom: solid 1px #E6E6E6; margin-left: 10px}
footer.row { margin-top: 40px; border-top: solid 1px #E6E6E6; padding-top: 20px; }
/*
@package Molajo
@copyright Copyright (C) 2012 Amy Stephen. All rights reserved.
@license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html
*/
header.row { margin-bottom:40px; border-bottom: solid 1px #E6E6E6; margin-left: 10px}
footer.row { margin-top: 20px; border-top: solid 1px #E6E6E6; padding-top: 20px; }
@@ -20,7 +20,6 @@
} else {
$ccDateSpan = $first_year . '-' . $current_year;
}

?>
<p>
<?php echo '&#169;' . ' ' . $ccDateSpan . ' ' . $this->row->copyright_holder; ?>
@@ -5,7 +5,8 @@
* @license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html
*/
use Molajo\Service\Services;

defined('MOLAJO') or die;

$listname = 'list_' . $this->row->listname .'*'; ?>
$listname = 'list_' . $this->row->listname . '*'; ?>
<include:template name=formselect wrap=div wrap-class=filter value=<?php echo $listname; ?>/>
@@ -6,7 +6,7 @@
*/
use Molajo\Service\Services;
defined('MOLAJO') or die;

//todo - add first and last indicators in the row
if ($this->row->title == 'Install') {
$liclass = ' class="last-in-row"';
} else {
@@ -113,6 +113,14 @@ class Controller
*/
protected $pagination;

/**
* $triggers
*
* @var object
* @since 1.0
*/
protected $triggers;

/**
* __construct
*
@@ -125,6 +133,7 @@ class Controller
*/
public function __construct()
{
$this->triggers = array();
$this->parameters = array();
$this->table_registry_indicators = array();
}
@@ -82,6 +82,8 @@ public function display()

$table_registry_name = ucfirst(strtolower($model_type)) . ucfirst(strtolower($model_name));

$this->getTriggerList($model_query_object);

if ($model_name == '') {
$this->query_results = array();

@@ -103,16 +105,6 @@ public function display()

$this->pagination = array();

/**
* For primary content (the extension determined in Application::Request),
* save query results in the Request object for reuse by other
* extensions. MolajoRequestModel retrieves data.
*/
if ($this->get('extension_primary') == true) {
Services::Registry()->set('Parameters', 'query_resultset', $this->query_results);
Services::Registry()->set('Parameters', 'query_pagination', $this->pagination);
}

/** no results */
if (count($this->query_results) == 0
&& (int)$this->get('criteria_display_view_on_no_results', 0) == 0
@@ -132,14 +124,26 @@ public function display()
$this->view_path = $this->get('template_view_path');
$this->view_path_url = $this->get('template_view_path_url');

$renderedOutput = $this->renderView();
/** Trigger Pre-View Render Event */
$this->onBeforeViewRender();

/**
* For primary content (the extension determined in Application::Request),
* save query results in the Request object for reuse by other
* extensions.
*
* todo: simplify all of the various dbo's into 'long term' and one view storage
*/
if ($this->get('extension_primary') == true) {
Services::Registry()->set('Parameters', 'query_resultset', $this->query_results);
Services::Registry()->set('Parameters', 'query_pagination', $this->pagination);
}

//todo make this a scheduled event so that twig/mustache, etc can be used
/** Render View */
$renderedOutput = $this->renderView();

/** Mustache */
if ($this->get('mustache', 0) == 1) {
$renderedOutput = $this->processRenderedOutput($renderedOutput);
}
/** Trigger After-View Render Event */
$this->onAfterViewRender($renderedOutput);
}

/** Wrap template view results */
@@ -175,6 +179,37 @@ public function wrapView($view, $renderedOutput)
return $this->renderView();
}

/**
* Schedule onBeforeViewRender Event - could update query_results objects
*
* @return bool
* @since 1.0
*/
protected function onBeforeViewRender()
{
if ((int)$this->get('process_triggers') == 0) {
return true;
}

/** Process the entire query_results set */
$arguments = array(
'table_registry_name' => $this->table_registry_name,
'parameters' => $this->parameters,
'query_results' => $this->query_results,
'model_name' => $this->get('model_name')
);

$arguments = Services::Event()->schedule('onBeforeViewRender', $arguments);

if ($arguments == false) {
return false;
}

$this->query_results = $arguments['query_results'];

return true;
}

/**
* renderView
*
@@ -183,13 +218,19 @@ public function wrapView($view, $renderedOutput)
* 1. Include a single Custom.php file to process all query results in $this->query_results
*
* 2. Include Header.php, Body.php, and/or Footer.php views for Molajo to
* perform the looping, sending $row into the views
* perform the looping, injecting $row into each of the three views
*
* On no query results
*
* @return string
* @since 1.0
*/
protected function renderView()
{
//todo think about empty queryresults processing when parameter set to true (custom and footer?)
//todo think about the result, item, and list processing - get dbo's in shape, triggers
//todo when close to done - do encoding - bring in filters - how?
/** start collecting output */
ob_start();

@@ -206,42 +247,6 @@ protected function renderView()
$first = true;
foreach ($this->query_results as $this->row) {

/** @var $css_class */
$class = '';
if (isset($this->row->css_class)) {
$class = $this->row->css_class;
}
$class .= ' ' . $this->get('view_css_class', '');
if (trim($class) == '') {
$class = '';
} else {
$class = ' class="' . htmlspecialchars(trim($class), ENT_NOQUOTES, 'UTF-8') . '"';
}

if (is_object($this->row)) {
$this->row->css_class = $class;
} else {
$this->row['css_class'] = $class;
}

/** @var $css_id */
$id = '';
if (isset($this->row->css_id)) {
$id = $this->row->css_id;
}
$id .= ' ' . $this->get('view_css_id', '');
if (trim($id) == '') {
$id = trim($id);
} else {
$id = ' id="' . htmlspecialchars(trim($id), ENT_NOQUOTES, 'UTF-8') . '"';
}

if (is_object($this->row)) {
$this->row->css_id = $id;
} else {
$this->row['css_id'] = $id;
}

/** header: before any rows are processed */
if ($first == true) {
$first = false;
@@ -250,6 +255,7 @@ protected function renderView()
}
}

/** body: once for each row */
if (file_exists($this->view_path . '/View/Body.php')) {
include $this->view_path . '/View/Body.php';
}
@@ -268,6 +274,44 @@ protected function renderView()
return $output;
}

/**
* Schedule onAfterViewRender Event - can update rendered results
*
* Position where mustache and Twig can process on rendered results
*
* @return bool
* @since 1.0
*/
protected function onAfterViewRender($renderedOutput)
{
if ((int)$this->get('process_triggers') == 0) {
return true;
}

/** Mustache */
// if ($this->get('mustache', 0) == 1) {
// $renderedOutput = $this->processRenderedOutput($renderedOutput);
// }

/** Process the entire query_results set */
$arguments = array(
'table_registry_name' => $this->table_registry_name,
'parameters' => $this->parameters,
'rendered_output' => $renderedOutput,
'model_name' => $this->get('model_name')
);

$arguments = Services::Event()->schedule('onAfterViewRender', $arguments);

if ($arguments == false) {
return false;
}

$renderedOutput = $arguments['renderedOutput'];

return $renderedOutput;
}

/**
* todo: create a trigger action here to invoke template tools, like mustache.
*
@@ -234,8 +234,8 @@ public function getData($query_object = 'list')
$query_object = 'list';
}

/** Retrieve list of potential $triggers for this model (result type does not use events) */
$triggers = $this->getTriggerList($query_object);
/** Retrieve list of potential $this->triggers for this model (result type does not use events) */
$this->getTriggerList($query_object);

/** Base query */
if ($query_object == 'item') {
@@ -281,8 +281,8 @@ public function getData($query_object = 'list')
}

/** Schedule onBeforeRead Event */
if (count($triggers) > 0) {
$this->onBeforeReadEvent($triggers);
if (count($this->triggers) > 0) {
$this->onBeforeReadEvent();
}

/** Executes Query */
@@ -357,8 +357,8 @@ public function getData($query_object = 'list')
$this->query_results = $q;

/** Schedule onAfterRead Event */
if (count($triggers) > 0) {
$this->onAfterReadEvent($triggers);
if (count($this->triggers) > 0) {
$this->onAfterReadEvent();
}
/**
echo $query_object.'<br />';
@@ -381,48 +381,47 @@ public function getData($query_object = 'list')
*
* @param $query_object
*
* @return array
* @return void
* @since 1.0
*/
protected function getTriggerList($query_object)
{
if ($query_object == 'result') {
return array();
$this->triggers = array();
return;
}

if ((int)$this->get('process_triggers') == 1) {

$triggers = Services::Registry()->get($this->table_registry_name, 'triggers', array());
$this->triggers = Services::Registry()->get($this->table_registry_name, 'triggers', array());

if (is_array($triggers)) {
if (is_array($this->triggers)) {
} else {
if ($triggers == '' || $triggers == false || $triggers == null) {
$triggers = array();
if ($this->triggers == '' || $this->triggers == false || $this->triggers == null) {
$this->triggers = array();
} else {
$temp = $triggers;
$triggers = array();
$triggers[] = $temp;
$temp = $this->triggers;
$this->triggers = array();
$this->triggers[] = $temp;
}
}

} else {
$triggers = array();
$this->triggers = array();
}

return $triggers;
return;
}

/**
* Schedule onBeforeRead Event - could update model and parameter objects
*
* @param array $triggers
*
* @return boolean
* @since 1.0
*/
protected function onBeforeReadEvent($triggers = array())
protected function onBeforeReadEvent()
{
if (count($triggers) == 0
if (count($this->triggers) == 0
|| (int)$this->get('process_triggers') == 0
) {
return true;
@@ -439,7 +438,7 @@ protected function onBeforeReadEvent($triggers = array())
'model_name' => $this->get('model_name')
);

$arguments = Services::Event()->schedule('onBeforeRead', $arguments, $triggers);
$arguments = Services::Event()->schedule('onBeforeRead', $arguments, $this->triggers);
if ($arguments == false) {
return false;
}
@@ -454,15 +453,13 @@ protected function onBeforeReadEvent($triggers = array())
/**
* Schedule onAfterRead Event - could update parameters and query_results objects
*
* @param array $triggers
*
* @return bool
* @since 1.0
*/
protected function onAfterReadEvent($triggers = array())
protected function onAfterReadEvent()
{
/** Prepare input */
if (count($triggers) == 0
if (count($this->triggers) == 0
|| (int)$this->get('process_triggers') == 0
) {
return true;
@@ -481,7 +478,7 @@ protected function onAfterReadEvent($triggers = array())
'model_name' => $this->get('model_name')
);

$arguments = Services::Event()->schedule('onAfterRead', $arguments, $triggers);
$arguments = Services::Event()->schedule('onAfterRead', $arguments, $this->triggers);

if ($arguments == false) {
return false;

This file was deleted.

This file was deleted.

This file was deleted.

@@ -7,26 +7,26 @@
defined('MOLAJO') or die;
use Molajo\Service\Services;

$class = 'alert-box';
if ($this->row->type == MESSAGE_TYPE_SUCCESS) {
$heading = Services::Language()->translate('Success');
$class = 'alert alert-success';
$class .= ' success';

} elseif ($this->row->type == MESSAGE_TYPE_WARNING) {
$heading = Services::Language()->translate('Warning');
$class = 'alert alert-warning';
$class .= ' warning';

} elseif ($this->row->type == MESSAGE_TYPE_ERROR) {
$heading = Services::Language()->translate('Error');
$class = 'alert alert-error';
$class .= ' error';

} else {
// defaults MESSAGE_TYPE_INFORMATION
$heading = Services::Language()->translate('Information');
$class = 'alert alert-info';
}
?>
<div class="<?php echo $class; ?>">
<a class="close" data-dismiss="alert" href="#">×</a>
<h4 class="alert-heading"><?php echo $heading; ?></h4>
<?php echo $this->row->message; ?>
<a class="close" href="">&times;</a>
<h4 class="alert-heading"><?php echo $heading; ?></h4>
</div>
@@ -0,0 +1,9 @@
<?php
/**
* @package Molajo
* @copyright 2012 Amy Stephen. All rights reserved.
* @license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html
*/
defined('MOLAJO') or die; ?>
</section>
<div class="one columns">&nbsp;</div>
@@ -0,0 +1,9 @@
<?php
/**
* @package Molajo
* @copyright Copyright (C) 2011 Amy Stephen. All rights reserved.
* @license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html
*/
defined('MOLAJO') or die; ?>
<div class="one columns">&nbsp;</div>
<section class="ten columns">