getDBDriver(); $assoObjectsQueryTmp = 'SELECT objectId FROM #__cjtoolbox_package_objects WHERE packageId = %d AND objectType = "%s" AND relType = "%s";'; // Delete the package. CJTxTable::getInstance('package') ->set('id', $id) ->delete(); // Delete blocks. $blockIds = array_keys($dbd->select(sprintf($assoObjectsQueryTmp, $id, 'block', 'add'))); if (!empty($blockIds)) { // Delete blocks! CJTModel::getInstance('blocks') ->delete($blockIds) ->save(); } // Delete templates. $modelTemplates->inputs['ids'] = array_keys($dbd->select(sprintf($assoObjectsQueryTmp, $id, 'template', 'add'))); // Templates muct be in trash state before deleted! $modelTemplates->inputs['state'] = 'trash'; // Move to Trash + Delete only if there is at least one Id! empty($modelTemplates->inputs['ids']) OR ($modelTemplates->changeState() AND $modelTemplates->delete()); // Delete package objects map. CJTxTable::getInstance('package-objects') ->set('packageId', $id) ->delete(array('packageId')); } /** * put your comment there... * * @param mixed $packageName */ public function exists($packageName) { // Load by name. $tablePackage = CJTxTable::getInstance('package') ->set('name', $packageName) ->load(array('name')); // The object table if exists FALSE otherwise. return ($tablePackage->get('id') ? $tablePackage : FALSE); } /** * put your comment there... * */ public function getFileContent() { // Get package ID. $packageId = $_REQUEST['packageId']; // Get Field/File to read. $file = $this->getParam('file'); // LOAD file content from database. $tblPackage = CJTxTable::getInstance('package'); $content = $tblPackage->set('id', $packageId) ->load(array('id')) ->get($file); // Return file content. return $content; } /** * put your comment there... * * @param mixed $name */ public function getParam($name) { return isset($this->params[$name]) ? $this->params[$name] : null; } /** * put your comment there... * * @param mixed $package * @param mixed $objects * @return CJTxTable */ public function save($package, $types) { // Add package. $tablePackage = CJTxTable::getInstance('package') ->setData($package) ->save(); // Add package objects map. $tablePackageObjects = CJTxTable::getInstance('package-objects'); // Fetch objects under each type (block ,template). foreach ($types as $type => $objects) { // For each types get all object IDs! foreach ($objects as $object) { $tablePackageObjects->setItem() // Reset is needed as the object used accross multiple records // and might cause interfering between records! ->setData($object) ->set('packageId', $tablePackage->get('id')) ->set('objectType', $type) ->save(); } } return $tablePackage->get('id'); } /** * put your comment there... * * @param mixed $name * @param mixed $value */ public function setParam($name, $value) { // Set internal parameter value. $this->params[$name] = $value; // Chaining. return $this; } } // End class. // Hookable! CJTPackageModel::define('CJTPackageModel', array('hookType' => CJTWordpressEvents::HOOK_FILTER));