/** * Constructor * @param string $objKey Unify object name * @throws Exception */ public function __construct($objKey) { parent::__construct(); $this->objKey = $objKey; if (!($class = Storage::getClass($objKey))) { throw new Exception('objKey \'' . $objKey . '\' does not exist.'); } $this->order = $class::getDefaultOrder() ? (array) $class::getDefaultOrder() : null; $this->orderDesc = $class::getDefaultOrderDesc() ? (array) $class::getDefaultOrderDesc() : null; }
public function deleteAjaxAction(\Difra\Param\AnyInt $id) { $this->subInit(); try { $class = \Difra\Unify\Storage::getClass('WidgetsDirectory'); $object = $class::get((string) $id); if ($object->directory != static::directory) { throw new \Difra\Exception('This item does not exist in this directory.'); } $object->delete(); } catch (\Difra\Exception $ex) { } \Difra\Ajaxer::getInstance()->load('#DirectoryWindow', $this->renderWindow()); }
/** * Alter table for Unify object * * @param \Difra\Param\AnyString $name */ public function alterAjaxAction(\Difra\Param\AnyString $name) { try { /** @var \Difra\Unify\Item $class */ $class = \Difra\Unify\Storage::getClass($name->val()); $status = $class::getObjDbStatus(); if ($status['status'] == 'alter') { \Difra\MySQL::getInstance()->query($status['sql']); } } catch (\Difra\Exception $ex) { \Difra\Ajaxer::notify($ex->getMessage()); } \Difra\Ajaxer::refresh(); }
/** * Generates SQL string for key create/alter * @param $name * @param $prop * @return string * @throws Exception */ private static function getIndexDefinition($name, $prop) { switch ($prop['type']) { case 'unique': return 'UNIQUE KEY `' . $name . '` (`' . implode('`,`', (array) $prop['columns']) . '`)'; case 'index': return 'KEY `' . $name . '` (`' . implode('`,`', (array) $prop['columns']) . '`)'; case 'primary': return 'PRIMARY KEY (`' . implode('`,`', (array) $prop['columns']) . '`)'; case 'fulltext': return 'FULLTEXT KEY `' . $name . '` (`' . implode('`,`', (array) $prop['columns']) . '`)'; case 'foreign': /** @var Item $targetObj */ $targetTable = ($targetObj = Storage::getClass($prop['target'])) ? $targetObj::getTable() : $prop['target']; return 'CONSTRAINT `' . $name . '`' . ' FOREIGN KEY (`' . implode('`,`', (array) $prop['source']) . '`)' . ' REFERENCES `' . $targetTable . '` (`' . implode('`,`', (array) $prop['keys']) . '`)' . ' ON DELETE ' . ((isset($prop['ondelete']) and $prop['ondelete']) ? $prop['ondelete'] : 'CASCADE') . ' ON UPDATE ' . ((isset($prop['onupdate']) and $prop['onupdate']) ? $prop['onupdate'] : 'CASCADE'); default: throw new Exception('I don\'t know how to define key type ' . $prop['type'] . "\n"); } }