示例#1
0
 /**
  * One_Renderer_Interspire renders an instance of One_Query into an understandable "query" for Interspire
  * @param One_Query $query
  * @return array
  */
 public function render(One_Query $query)
 {
     $this->query = $query;
     $this->scheme = $this->query->getScheme();
     $resources = $this->scheme->getResources();
     // add possible filters to the query
     if (isset($resources['filter'])) {
         $filters = explode(';', $resources['filter']);
         if (count($filters) > 0) {
             foreach ($filters as $filterName) {
                 if ($filterName != '') {
                     $filter = One_Repository::getFilter($filterName, $query->getScheme()->name());
                     $filter->affect($query);
                 }
             }
         }
     }
     $details = array();
     // For interspire, you can basicly only use the where clauses and even still only certain fields
     // The validation of the fields must be done in the functions themselves because they are too random
     // get where clauses
     $whereClauses = $query->getWhereClauses();
     if (!is_null($whereClauses)) {
         $details = $this->whereClauses($whereClauses);
     }
     $order = $query->getOrder();
     if (!is_null($query->getOrder())) {
         $details['SortInfo'] = $this->createOrder();
     }
     return $details;
 }
示例#2
0
 public static function slimSetup(\Slim\Slim &$slim, One_Scheme $scheme)
 {
     //TODO: read specs from behaviour options or from a file
     $opt = $scheme->get('behaviorOptions.restable');
     $route = $opt['route'];
     // retrieve
     $slim->get("/{$route}", function () use($scheme) {
         One_Controller_Rest::restGetAll($scheme);
     });
     // retrieve one
     $slim->get("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) {
         One_Controller_Rest::restGet($scheme, $idOrAlias);
     });
     // create new
     $slim->post("/{$route}", function () use($scheme) {
         One_Controller_Rest::restPost($scheme);
     });
     // update existing
     $slim->put("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) {
         One_Controller_Rest::restPut($scheme, $idOrAlias);
     });
     // delete existing
     $slim->delete("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) {
         One_Controller_Rest::restDelete($scheme, $idOrAlias);
     });
 }
示例#3
0
 /**
  * Get an instance of One_Controller_Flow for the proper scheme
  *
  * @param One_Scheme $scheme
  * @param array $redirects
  * @return One_Controller_Flow
  */
 public static function getInstance(One_Scheme $scheme, array $redirects = array())
 {
     if (!array_key_exists(One_Config::get('app.name'), self::$_flowCache) || !array_key_exists($scheme->getName(), self::$_flowCache[One_Config::get('app.name')])) {
         self::$_flowCache[One_Config::get('app.name')][$scheme->getName()] = new One_Controller_Flow($scheme, $redirects);
     }
     return self::$_flowCache[One_Config::get('app.name')][$scheme->getName()];
 }
示例#4
0
 /**
  *  find out what the scheme's FK field for this relationship is called.
  *  By default, this is formed by
  *      ROLENAME_NAMEOFTARGETIDCOLUMN,
  *  but this can be overridden by the FK setting in the meta description.
  *
  * @param One_Relation_Adapter $adapter
  * @param One_Scheme $source
  * @param One_Relation_Adapter $backlink
  * @return string
  */
 public function remoteFK(One_Relation_Adapter $adapter, One_Scheme $source, One_Relation_Adapter $backlink)
 {
     if ($adapter->meta['fk:remote']) {
         return $adapter->meta['fk:remote'];
     }
     $column = $source->getIdentityAttribute()->getName();
     return $backlink->getName() . "_" . $column;
 }
示例#5
0
 /**
  * Adds the fields that are searchable to the scheme on loading of the scheme
  *
  * @param One_Scheme $scheme
  */
 public function onLoadScheme($scheme)
 {
     $options = $scheme->get('behaviorOptions.searchable');
     if (is_null($options['search']) || trim($options['search']) == '') {
         throw new One_Exception('When defining a searchable behavior, you must define an attribute.');
     }
     $scheme->oneSearchableFields = explode(':', $options['search']);
 }
示例#6
0
 /**
  * This will show the identity-attribute when the model is loaded
  *
  * @param One_Scheme $scheme
  * @param One_Model $model
  */
 public function afterLoadModel(One_Scheme $scheme, One_Model $model)
 {
     echo '<div style="display: inline; padding: 1px 3px;background-color: darkgreen;margin: 1px 2px;border: 1px solid green;">';
     echo $scheme->getName();
     echo ':';
     $at = $scheme->getIdentityAttribute()->getName();
     echo $model->{$at};
     echo '</div>';
 }
