1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-20 05:11:42 +02:00

Admin UI - batch navigation link creation improvements, testing required

This commit is contained in:
SecretR
2013-02-27 19:36:53 +02:00
parent af8c9af775
commit d4509edf7d
5 changed files with 164 additions and 82 deletions

View File

@@ -244,7 +244,8 @@ class page_admin_ui extends e_admin_ui
protected $batchLink = true; protected $batchLink = true;
protected $sortField = 'page_order'; protected $sortField = 'page_order';
protected $orderStep = 10; protected $orderStep = 10;
protected $url = array('profile'=>'page/view', 'name' => 'page_title', 'description' => '', 'link'=>'{e_BASE}page.php?id=[id]'); // 'link' only needed if profile not provided. //protected $url = array('profile'=>'page/view', 'name' => 'page_title', 'description' => '', 'link'=>'{e_BASE}page.php?id=[id]'); // 'link' only needed if profile not provided.
protected $url = array('route'=>'page/view/index', 'vars' => array('id' => 'page_id', 'sef' => 'page_sef'), 'name' => 'page_title', 'description' => ''); // 'link' only needed if profile not provided.
protected $tabs = array("Main","Advanced"); protected $tabs = array("Main","Advanced");
// protected $listSorting = true; // protected $listSorting = true;

View File

@@ -353,7 +353,13 @@ class news_admin_ui extends e_admin_ui
protected $batchCopy = true; protected $batchCopy = true;
protected $batchLink = true; protected $batchLink = true;
protected $listOrder = "news_id desc"; protected $listOrder = "news_id desc";
protected $url = array('profile'=>'news/view/item', 'name' => 'news_title', 'description' => 'news_summary', 'link'=>'{e_BASE}news.php?extend.[id]'); // 'link' only needed if profile not provided. // true for 'vars' value means use same var
protected $url = array(
'route'=>'news/view/item',
'name' => 'news_title',
'description' => 'news_summary',
'vars'=> array('news_id' => true, 'news_sef' => true, 'category_id' => 'news_category', 'category_sef' => true) // FIXME category_sef missing, we have to retrieve category data on the list view
); // 'link' only needed if profile not provided.
protected $listQry = "SELECT n.*,u.user_id,u.user_name FROM #news AS n LEFT JOIN #user AS u ON n.news_author = u.user_id "; // without any Order or Limit. protected $listQry = "SELECT n.*,u.user_id,u.user_name FROM #news AS n LEFT JOIN #user AS u ON n.news_author = u.user_id "; // without any Order or Limit.

View File

