Example #1
0
 /**
  * Class constructor, with different prototypes:
  *   new One_View( One_Scheme, ...)
  *   new One_View( 'schemename', ...)
  *   new One_View( One_Model, ...)
  *   new One_View( [One_Model ...], ...)
  *
  * @param mixed $modelThing
  * @param string $viewName
  */
 public function __construct($modelThing, $viewName = 'default')
 {
     $this->name = $viewName;
     // which scheme are we rendering for ?
     if ($modelThing instanceof One_Scheme) {
         $this->schemeName = $modelThing->getName();
     } elseif ($modelThing instanceof One_Model) {
         $this->schemeName = $modelThing->getSchemeName();
     } elseif (is_array($modelThing) && count($modelThing) > 0) {
         $this->schemeName = $modelThing[0]->getSchemeName();
     } else {
         $this->schemeName = $modelThing;
     }
     // setup templater
     $this->templater = One_Repository::getTemplater();
     $this->setDefaultViewSearchPath();
     //      $this->templater->setFile($viewName . '.' . $type);
     // the templater knows what to use
     // *** does this not restrict us for view filenames ??
     $this->templater->setFile($viewName);
     if ($this->templater->hasError()) {
         throw new One_Exception("Could not load view '" . $viewName . "' for scheme '" . $this->schemeName . "' : " . $this->templater->getError());
     }
     $this->setModel($modelThing);
 }
Example #2
0
 /**
  * Loads a form definition
  *
  * @param One_Scheme $scheme
  * @param $formFile
  * @return One_Form_Container_Form
  */
 public static function load($filepath, $scheme, $language = NULL, $formName = 'oneForm', $action = '', $method = 'post')
 {
     $templater = One_Repository::getTemplater(NULL, false);
     // -----------------
     // TODO: this section of code is absolute horror
     //    $filepath = One::getInstance()->locate('meta'.DIRECTORY_SEPARATOR.'scheme'.DIRECTORY_SEPARATOR.$fileName.'.xml');
     //    $oldSearchpaths = $templater->getSearchpath();
     //    $templater->clearSearchpath();
     //    $pattern = "%ROOT%/views/"
     //      . "{" . ($scheme->getName() != '' ? "%APP%/{$scheme->getName()}," : "") . "%APP%,default}" . DIRECTORY_SEPARATOR
     //      . "{%LANG%" . DIRECTORY_SEPARATOR . ",}";
     //
     //    $templater->addSearchPath($pattern);
     //    $templater->setFile('form.xml');
     //    if ($templater->hasError()) {
     //      return self::createDefaultForm($scheme, $formFile, $language, $formName, $action, $method);
     ////      throw new One_Exception($templater->getError());
     //    }
     //    $templater->setSearchpath($oldSearchpaths);
     $script = new One_Script();
     $script->load($filepath);
     $parsedContent = $script->execute();
     if ($templater->hasError()) {
         throw new One_Exception($templater->getError());
     }
     // -----------------
     self::$_dom = new DOMDocument('1.0', 'utf-8');
     $validFile = self::$_dom->loadXML($parsedContent);
     if ($validFile !== false) {
         // load rules if any
         self::loadConditions();
         // load redirects if any
         $redirects = self::loadRedirects();
         // first element in the xml file should be a container of the type 'form'
         if (strtolower(self::$_dom->firstChild->localName) == 'form') {
             $formEle = self::$_dom->firstChild;
             $formName = trim($formEle->getAttribute('id')) != '' ? trim($formEle->getAttribute('id')) : $formName;
             $action = trim($formEle->getAttribute('action')) != '' ? trim($formEle->getAttribute('action')) : $action;
             $attributes = array();
             $rawAttributes = $formEle->attributes;
             for ($i = 0; $i < $rawAttributes->length; $i++) {
                 $attribute = $rawAttributes->item($i);
                 $attributes[$attribute->localName] = $attribute->value;
             }
             if (isset($attributes['type']) && trim(strtolower($attributes['type'])) == 'search') {
                 self::$_defaultWidget = 'search';
             } else {
                 self::$_defaultWidget = 'scalar';
             }
             if (count($redirects) > 0) {
                 $attributes['redirects'] = $redirects;
             }
             $form = new One_Form_Container_Form($formName, $action, $method, $attributes);
             foreach ($formEle->childNodes as $child) {
                 if ($child instanceof DOMElement) {
                     self::_parseToForm($child, $form);
                 }
             }
         } else {
             throw new One_Exception('Form definition "' . $fileName . '" found, but no form defined');
         }
     } else {
         return self::createDefaultForm($scheme, $formFile, $language, $formName, $action, $method);
     }
     //    $templater->clearSearchpath();
     //    $templater->setSearchpath($oldSearchpaths);
     //      print_r($form);
     return $form;
 }