示例#7
0
 /**
  * Returns the class that overrides the default One_Model
  *
  * @param One_Scheme $scheme
  * @return One_Model
  */
 public function onCreateModel(One_Scheme $scheme)
 {
     $options = $scheme->get('behaviorOptions.class');
     $className = $options['className'];
     if (!$className) {
         $className = 'One_Model_' . ucFirst($scheme->getName());
     }
     return new $className($scheme);
 }
示例#8
0
 /**
  * Parse the flow definition and return an array with all redirects
  * @param One_Scheme $scheme
  * @return array
  */
 public static function load(One_Scheme $scheme)
 {
     $defaultFile = self::getFlowFile('default');
     $file = self::getFlowFile($scheme->getName());
     $redirects = self::parseFile($defaultFile, true);
     if ($file !== null) {
         $redirects = array_merge($redirects, self::parseFile($file));
     }
     foreach ($redirects as $key => $parts) {
         if (isset($parts['scheme']) && strtoupper(trim($parts['scheme'])) == '::SCHEME::') {
             $redirects[$key]['scheme'] = $scheme->getName();
         }
     }
     return $redirects;
 }
示例#9
0
文件: rest.php 项目: pdelbar/onethree
 /**
  * Convert an array to an instance of the specified scheme
  *
  * @param One_Scheme $scheme
  * @param array $row
  * @return One_Model
  */
 private function &arrayToInstance(&$scheme, &$row)
 {
     // check the scheme cache
     $idAttribute = $scheme->getIdentityAttribute();
     $id = $row[$idAttribute->getName()];
     $cached = One_Model_IdentityMap::find($scheme->getName(), $id);
     if ($cached) {
         return $cached;
     }
     // not found : create a new instance
     // @TODO: use a specific class specified in the scheme
     $model = One::make($scheme->getName());
     $model->fromArray($row);
     // fire afterLoad event for model
     $model->afterLoad();
     One_Model_IdentityMap::add($model);
     return $model;
 }
示例#10
0
 /**
  * Convert all the excessive data into a json string
  *
  * @param One_Scheme $scheme
  * @param One_Model $model
  */
 private function flexToJson(One_Scheme $scheme, One_Model $model)
 {
     $ignoreAttributes = array_merge(self::$_ignoreAttributes, $scheme->getForeignKeys());
     // ignore all local foreign key attributes as well
     $bOptions = $scheme->get('behaviorOptions.' . strtolower($this->getName()));
     $flexfield = $bOptions['flexfield'];
     unset($model->{$flexfield});
     // Flexfields should not be set manually
     //		// only auto-set the flexfield, if it's not in the modified fields
     //		// if it is set in the modified fields, then the flex field was intentionally set manually
     //		if(!array_key_exists($flexfield, $model->getModified()))
     //		{
     $data = $model->toArray();
     $attributes = $scheme->get('attributes');
     foreach ($attributes as $attr) {
         unset($data[$attr->getName()]);
     }
     foreach ($ignoreAttributes as $ignore) {
         unset($data[$ignore]);
     }
     $model->{$flexfield} = json_encode($data);
     //		}
 }