@@ -3933,25 +3933,100 @@ class e_admin_ui extends e_admin_controller_ui
protected function handleListCopyBatch($selected) protected function handleListCopyBatch($selected)
{ {
// Batch Copy // Batch Copy
$set_messages = true;
$this->getTreeModel()->copy($selected); $this->getTreeModel()->copy($selected);
if($set_messages) $this->getTreeModel()->setMessages(); // move messages to default stack
$this->getTreeModel()->setMessages();
// send messages to session
e107::getMessage()->moveToSession();
// redirect
$this->redirect(); $this->redirect();
} }
/** TODO /**
* Batch copy trigger * Batch URL trigger
* @param array $selected * @param array $selected
* @return void * @return void
*/ */
protected function handleListUrlBatch($selected) protected function handleListUrlBatch($selected)
{ {
// Batch Copy // Batch Copy
$set_messages = true; if($this->_add2nav($selected))
$this->getTreeModel()->url($selected); {
if($set_messages) $this->getTreeModel()->setMessages(); //e107::getMessage()->moveToSession();
$this->redirect(); //$this->redirect();
}
} }
protected function _add2nav($selected)
{
if(empty($selected)) return false;// TODO warning message
if(!is_array($selected)) $selected = array($selected);
$sql = e107::getDb();
$urlData = $this->getUrl();
$allData = $this->getTreeModel()->url($selected, array('sc' => true), true);
e107::getMessage()->addDebug('Using Url Route:'.$urlData['route']);
$scount = 0;
foreach($allData as $id => $data)
{
$name = $data['name'];
$desc = $data['description'];
$link = $data['url'];
$link = str_replace('{e_BASE}', "", $link); // TODO temporary here, discuss
// _FIELD_TYPES auto created inside mysql handler now
$linkArray = array(
'link_name' => $name,
'link_url' => $link,
'link_description' => e107::getParser()->toDB($desc), // retrieved field type is string, we might need todb here
'link_button' => '',
'link_category' => 255, // Using an unassigned template rather than inactive link-class, since other inactive links may already exist.
'link_order' => 0,
'link_parent' => 0,
'link_open' => '',
'link_class' => 0,
'link_sefurl' => e107::getParser()->toDB($urlData['route'].'?'.$id),
);
$res = $sql->insert('links', $linkArray);
// FIXME lans
if($res !== FALSE)
{
e107::getMessage()->addSuccess('Created Sitelink: <b>'.($name ? $name : 'n/a')."</b>");
$scount++;
}
else
{
if($sql->getLastErrorNumber())
{
e107::getMessage()->addError('SQL Link Creation Error'); //TODO - Lan
e107::getMessage()->addDebug('SQL Link Creation Error #'.$sql->getLastErrorNumber().': '.$sql->getLastErrorText());
}
else
{
e107::getMessage()->addError('Unknown error: <b>'.$name."</b> not added");
}
}
}
if($scount > 0)
{
e107::getMessage()->addSuccess("<br /><strong>{$scount}</strong> new sitelinks were added but are currently unassigned. You should now modify these links to your liking.<br /><br /><a class='btn btn-small btn-primary' href='".e_ADMIN_ABS."links.php?searchquery=&filter_options=link_category__255'>Modify Links</a>");
return $scount;
}
return false;
}
/** /**
* Batch boolean trigger * Batch boolean trigger
* @param array $selected * @param array $selected

View File

@@ -2188,7 +2188,7 @@ class e_form
{ {
$value = $tp->htmlwrap($value, (int)$parms['wrap'], varset($parms['wrapChar'], ' ')); $value = $tp->htmlwrap($value, (int)$parms['wrap'], varset($parms['wrapChar'], ' '));
} }
if(vartrue($parms['link']) && $id && is_numeric($id)) if(vartrue($parms['link']) && $id/* && is_numeric($id)*/)
{ {
$link = str_replace('[id]',$id,$parms['link']); $link = str_replace('[id]',$id,$parms['link']);
$link = $tp->replaceConstants($link); // SEF URL is not important since we're in admin. $link = $tp->replaceConstants($link); // SEF URL is not important since we're in admin.
@@ -2197,19 +2197,21 @@ class e_form
$ext = vartrue($parms['target']) =='blank' ? " rel='external' " : ""; // new window $ext = vartrue($parms['target']) =='blank' ? " rel='external' " : ""; // new window
$modal = vartrue($parms['target']) =='modal' ? " data-toggle='modal' data-cache='false' data-target='#uiModal' " : ""; $modal = vartrue($parms['target']) =='modal' ? " data-toggle='modal' data-cache='false' data-target='#uiModal' " : "";
$data = $this->getController()->getListModel()->toArray(); if($parms['link'] == 'sef' && $this->getController()->getListModel())
if($parms['link'] == 'sef') //XXX @Miro - Thoughts? {
{ $model = $this->getController()->getListModel();
$urlData = $this->getController()->getUrl(); // copy url config
$link = e107::getUrl()->create($urlData['profile'], $data); $model->setUrl($this->getController()->getUrl());
// assemble the url
$link = $model->url();
} }
elseif(vartrue($data[$parms['link']])) // support for a field-name as the link. eg. link_url. elseif(vartrue($data[$parms['link']])) // support for a field-name as the link. eg. link_url.
{ {
$link = $tp->replaceConstants(vartrue($data[$parms['link']])); $link = $tp->replaceConstants(vartrue($data[$parms['link']]));
} }
// in case something goes wrong...
$value = "<a class='e-tip{$dialog}' {$ext} href='".$link."' {$modal} title='Quick View'>".$value."</a>"; if($link) $value = "<a class='e-tip{$dialog}' {$ext} href='".$link."' {$modal} title='Quick View'>".$value."</a>";
} }
if(!vartrue($attributes['noedit']) && vartrue($parms['editable']) && !vartrue($parms['link'])) // avoid bad markup, better solution coming up if(!vartrue($attributes['noedit']) && vartrue($parms['editable']) && !vartrue($parms['link'])) // avoid bad markup, better solution coming up

View File

