Exemplo n.º 1
0
 /**
  * Puts all variables to the template inc_pagination.htm so that it can be included.
  *
  * @param TDL_URL $url the URL-instance
  */
 public function populate_tpl($url)
 {
     $tpl = FWS_Props::get()->tpl();
     if (!$url instanceof TDL_URL) {
         FWS_Helper::def_error('instance', 'url', 'TDL_URL', $url);
     }
     if ($this->get_page_count() > 1) {
         $param = $this->get_page_param();
         $page = $this->get_page();
         $numbers = $this->get_page_numbers();
         $tnumbers = array();
         foreach ($numbers as $n) {
             $number = $n;
             $link = '';
             if (FWS_Helper::is_integer($n)) {
                 $url->set($param, $n);
                 $link = $url->to_url();
             } else {
                 $link = '';
             }
             $tnumbers[] = array('number' => $number, 'link' => $link);
         }
         $start_item = $this->get_start() + 1;
         $end_item = $start_item + $this->get_per_page() - 1;
         $end_item = $end_item > $this->get_num() ? $this->get_num() : $end_item;
         $tpl->set_template('inc_pagination.htm');
         $tpl->add_variable_ref('numbers', $tnumbers);
         $tpl->add_variables(array('page' => $page, 'total_pages' => $this->get_page_count(), 'start_item' => $start_item, 'end_item' => $end_item, 'total_items' => $this->get_num(), 'prev_url' => $url->set($param, $page - 1)->to_url(), 'next_url' => $url->set($param, $page + 1)->to_url(), 'first_url' => $url->set($param, 1)->to_url(), 'last_url' => $url->set($param, $this->get_page_count())->to_url()));
         $tpl->restore_template();
     }
 }
Exemplo n.º 2
0
 /**
  * Sets the property-accessor for the properties
  *
  * @param FWS_PropAccessor $accessor the accessor
  */
 public static function set_accessor($accessor)
 {
     if (!$accessor instanceof FWS_PropAccessor) {
         FWS_Helper::def_error('instance', 'accessor', 'FWS_PropAccessor', $accessor);
     }
     self::$accessor = $accessor;
 }
Exemplo n.º 3
0
 /**
  * Constructor
  *
  * @param PC_Engine_Options $options the options
  */
 public function __construct($options)
 {
     parent::__construct();
     if (!$options instanceof PC_Engine_Options) {
         FWS_Helper::def_error('instance', 'options', 'PC_Engine_Options', $options);
     }
     $this->options = $options;
 }
Exemplo n.º 4
0
 /**
  * Reports the given error
  * 
  * @param PC_Obj_Location $locsrc an object from which the location will be copied (null = current)
  * @param string $msg the error-message
  * @param int $type the error-type
  */
 public function report($locsrc, $msg, $type)
 {
     if (!$locsrc instanceof PC_Obj_Location) {
         FWS_Helper::def_error('instance', 'locsrc', 'PC_Obj_Location', $locsrc);
     }
     $locsrc = new PC_Obj_Location($locsrc->get_file(), $locsrc->get_line());
     $this->errors[] = new PC_Obj_Error($locsrc, $msg, $type);
 }
 /**
  * Constructor
  * 
  * @param PC_Engine_Env $env the environment
  */
 public function __construct($env)
 {
     parent::__construct();
     if (!$env instanceof PC_Engine_Env) {
         FWS_Helper::def_error('instance', 'env', 'PC_Engine_Env', $env);
     }
     $this->env = $env;
 }
 /**
  * Constructor
  * 
  * @param string $module your module-name
  * @param array $subs the sub-module names that are possible
  * @param string $default the default sub-module
  */
 public function __construct($module, $subs = array(), $default = 'default')
 {
     $input = FWS_Props::get()->input();
     if (count($subs) == 0) {
         FWS_Helper::error('Please provide the possible submodules of this module!');
     }
     $sub = $input->correct_var('sub', 'get', FWS_Input::STRING, $subs, $default);
     // include the sub-module and create it
     include_once FWS_Path::server_app() . 'module/' . $module . '/sub_' . $sub . '.php';
     $classname = 'PC_SubModule_' . $module . '_' . $sub;
     $this->sub = new $classname();
 }
