/** * Getting widget info * * @param sfWebRequest $request * @author Sergey Startsev */ public function executeGetWidget(sfWebRequest $request) { $action = $request->getParameter('action_name'); $module = $request->getParameter('module_name'); ($info = afsWidgetModelHelper::find($action, $module)) ? extract($info) : (list($place, $placeType) = array('frontend', 'app')); $parameters = array('uri' => "{$module}/{$action}", 'place' => $request->getParameter('place', $place), 'type' => $request->getParameter('place_type', $placeType)); return $this->renderJson(afStudioCommand::process('widget', 'getInfo', $parameters)->asArray()); }
/** * Generate widget functionality * * @return afResponse * @author Sergey Startsev */ protected function processGenerate() { $model = $this->getParameter('model'); $module = $this->getParameter('module_name', lcfirst(sfInflector::camelize($model))); $type = $this->getParameter('type', 'list,edit,show'); $fields = $this->getParameter('fields', ''); $place_type = $this->getParameter('place_type', 'app'); $place = $this->getParameter('place', 'frontend'); $refresh = $this->getParameter('refresh', 'false'); $data = array(); $not_refreshed = array(); if ($refresh == 'false') { foreach (explode(',', $type) as $type_generate) { $action = lcfirst(sfInflector::camelize($model)) . ucfirst(strtolower($type_generate)); $widget = afsWidgetModelHelper::retrieve($action, $module, $place, $place_type, $model); if (!$widget->isNew()) { $not_refreshed[] = $action; } } } $console = afStudioConsole::getInstance(); $console_output = $console->execute("sf afs:generate-widget " . "--model={$model} --module={$module} --type={$type} --fields={$fields} --place-type={$place_type} --place={$place} --refresh={$refresh}"); $created = array(); $not_created = array(); foreach (explode(',', $type) as $type_generate) { $action = lcfirst(sfInflector::camelize($model)) . ucfirst(strtolower($type_generate)); $widget = afsWidgetModelHelper::retrieve($action, $module, $place, $place_type, $model); !$widget->isNew() && !in_array($action, $not_refreshed) ? $created[] = $action : ($not_created[] = $action); } $data = array('place' => $place, 'place_type' => $place_type, 'module' => $module, 'widgets' => $created); $message = ''; if (!empty($created)) { $message .= 'Created: <b>' . implode(', ', $created) . '</b>. <br/>'; } if (!empty($not_created) && $not_created != $not_created) { $message .= 'Not Created: <b>' . implode(', ', $not_created) . '</b>. <br/>'; } if (!empty($not_refreshed)) { $message .= 'Already Exists: <b>' . implode(', ', $not_refreshed) . '</b>.'; } return afResponseHelper::create()->success($console->wasLastCommandSuccessfull())->message($message)->data(array(), $data, 0)->console($console_output); }
/** * Retrieve widget and update definition * * @param string $app_name * @param string $module_name * @param string $widget_name * @param string $model_name * @return Widget * @author Sergey Startsev */ public function retrieveAndUpdate($widget_name, $module_name, $app_name, $place_type = 'app', $model_name = '') { return $this->update(\afsWidgetModelHelper::retrieve($widget_name, $module_name, $app_name, $place_type, $model_name)); }