ACC SHELL
<?php
class o__reference extends object
{
public function initialize($phase)
{
parent::initialize($phase);
if ($phase == 0)
{
$this->set('order', array('-ocreated'));
$this->f('otitle')->get = 'return ($object->oid ? $object->title : "");';
$f = $this->defineIdAutoIncrement();
$f = $this->defineOCreated();
//$f = $this->defineImage();
$f = $this->defineStringLocalized('title');
//$f = $this->defineTextLocalized('summary');
//$f = $this->defineTextLocalizedHTML('text');
$f = $this->defineImages();
$f = $this->defineV('url', Field::TYPE_STRING);
$f->get = 'return (!$object->oid ? "" : (U::urlize($object->title) . "-" . $object->id));';
}
}
}
class _reference extends ObjectModule
{
public function initialize($phase)
{
parent::initialize($phase);
if ($phase == 4)
{
$this->action('list')->set('columns', array('title'));
$this->action('list')->set('actions', array('new', 'edit', 'delete'));
$this->action('get')->set('object-fields', array('id'));
//$this->action('get')->set('page-size', 12);
}
}
public function index($options = array())
{
Router::add(Router::TYPE_EQUALS, __('get-url'), array('page.location' => $this->id.'/get#list'));
Router::add(Router::TYPE_REGEX, __('get-url').'([^/]*)-(\d+)', array('page.location' => $this->id.'/get#detail'), array('title', 'id'));
Router::process();
if (page()->location("~^{$this->id}/get~"))
$this->mainTemplate();
}
public function page($options = array())
{
if (page()->location("~^{$this->id}/get~"))
{
page()->breadcrumb(__('module-name', $this->id), $this->url('get'));
if (i()->get('id'))
page()->breadcrumb($GLOBALS['result']['object']->oid ? $GLOBALS['result']['object']->otitle : __('not-found', '@core'));
return true;
}
}
public function url($action, $options = array(), $type = null)
{
if (($type == 'pager') && ($action == 'get'))
return parent::url('get');
else
return parent::url($action, $options, $type);
}
public function select_id($value = null)
{
$result = Cache::get($this->id, __FUNCTION__);
if ($result === null)
{
$result = array('' => '');
$rows = qa("SELECT `id`, `title_#L#` FROM `##{$this->id}` ORDER BY `title_#L#`");
if (is_array($rows) && count($rows))
foreach ($rows as $row)
$result[$row['id']] = $row['title'.LL];
Cache::set($result, $this->id, __FUNCTION__);
}
return parent::select($value, $result);
}
public function select_oid($value = null)
{
$result = Cache::get($this->id, __FUNCTION__);
if ($result === null)
{
$result = array('' => '');
$rows = qa("SELECT `oid`, `title_#L#` FROM `##{$this->id}` ORDER BY `title_#L#`");
if (is_array($rows) && count($rows))
foreach ($rows as $row)
$result[$row['oid']] = $row['title'.LL];
Cache::set($result, $this->id, __FUNCTION__);
}
return parent::select($value, $result);
}
/************************************************** ACTIONS **************************************************/
}
?>
ACC SHELL 2018