Exemplo n.º 7
0
 public function perform_action()
 {
     $input = FWS_Props::get()->input();
     $id = $input->get_var('id', 'get', FWS_Input::STRING);
     if (!FWS_Helper::is_integer($id) || $id <= 0) {
         return 'The id is invalid';
     }
     PC_DAO::get_calls()->delete_by_project($id);
     PC_DAO::get_classes()->delete_by_project($id);
     PC_DAO::get_classfields()->delete_by_project($id);
     PC_DAO::get_constants()->delete_by_project($id);
     PC_DAO::get_errors()->delete_by_project($id);
     PC_DAO::get_functions()->delete_by_project($id);
     PC_DAO::get_vars()->delete_by_project($id);
     $this->set_redirect(false);
     $this->set_success_msg('The project has been cleaned successfully');
     $this->set_show_status_page(true);
     $this->set_action_performed(true);
     return '';
 }
Exemplo n.º 8
0
 /**
  * Constructor
  *
  * @param int $id the project-id
  * @param string $name the name
  * @param int $created the timestamp
  * @param string $type_folders the folders for the type-scanner
  * @param string $type_exclude the excluded items for the type-scanner
  * @param string $stmt_folders the folders for the statement-scanner
  * @param string $stmt_exclude the excluded items for the statement-scanner
  * @param boolean $report_argret_strictly report errors strictly?
  */
 public function __construct($id, $name, $created, $type_folders, $type_exclude, $stmt_folders, $stmt_exclude, $report_argret_strictly)
 {
     parent::__construct();
     if (!FWS_Helper::is_integer($id) || $id < 0) {
         FWS_Helper::def_error('intgt0', 'id', $id);
     }
     if (!FWS_Helper::is_integer($created) || $created < 0) {
         FWS_Helper::def_error('intge0', 'created', $created);
     }
     $this->id = $id;
     $this->name = $name;
     $this->created = $created;
     $this->type_folders = $type_folders;
     $this->type_exclude = $type_exclude;
     $this->stmt_folders = $stmt_folders;
     $this->stmt_exclude = $stmt_exclude;
     $this->report_argret_strictly = $report_argret_strictly;
     $this->req = array();
     $this->set_project_deps(array());
 }
Exemplo n.º 9
0
 /**
  * This method checks a field for a given type. By default the check will only be performed
  * if the value is not NULL. You can force the check by setting <var>$is_required</var> to true.
  * The possible values for $for are:
  * <ul>
  * 	<li>timestamp		=> uses {@link FWS_Date::is_valid_timestamp()}</li>
  * 	<li>empty				=> has to be empty</li>
  * 	<li>notempty		=> has to be not-empty</li>
  * 	<li>id					=> has to be a positive integer
  * 	<li>numeric			=> uses <var>is_numeric()</var></li>
  * 	<li>enum				=> requires <var>$values</var> and uses <var>in_array()</var></li>
  * </ul>
  * Will add a default-error message if invalid
  * 
  * @param string $field the field-name
  * @param string $for the type to check for. See the list above!
  * @param boolean $is_required force the check?
  * @param array $values possible values for the field. empty if it should not be used
  * @return boolean true if the value is ok
  */
 protected function check_field_for($field, $for = 'timestamp', $is_required = false, $values = array())
 {
     $errors = 0;
     $method = 'get_' . $field;
     $val = $this->{$method}();
     if ($val !== null || $is_required) {
         $error = false;
         switch ($for) {
             case 'empty':
                 $error = !empty($val);
                 break;
             case 'notempty':
                 $error = empty($val);
                 break;
             case 'timestamp':
                 $error = !FWS_Date::is_valid_timestamp($val);
                 break;
             case 'id':
                 $error = !FWS_Helper::is_integer($val) || $val <= 0;
                 break;
             case 'numeric':
                 $error = !is_numeric($val);
                 break;
             case 'enum':
                 if (!is_array($values) || count($values) == 0) {
                     FWS_Helper::def_error('array>0', 'values', $values);
                 }
                 $error = !in_array($val, $values);
                 break;
         }
         if ($error) {
             if ($is_required && empty($val)) {
                 $this->add_error($this->missing_field_msg($field), $field);
             } else {
                 $this->add_error($this->invalid_field_msg($field), $field);
             }
             $errors++;
         }
     }
     return $errors == 0;
 }