示例#11
0
 /**
  * Deletes children of a certain model on deletion of the parent model
  *
  * @param One_Scheme $scheme
  * @param One_Model $model
  */
 public function beforeDeleteModel(One_Scheme $scheme, One_Model $model)
 {
     $options = $scheme->get('behaviorOptions.deletechildren');
     $dependent = explode(';', $options['dependent']);
     $cascade = explode(';', $options['cascade']);
     $dependentLeft = array();
     if (count($dependent) > 0) {
         foreach ($dependent as $depends) {
             if (trim($depends) != '') {
                 $related = $model->getRelated(trim($depends));
                 if (count($related) > 0) {
                     $dependentLeft[] = trim($depends);
                     break;
                 }
             }
         }
     }
     if (count($dependentLeft) > 0) {
         throw new One_Exception('You can not delete this item untill all items of "' . implode('", "', $dependentLeft) . '" have been deleted.');
         return false;
     } else {
         $tbds = array_merge($dependent, $cascade);
         if (count($tbds) > 0) {
             foreach ($tbds as $tbd) {
                 if (trim($tbd) != '') {
                     $related = $model->getRelated($tbd);
                     if (count($related) > 0) {
                         foreach ($related as $relation) {
                             $relation->delete();
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
示例#12
0
 /**
  * When the model is loaded, add a slug-field to the model that is composed of the specified fields
  *
  * @param One_Scheme $scheme
  * @param One_Model $model
  */
 public function afterLoadModel(One_Scheme $scheme, One_Model $model)
 {
     if (null !== $scheme->getAttribute('slug')) {
         // don't create the slug if the attribute "slug" actually exists
         return;
     }
     $options = $scheme->get('behaviorOptions.slug');
     $createFrom = $options['createFrom'];
     $parts = preg_split('/\\+/', $createFrom);
     $mangled = array();
     foreach ($parts as $part) {
         if (preg_match('/^([a-z0-9\\_\\-]+):([a-z0-9\\_\\-]+)$/', $part, $matches) > 0) {
             $scheme = $model->getScheme();
             $link = $scheme->getLink($matches[1]);
             if (!is_null($link)) {
                 if ($link->getAdapterType() == 'manytoone') {
                     $related = $model->getRelated($matches[1]);
                     if (!is_null($related)) {
                         $targetPart = $matches[2];
                         $mangle = !is_null($related->{$targetPart}) ? trim($this->mangle($related->{$targetPart})) : NULL;
                         if (!is_null($mangle)) {
                             $mangled[] = $mangle;
                         }
                     }
                 }
             }
         } else {
             $mangle = !is_null($model->{$part}) ? trim($this->mangle($model->{$part})) : NULL;
             if (!is_null($mangle)) {
                 $mangled[] = $mangle;
             }
         }
     }
     if (count($mangled) > 0) {
         $model->slug = implode('_', $mangled);
     }
 }
示例#13
0
 /**
  * Creates a link from one scheme to another
  *
  * @param One_Scheme $scheme
  * @param One_Relation_Role $role
  * @param One_Relation_Role $otherRole
  */
 public function createLink(One_Scheme $scheme, One_Relation_Role $targetRole, One_Relation_Role $schemeRole)
 {
     $params = array();
     $params['id'] = $this->name;
     $params['name'] = $targetRole->name;
     $params['target'] = $targetRole->schemeName;
     $params['style'] = $schemeRole->cardinality . 'To' . ucfirst($targetRole->cardinality);
     // insert fk information
     if ($schemeRole->cardinality == "many") {
         $params['fk:local'] = $schemeRole->meta['fk'];
     }
     if ($targetRole->cardinality == "many") {
         $params['fk:remote'] = $targetRole->meta['fk'];
     }
     //PD 22OCT08: remember that this is a hybrid target
     if ($schemeRole->schemeName == "*") {
         $params['hybrid'] = $schemeRole->name;
     }
     $meta = array_merge($this->meta, $params);
     $lnk = new One_Relation_Adapter($meta);
     $scheme->addLink($lnk);
 }
示例#14
0
 /**
  * Get the table used for the scheme
  *
  * @param One_Scheme $scheme
  * @return string Table name used for the scheme
  */
 protected function getTable(One_Scheme $scheme)
 {
     $resources = $scheme->getResources();
     if (isset($resources['table'])) {
         return $resources['table'];
     } else {
         throw new One_Exception('A table must be defined for the scheme "' . $scheme->getName() . '"');
     }
 }
示例#15
0
 /**
  * Return alias for specified options for a specified scheme
  * @param One_Scheme $scheme
  * @param array $options
  * @return array Return array if found, NULL if no match found
  */
 public static function getAliasForOptions(One_Scheme $scheme, $options)
 {
     if (!array_key_exists($scheme->getName(), self::$_optionsHash)) {
         return NULL;
     }
     if (!isset($options['task']) || !isset($options['view'])) {
         return NULL;
     }
     $supposedHash = md5($scheme->getName() . $options['task'] . $options['view']);
     if (array_key_exists($supposedHash, self::$_optionsHash[$scheme->getName()])) {
         return self::$_optionsHash[$scheme->getName()][$supposedHash];
     } else {
         // modified, now take a look at standard actions
         $actionClass = 'One_Controller_Action_' . ucfirst($options['task']);
         if (class_exists($actionClass)) {
             return $actionClass::getStandardRouting($options);
         } else {
             return NULL;
         }
     }
 }
示例#16
0
 static function addObligatedWidgets(One_Form_Container_Form $form, One_Scheme $scheme)
 {
     // the form should always have a (hidden) widget with the value of the identityAttribute unless there is no identityAttribute
     if (!is_null($scheme->getIdentityAttribute()) && !$form->hasWidget($scheme->getIdentityAttribute()->getName())) {
         $form->addWidget(new One_Form_Widget_Scalar_Hidden($scheme->getIdentityAttribute()->getName(), $scheme->getIdentityAttribute()->getName(), NULL, array('one' => 'one', 'language' => strtolower(One_Config::get('app.language')))));
     }
     if (!$form->hasWidget('task')) {
         $form->addWidget(new One_Form_Widget_Scalar_Hidden('task', 'task', NULL, array('default' => 'edit', 'one' => 'one', 'language' => strtolower(One_Config::get('app.language')))));
     }
     if (!$form->hasWidget('scheme')) {
         $form->addWidget(new One_Form_Widget_Scalar_Hidden('scheme', 'scheme', NULL, array('default' => $scheme->getName(), 'one' => 'one', 'language' => strtolower(One_Config::get('app.language')))));
     }
 }
示例#17
0
文件: rest.php 项目: pdelbar/onethree
 /**
  * @param One_Scheme $scheme
  * @param $idOrAlias
  *
  * DELETE schemename/ID
  * Delete an item
  */
 public static function restDelete(One_Scheme $scheme, $idOrAlias)
 {
     try {
         $model = One_Repository::selectOne($scheme->getName(), $idOrAlias);
         if ($model === null) {
             throw new One_Exception_Rest_404('Cannot locate instance of scheme ' . $scheme->getName() . ' identified by ' . $idOrAlias);
         }
         $model->delete();
         $this->slim->response()->status(200);
         echo 'OK';
     } catch (One_Exception_Rest_404 $e) {
         // return 404 server error
         $this->slim->response()->status(404);
         echo '{}';
     } catch (Exception $e) {
         $this->slim->response()->status(400);
         $this->slim->response()->header('X-Status-Reason', $e->getMessage());
     }
 }
示例#18
0
 /**
  * Unset the attribute so that it is never inserted or updated
  * @param One_Scheme $scheme
  * @param One_Model $model
  */
 protected function unsetAttribute(One_Scheme $scheme, One_Model $model)
 {
     $bOptions = $scheme->get('behaviorOptions.' . strtolower($this->getName()));
     $forAttribute = $bOptions['attribute'];
     unset($model->{$forAttribute});
 }
示例#19
0
 /**
  * Returns whether the user is allowed to perform this task
  *
  * @param One_Scheme $scheme
  * @param mixed $id
  * @return boolean
  */
 public function authorize($scheme, $id)
 {
     return One_Permission::authorize('search', $scheme->getName(), $id);
 }
示例#20
0
文件: xml.php 项目: pdelbar/onethree
 /**
  * Set any extra information to the scheme if present
  * This can be a better readable title, descriptions, whether it's an internal scheme or not, ...
  *
  * @param One_Scheme $scheme
  * @param DOMXPath $xpath
  * @param DOMElement $meta
  */
 protected static function setInformation(One_Scheme $scheme, DOMXPath $xpath, DOMElement $meta)
 {
     $infoSpec = $xpath->query($meta->getNodePath() . '/info');
     if ($infoSpec->length == 1) {
         $info = $infoSpec->item(0);
         if ($info->hasChildNodes()) {
             $child = $info->firstChild;
             do {
                 if ($child->nodeType == XML_ELEMENT_NODE) {
                     $nodeName = $child->nodeName;
                     $content = $child->textContent;
                     if (in_array($nodeName, array('title', 'description', 'image', 'group', 'grouporder'))) {
                         $scheme->set("info.{$nodeName}", $content);
                         //                $scheme->$nodeName = $content;
                     } elseif ($nodeName == 'options') {
                         $options = explode(',', $content);
                         foreach ($options as $option) {
                             $scheme->set("info.options.{$option}", $option);
                         }
                     } else {
                         $scheme->information[$nodeName] = $content;
                     }
                 }
                 $child = $child->nextSibling;
             } while (!is_null($child));
         }
     }
 }