added some useful models and controllers
This commit is contained in:
parent
9bb724147e
commit
1d4b2a3314
44 changed files with 6424 additions and 0 deletions
17
application/model/Access.php
Normal file
17
application/model/Access.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
class Access extends Katharsis_Model_Abstract
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
public static function isLogged()
|
||||
{
|
||||
if(isset($_SESSION['logged']) && $_SESSION['logged'] == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
288
application/model/Navigation.php
Normal file
288
application/model/Navigation.php
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
<?php
|
||||
class Navigation extends Katharsis_Model_Abstract
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
public function getAllItems()
|
||||
{
|
||||
$tidyResult = array();
|
||||
$result = $this->_con->fetchAll("SELECT * FROM navigation WHERE parent_id IS NULL ORDER BY sorting");
|
||||
foreach($result as $item)
|
||||
{
|
||||
$subSet = array();
|
||||
$sql = "SELECT * FROM navigation WHERE parent_id = :parentId ORDER BY sorting";
|
||||
$sql = $this->_con->createStatement($sql, array('parentId' => $item['id']));
|
||||
|
||||
$item['children'] = $this->_con->fetchAll($sql);
|
||||
$tidyResult[] = $item;
|
||||
}
|
||||
return $tidyResult;
|
||||
}
|
||||
|
||||
public function getMainItems()
|
||||
{
|
||||
return $this->_con->fetchAll("SELECT id, name FROM navigation WHERE parent_id IS NULL ORDER BY sorting");
|
||||
}
|
||||
|
||||
public function getItem($id)
|
||||
{
|
||||
if($id !== null)
|
||||
{
|
||||
$sql = "SELECT * FROM navigation WHERE id = :id";
|
||||
$sql = $this->_con->createStatement($sql, array('id' => $id));
|
||||
if(!$result = $this->_con->fetchOne($sql))
|
||||
{
|
||||
throw new DidgeridooArtwork_Exception('Item with this id not existent');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SHOW COLUMNS FROM navigation";
|
||||
$res = $this->_con->fetchAll($sql);
|
||||
foreach($res as $it)
|
||||
{
|
||||
$result[$it['Field']] = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$sql = "DELETE FROM navigation WHERE id = :id";
|
||||
$sql = $this->_con->createStatement($sql, array('id' => $id));
|
||||
$this->_con->run($sql);
|
||||
}
|
||||
|
||||
public function move($direction, $id)
|
||||
{
|
||||
$sql = "SELECT sorting, parent_id FROM navigation WHERE id = :id";
|
||||
$sql = $this->_con->createStatement($sql, array('id' => $id));
|
||||
|
||||
if($active = $this->_con->fetchOne($sql))
|
||||
{
|
||||
$parentPart = ($active['parent_id'] === null) ? "parent_id IS NULL" : "parent_id = :parentId";
|
||||
|
||||
if($direction == 'up')
|
||||
{
|
||||
$sql = "SELECT id, sorting FROM navigation
|
||||
WHERE
|
||||
" . $parentPart . "
|
||||
AND sorting < :sorting
|
||||
ORDER BY sorting DESC
|
||||
LIMIT 1
|
||||
";
|
||||
}
|
||||
else if($direction == 'down')
|
||||
{
|
||||
$sql = "SELECT id, sorting FROM navigation
|
||||
WHERE
|
||||
" . $parentPart . "
|
||||
AND sorting > :sorting
|
||||
ORDER BY sorting ASC
|
||||
LIMIT 1
|
||||
";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DidgeridooArtwork_Exception('Wrong Direction');
|
||||
}
|
||||
|
||||
$sql = $this->_con->createStatement($sql, array(':id' => $id, 'parentId' => $active['parent_id'], 'sorting' => $active['sorting']));
|
||||
|
||||
$passiveItem = $this->_con->fetchOne($sql);
|
||||
|
||||
//updating active item
|
||||
$sql = "UPDATE navigation SET sorting = :sorting WHERE id = :id";
|
||||
$sql = $this->_con->createStatement($sql, array('id' => $id, 'sorting' => $passiveItem['sorting']));
|
||||
$this->_con->run($sql);
|
||||
|
||||
//updating passive item
|
||||
$sql = "UPDATE navigation SET sorting = :sorting WHERE id = :id";
|
||||
$sql = $this->_con->createStatement($sql, array('id' => $passiveItem['id'], 'sorting' => $active['sorting']));
|
||||
$this->_con->run($sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DidgeridooArtwork_Exception('Wrong Parameters');
|
||||
}
|
||||
}
|
||||
|
||||
public static function buildLink($base, $item, $simpleMode = false)
|
||||
{
|
||||
if($item['link'] !== null)
|
||||
{
|
||||
return $item['link'];
|
||||
}
|
||||
|
||||
$link = $base . '/' . $item['controller'];
|
||||
if($simpleMode)
|
||||
{
|
||||
$link = $item['controller'];
|
||||
}
|
||||
|
||||
if($item['action'] !== null)
|
||||
{
|
||||
$link .= '/' . $item['action'];
|
||||
|
||||
if($simpleMode) return $link;
|
||||
|
||||
if($item['controller'] == 'page')
|
||||
{
|
||||
$link .= '/preview';
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
public static function getTitle()
|
||||
{
|
||||
|
||||
if(substr(Katharsis_Request::getControllerName(), 0, 5) == 'admin')
|
||||
{
|
||||
return 'Admin';
|
||||
}
|
||||
|
||||
$con = Katharsis_DatabaseConnector::getConnection();
|
||||
|
||||
if(Katharsis_Request::getControllerName() == 'page')
|
||||
{
|
||||
$sql = "SELECT title FROM page WHERE url = :url";
|
||||
$sql = $con->createStatement($sql, array('url' => Katharsis_Request::getActionName()));
|
||||
if($field = $con->fetchField($sql))
|
||||
{
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
$menuItemId = Katharsis_View::getInstance()->activeMenuItem;
|
||||
$sql = "SELECT name FROM navigation WHERE id = :menuItemId";
|
||||
$sql = $con->createStatement($sql, array('menuItemId' => $menuItemId));
|
||||
if($field = $con->fetchField($sql))
|
||||
{
|
||||
return $field;
|
||||
}
|
||||
|
||||
return Katharsis_Registry::getInstance()->defaults['title'];
|
||||
}
|
||||
|
||||
public static function getSubtitle()
|
||||
{
|
||||
$con = Katharsis_DatabaseConnector::getConnection();
|
||||
|
||||
if(Katharsis_Request::getControllerName() == 'page')
|
||||
{
|
||||
$sql = "SELECT subtitle FROM page WHERE url = :url";
|
||||
$sql = $con->createStatement($sql, array('url' => Katharsis_Request::getActionName()));
|
||||
if($field = $con->fetchField($sql))
|
||||
{
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
return Katharsis_Registry::getInstance()->defaults['subtitle'];
|
||||
}
|
||||
|
||||
public function getSites()
|
||||
{
|
||||
$sql = "SELECT url FROM page";
|
||||
$sql = $this->_con->createStatement($sql, array('url' => Katharsis_Request::getActionName()));
|
||||
$sites = $this->_con->fetchAll($sql);
|
||||
|
||||
foreach($sites as &$site)
|
||||
{
|
||||
$site = 'page/' . $site['url'];
|
||||
}
|
||||
$sites = array(
|
||||
'defaults' => explode(", ", Katharsis_Registry::getInstance()->defaults['sites']),
|
||||
'pages' => $sites
|
||||
);
|
||||
|
||||
return $sites;
|
||||
}
|
||||
|
||||
public function save($params)
|
||||
{
|
||||
$transformed = $this->_transformUrl($params['url'], $params['external']);
|
||||
|
||||
$values = array(
|
||||
'id' => $params['id'],
|
||||
'name' => $params['name'],
|
||||
'parent_id' => $params['parentId'],
|
||||
'active' => $params['active']
|
||||
);
|
||||
|
||||
$values = array_merge($values, $transformed);
|
||||
|
||||
if(isset($values['id']) && is_numeric($values['id']))
|
||||
{
|
||||
$sql = "UPDATE navigation
|
||||
SET
|
||||
name = :name,
|
||||
controller = :controller,
|
||||
action = :action,
|
||||
link = :link,
|
||||
parent_id = parent_id,
|
||||
active = :active
|
||||
WHERE
|
||||
id = :id
|
||||
";
|
||||
$sql = $this->_con->createStatement($sql, $values);
|
||||
$this->_con->run($sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($values['parent_id'] === null)
|
||||
{
|
||||
$sql = "SELECT max(sorting) + 1 as maxi FROM `navigation` WHERE parent_id IS NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT max(sorting) + 1 as maxi FROM `navigation` WHERE parent_id = :parentId";
|
||||
$sql = $this->_con->createStatement($sql, array('parentId' => $values['parent_id']));
|
||||
}
|
||||
|
||||
|
||||
$max = $this->_con->fetchField($sql);
|
||||
$max = ($max === null) ? 1 : $max;
|
||||
$values['sorting'] = $max;
|
||||
|
||||
$this->_con->insert('navigation', $values);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _transformUrl($url, $external = null)
|
||||
{
|
||||
$values = array(
|
||||
'controller' => null,
|
||||
'action' => null,
|
||||
'link' => null
|
||||
);
|
||||
|
||||
if($url == '-external-')
|
||||
{
|
||||
$values['link'] = $external;
|
||||
return $values;
|
||||
}
|
||||
|
||||
$e = explode('/', $url);
|
||||
if(array_key_exists(1, $e))
|
||||
{
|
||||
$values['controller'] = $e[0];
|
||||
$values['action'] = $e[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$values['controller'] = $url;
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
87
application/model/Page.php
Normal file
87
application/model/Page.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
class Page extends Katharsis_Model_Abstract
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
public function render($url, $preview)
|
||||
{
|
||||
$activeTerm = '';
|
||||
if(!$preview)
|
||||
{
|
||||
$activeTerm = 'AND active = 1';
|
||||
}
|
||||
$sql = $this->_con->createStatement("SELECT * FROM page WHERE url = :url " . $activeTerm, array("url" => $url));
|
||||
if($result = $this->_con->fetchOne($sql))
|
||||
{
|
||||
return $result['content'];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DidgeridooArtwork_Exception('Die von Ihnen angeforderte Seite (Page) "' . $url . '" konnte nicht gefunden werden.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getPages()
|
||||
{
|
||||
$sql = "SELECT id, title, subtitle, url, active FROM page ORDER BY id";
|
||||
return $this->_con->fetchAll($sql);
|
||||
}
|
||||
|
||||
public function getPage($pageId)
|
||||
{
|
||||
$default = $this->_con->getEmptyColumnArray('page');
|
||||
|
||||
if($pageId === null) return $default;
|
||||
|
||||
$sql = "SELECT * FROM page WHERE id = :pageId";
|
||||
$sql = $this->_con->createStatement($sql, array('pageId' => $pageId));
|
||||
|
||||
if($result = $this->_con->fetchOne($sql))
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function save($params)
|
||||
{
|
||||
$values = array(
|
||||
'title' => $params['title'],
|
||||
'subtitle' => $params['subtitle'],
|
||||
'url' => $params['url'],
|
||||
'content' => $params['content'],
|
||||
'active' => $params['active']
|
||||
);
|
||||
|
||||
if(isset($params['id']) && is_numeric($params['id']))
|
||||
{
|
||||
$values['id'] = $params['id'];
|
||||
$sql = "UPDATE page
|
||||
SET
|
||||
title = :title,
|
||||
subtitle = :subtitle,
|
||||
url = :url,
|
||||
content = :content,
|
||||
active = :active
|
||||
WHERE
|
||||
id = :id
|
||||
";
|
||||
$sql = $this->_con->createStatement($sql, $values);
|
||||
$this->_con->run($sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_con->insert('page', $values);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($pageId)
|
||||
{
|
||||
$sql = "DELETE FROM page WHERE id = :pageId";
|
||||
$sql = $this->_con->createStatement($sql, array('pageId' => (int) $pageId));
|
||||
$this->_con->run($sql);
|
||||
}
|
||||
}
|
||||
?>
|
||||
79
application/model/Upload.php
Normal file
79
application/model/Upload.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
class Upload extends Katharsis_Model_Abstract
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function product($id, $files)
|
||||
{
|
||||
$dir = getcwd() . '/img/shop/product';
|
||||
|
||||
$name = $this->_uploadFile($id, $files['small'], $dir . '/small');
|
||||
$this->_uploadFile($id, $files['big'], $dir . '/big', $name);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function category($id, $file)
|
||||
{
|
||||
$dir = getcwd() . '/img/shop/category';
|
||||
return $this->_uploadFile($id, $file, $dir);
|
||||
}
|
||||
|
||||
public function sound($id, $file)
|
||||
{
|
||||
$dir = getcwd() . '/sound';
|
||||
return $this->_uploadFile($id, $file, $dir);
|
||||
}
|
||||
|
||||
public function event($id, $files)
|
||||
{
|
||||
$dir = getcwd() . '/img/event';
|
||||
|
||||
$name = $this->_uploadFile($id, $files['image'], $dir);
|
||||
$this->_uploadFile($id, $files['image_full'], $dir . '/full', $name);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function page($file)
|
||||
{
|
||||
$dir = getcwd() . '/img/page';
|
||||
return $this->_uploadFile(null, $file, $dir, $file['name'] . '-' . time());
|
||||
}
|
||||
|
||||
protected function _uploadFile($id, $file, $dir, $name = null)
|
||||
{
|
||||
if($name === null)
|
||||
{
|
||||
$name = $id . '-' . time();
|
||||
}
|
||||
else
|
||||
{
|
||||
if($nameparts = explode(".", $name))
|
||||
{
|
||||
$name = $nameparts[0];
|
||||
}
|
||||
}
|
||||
|
||||
$handle = new Verot_Upload($file);
|
||||
$handle->file_new_name_body = $name;
|
||||
if ($handle->uploaded)
|
||||
{
|
||||
$handle->Process($dir);
|
||||
if (!$handle->processed)
|
||||
{
|
||||
throw new DidgeridooArtwork_Exception('Datei konnte nicht verschoben werden (' . $handle->error . ').');
|
||||
}
|
||||
$handle->Clean();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DidgeridooArtwork_Exception('Datei konnte nicht hochgeladen werden (' . $handle->error . ').');
|
||||
}
|
||||
$returnName = $handle->file_dst_name;
|
||||
return $returnName;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue