/** * Delete a default widget and ensure that it can be recreated */ public function testDefaultWidgetRecreation() { $profile = $this->profiles('adminProfile'); $widgetSubtype = 'ContactsGridViewProfileWidget'; $success = SortableWidget::deleteSortableWidget($profile, $widgetSubtype, '', 'profile'); $this->assertTrue($success); $widgetLayoutBefore = $profile->profileWidgetLayout; $widgetSettings = $widgetLayoutBefore[$widgetSubtype]; $this->assertTrue($widgetSettings['softDeleted']); list($success, $uid) = SortableWidget::createSortableWidget($profile, $widgetSubtype, 'profile'); $this->assertTrue($success); $widgetLayoutAfter = $profile->profileWidgetLayout; $widgetSettings = $widgetLayoutAfter[$widgetSubtype]; $this->assertFalse($widgetSettings['softDeleted']); $this->assertEquals(array_keys($widgetLayoutBefore), array_keys($widgetLayoutAfter)); }
public function actionCreateChartingWidget() { if (!isset($_POST['widgetLayoutName']) || !isset($_POST['chartId'])) { throw new CHttpException(400, 'Bad Request'); } $chartId = $_POST['chartId']; $widgetSettings = array(); $chart = Charts::findByPk($chartId); if (preg_match('/::/', $widgetClass)) { // Custom module summary widget. extract model name $widgetSettings['modelType'] = preg_replace('/::.*$/', '', $widgetClass); $widgetSettings['label'] = $widgetSettings['modelType'] . ' Summary'; $widgetClass = preg_replace('/^.*::/', '', $widgetClass); if (!class_exists($widgetSettings['modelType'])) { echo 'false'; } } $widgetLayoutName = $_POST['widgetLayoutName']; list($success, $uid) = SortableWidget::createSortableWidget(Yii::app()->params->profile, $widgetClass, $widgetLayoutName, $widgetSettings); if ($success) { echo $widgetClass::getWidgetContents($this, Yii::app()->params->profile, $widgetLayoutName, $uid); } else { echo 'false'; } }