/** * Performs an action on one or more selected elements. * * @throws HttpException * @return null */ public function actionPerformAction() { $this->requirePostRequest(); $this->requireAjaxRequest(); $requestService = craft()->request; $actionHandle = $requestService->getRequiredPost('elementAction'); $elementIds = $requestService->getRequiredPost('elementIds'); // Find that action from the list of available actions for the source if ($this->_actions) { foreach ($this->_actions as $availableAction) { if ($actionHandle == $availableAction->getClassHandle()) { $action = $availableAction; break; } } } if (!isset($action)) { throw new HttpException(400); } // Check for any params in the post data $params = $action->getParams(); foreach ($params->attributeNames() as $paramName) { $paramValue = $requestService->getPost($paramName); if ($paramValue !== null) { $params->setAttribute($paramName, $paramValue); } } // Make sure they validate if (!$params->validate()) { throw new HttpException(400); } // Perform the action $actionCriteria = $this->_criteria->copy(); $actionCriteria->offset = 0; $actionCriteria->limit = null; $actionCriteria->order = null; $actionCriteria->positionedAfter = null; $actionCriteria->positionedBefore = null; $actionCriteria->id = $elementIds; $success = $action->performAction($actionCriteria); // Respond $response = array('success' => $success, 'message' => $action->getMessage()); if ($success) { // Send a new set of elements $response['html'] = $this->_getElementHtml(false); $includeLoadMoreInfo = true; } else { $includeLoadMoreInfo = false; } $this->_respond($response, $includeLoadMoreInfo); }
/** * Performs an action on one or more selected elements. * * @throws HttpException * @return null */ public function actionPerformAction() { $this->requirePostRequest(); $this->requireAjaxRequest(); $requestService = craft()->request; $actionHandle = $requestService->getRequiredPost('elementAction'); $elementIds = $requestService->getRequiredPost('elementIds'); // Find that action from the list of available actions for the source if ($this->_actions) { foreach ($this->_actions as $availableAction) { if ($actionHandle == $availableAction->getClassHandle()) { $action = $availableAction; break; } } } if (!isset($action)) { throw new HttpException(400); } // Check for any params in the post data $params = $action->getParams(); foreach ($params->attributeNames() as $paramName) { $paramValue = $requestService->getPost($paramName); if ($paramValue !== null) { $params->setAttribute($paramName, $paramValue); } } // Make sure they validate if (!$params->validate()) { throw new HttpException(400); } // Perform the action $actionCriteria = $this->_criteria->copy(); $actionCriteria->offset = 0; $actionCriteria->limit = null; $actionCriteria->order = null; $actionCriteria->positionedAfter = null; $actionCriteria->positionedBefore = null; $actionCriteria->id = $elementIds; // Fire an 'onBeforePerformAction' event $event = new ElementActionEvent($this, array('action' => $action, 'criteria' => $actionCriteria)); craft()->elements->onBeforePerformAction($event); if ($event->performAction) { $success = $action->performAction($actionCriteria); $message = $action->getMessage(); if ($success) { // Fire an 'onPerformAction' event craft()->elements->onPerformAction(new Event($this, array('action' => $action, 'criteria' => $actionCriteria))); } } else { $success = false; $message = $event->message; } // Respond $responseData = array('success' => $success, 'message' => $message); if ($success) { // Send a new set of elements $responseData = array_merge($responseData, $this->_getElementResponseData(true, true)); } $this->returnJson($responseData); }
/** * Returns a clone of the criteria model. * * @return Neo_CriteriaModel */ public function copy() { $copy = parent::copy(); $copy->setState($this); return $copy; }