public function test_get_current_message()
 {
     $m = new messages();
     //No message has been set
     $this->assertEquals('', $m->get_current_message());
     //Set a message and check if it's ok
     $m->set_message('general-ok-0');
     $this->assertEquals('Command OK', $m->get_current_message());
 }
Esempio n. 2
0
 public static function add_content($content_id, $content_name)
 {
     ob_start();
     if (file_exists(config::get_config('tpl_config')['bloks_folder'] . '/' . $content_name . '.php')) {
         require config::get_config('tpl_config')['bloks_folder'] . '/' . $content_name . '.php';
     } else {
         messages::set_message('20', 'alert-danger');
     }
     self::$content[$content_id] = ob_get_contents();
     ob_end_clean();
 }
Esempio n. 3
0
 public function set($params, $options = null)
 {
     //var_dump($params);
     $last_id = 0;
     if ($options != null) {
         $this->options = $options;
     }
     $this->prepared = $this->pdo->prepare($this->query_builder->get_query(), $this->options);
     $this->pdo->beginTransaction();
     var_dump($this->prepared);
     if (!$this->prepared) {
         $this->pdo->rollBack();
         messages::set_message('30', 'alert-danger');
         return $last_id;
     }
     $this->prepared->execute($params);
     $last_id = $this->pdo->lastInsertId();
     $this->pdo->commit();
     return $last_id;
 }
Esempio n. 4
0
 public static function call($route, $params = null)
 {
     self::$route = $route;
     self::$params = $params;
     if (!class_exists(self::$route[0] . '_controller')) {
         self::$route[0] = config::get_config('app_config')['default_controller'] . '_controller';
         messages::set_message('00', 'alert-danger');
     } else {
         self::$route[0] = self::$route[0] . '_controller';
     }
     if (!isset(self::$route[1])) {
         self::$route[1] = config::get_config('app_config')['default_action'];
     }
     if (method_exists(self::$route[0], self::$route[1])) {
         self::$route[1] = self::$route[1];
     } else {
         self::$route[1] = config::get_config('app_config')['default_action'];
         messages::set_message('01', 'alert-danger');
     }
     call_user_func_array(self::$route, self::$params);
 }
Esempio n. 5
0
 /**
  * This method process the command given by the user and call the right action to be applied.
  * @param Array $command 
  * @param string $canvas_string 
  * @return string
  */
 public function process_command()
 {
     //Obj to handle messages
     $messages = new messages();
     if ($this->values_ok) {
         switch (strtoupper($this->command_array[0])) {
             //Create a Canvas
             case 'C':
                 if (count($this->command_array) == 3) {
                     $command = $this->command_array;
                     $this->canvas = new canvas($command[1], $command[2]);
                     $messages->set_message('general-ok-0');
                 } else {
                     $messages->set_message('general-error-0');
                     $messages->is_reload();
                 }
                 break;
                 //Print a Line
             //Print a Line
             case 'L':
                 if (!$this->canvas->get_canvas_state()) {
                     $messages->set_message('line-error-1');
                 } elseif (count($this->command_array) == 5) {
                     $command = $this->command_array;
                     $this->canvas->draw_line(array($command[1], $command[2]), array($command[3], $command[4]), $messages);
                     $messages->set_message('general-ok-0');
                 } else {
                     $messages->set_message('general-error-0');
                 }
                 break;
                 //Print a Rectangle
             //Print a Rectangle
             case 'R':
                 if (!$this->canvas->get_canvas_state()) {
                     $messages->set_message('rec-error-0');
                 } elseif (count($this->command_array) == 5) {
                     $command = $this->command_array;
                     $this->canvas->draw_rectangle(array($command[1], $command[2]), array($command[3], $command[4]));
                     $messages->set_message('general-ok-0');
                 } else {
                     $messages->set_message('general-error-0');
                 }
                 break;
                 //Bucket fill action
             //Bucket fill action
             case 'B':
                 if (!$this->canvas->get_canvas_state()) {
                     $messages->set_message('line-error-1');
                 } elseif (count($this->command_array) == 4) {
                     $command = $this->command_array;
                     $this->canvas->bucket_fill(array($command[1], $command[2]), $command[3]);
                     $messages->set_message('general-ok-0');
                 } else {
                     $messages->set_message('general-error-0');
                 }
                 break;
                 //Restart the app
             //Restart the app
             case 'Q':
                 $messages->set_message('general-ok-0');
                 $messages->is_reload();
                 break;
             default:
                 break;
         }
     } else {
         return false;
     }
     return $this->canvas->get_canvas_string($messages) . '<br/>' . $messages->get_current_message();
 }