Exemple #1
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()];
 }
Exemple #2
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;
 }
Exemple #3
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>';
 }
Exemple #4
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);
 }
Exemple #5
0
 /**
  * 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;
 }
Exemple #6
0
 /**
  * Load the calculated fields into the model
  */
 public function afterLoadModel(One_Scheme $scheme, One_Model $model)
 {
     $bOptions = $scheme->get('behaviorOptions.' . strtolower($this->getName()));
     $forAttribute = $bOptions['attribute'];
     $typeClass = 'One_Type_Calculated_' . ucfirst($scheme->getName()) . '_' . ucfirst($forAttribute);
     if (class_exists($typeClass)) {
         $type = new $typeClass();
         $model->{$forAttribute} = $type->calculate($model);
     }
 }
Exemple #7
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() . '"');
     }
 }
Exemple #8
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;
         }
     }
 }
Exemple #9
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')))));
     }
 }
Exemple #10
0
 /**
  * @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());
     }
 }
Exemple #11
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);
 }
Exemple #12
0
 /**
  * Set behaviors for the scheme when present
  *
  * @param One_Scheme $scheme
  * @param DOMXPath $xpath
  * @param DOMElement $meta
  */
 protected static function setBehaviors(One_Scheme $scheme, DOMXPath $xpath, DOMElement $meta)
 {
     $behaviorsSpec = $xpath->query($meta->getNodePath() . '/behaviors/behavior');
     $behaviors = array();
     $behaviorOptions = array();
     for ($i = 0; $i < $behaviorsSpec->length; $i++) {
         $behaviorSpec = $behaviorsSpec->item($i);
         $behavior = One_Repository::getBehavior($behaviorSpec->getAttribute('name'), $scheme->getName());
         $spec = array();
         for ($j = 0; $j < $behaviorSpec->attributes->length; $j++) {
             $attr = $behaviorSpec->attributes->item($j);
             $spec[$attr->name] = $attr->value;
         }
         $behaviors[] = $behavior;
         $behaviorOptions[strtolower($behavior->getName())] = $spec;
     }
     $scheme->set('behaviors', $behaviors);
     $scheme->set('behaviorOptions', $behaviorOptions);
 }