public function __construct($record = null) { parent::__construct(); $this->record = $record; $this->model = new Placid_RequestsModel(); if (is_null($this->record)) { $this->record = Placid_RequestsRecord::model(); } // Get the plugin settings $this->placid_settings = $this->settings; }
/** * Save a request * * @param object RequestsModel object * * @return bool true or false if request has been saved */ public function saveRequest(Placid_RequestsModel &$model) { // Determine whether this is an existing request or if we need to create a new one // -------------------------------------------------------------------------------- if ($id = $model->getAttribute('id')) { $record = $this->record->findByPk($id); } else { $record = new Placid_RequestsRecord(); } // Get the attributes from the passed model $attributes = $model->getAttributes(); // Set the new attributes to the record $record->setAttributes($attributes, false); // Save the new request // ----------------------------------------------------------------------------- if ($record->save()) { $model->setAttribute('id', $record->getAttribute('id')); return true; } else { $model->addErrors($record->getErrors()); return false; } }
/** * Deletes a Widget based on the record * @param Int $id The id of the record * @return Bool True */ private function _deleteWidgetsByRecord($id) { $record = Placid_RequestsRecord::model()->findByPk($id); $currentWidgets = craft()->dashboard->getUserWidgets(); foreach ($currentWidgets as $widget) { $settings = $widget->settings; if ($settings && is_array($settings)) { if (array_key_exists('request', $settings) && $settings['request'] == $record->handle) { craft()->dashboard->deleteUserWidgetById($widget->id); } } } return true; }