Exemplo n.º 1
0
 /**
  * Get the list of instances for this action.
  *
  * @return mixed
  */
 protected function getData()
 {
     $schemeName = $this->scheme;
     if ($this->scheme instanceof One_Scheme) {
         $schemeName = $this->scheme->getName();
     }
     // First, create the query
     $factory = One_Repository::getFactory($schemeName);
     $query = $factory->selectQuery($this->scheme);
     // Set the order if needed
     $orderField = $this->getVariable('order', '');
     if (!in_array(substr($orderField, -1, 1), array('-', '+'))) {
         if (in_array($this->getVariable('orderdirection', '+'), array('-', 'desc'))) {
             $orderField .= '-';
         } else {
             $orderField .= '+';
         }
     }
     $query->setOrder($orderField);
     // Set paging variables
     $start = $this->getVariable('start', 0);
     $cnt = $this->getVariable('count', 0);
     $query->setLimit($cnt, $start);
     // Apply the filters
     $this->processQueryConditions($query);
     // Execute the query
     $results = $query->execute();
     return $results;
 }
Exemplo n.º 2
0
 public function execute()
 {
     //$this->id = $this->getVariable('id');
     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);
     $model = $factory->getInstance($schemeName);
     if (is_null($model)) {
         throw new One_Exception('Item could not be found');
     }
     foreach ($scheme->get('attributes') as $attr) {
         $v = $this->getVariable($attr->getName(), null);
         if ($v !== null) {
             $an = $attr->getName();
             $model->{$an} = $v;
         }
     }
     //$model->$idat = $this->id;
     $model->insert();
     exit;
 }
Exemplo n.º 3
0
 /**
  * This method composes the form and returns the output
  *
  * @return string Output of the form
  */
 public function execute()
 {
     // Fetch the model needed for this form. We will need it because authorization can depend on the model itself
     if ($this->id) {
         $factory = One_Repository::getFactory($this->scheme->getName());
         $model = $factory->selectOne($this->id);
     } else {
         $model = One::make($this->scheme->getName());
     }
     if (is_null($model)) {
         throw new One_Exception('Could not generate a form for scheme "' . $this->scheme->getName() . '" with id ' . $this->id);
     }
     $this->authorize($this->scheme->getName(), $model->id);
     $session = One_Repository::getSession();
     $formFile = $this->getVariable('formFile', 'form');
     $form = One_Form_Factory::createForm($this->scheme, $formFile, $this->getVariable('lang'), 'oneForm', '');
     // Create a DOM and render the form in it
     $dom = One_Repository::createDom();
     $form->render($model, $dom);
     //    print_r($dom);
     $this->view->setModel($model);
     $this->view->set('scheme', $this->scheme);
     $this->view->set('form', $form);
     $this->view->set('dom', $dom);
     $this->view->set('errors', $session->get('errors', 'OneFormErrors'));
     $vForm = $this->view->show();
     $session->remove('errors', 'OneFormErrors');
     $session->remove('posted', 'OneFormErrors');
     return $vForm;
 }
