Added sharing of snippets option and started adding get snippets custom admin view gh-92. Fixed gh-153 published settings for categories.
This commit is contained in:
@ -53,6 +53,120 @@ class ComponentbuilderModelSnippets extends JModelList
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Method to build the export package
|
||||
*
|
||||
* @return bool on success.
|
||||
*/
|
||||
public function shareSnippets($pks)
|
||||
{
|
||||
// setup the query
|
||||
if (ComponentbuilderHelper::checkArray($pks))
|
||||
{
|
||||
// Get the user object.
|
||||
if (!ComponentbuilderHelper::checkObject($this->user))
|
||||
{
|
||||
$this->user = JFactory::getUser();
|
||||
}
|
||||
// Create a new query object.
|
||||
if (!ComponentbuilderHelper::checkObject($this->_db))
|
||||
{
|
||||
$this->_db = JFactory::getDBO();
|
||||
}
|
||||
$query = $this->_db->getQuery(true);
|
||||
|
||||
// Select some fields
|
||||
$query->select($this->_db->quoteName(
|
||||
array('a.name','a.heading','a.description','a.usage','a.snippet','a.url','b.name','c.name','a.created','a.modified'),
|
||||
array('name','heading','description','usage','snippet','url','type','library','created','modified')
|
||||
));
|
||||
|
||||
// From the componentbuilder_snippet table
|
||||
$query->from($this->_db->quoteName('#__componentbuilder_snippet', 'a'));
|
||||
// From the componentbuilder_snippet_type table.
|
||||
$query->join('LEFT', $this->_db->quoteName('#__componentbuilder_snippet_type', 'b') . ' ON (' . $this->_db->quoteName('a.type') . ' = ' . $this->_db->quoteName('b.id') . ')');
|
||||
// From the componentbuilder_library table.
|
||||
$query->join('LEFT', $this->_db->quoteName('#__componentbuilder_library', 'c') . ' ON (' . $this->_db->quoteName('a.library') . ' = ' . $this->_db->quoteName('c.id') . ')');
|
||||
$query->where('a.id IN (' . implode(',',$pks) . ')');
|
||||
|
||||
// Implement View Level Access
|
||||
if (!$this->user->authorise('core.options', 'com_componentbuilder'))
|
||||
{
|
||||
$groups = implode(',', $this->user->getAuthorisedViewLevels());
|
||||
$query->where('a.access IN (' . $groups . ')');
|
||||
}
|
||||
|
||||
// Order the results by ordering
|
||||
$query->order('a.ordering ASC');
|
||||
|
||||
// Load the items
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
if ($this->_db->getNumRows())
|
||||
{
|
||||
// load the items from db
|
||||
$items = $this->_db->loadObjectList();
|
||||
// check if we have items
|
||||
if (ComponentbuilderHelper::checkArray($items))
|
||||
{
|
||||
// get the shared paths
|
||||
$this->fullPath = rtrim(ComponentbuilderHelper::getFolderPath('path', 'sharepath', JFactory::getConfig()->get('tmp_path')), '/') . '/snippets';
|
||||
// remove old folder with the same name
|
||||
if (JFolder::exists($this->fullPath))
|
||||
{
|
||||
// remove if old folder is found
|
||||
ComponentbuilderHelper::removeFolder($this->fullPath);
|
||||
}
|
||||
// create the full path
|
||||
JFolder::create($this->fullPath);
|
||||
// set zip path
|
||||
$this->zipPath = $this->fullPath .'.zip';
|
||||
// remove old zip files with the same name
|
||||
if (JFile::exists($this->zipPath))
|
||||
{
|
||||
// remove file if found
|
||||
JFile::delete($this->zipPath);
|
||||
}
|
||||
// set params
|
||||
$this->params = JComponentHelper::getParams('com_componentbuilder');
|
||||
// Set the person sharing information (default VDM ;)
|
||||
$info = array();
|
||||
$info['company'] = $this->params->get('export_company', 'Vast Development Method');
|
||||
$info['owner'] = $this->params->get('export_owner', 'Llewellyn van der Merwe');
|
||||
$info['email'] = $this->params->get('export_email', 'joomla@vdm.io');
|
||||
$info['website'] = $this->params->get('export_website', 'https://www.vdm.io/');
|
||||
// prep the item
|
||||
foreach($items as $item)
|
||||
{
|
||||
// just unlock the snippet
|
||||
$item->snippet = base64_decode($item->snippet);
|
||||
// load the company detail to each snippet
|
||||
$item->contributor_company = $info['company'];
|
||||
$item->contributor_name = $info['owner'];
|
||||
$item->contributor_email = $info['email'];
|
||||
$item->contributor_website = $info['website'];
|
||||
// now store the snippet info
|
||||
ComponentbuilderHelper::writeFile($this->fullPath . '/' .ComponentbuilderHelper::safeString($item->library . ' - (' . $item->type . ') ' . $item->name, 'filename', '', false). '.json', json_encode($item, JSON_PRETTY_PRINT));
|
||||
}
|
||||
// zip the folder
|
||||
if (!ComponentbuilderHelper::zip($this->fullPath, $this->zipPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// remove the folder
|
||||
if (!ComponentbuilderHelper::removeFolder($this->fullPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user