--
You received this message because you are subscribed to the Google Groups "Joomla Component Builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcb+uns...@vdm.io.
To view this discussion on the web visit https://groups.google.com/a/vdm.io/d/msgid/jcb/86d2c720-58b6-43b2-9254-cf9ebbb4fcf8%40vdm.io.
Copyright © Vast Development Method | Terms of Service | Privacy Policy | Company
--
You received this message because you are subscribed to the Google Groups "Joomla Component Builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcb+uns...@vdm.io.
To view this discussion on the web visit https://groups.google.com/a/vdm.io/d/msgid/jcb/c86020b3-cfa7-4e41-ab11-20ec0ddb4460%40vdm.io.
/** * Load the tabs * * @param object $item Data for the form * @param string $view The view name * @param string $return The return value if found * * @return string * */public static function loadDynamicTabs(&$item, $view = 'member', $return = ''){ // only loads if type and account is set if (is_numeric($item->type) && $item->type > 0 && is_numeric($item->account) && $item->account > 0) { // get all the available component calling metods $class = new ReflectionClass('[[[Component]]]Helper'); $methods = array_filter($class->getMethods(ReflectionMethod::IS_PUBLIC), function ($method) { if (strpos($method->name, 'get') !== false && strpos($method->name, 'Availlable') !== false ) // The spelling mistake (Availlable) is to unique identify those classes. { return true; } return false; } ); // set the tabs $tabs = array(); $layout = array(); if (self::checkArray($methods)) { foreach ($methods as $method) { // get components $components = self::{$method->name}($item->type, $item->account); // check if we found components if (self::checkArray($components)) { // get assessment details foreach ($components as $_name => $component) { if (self::checkArray($component)) { $tables = array(); foreach ($component as $_nr => $comp) { if (($ids = self::getVars('form', $item->id, $view, 'id', 'IN', str_replace('com_', '', $comp->element))) !== false && self::checkArray($ids)) { $tables[] = self::getTabLinksTable($ids, $item, $comp, $view, $return); } } // load the tables to the layout if (self::checkArray($tables)) { foreach ($tables as $table) { if (self::checkString($table)) { if (!isset($layout[$_name])) { $layout[$_name] = $table; } else { $layout[$_name] .= $table; } } } } // add layout to tabs if (self::checkArray($layout) && count((array) $layout) == 2) { $tabs[] = self::setTab($layout, $view); $layout = array(); } } elseif (self::checkObject($component) && isset($component->element)) { if (($id = self::getVar('form', $item->id, $view, 'id', '=', str_replace('com_', '', $component->element))) === false) // get item ID { // if no item was found set to zero $id = 0; } // check if user are allowed to edit form values or create form values if (($id > 0 && JFactory::getUser()->authorise('form.edit', $component->element . '.form.' . (int) $id)) || ($id == 0 && JFactory::getUser()->authorise('form.create', $component->element))) { $fields = self::getTabFields($id, $component); // load the fields to the layout if (self::checkString($fields)) { $layout[$_name] = $fields; } // add layout to tabs if (self::checkArray($layout) && count((array) $layout) == 2) { $tabs[] = self::setTab($layout, $view); $layout = array(); } } } } } } } // add layout to tabs if (self::checkArray($layout)) { $tabs[] = self::setTab($layout, $view); } // check if we have tabs if (self::checkArray($tabs)) { return implode("\n", $tabs); } } return '';}
/** * get the tabe fields * * @param int $id The item id * @param object $component The target component details * * @return string * */protected static function getTabFields($id, &$component){ // build the rows $rows = ''; // get the form if (method_exists(__CLASS__, "getMemberForms") && ($form = self::getMemberForms($id, $component->element)) !== false && self::checkObject($form)) { // get the fields for this form if (($fields = JComponentHelper::getParams($component->element)->get('edit_fields', false)) !== false && self::checkObject($fields)) { // add the id field if the id was found (but hidden) if ($id > 0) { $form->setFieldAttribute('id', 'type', 'hidden'); $rows = $form->renderField('id'); } // add the rest of the fields foreach ($fields as $row) { if ($form->getField($row->field)) { $rows .= PHP_EOL . $form->renderField($row->field); } } } } return $rows;}
/** * get the tab table of links * * @param array $ids The target ids * @param object $item The target item details * @param object $component The target component details * @param string $view The view name * @param string $return The return value if found * * @return string * */protected static function getTabLinksTable($ids, &$item, &$comp, &$view, &$return){ // set some defaults $_return = '&ref=' . $view . '&refid=' . $item->id . '&return=' . urlencode(base64_encode('index.php?option=com_[[[component]]]&view=' . $view . '&layout=edit&id=' . $item->id . $return)); $rows = array(); // add a row to create a new item if (($create_button = self::getCreateButton('form', 'forms', $_return, $comp->element)) !== false && self::checkString($create_button)) { $rows[] = '<td data-column="'.$comp->name.'">' . $create_button . '</td>'; } // build the links foreach ($ids as $id) { $created = self::getVar('form', $id, 'id', 'created', '=', str_replace('com_', '', $comp->element)); $rows[] = '<td data-column="'.$comp->name.'">' . self::fancyDayTimeDate($created) . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . '</td>'; } // set the header $head = array($comp->name); // return the table return self::setSubformTable($head, $rows, $view . '_' . $comp->name);}
/** * save the dynamic values * * @param object $date The main Data * @param string $view The view name * * @return string * */public static function saveDynamicValues(&$data, $view = 'member'){ // get all the available component calling metods $class = new ReflectionClass('[[[Component]]]Helper'); $methods = array_filter($class->getMethods(ReflectionMethod::IS_PUBLIC), function ($method) { if (strpos($method->name, 'get') !== false && strpos($method->name, 'Availlable') !== false ) { return true; } return false; } ); // check if we have methods if (self::checkArray($methods)) { // get the app object $app = JFactory::getApplication(); // get the post object $post = JFactory::getApplication()->input->post; // get the user object $user = JFactory::getUser(); // get the database object $db = JFactory::getDBO(); // start looping the metods foreach ($methods as $method) { // get components $components = self::{$method->name}($data['type'], $data['account']); // check if we found components if (self::checkArray($components)) { // get assessment details foreach ($components as $_name => $comp) { // only save one to one components if (self::checkObject($comp) && isset($comp->element)) { $_component = $comp->element; $component = str_replace('com_', '', $_component); $Component = self::safeString($component, 'F'); $COMponent = self::safeString($component, 'W'); // get the posted date if there were any $_data = $post->get($component, array(), 'array'); // check if user are allowed to edit form values or create form values if (self::checkArray($_data)) { // make sure the ID is set if (!isset($_data['id']) || !is_numeric($_data['id'])) { $_data['id'] = 0; } // check if user may edit if ($_data['id'] > 0 && !$user->authorise('form.edit', $_component . '.form.' . (int) $_data['id'])) { // check edit own if (($created_by = self::getVar('form', $_data['id'], 'id', 'created_by', '=', $component)) === false || $created_by != $user->id || !$user->authorise('form.edit.own', $_component)) { $app->enqueueMessage(JText::sprintf('You do not have permission to edit %s, please contact your system administrator.', $COMponent, $_data['id']), 'warning'); continue; } } // check if user may create if ($_data['id'] == 0 && !$user->authorise('form.create', $_component)) { $app->enqueueMessage(JText::sprintf('You do not have permission to add data to %s, please contact your system administrator.', $COMponent), 'warning'); continue; } // make sure the member ID is set if view is member if ('member' === $view && !isset($_data[$view]) || !is_numeric($_data[$view]) || $_data[$view] == 0) { if ($_data['id'] > 0 && $data['id'] > 0) { // get the member ID if (($member = self::getVar('form', $_data['id'], 'id', $view, '=', $component)) === false || $member != $data['id']) { $app->enqueueMessage(JText::sprintf('Member ID mismatch, %s-%s could not be saved.', $COMponent, $_data['id']), 'error'); continue; } } elseif ($_data['id'] > 0) { // get the member ID if (($member = self::getVar('form', $_data['id'], 'id', $view, '=', $component)) === false || $member == 0) { $app->enqueueMessage(JText::sprintf('Member ID mismatch, %s-%s could not be saved.', $COMponent, $_data['id']), 'error'); continue; } } elseif ($data['id'] > 0) { // get the member ID $member = $data['id']; } else { $app->enqueueMessage(JText::sprintf('%s could not be saved, please try again. This could be due to the fact this the member ID was not ready.', $COMponent), 'error'); continue; } // set the member ID $_data[$view] = $member; } // get the model $model = self::getModel('form', JPATH_ADMINISTRATOR . '/components/' . $_component, $Component); // do we have the model if ($model) { // force other component path (TODO) will be an issue if forms and fields are the same \JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/' . $_component . '/models/forms'); \JForm::addFieldPath(JPATH_ADMINISTRATOR . '/components/' . $_component . '/models/fields'); // Validate the posted data. // Sometimes the form needs some posted data, such as for plugins and modules. $form = $model->getForm($_data, false); if (!$form) { $app->enqueueMessage($model->getError(), 'error'); continue; } // remove all fields not part of the allowed edit fields if (($fields = JComponentHelper::getParams($_component)->get('edit_fields', false)) !== false && self::checkObject($fields)) { // build a fields array bucket $fieldActive = array(); foreach ($fields as $row) { $fieldActive[$row->field] = $row->field; } // set the keep values $fieldActive['id'] = 'id'; $fieldActive['member'] = 'member'; $fieldActive['asset_id'] = 'asset_id'; $fieldActive['created'] = 'created'; $fieldActive['created_by'] = 'created_by'; $fieldActive['modified'] = 'modified'; $fieldActive['modified_by'] = 'modified_by'; $fieldActive['version'] = 'version'; $fieldActive['rules'] = 'rules'; // get the database columns of this table $columns = $db->getTableColumns("#__" . $component . "_form", false); // no make sure the fields that are not editable are removed (so can't be updated via this form) foreach(array_keys($columns) as $field) { if (!isset($fieldActive[$field])) { $form->removeField($field); } } } // Send an object which can be modified through the plugin event $objData = (object) $_data; $app->triggerEvent( 'onContentNormaliseRequestData', array($_component . '.form', $objData, $form) ); $_data = (array) $objData; // Test whether the data is valid. $validData = $model->validate($form, $_data); // Check for validation errors. if ($validData === false) { // Get the validation messages. $errors = $model->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof \Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } continue; } // Attempt to save the data. if (!$model->save($validData)) { $app->enqueueMessage(JText::sprintf('%s data could not be saved', $COMponent), 'error'); } } } } } } } }}