Exemplo n.º 10
0
 /**
  * Puts constants, fields and methods from the given statements into $class
  * 
  * @param PC_Obj_Class $class the class
  * @param array $stmts an array of PC_Obj_Constant, PC_Obj_Field and PC_Obj_Method
  */
 private function handle_class_stmts($class, $stmts)
 {
     foreach ($stmts as $stmt) {
         if ($stmt instanceof PC_Obj_Constant) {
             $class->add_constant($stmt);
         } else {
             if ($stmt instanceof PC_Obj_Field) {
                 $class->add_field($stmt);
             } else {
                 if ($stmt instanceof PC_Obj_Method) {
                     // methods in interfaces are implicitly abstract
                     if ($class->is_interface()) {
                         $stmt->set_abstract(true);
                     }
                     // convert old-style constructors to the new ones
                     if (strcasecmp($stmt->get_name(), $class->get_name()) == 0) {
                         $stmt->set_name('__construct');
                     }
                     // constructors return an object of the class
                     if ($stmt->is_constructor() && ($stmt->get_return_type() && !$stmt->get_return_type()->is_unknown())) {
                         $spec = $stmt->get_return_type();
                         $this->report_error('The constructor of class ' . $class->get_name() . ' specifies return type ' . $spec, PC_Obj_Error::E_T_RETURN_DIFFERS_FROM_DOC, $stmt->get_line());
                     }
                     $class->add_method($stmt);
                 } else {
                     FWS_Helper::error('Unknown statement: ' . $stmt);
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
 /**
  * Constructor
  *
  * @param PC_Obj_Location $loc the location of the error
  * @param string $msg the message to display
  * @param int $type the error-type. See self::E_*
  */
 public function __construct($loc, $msg, $type)
 {
     parent::__construct();
     if (!$loc instanceof PC_Obj_Location) {
         FWS_Helper::def_error('instance', 'loc', 'PC_Obj_Location', $loc);
     }
     if (!FWS_Helper::is_integer($type) || $type < 0) {
         FWS_Helper::def_error('intge0', 'type', $type);
     }
     $this->loc = $loc;
     $this->msg = $msg;
     $this->type = $type;
 }
Exemplo n.º 12
0
 /**
  * Constructor
  * 
  * @param string $str the file or string
  * @param bool $is_file whether $str is a file
  * @param PC_Engine_Env $env the environment
  */
 public function __construct($str, $is_file, $env)
 {
     parent::__construct($str, $is_file);
     if (!$env instanceof PC_Engine_Env) {
         FWS_Helper::def_error('instance', 'env', 'PC_Engine_Env', $env);
     }
     $this->env = $env;
     $this->scope = new PC_Engine_Scope();
     $this->vars = new PC_Engine_VarContainer();
     $this->methods_analyzer = new PC_Analyzer_Methods($env);
     $this->calls_analyzer = new PC_Analyzer_Calls($env);
     $this->classes_analyzer = new PC_Analyzer_Classes($env);
     $this->req_analyzer = new PC_Analyzer_Requirements($env);
     $this->ret_analyzer = new PC_Analyzer_Returns($env);
     $this->throws_analyzer = new PC_Analyzer_Throws($env);
     $this->modifiers_analyzer = new PC_Analyzer_Modifiers($env);
     $this->vars_analyzer = new PC_Analyzer_Vars($env);
 }
Exemplo n.º 13
0
 /**
  * Adds all given errors
  * 
  * @param array $errors
  */
 public function add_errors($errors)
 {
     if (!is_array($errors)) {
         FWS_Helper::def_error('array', 'errors', $errors);
     }
     $this->errors = array_merge($this->errors, $errors);
 }
Exemplo n.º 14
0
    /**
     * Deletes the projects with given ids
     *
     * @param array $ids the ids
     * @return int the number of affected rows
     */
    public function delete($ids)
    {
        if (!FWS_Array_Utils::is_numeric($ids) || count($ids) == 0) {
            FWS_Helper::def_error('numarray>0', 'ids', $ids);
        }
        $db = FWS_Props::get()->db();
        $stmt = $db->get_prepared_statement('DELETE FROM ' . PC_TB_PROJECT_DEPS . '
			 WHERE project_id IN (:ids) OR dep_id IN (:ids)');
        $stmt->bind(':ids', $ids);
        $db->execute($stmt->get_statement());
        $stmt = $db->get_prepared_statement('DELETE FROM ' . PC_TB_PROJECTS . ' WHERE id IN (:ids)');
        $stmt->bind(':ids', $ids);
        $db->execute($stmt->get_statement());
        return $db->get_affected_rows();
    }
Exemplo n.º 15
0
 /**
  * Sets the type
  *
  * @param int $type the new value
  */
 public function set_type($type)
 {
     if (!FWS_Helper::is_integer($type)) {
         FWS_Helper::def_error('int', 'type', $type);
     }
     $this->_type = $type;
 }
Exemplo n.º 16
0
 /**
  * Sets the type
  * 
  * @param PC_Obj_MultiType $type the new value
  */
 public function set_type($type)
 {
     if (!$type instanceof PC_Obj_MultiType) {
         FWS_Helper::def_error('instance', 'type', 'PC_Obj_MultiType', $type);
     }
     if ($this->arrayref !== null) {
         assert(!$this->arrayref->type->is_multiple() && !$this->arrayref->type->is_unknown());
         $this->arrayref->type->get_first()->set_array_type($this->arrayoff, $type);
     }
     $this->type = $type;
 }
Exemplo n.º 17
0
 /**
  * Checks whether it contains the given type
  *
  * @param PC_Obj_Type $type the type
  * @return boolean true if so
  */
 public function contains($type)
 {
     if (!$type instanceof PC_Obj_Type) {
         FWS_Helper::def_error('instance', 'type', 'PC_Obj_Type', $type);
     }
     foreach ($this->types as $t) {
         if ($t->equals($type)) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 18
0
 /**
  * Adds the given method to the class
  *
  * @param PC_Obj_Method $method the method
  */
 public function add_method($method)
 {
     if (!$method instanceof PC_Obj_Method) {
         FWS_Helper::def_error('instance', 'method', 'PC_Obj_Method', $method);
     }
     $this->load_methods();
     $this->methods[strtolower($method->get_name())] = $method;
 }
Exemplo n.º 19
0
 /**
  * Sets the type
  * 
  * @param PC_Obj_MultiType $type the new type
  */
 public function set_type($type)
 {
     if ($type !== null && !$type instanceof PC_Obj_MultiType) {
         FWS_Helper::def_error('instance', 'type', 'PC_Obj_MultiType', $type);
     }
     $this->type = $type;
 }
Exemplo n.º 20
0
 /**
  * Determines the type from the operation (assumes that the type or the value is unknown)
  * 
  * @param string $op the operator
  * @param PC_Obj_MultiType $t1 the type of the first operand
  * @param PC_Obj_MultiType $t2 the type of the second operand (may be null for unary ops)
  * @return PC_Obj_MultiType the variable
  */
 protected function get_type_from_op($op, $t1, $t2 = null)
 {
     switch ($op) {
         // bitwise operators have always int as result
         case '|':
         case '&':
         case '^':
         case '>>':
         case '<<':
         case '~':
         case '?:':
             return PC_Obj_MultiType::create_int();
             // concatenation leads always to string
         // concatenation leads always to string
         case '.':
             return PC_Obj_MultiType::create_string();
         case '+':
         case '-':
         case '*':
         case '/':
         case '%':
             // if one of them is unknown we don't know whether we would get a float or int
             if ($t1->is_unknown() || $t1->is_multiple() || $t2 !== null && ($t2->is_unknown() || $t2->is_multiple())) {
                 return new PC_Obj_MultiType();
             }
             $ti1 = $t1->get_first()->get_type();
             $ti2 = $t2 === null ? -1 : $t2->get_first()->get_type();
             // if both are arrays, the result is an array
             if ($ti1 == PC_Obj_Type::TARRAY && $ti2 == PC_Obj_Type::TARRAY) {
                 return PC_Obj_MultiType::create_array();
             }
             // if one of them is float, the result is float
             if ($ti1 == PC_Obj_Type::FLOAT || $ti2 == PC_Obj_Type::FLOAT) {
                 return PC_Obj_MultiType::create_float();
             }
             // otherwise its always int
             return PC_Obj_MultiType::create_int();
         case '==':
         case '!=':
         case '===':
         case '!==':
         case '<':
         case '>':
         case '<=':
         case '>=':
         case '&&':
         case '||':
         case 'xor':
         case '!':
             // always bool
             return PC_Obj_MultiType::create_bool();
         default:
             FWS_Helper::error('Unknown operator "' . $op . '"');
     }
 }
Exemplo n.º 21
0
 /**
  * Adds the given type as argument
  *
  * @param PC_Obj_MultiType $type the type
  */
 public function add_argument($type)
 {
     if (!$type instanceof PC_Obj_MultiType) {
         FWS_Helper::def_error('instance', 'type', 'PC_Obj_MultiType', $type);
     }
     $this->arguments[] = clone $type;
 }
Exemplo n.º 22
0
 /**
  * Puts the parameter to the method
  *
  * @param PC_Obj_Parameter $param the param
  */
 public function put_param($param)
 {
     if (!$param instanceof PC_Obj_Parameter) {
         FWS_Helper::def_error('instance', 'param', 'PC_Obj_Parameter', $param);
     }
     $this->params[$param->get_name()] = $param;
 }
Exemplo n.º 23
0
 /**
  * Deletes all class-fields from the project with given id
  *
  * @param int $id the project-id
  * @return int the number of affected rows
  */
 public function delete_by_project($id)
 {
     $db = FWS_Props::get()->db();
     if (!PC_Utils::is_valid_project_id($id)) {
         FWS_Helper::def_error('intge0', 'id', $id);
     }
     $stmt = $db->get_prepared_statement('DELETE FROM ' . PC_TB_CLASS_FIELDS . ' WHERE project_id = :id');
     $stmt->bind(':id', $id);
     $db->execute($stmt->get_statement());
     return $db->get_affected_rows();
 }
Exemplo n.º 24
0
 /**
  * Sets the multi-type-instance for this parameter. Will reset is_mtype_default() to false.
  *
  * @param PC_Obj_MultiType $mtype the new value
  */
 public function set_mtype($mtype)
 {
     if (!$mtype instanceof PC_Obj_MultiType) {
         FWS_Helper::def_error('instance', 'mtype', 'PC_Obj_MultiType', $mtype);
     }
     $this->mtype = $mtype;
     $this->mtype_is_default = false;
 }
Exemplo n.º 25
0
 /**
  * Builds the delete-items to a text
  * 
  * @param array $ids a numeric array with the ids
  * @param string $sql the sql-statement
  * @param string $field the field which should be used to show the entries to delete to the user
  * @return string the item-string
  */
 public function get_delete_items($ids, $sql, $field)
 {
     $db = FWS_Props::get()->db();
     $locale = FWS_Props::get()->locale();
     if (!is_array($ids) || count($ids) == 0) {
         FWS_Helper::def_error('array>0', 'ids', $ids);
     }
     if (empty($sql)) {
         FWS_Helper::def_error('notempty', 'sql', $sql);
     }
     if (empty($field)) {
         FWS_Helper::def_error('notempty', 'field', $field);
     }
     $text = '';
     $num = count($ids);
     $i = 0;
     foreach ($db->get_rows($sql) as $data) {
         $text .= '"' . $data[$field] . '"';
         if ($i < $num - 2) {
             $text .= ', ';
         } else {
             if ($i == $num - 2) {
                 $text .= ' ' . $locale->lang('and') . ' ';
             }
         }
         $i++;
     }
     return $text;
 }
Exemplo n.º 26
0
 /**
  * @see PC_Obj_Visible::set_visibility()
  *
  * @param string $visibility
  */
 public function set_visibility($visibility)
 {
     $valid = array(self::V_PUBLIC, self::V_PROTECTED, self::V_PRIVATE);
     if (!in_array($visibility, $valid)) {
         FWS_Helper::def_error('inarray', 'visibility', $valid, $visibility);
     }
     $this->visibility = $visibility;
 }