Exemplo n.º 1
0
 /**
  * Similar to the above function, but uses Elation's Zend Framework integration,
  * specifically Zend_Form and associated components to created the form from the JSON
  * .model file, validate/filter it, and display it.
  * 
  * @param object $args
  * @param object $output [optional]
  * @return object ComponentResponse
  */
 public function controller_create_postZend($args, $output = "inline")
 {
     $vars["args"] = $args;
     $vars["blogname"] = $args["blogname"];
     if (!empty($args["blog"])) {
         $vars["blog"] = $args["blog"];
         $vars["blogname"] = $vars["blog"]->blogname;
     } else {
         if (!empty($args["blogname"])) {
             $vars["blogname"] = $args["blogname"];
             try {
                 $vars["blog"] = OrmManager::load("Blog", $vars["blogname"]);
             } catch (Exception $e) {
             }
         }
     }
     if (empty($vars["blog"])) {
         $vars["blogs"] = OrmManager::select("Blog");
         $ret = $this->GetComponentResponse("./select.tpl", $vars);
     } else {
         $vars["formname"] = $formname = "blogpost";
         $form = new Elation_Form(array('file' => 'components/blog/blog.model', 'class' => 'Blog', 'variables' => array('[[validator1]]' => 'Alnum', '[[validator2]]' => 'Alpha')), Elation_Form::ELATION_OPTIONS_ZEND);
         $blogName = new Zend_Form_Element_Hidden(array("name" => 'blogname', "value" => $vars["blogname"]));
         $form->addElement($blogName);
         $vars['blogForm'] = $form->render('blog.form', $args);
         //use a component to route the form through
         //$vars['blogForm'] = $form->render(); //or use the default Zend_Form renderer
         if (!empty($args["blogpost"])) {
             if ($form->isValid($args)) {
                 $args["blogpost"]["timestamp"] = new DateTime();
                 $blogpost = $vars[$formname] = new BlogPost($args["blogpost"]);
                 $blogpost->SetBlog($vars["blog"]);
                 if ($blogpost->isValid()) {
                     if ($blogpost->Save()) {
                         // FIXME - make configurable
                         //Perhaps redirect back to this controller so we can show success
                         header("Location: ?blogname=" . urlencode($vars["blogname"]) . "#blog_posts_create_success:" . $blogpost->blogpostid);
                     }
                 }
             } else {
                 $vars['formError'] = true;
                 $formErrors = $form->getMessages();
                 $vars['subjectErrors'] = $formErrors['subject'];
                 $vars['contentErrors'] = $formErrors['content'];
             }
         }
         $ret = $this->GetComponentResponse("./create_postZend.tpl", $vars);
     }
     return $ret;
 }
Exemplo n.º 2
0
 public static function get($usertype, $userid)
 {
     $user = OrmManager::load("UserModel", array($usertype, $userid));
     if (!empty($user)) {
         $user->credentials = false;
         // strip out credentials
         return new User($user);
     }
     return false;
 }