Exemplo n.º 4
0
 function execute(&$data, &$parent)
 {
     $output = '';
     $selected = NULL;
     $parts = explode(':', trim($this->data), 2);
     if (count($parts) < 2) {
         return '';
     }
     $scheme = One_Repository::getScheme($parts[0]);
     $factory = One_Repository::getFactory($parts[0]);
     $requested = $parts[1];
     $behaviorOptions = $scheme->get('behaviorOptions.linkalias');
     if (is_null($behaviorOptions)) {
         $selected = $factory->selectOne($requested);
         if (is_null($selected)) {
             return '';
         }
         $output = $scheme->title() . ' ( ' . $requested . ' )';
     } else {
         if (isset($behaviorOptions['lookup'])) {
             $query = $factory->selectQuery();
             $query->where($behaviorOptions['lookup'], 'eq', $requested);
             $results = $query->result();
             if (count($results) == 0) {
                 return '';
             } else {
                 $selected = $results[0];
             }
         } else {
             $selected = $factory->selectOne($requested);
             if (is_null($selected)) {
                 return '';
             }
         }
         if (isset($behaviorOptions['show'])) {
             $shown = $behaviorOptions['show'];
             $output = $selected->{$shown};
         } else {
             $output = $scheme->title() . ' ( ' . $requested . ' )';
         }
     }
     if (trim($output) == '' || is_null($selected)) {
         return '';
     } else {
         $idAttr = $scheme->getIdentityAttribute()->getName();
         $task = 'detail';
         $view = 'detail';
         if (isset($behaviorOptions['task'])) {
             $task = $behaviorOptions['task'];
         }
         if (isset($behaviorOptions['view'])) {
             $view = $behaviorOptions['view'];
         }
         $link = JRoute::_('index.php?option=com_one&scheme=' . $scheme->getName() . '&task=' . $task . '&view=' . $view . '&id=' . $selected->{$idAttr});
         return '<a href="' . $link . '">' . $output . '</a>';
     }
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
 /**
  * This method returns the detail view of the currently chosen item
  *
  * @return string The detail view of the currently chosen item
  */
 public function execute()
 {
     $this->authorize($this->scheme->getName(), $this->id);
     $factory = One_Repository::getFactory($this->scheme->getName());
     $model = $factory->selectOne($this->id);
     if (is_null($model)) {
         throw new One_Exception('Item could not be found');
     }
     $this->view->setModel($model);
     return $this->view->show();
 }
Exemplo n.º 7
0
 /**
  * This method will return a feed for the chosen scheme
  *
  * @return string The feed string
  */
 public function execute()
 {
     $this->authorize();
     $factory = One_Repository::getFactory($this->scheme->getName());
     $q = $factory->selectQuery();
     $q->setOrder($this->getVariable('order', ''));
     $q->setLimit($this->getVariable('count', 0), $this->getVariable('start', 0));
     $this->processQueryConditions($q);
     $results = $q->result(false);
     $this->view->set('scheme', $this->scheme);
     $this->view->setModel($results);
     echo $this->view->show();
     exit;
     // exit here because nothing else should be outputted after the feed
 }
Exemplo n.º 8
0
 protected function getData()
 {
     $schemeName = $this->scheme;
     if ($this->scheme instanceof One_Scheme) {
         $schemeName = $this->scheme->getName();
     }
     $factory = One_Repository::getFactory($schemeName);
     $query = $factory->selectQuery($this->scheme);
     $ids = explode(',', $this->options['listFormData']);
     $idAttr = One_Repository::getScheme($schemeName)->getIdentityAttribute()->getName();
     $query->where($idAttr, 'in', $ids);
     $this->processQueryConditions($query);
     $results = $query->execute();
     return $results;
 }
Exemplo n.º 9
0
 /**
  * This method removes the chosen item and redirects to the proper page
  */
 public function execute()
 {
     $factory = One_Repository::getFactory($this->scheme->getName());
     foreach ($this->id as $id) {
         $this->authorize($this->scheme->getName(), $id);
         $model = $factory->selectOne($id);
         if (is_null($model)) {
             throw new One_Exception('Item could not be found');
         }
         $model->delete();
     }
     $redirects = One_Controller_Flow::getInstance($this->scheme)->getRedirects();
     $redirect = $redirects['default'];
     if (isset($redirects['remove'])) {
         $redirect = $redirects['remove'];
     }
     $redirect = $this->replaceOtherVariables($redirect);
     $this->getController()->setRedirect($redirect);
 }
Exemplo n.º 10
0
 /**
  * This method copies the current model into a new item
  */
 public function execute()
 {
     if (!$this->id) {
         throw new One_Exception('Can not copy a non existing item');
     } else {
         $factory = One_Repository::getFactory($this->scheme->getName());
         $model = $factory->selectOne($this->id);
         if (is_null($model)) {
             throw new One_Exception('Can not copy a non existing item');
         }
     }
     $idAttrName = $model->getScheme()->getIdentityAttribute()->getName();
     $this->authorize($this->scheme->getName(), $model->{$idAttrName});
     // Get an instance of the current model
     $copy = clone $model;
     // Not really necessary as when the ID-attribute equals NULL it will treat the model as new
     //		$attributes = $this->scheme->getAttributes();
     //		foreach($attributes as $attribute)
     //		{
     //			$attr = $attribute->getName();
     //			$copy->$attr = $model->$attr;
     //		}
     $copy->{$idAttrName} = NULL;
     $copy->insert();
     // create the copy
     $flow = One_Controller_Flow::getInstance($this->scheme)->getRedirects();
     $todo = is_null($this->getVariable('action')) ? $this->getVariable('task') : $this->getVariable('action');
     $redirect = $flow['default'];
     if (isset($flow['copy'])) {
         $redirect = $flow['copy'];
     }
     if (isset($redirect['id']) && strtoupper(trim($redirect['id'])) == '::ID::') {
         $redirect['id'] = $copy->{$idAttrName};
     }
     $redirect = $this->replaceOtherVariables($redirect);
     $this->controller->setRedirect($redirect);
 }
Exemplo n.º 11
0
 protected function getTotalNumberRows()
 {
     $factory = One_Repository::getFactory($this->scheme->getName());
     return $factory->selectCount($this->scheme);
 }
Exemplo n.º 12
0
 public function getInstance($schemeName)
 {
     $fac = One_Repository::getFactory($schemeName);
     $instance = $fac->getInstance();
     return $instance;
 }
Exemplo n.º 13
0
 /**
  * This method validates a submitted form and returns to the proper page according to whether the submission
  * contained errors or whether the form was saved or applied
  */
 public function execute()
 {
     $session = One_Repository::getSession();
     $isNew = false;
     if ($this->id) {
         // update existing
         $factory = One_Repository::getFactory($this->scheme->getName());
         $model = $factory->selectOne($this->id);
         if (is_null($model) && !$factory->getScheme()->getIdentityAttribute()->isAutoInc()) {
             $model = One::make($this->scheme->getName());
             $isNew = true;
         }
     } else {
         $model = One::make($this->scheme->getName());
     }
     $idAttrName = $model->getScheme()->getIdentityAttribute()->getName();
     $this->authorize($this->scheme->getName(), $model->{$idAttrName});
     $formFile = $this->getVariable('formFile', 'form');
     $form = One_Form_Factory::createForm($this->scheme, $formFile, $this->getVariable('lang'), 'oneForm', '');
     $flow = One_Controller_Flow::getInstance($this->scheme)->getRedirects();
     $noErrors = $form->validate();
     if ($noErrors || is_array($noErrors) && count($noErrors) == 0) {
         $form->bindModel($model);
         if ($this->id && !$isNew) {
             $model->update();
             $id = $this->id;
         } else {
             $model->insert();
             $idAttr = $this->scheme->getIdentityAttribute()->getName();
             $id = $model->{$idAttr};
         }
         $this->model = $model;
         // handle redirects
         // @TODO this code can use some cleanup
         $redirects = array_merge($flow, $form->getRedirects());
         $todo = is_null($this->getVariable('action')) ? $this->getVariable('task') : $this->getVariable('action');
         if (isset($this->options['flow'])) {
             $todo = $this->options['flow'];
         }
         $redirect = $redirects['default'];
         if (isset($redirects[$todo])) {
             $redirect = $redirects[$todo];
         }
         if (isset($redirect['id']) && strtoupper(trim($redirect['id'])) == '::ID::') {
             $redirect['id'] = $model->{$idAttrName};
         }
         $redirect = $this->replaceOtherVariables($redirect);
         $this->controller->setRedirect($redirect);
     } else {
         $errors = base64_encode(serialize($form->getErrors()));
         $session->set('executedReturn', $model, 'executedForm');
         $session->set('errors', $form->getErrors(), 'OneFormErrors');
         $session->set('posted', $_REQUEST, 'OneFormErrors');
         $id = $this->id;
         $toView = 'edit';
         if (!is_null($this->getVariable('returnToOne'))) {
             parse_str(base64_decode($this->getVariable('returnToOne')), $returnVals);
             $this->controller->setRedirect($returnVals);
         } else {
             $redirects = array_merge($flow, $form->getRedirects());
             $todo = 'default';
             if (isset($this->options['flowerror'])) {
                 $todo = $this->options['flowerror'];
             } elseif (isset($redirects['formerror'])) {
                 $todo = 'formerror';
             }
             $redirect = $redirects[$todo];
             if (isset($redirect['id']) && strtoupper(trim($redirect['id'])) == '::ID::') {
                 $redirect['id'] = $model->{$idAttrName};
             }
             $redirect = $this->replaceOtherVariables($redirect);
             $this->controller->setRedirect($redirect);
         }
         return false;
     }
 }
Exemplo n.º 14
0
 /**
  * Gets all the columns that should be shown in the list
  *
  * @return array Array of all columns in the form of object with extra data
  */
 private function getColumns()
 {
     $session = One_Repository::getSession();
     $exists = true;
     $filename = One_Locator::locateUsing('list.xml', ONE_LOCATOR_ROOTPATTERN . 'views/' . One_Config::get('app.name') . '/' . $this->scheme->getName() . '/');
     if ($filename === null) {
         $exists = false;
     }
     if ($exists) {
         $xml = @simplexml_load_file($filename);
     }
     if ($exists && $xml) {
         // JL06JAN2009 - if no sorting was clicked, check if the default sort column was set
         // in the xml file
         $xmlarray_defs = xmlpm($xml, "/view/columns");
         $sort = (string) $xmlarray_defs[0]->attributes()->sort;
         $limit = (string) $xmlarray_defs[0]->attributes()->limit;
         if ('' != trim($sort)) {
             preg_match('/^([^\\+\\-]+)(\\+|\\-)?$/i', $sort, $sortMatch);
             $this->_sortOrder = 'asc';
             $this->_sort = $sortMatch[1];
             if (isset($sortMatch[2]) && $sortMatch[2] == '-') {
                 $this->_sortOrder = 'desc';
             }
         }
         if (0 < abs(intval($limit))) {
             $this->_limit = abs(intval($limit));
         }
         $xmlarray = $xmlarray_defs[0]->column;
         $this->_columns = array();
         foreach ($xmlarray as $xmlpart) {
             $tmp = new stdClass();
             $name = '';
             $setFilter = false;
             $filterType = 'text';
             $filterOptions = array();
             $operator = 'contains';
             foreach ($xmlpart->attributes() as $key => $val) {
                 switch (strtolower($key)) {
                     case 'name':
                         $tmp->name = (string) $val;
                         break;
                     case 'label':
                         $tmp->label = (string) $val;
                         break;
                     case 'filter':
                         if ($val == 1) {
                             $setFilter = true;
                         }
                         break;
                     case 'filtertype':
                         if (in_array(strtolower($val), array('dropdown', 'text', 'daterange'))) {
                             $filterType = strtolower($val);
                         }
                         break;
                     case 'filteroptions':
                         $options = explode(';', $val);
                         foreach ($options as $option) {
                             $parts = explode('=', $option, 2);
                             $filterOptions[$parts[0]] = $parts[1];
                         }
                     case 'operator':
                         if (in_array((string) $val, $this->_operators)) {
                             $operator = (string) $val;
                         }
                     default:
                         $tmp->{$key} = (string) $val;
                 }
             }
             if ($filterType == 'dropdown' && count($filterOptions) == 0 && trim($tmp->name) != '') {
                 preg_match('/([^:]+)((:)(.+))?/', $tmp->name, $matches);
                 if (!is_null($matches[4])) {
                     $link = $this->scheme->getLink($matches[1]);
                     $target = One_Repository::getScheme($link->getTarget());
                     $tAtt = $matches[4];
                     $tFac = One_Repository::getFactory($target->getName());
                     $tQ = $tFac->selectQuery();
                     $tQ->setSelect(array($tAtt));
                     $tQ->setOrder(array($matches[4] . '+'));
                     $options = $tQ->execute(false);
                     foreach ($options as $option) {
                         $filterOptions[$option->{$tAtt}] = $option->{$tAtt};
                     }
                 }
             }
             //PD16SEP09: if no name is given, interpret the body of the tag as CDATA containing nanoScript
             // TR20100408: change this to only set the name as the label if no name is given.
             if (!isset($tmp->name)) {
                 $tmp->name = $tmp->label;
             }
             //filter operator defaults to contains
             if (!isset($tmp->name)) {
                 $tmp->operator = 'contains';
             }
             // TR20100408: change this to interpret as nanoscript if a value is passed to the tag
             if (trim((string) $xmlpart) != '') {
                 $tmp->nScript = (string) $xmlpart;
             }
             $this->_columns[$tmp->name] = $tmp;
             if ($setFilter) {
                 if ($filterType != 'daterange') {
                     $value = JRequest::getVar('s' . $tmp->name, NULL);
                 } else {
                     $value = array(JRequest::getVar('s' . $tmp->name . 'Start', NULL), JRequest::getVar('s' . $tmp->name . 'End', NULL));
                 }
                 if (is_null($value)) {
                     $value = $session->get($tmp->name, $this->scheme->getName() . '--list');
                 }
                 $session->set($tmp->name, $value, $this->scheme->getName() . '--list');
                 $this->_filters[$tmp->name] = array('label' => $tmp->label, 'value' => $value, 'type' => $filterType, 'options' => $filterOptions, 'operator' => $operator);
             }
         }
     }
     if (is_null($this->_columns)) {
         $columns = $this->scheme->get('attributes');
         $this->_columns = array();
         foreach ($columns as $name => $column) {
             $tmp = new stdClass();
             $tmp->label = $column->getName();
             $tmp->name = $column->getName();
             // TR20100317 used to be $column->column() but should not be used anymore
             $this->_columns[$tmp->name] = $tmp;
         }
     }
     return $this->_columns;
 }