@@ -523,7 +523,8 @@ class e_model extends e_object
protected $_db_table; protected $_db_table;
/** /**
* Current url Profile * Current url Profile data
* Example: array('route'=>'page/view/index', 'vars' => array('id' => 'page_id', 'sef' => 'page_sef'), 'name' => 'page_title', 'description' => '');
* @var string * @var string
*/ */
protected $_url; protected $_url;
@@ -599,7 +600,6 @@ class e_model extends e_object
return $this; return $this;
} }
/** /**
* Get url profile * Get url profile
* @return array * @return array
@@ -609,6 +609,52 @@ class e_model extends e_object
return $this->_url; return $this->_url;
} }
/**
* Generic URL assembling method
* @param array $options [optional] see eRouter::assemble() for $options structure
* @param boolean $extended [optional] if true, method will return an array containing url, title and description of the url
* @return mixed URL string or extended array data
*/
public function url($options = array(), $extended = false)
{
$urldata = $this->getUrl();
if(empty($urldata) || !vartrue($urldata['route'])) return ($extended ? array() : null);
$eurl = e107::getUrl();
if(empty($options)) $options = array();
elseif(!is_array($options)) parse_str($options, $options);
$vars = $this->toArray();
if(!vartrue($options['allow']))
{
if(vartrue($urldata['vars']) && is_array($urldata['vars']))
{
$vars = array();
foreach ($urldata['vars'] as $var => $field)
{
if($field === true) $field = $var;
$vars[$var] = $this->get($field);
}
}
}
$method = isset($options['sc']) ? 'sc' : 'create';
$url = e107::getUrl()->$method($urldata['route'], $vars, $options);
if(!$extended)
{
return $url;
}
return array(
'url' => $url,
'name' => vartrue($urldata['name']) ? $this->get($urldata['name']) : '',
'description' => vartrue($urldata['description']) ? $this->get($urldata['description']) : '',
);
}
/** /**
* Get data fields array * Get data fields array
* @return array * @return array
@@ -3446,69 +3492,21 @@ class e_admin_tree_model extends e_front_tree_model
} }
/** /**
* Batch Url Creation Table Rows. * Get urls/url data for given nodes
*/ */
public function url($ids) public function url($ids, $options = array(), $extended = false)
{ {
$tp = e107::getParser(); $ret = array();
$ids = array_map(array($tp, 'toDB'), $ids); foreach ($ids as $id)
$idstr = implode(', ', $ids); {
$sql = e107::getDb(); if(!$this->hasNode($id)) continue;
$allData = $this->toArray();
$urlData = $this->getUrl(); $model = $this->getNode($id);
if($this->getUrl()) $model->setUrl($this->getUrl()); // copy url config data if available
$this->addMessageDebug('Using Url Profile:'.$urlData['profile']); $ret[$id] = $model->url($options, $extended);
}
foreach($ids as $id) return $ret;
{
$data = vartrue($allData[$id]);
$name = $urlData['name'];
$desc = $urlData['description'];
$link = vartrue($urlData['profile']) ? e107::getUrl()->create($urlData['profile'], $data) : str_replace("[id]", $id, $urlData['link']);
$link = str_replace(e_HTTP,"",$link); // work-around fix.
$linkArray = array(
'link_name' => $tp->toDB($data[$name]),
'link_url' => $link,
'link_description' => $tp->toDB($desc),
'link_button' => '',
'link_category' => 255, // Using an unassigned template rather than inactive link-class, since other inactive links may already exist.
'link_order' => 0,
'link_parent' => 0,
'link_open' => '',
'link_class' => 0
);
$res = $sql->insert('links',$linkArray);
if($res !== FALSE)
{
$this->addMessageSuccess('Created Sitelink: <b>'.$data[$name]."</b>");
}
else
{
if($sql->getLastErrorNumber())
{
$this->addMessageError('SQL Link Creation Error', $session_messages); //TODO - Lan
$this->addMessageDebug('SQL Link Creation Error #'.$sql->getLastErrorNumber().': '.$sql->getLastErrorText());
}
$this->_db_errno = $sql->getLastErrorNumber();
$this->_db_errmsg = $sql->getLastErrorText();
}
}
if($res !== FALSE)
{
$this->addMessageSuccess("<br />New sitelinks are currently unassigned. You should now modify these links to your liking.<br /><br /><a class='btn btn-small btn-primary' href='".e_ADMIN."links.php?searchquery=&filter_options=link_category__255'>Modify Links</a>");
}
return true;
} }
} }