public function notInBlock($blockPk) { //don't show widgets that already in block $existWidgets = TemplateBlock::model()->findByPk($blockPk)->widgets; $ids = CHtml::listData($existWidgets, 'pk', 'pk'); return $this->notIn($ids); }
public function actionMakeOwn($catPk, $blockPk) { $cat = Category::model()->findByPk($catPk); $block = TemplateBlock::model()->findByPk($blockPk); $newBlock = $block->copy(); $db = Yii::app()->db; $transaction = $db->beginTransaction(); try { //create new Block $newBlock->category_id = null; $cat->blocks = array($newBlock); $cat->save(); //Create copies of components $widgets = $block->widgets; foreach ($widgets as $widget) { $widget->pk = null; $widget->block_id = null; } //save components $newBlock->widgets = $widgets; $newBlock->save(); $transaction->commit(); echo 'ok'; } catch(CException $e) { $transaction->rollBack(); echo $e->__toString(); } }