public function get($formFile, One_Model $model, array $options = array()) { $cx = new One_Context(); $formName = 'oneForm'; $action = ''; $task = 'edit'; $scheme = $model->getScheme(); if (isset($options['action'])) { $action = $options['action']; } if (isset($options['formName'])) { $formName = $options['formName']; } if (is_null($model->task) || trim($model->task) == '') { if (!is_null($cx->get('task'))) { $task = $cx->get('task'); } if (isset($options['task'])) { $task = $options['task']; } } else { $task = $model->task; } $form = One_Form_Factory::createForm($scheme, $formFile, NULL, $formName, $action); return $form; }
public function execute() { $this->id = $this->getVariable('id'); $fromJQGrid = intval($this->getVariable('fromJqgrid', 0)); if ($this->scheme instanceof One_Scheme) { $scheme = $this->scheme; $idattr = $this->scheme->getIdentityAttribute(); } else { $scheme = One_Repository::getScheme($this->scheme); $idattr = $scheme->getIdentityAttribute(); } $idat = $idattr->getName(); $schemeName = $scheme->getName(); $this->authorize($schemeName, $this->id); $factory = One_Repository::getFactory($schemeName); $model = $factory->selectOne($this->id); if (is_null($model)) { throw new One_Exception('Item could not be found'); } foreach ($scheme->get('attributes') as $attr) { if ($idat != $attr->getName() && !in_array($attr->getName(), array('id', 'oper'))) { $v = $this->getVariable($attr->getName(), null); if ($v !== null) { $an = $attr->getName(); $model->{$an} = $v; } } } $model->{$idat} = $this->id; $model->update(); $context = new One_Context(); $posted = $context->getPost(); // Check for posted reltional fields foreach ($posted as $field => $val) { if (false === strpos($field, ':')) { continue; } // Get the role and targetAttribute to change list($role, $rAttr) = explode(':', $field, 2); // Surround in try-catch block to avoid errors on non-existing relations try { // Only save one-to-many relations $rel = $model->getRelated($role); if (false === is_array($rel) && null !== $rel) { $tIdAttrName = $rel->getScheme()->getIdentityAttribute()->getName(); if ($rAttr == $tIdAttrName) { continue; } $rel->{$rAttr} = $val; $rel->update(); } } catch (Exception $e) { } } exit; }
/** * Apply filters to the queryscheme * * @param One_Query $q */ public function affect(One_Query $query) { $cx = new One_Context(); $term = $cx->get('term', ''); $field = $cx->get('field', $query->getScheme()->getIdentityAttribute()->getName()); if ('' != trim($term)) { $query->where($field, 'contains', $term); } else { $query->where('isFalse', 'literal', 'false'); } }
/** * Gets the variable passed to the method out of the context. * If the variable is not set, return the default value. * * @param string $key The required variable * @param mixed $default The default value that should be returned in case the required variable is not set * @return mixed */ protected function getVariable($key, $default = NULL) { $cx = new One_Context($this->options); $value = $cx->get($key); if (is_null($value)) { // TR20090604 Added the following checks in case that $this->options is an object if (is_array($this->options)) { $value = $this->options[$key]; } else { if (is_object($this->options)) { $value = $this->options->options[$key]; } } } return is_null($value) ? $default : $value; }
/** * Get the search value from the context * * @return mixed */ public function getValue() { $session = One_Repository::getSession(); if ($session->varExists('usedSearchOptions', 'one_search')) { $cx = new One_Context($session->get('usedSearchOptions', 'one_search')); } else { $cx = new One_Context(); } $name = $this->getName(); $value = $cx->get($name); if (!is_null($value)) { return trim($value); } else { return NULL; } }
/** * This method renders the search form and if needed fetches and show the search results * @see plugins/system/one/lib/action/One_Controller_Action#execute() */ public function execute() { $this->authorize($this->scheme, $model->id); $results = NULL; $model = One::make($this->scheme->getName()); $cx = new One_Context(); $session = One_Repository::getSession(); if (!is_null($cx->get('doSearch'))) { $session->remove('usedSearchOptions', 'one_search'); $results = $this->performSearch(); $session->set('usedSearchOptions', $this->options, 'one_search'); } else { if (!is_null($cx->get('doWeightSearch'))) { $session->remove('usedSearchOptions', 'one_search'); $results = $this->performWeightSearch(); $session->set('usedSearchOptions', $this->options, 'one_search'); } else { if (isset($this->options['savedSearch'])) { if ($session->varExists('usedSearchOptions', 'one_search')) { $this->options = $session->get('usedSearchOptions', 'one_search'); if (isset($this->options['doSearch'])) { $results = $this->performSearch(); } else { if (isset($this->options['doWeightSearch'])) { $results = $this->performWeightSearch(); } } } } else { $session->remove('usedSearchOptions', 'one_search'); $session->remove('results', 'one_search'); } } } $dom = One_Repository::createDom(); $this->view->setModel($model); $this->view->set('scheme', $this->scheme); $this->view->set('formfile', $this->searchform); $this->view->set('results', $results); $vForm = $this->view->show(); return $vForm; }
/** * Validate whether the form has been submitted correctly * * @param boolean $root * @param One_Form_Container_Abstract $container * @return boolean */ public function validate($root = true, $container = NULL) { $checksOut = true; $oc = new One_Context(); $scheme = $oc->get('scheme'); $schemes = One::meta('schemes'); if (in_array($scheme, $schemes)) { $scheme = One_Repository::getScheme($scheme); $use = $root ? $this : $container; foreach ($use->getContent() as $widget) { if ($widget instanceof One_Form_Widget_Abstract) { $attr = $scheme->getAttribute($widget->getName()); if ($attr instanceof One_Scheme_Attribute) { $type = strtolower(str_replace('One_Scheme_Attribute_Type', '', get_class($attr->getType()))); $widget->setCfg('type', $type); } if (!$widget->validate()) { $checksOut = false; $this->_errors[$widget->getName()]['error'] = $widget->getErrors(); $this->_errors[$widget->getName()]['label'] = $widget->getLabel(); } } else { if ($widget instanceof One_Form_Container_Abstract) { if (!self::validate(false, $widget)) { $checksOut = false; } } } } return $checksOut; } else { return false; } }
/** * Get the value for the widget * * @return mixed */ public function getValue($model) { if (!$model) { return null; } if ($this->getCfg('js')) { return parent::getValue($model); } else { $oc = new One_Context(); $day = $oc->get($this->getName() . 'Day'); $month = $oc->get($this->getName() . 'Month'); $year = $oc->get($this->getName() . 'Year'); if ($day == 0 || $month == 0 || $year == 0) { return '0000-00-00'; } else { return $year . '-' . $month . '-' . $day; } } }
/** * Creates a list of items according to the given options ( and filter parameters ) * * @return string The list of the items */ public function execute() { $this->authorize(); $cx = new One_Context(); $session = new One_Session(); $schemeName = $this->scheme->getName(); $idAttr = $this->scheme->getIdentityAttribute()->getName(); $columns = $this->getColumns(); // determine limit $defaultlimit = !is_null($this->_limit) ? $this->_limit : 20; if (!is_null($session->get('limit', $schemeName . '--list'))) { $defaultlimit = $session->get('limit', $schemeName . '--list'); } $session->set('limit', intval($cx->get('limit', $defaultlimit)), $schemeName . '--list'); // determine page you're on if (intval($session->get('limit', $schemeName . '--list')) > 0) { $defaultStart = 1; if (!is_null($session->get('start', $schemeName . '--list'))) { $defaultStart = $session->get('start', $schemeName . '--list'); } $session->set('start', intval($cx->get('start', $defaultStart)), $schemeName . '--list'); } else { $session->set('start', 1, $schemeName . '--list'); } // determine sortorder and sortorder direction $defaultSortorder = !is_null($this->_sort) ? $this->_sort : $idAttr; $defaultSortorderDir = !is_null($this->_sortOrder) ? $this->_sortOrder : 'asc'; if (!is_null($session->get('sortorder', $schemeName . '--list'))) { $defaultSortorder = $session->get('sortorder', $schemeName . '--list'); } if (!is_null($session->get('sortorderDir', $schemeName . '--list'))) { $defaultSortorderDir = $session->get('sortorderDir', $schemeName . '--list'); } $session->set('sortorder', $cx->get('sortorder', $defaultSortorder), $schemeName . '--list'); $session->set('sortorderDir', $cx->get('sortorderDir', $defaultSortorderDir), $schemeName . '--list'); $data = $this->getList(); $results = $data['results']; $rowcount = $data['count']; $limit = $session->get('limit', $schemeName . '--list'); // If you're page is higher than the available rows, default the page to 1 // $start = ($session->get('limit', $schemeName . '--list') * $session->get('start', $schemeName . '--list')) <= $rowcount ? $session->get('start', $schemeName . '--list') : 1; if ($session->get('limit', $schemeName . '--list') > 0) { $start = $session->get('start', $schemeName . '--list') <= ceil($rowcount / $session->get('limit', $schemeName . '--list')) ? $session->get('start', $schemeName . '--list') : 1; $session->set('start', $start, $schemeName . '--list'); } else { $start = 1; $session->set('start', 1, $schemeName . '--list'); } $sortorder = $session->get('sortorder', $schemeName . '--list'); $sortorderDir = $session->get('sortorderDir', $schemeName . '--list'); $counter = ($start - 1) * $limit + 1; $pages = $limit > 0 ? ceil($rowcount / $limit) : 1; $this->view->set('scheme', $this->scheme); $this->view->set('columns', $columns); $this->view->set('filters', $this->_filters); $this->view->set('rowcount', $rowcount); $this->view->set('limit', $limit); $this->view->set('start', $start); $this->view->set('sortorder', $sortorder); $this->view->set('sortorderDir', $sortorderDir); $this->view->set('counter', $counter); $this->view->set('pages', $pages); $this->view->setModel($results); return $this->view->show(); }