@@ -1,11 +1,12 @@
<?php
/**
* @package Molajo
* @copyright 2012 Amy Stephen. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* @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\MVC\Controller;

use Molajo\Service\Services\Configuration\ConfigurationService;
use Molajo\Service\Services;

defined('MOLAJO') or die;
@@ -39,6 +40,29 @@
*/
Class EntryController extends DisplayController
{
/**
* 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 EntryController();
}
return self::$instance;
}

/**
* Constructor.
*
@@ -48,4 +72,128 @@ public function __construct()
{
return parent::__construct();
}

/**
* Prepares data needed for the model
*
* Single-table queries - retrieve Table Definitions, create a model instance,
* and sets model properties examples include User, Site Application, and
* Authorisation queries
*
* More complex queries
*
* @param string $table
*
* @return object
*
* @since 1.0
* @throws \RuntimeException
*/
public function connect($table = null)
{
/** Specific table model interaction - or - complex data query */
if ($table === null) {
} else {
$this->setModelTable($table);
$this->dbDriver = $this->default_dbDriver;
}
$dbo = $this->dbDriver;

/* 2. Instantiate Model Class */
$modelClass = 'Molajo\\MVC\\Model\\EntryModel';

try {
$this->model = new $modelClass();
}
catch (\Exception $e) {
throw new \RuntimeException('Model entry failed. Error: ' . $e->getMessage());
}

/** 3. Set Model Properties */
$this->model->set('model_name', $this->model_name);
$this->model->set('table_name', $this->table_name);
$this->model->set('table_xml', $this->table_xml);
$this->model->set('primary_key', $this->primary_key);
$this->model->set('primary_prefix', 'a');
$this->model->set('get_special_fields', 1);
$this->model->set('get_item_children', true);
$this->model->set('use_special_joins', true);
$this->model->set('add_acl_check', true);

/** 4. Set DB Properties */
$this->model->set('db', Services::$dbo()->get('db'));
$this->model->set('query', Services::$dbo()->getQuery());
$this->model->set('nullDate', Services::$dbo()->get('db')->getNullDate());

$dateClass = 'Joomla\\date\\JDate';
$dateFromJDate = new $dateClass('now');
$now = $dateFromJDate->toSql(false, Services::$dbo()->get('db'));
$this->model->set('now', $now);

Services::$dbo()->getQuery()->clear();

return $this;
}

/**
* Set model properties needed for specific table model interaction
*
* @param $table
*
* @return object
* @throws \RuntimeException
*/
protected function setModelTable($table)
{
$this->table_xml = ConfigurationService::loadFile($table, 'Table');

$this->model_name = (string)$this->table_xml['name'];
if ($this->model_name == '') {
throw new \RuntimeException('No model name for table: ' . $table);
}

$this->table_name = (string)$this->table_xml['table'];
if ($this->table_name == '') {
$this->table_name = '#__content';
}

$this->primary_key = (string)$this->table_xml['primary_key'];
if ($this->primary_key === '') {
$this->primary_key = 'id';
}

$this->dbDriver = (string)$this->table_xml['data_source'];
if ($this->dbDriver === '') {
$this->dbDriver = $this->default_dbDriver;
}

return $this;
}

/**
* Method to execute a model method which interacts with the data source
* and returns results
*
* @param string $query_object
*
* @return mixed Depends on QueryObject selected
*
* @since 1.0
* @throws \RuntimeException
*/
public function getData($query_object = 'loadObjectList')
{
if (in_array($query_object, $this->query_objects)) {
} else {
$query_object = 'loadObjectList';
}

try {
return $this->model->$query_object();
}

catch (\Exception $e) {
throw new \RuntimeException('Model query failed for ' . $query_object . ' Error: ' . $e->getMessage());
}
}
}
@@ -6,6 +6,7 @@
*/
namespace Molajo\MVC\Model;

use Molajo\Application;
use Molajo\Service\Services;
use Molajo\Service\Services\Configuration\ConfigurationService;

@@ -258,7 +259,7 @@ protected function addItemChildren()

$name = (string)$child['name'];

$m = Services::Model()->connect($name);
$m = Application::Controller()->connect($name);

$join = (string)$child['join'];
$joinArray = explode(';', $join);
@@ -6,6 +6,7 @@
*/
namespace Molajo\Service\Services\Authorisation;

use Molajo\Application;
use Molajo\Service\Services;

defined('MOLAJO') or die;
@@ -79,7 +80,7 @@ protected function initialise()
}

/** retrieve action key pairs */
$items = Services::Model()->connect('Actions')->getData('loadObjectList');
$items = Application::Controller()->connect('Actions')->getData('loadObjectList');
foreach ($items as $item) {
Services::Registry()->set('action_to_action_id', $item->title, (int)$item->id);
}
@@ -98,7 +99,7 @@ protected function initialise()
*/
public function authoriseSiteApplication()
{
$m = Services::Model()->connect('SiteApplications');
$m = Application::Controller()->connect('SiteApplications');

$m->model->query->select($m->model->db->qn('application_id'));
$m->model->query->where($m->model->db->qn('site_id') . ' = ' . (int)SITE_ID);
@@ -254,7 +255,7 @@ public function authoriseTask($task, $catalog_id)
/** check for permission */
$action_id = 3;

$m = Services::Model()->connect('GroupPermissions');
$m = Application::Controller()->connect('GroupPermissions');

$m->model->query->where($m->model->db->qn('catalog_id') . ' = ' . (int)$catalog_id);
$m->model->query->where($m->model->db->qn('action_id') . ' = ' . (int)$action_id);
@@ -298,7 +299,7 @@ public function authoriseLogin($user_id)
return false;
}

$m = Services::Model()->connect('UserApplications');
$m = Application::Controller()->connect('UserApplications');

$m->model->query->where('application_id = ' . (int)APPLICATION_ID);
$m->model->query->where('user_id = ' . (int)$user_id);
@@ -6,6 +6,7 @@
*/
namespace Molajo\Service\Services\Configuration;

use Molajo\Application;
use Molajo\Service\Services;

defined('MOLAJO') or die;
@@ -101,7 +102,7 @@ public function getSite($configuration_file = null)
}

/** Retrieve Sites Data from DB */
$m = Services::Model()->connect('Sites');
$m = Application::Controller()->connect('Sites');

$m->model->set('id', (int)SITE_ID);
$m->model->set('get_item_children', false);
@@ -200,7 +201,7 @@ protected function getApplication()

try {

$m = Services::Model()->connect('Applications');
$m = Application::Controller()->connect('Applications');

$m->model->set('id_name', APPLICATION);
$m->model->set('name_field', 'name');

This file was deleted.

This file was deleted.

This file was deleted.

@@ -6,6 +6,7 @@
*/
namespace Molajo\Service\Services\User;

use Molajo\Application;
use Molajo\Service\Services;

defined('MOLAJO') or die;
@@ -69,7 +70,7 @@ protected function __construct($id = 0)
*/
protected function load()
{
$m = Services::Model()->connect('Users');
$m = Application::Controller()->connect('Users');

$m->model->set('id', $this->id);