/** * Phalcon\Mvc\Model\Resultset\Complex constructor * * @param array $columnsTypes * @param Phalcon\Db\ResultInterface $result * @param Phalcon\Cache\BackendInterface $cache */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, __construct){ zval *columns_types, *result, *cache = NULL, *fetch_assoc; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &columns_types, &result, &cache) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!cache) { PHALCON_INIT_NVAR(cache); } phalcon_update_property_zval(this_ptr, SL("_columnTypes"), columns_types TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_result"), result TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_cache"), cache TSRMLS_CC); phalcon_update_property_long(this_ptr, SL("_type"), 1 TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(result)) { PHALCON_INIT_VAR(fetch_assoc); ZVAL_LONG(fetch_assoc, 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(result, "setfetchmode", fetch_assoc, PH_NO_CHECK); } PHALCON_MM_RESTORE(); }
/** * Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch() * *<code> * //Return array with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_NUM); * * //Return associative array without integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_ASSOC); * * //Return associative array together with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_BOTH); * * //Return an object * $result->setFetchMode(Phalcon\Db::FETCH_OBJ); *</code> * * @param int $fetchMode */ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ long fetch_mode; zval *pdo_statement, *fetch_type; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fetch_mode) == FAILURE) { RETURN_MM_NULL(); } PHALCON_INIT_VAR(fetch_type); ZVAL_LONG(fetch_type, fetch_mode); PHALCON_OBS_VAR(pdo_statement); phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY TSRMLS_CC); if (Z_LVAL_P(fetch_type) != 0) { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_type); phalcon_update_property_long(this_ptr, SL("_fetchMode"), Z_LVAL_P(fetch_type) TSRMLS_CC); } RETURN_MM_NULL(); }
/** * Unserializing a resultset will allow to only works on the rows present in the saved state * * @param string $data */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, unserialize){ zval *data = NULL, *resultset = NULL, *model = NULL, *rows = NULL, *cache = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &data) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); PHALCON_INIT_VAR(resultset); PHALCON_CALL_FUNC_PARAMS_1(resultset, "unserialize", data); if (Z_TYPE_P(resultset) == IS_ARRAY) { PHALCON_INIT_VAR(model); phalcon_array_fetch_string(&model, resultset, SL("model"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_model"), model TSRMLS_CC); PHALCON_INIT_VAR(rows); phalcon_array_fetch_string(&rows, resultset, SL("rows"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_rows"), rows TSRMLS_CC); PHALCON_INIT_VAR(cache); phalcon_array_fetch_string(&cache, resultset, SL("cache"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_cache"), cache TSRMLS_CC); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); return; } PHALCON_MM_RESTORE(); }
/** * Rewinds resultset to its beginning * */ PHP_METHOD(Phalcon_Mvc_Model_Resultset, rewind){ zval *type = NULL, *result = NULL, *rows = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(type); phalcon_read_property(&type, this_ptr, SL("_type"), PH_NOISY_CC); if (zend_is_true(type)) { PHALCON_INIT_VAR(result); phalcon_read_property(&result, this_ptr, SL("_result"), PH_NOISY_CC); if (Z_TYPE_P(result) != IS_BOOL || (Z_TYPE_P(result) == IS_BOOL && Z_BVAL_P(result))) { phalcon_update_property_long(this_ptr, SL("_pointer"), 1 TSRMLS_CC); PHALCON_INIT_VAR(c0); ZVAL_LONG(c0, 0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(result, "dataseek", c0, PH_NO_CHECK); } } else { PHALCON_INIT_VAR(rows); phalcon_read_property(&rows, this_ptr, SL("_rows"), PH_NOISY_CC); Z_SET_ISREF_P(rows); PHALCON_CALL_FUNC_PARAMS_1_NORETURN("reset", rows); Z_UNSET_ISREF_P(rows); } PHALCON_MM_RESTORE(); }
/** * Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch() * *<code> * //Return array with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_NUM); * * //Return associative array without integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_ASSOC); * * //Return associative array together with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_BOTH); * * //Return an object * $result->setFetchMode(Phalcon\Db::FETCH_OBJ); *</code> * * @param int $fetchMode */ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ zval *fetch_mode, *fetch_arg1 = NULL, *fetch_arg2 = NULL; zval *pdo_statement; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &fetch_mode, &fetch_arg1, &fetch_arg2); PHALCON_SEPARATE_PARAM(fetch_mode); if (Z_TYPE_P(fetch_mode) != IS_LONG) { convert_to_long(fetch_mode); } pdo_statement = phalcon_read_property(getThis(), SL("_pdoStatement"), PH_NOISY); if (Z_LVAL_P(fetch_mode) != 0) { if (fetch_arg1 && fetch_arg2) { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_mode, fetch_arg1, fetch_arg2); } else if (fetch_arg1) { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_mode, fetch_arg1); } else if (fetch_arg2) { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_mode, fetch_arg2); } else { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_mode); } phalcon_update_property_long(getThis(), SL("_fetchMode"), Z_LVAL_P(fetch_mode)); } RETURN_MM_NULL(); }
/** * Phalcon\Mvc\Model\Resultset constructor * * @param Phalcon\Mvc\Model $model * @param Phalcon\Mvc\Model\Result $result * @param Phalcon\Cache\Backend $cache */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, __construct){ zval *model = NULL, *result = NULL, *cache = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &model, &result, &cache) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!cache) { PHALCON_ALLOC_ZVAL_MM(cache); ZVAL_NULL(cache); } phalcon_update_property_zval(this_ptr, SL("_model"), model TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_result"), result TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_cache"), cache TSRMLS_CC); phalcon_update_property_long(this_ptr, SL("_type"), 1 TSRMLS_CC); if (Z_TYPE_P(result) != IS_BOOL || (Z_TYPE_P(result) == IS_BOOL && Z_BVAL_P(result))) { PHALCON_INIT_VAR(c0); ZVAL_LONG(c0, 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(result, "setfetchmode", c0, PH_NO_CHECK); } PHALCON_MM_RESTORE(); }
/** * Disable view. No show any view or template * */ PHP_METHOD(Phalcon_View, disable){ PHALCON_MM_GROW(); phalcon_update_property_long(this_ptr, "_renderLevel", strlen("_renderLevel"), 0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Resets the view component to its factory default values * */ PHP_METHOD(Phalcon_Mvc_View, reset){ zval *znull; PHALCON_MM_GROW(); PHALCON_INIT_VAR(znull); phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); phalcon_update_property_bool(this_ptr, SL("_engines"), 0 TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_cache"), znull TSRMLS_CC); phalcon_update_property_long(this_ptr, SL("_renderLevel"), 5 TSRMLS_CC); phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_content"), znull TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_templatesBefore"), znull TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_templatesAfter"), znull TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon\Mvc\Model\Resultset\Simple constructor * * @param Phalcon\Mvc\Model $model * @param Phalcon\Db\Result\Pdo $result * @param Phalcon\Cache\Backend $cache */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, __construct){ zval *model = NULL, *result = NULL, *cache = NULL, *fetch_assoc = NULL, *limit = NULL; zval *row_count = NULL, *big_resultset = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &model, &result, &cache) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!cache) { PHALCON_ALLOC_ZVAL_MM(cache); ZVAL_NULL(cache); } phalcon_update_property_zval(this_ptr, SL("_model"), model TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_result"), result TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_cache"), cache TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(result)) { PHALCON_INIT_VAR(fetch_assoc); ZVAL_LONG(fetch_assoc, 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(result, "setfetchmode", fetch_assoc, PH_NO_CHECK); PHALCON_INIT_VAR(limit); ZVAL_LONG(limit, 32); PHALCON_INIT_VAR(row_count); PHALCON_CALL_METHOD(row_count, result, "numrows", PH_NO_CHECK); PHALCON_INIT_VAR(big_resultset); is_smaller_function(big_resultset, limit, row_count TSRMLS_CC); if (PHALCON_IS_TRUE(big_resultset)) { phalcon_update_property_long(this_ptr, SL("_type"), 1 TSRMLS_CC); } else { phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); } phalcon_update_property_zval(this_ptr, SL("_count"), row_count TSRMLS_CC); } PHALCON_MM_RESTORE(); }
/** * Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch() * *<code> * //Return array with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_NUM); * * //Return associative array without integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_ASSOC); * * //Return associative array together with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_BOTH); * * //Return an object * $result->setFetchMode(Phalcon\Db::FETCH_OBJ); *</code> * * @param int $fetchMode */ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ long fetch_mode; zval *pdo_statement, *fetch_type; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fetch_mode) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(fetch_type); PHALCON_INIT_VAR(pdo_statement); phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); if (fetch_mode == 1) { ZVAL_LONG(fetch_type, 2); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", fetch_type, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 2 TSRMLS_CC); } else { if (fetch_mode == 2) { ZVAL_LONG(fetch_type, 4); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", fetch_type, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 4 TSRMLS_CC); } else { if (fetch_mode == 3) { ZVAL_LONG(fetch_type, 3); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", fetch_type, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 3 TSRMLS_CC); } else { if (fetch_mode == 4) { ZVAL_LONG(fetch_type, 5); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", fetch_type, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 5 TSRMLS_CC); } } } } PHALCON_MM_RESTORE(); RETURN_NULL(); }
/** * Rewinds resultset to its beginning * */ PHP_METHOD(Phalcon_Mvc_Model_Resultset, rewind){ zval *type, *result = NULL, *active_row, *zero, *rows = NULL; PHALCON_MM_GROW(); PHALCON_OBS_VAR(type); phalcon_read_property_this(&type, this_ptr, SL("_type"), PH_NOISY_CC); if (zend_is_true(type)) { /** * Here, the resultset act as a result that is fetched one by one */ PHALCON_OBS_VAR(result); phalcon_read_property_this(&result, this_ptr, SL("_result"), PH_NOISY_CC); if (PHALCON_IS_NOT_FALSE(result)) { PHALCON_OBS_VAR(active_row); phalcon_read_property_this(&active_row, this_ptr, SL("_activeRow"), PH_NOISY_CC); if (Z_TYPE_P(active_row) != IS_NULL) { PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); phalcon_call_method_p1_noret(result, "dataseek", zero); } } } else { /** * Here, the resultset act as an array */ PHALCON_OBS_VAR(rows); phalcon_read_property_this(&rows, this_ptr, SL("_rows"), PH_NOISY_CC); if (Z_TYPE_P(rows) == IS_NULL) { PHALCON_OBS_NVAR(result); phalcon_read_property_this(&result, this_ptr, SL("_result"), PH_NOISY_CC); if (Z_TYPE_P(result) == IS_OBJECT) { PHALCON_INIT_NVAR(rows); phalcon_call_method(rows, result, "fetchall"); phalcon_update_property_this(this_ptr, SL("_rows"), rows TSRMLS_CC); } } if (Z_TYPE_P(rows) == IS_ARRAY) { Z_SET_ISREF_P(rows); phalcon_call_func_p1_noret("reset", rows); Z_UNSET_ISREF_P(rows); } } phalcon_update_property_long(this_ptr, SL("_pointer"), 0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
PHP_METHOD(Phalcon_Internal_TestTemp, e13c){ zval *a = NULL; zval *i0 = NULL, *i1 = NULL, *i2 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(i0); object_init(i0); PHALCON_CPY_WRT(a, i0); phalcon_update_property_long(a, "uno", strlen("uno"), 1 TSRMLS_CC); phalcon_update_property_long(a, "dos", strlen("dos"), 2 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i1); object_init(i1); phalcon_update_property_zval(a, "subA", strlen("subA"), i1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, a, "subA", sizeof("subA")-1, PHALCON_NOISY TSRMLS_CC); phalcon_update_property_long(t0, "uno", strlen("uno"), 1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, a, "subA", sizeof("subA")-1, PHALCON_NOISY TSRMLS_CC); phalcon_update_property_long(t1, "dos", strlen("dos"), 2 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i2); object_init(i2); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, a, "subA", sizeof("subA")-1, PHALCON_NOISY TSRMLS_CC); phalcon_update_property_zval(t2, "subSubA", strlen("subSubA"), i2 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t3); phalcon_read_property(&t3, a, "subA", sizeof("subA")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t4); phalcon_read_property(&t4, t3, "subSubA", sizeof("subSubA")-1, PHALCON_NOISY TSRMLS_CC); phalcon_update_property_long(t4, "uno", strlen("uno"), 1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t5); phalcon_read_property(&t5, a, "subA", sizeof("subA")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t6); phalcon_read_property(&t6, t5, "subSubA", sizeof("subSubA")-1, PHALCON_NOISY TSRMLS_CC); phalcon_update_property_long(t6, "dos", strlen("dos"), 2 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t7); phalcon_read_property(&t7, a, "subA", sizeof("subA")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t8); phalcon_read_property(&t8, t7, "subSubA", sizeof("subSubA")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t9); phalcon_read_property(&t9, t8, "dos", sizeof("dos")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_RETURN_CHECK_CTOR(t9); }
/** * Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetchArray * * @param int $fetchMode */ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode) { zval *fetch_mode = NULL, *pdo_statement = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &fetch_mode) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(pdo_statement); phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); if (phalcon_compare_strict_long(fetch_mode, 1 TSRMLS_CC)) { PHALCON_INIT_VAR(c0); ZVAL_LONG(c0, 2); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", c0, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 2 TSRMLS_CC); } else { if (phalcon_compare_strict_long(fetch_mode, 2 TSRMLS_CC)) { PHALCON_INIT_VAR(c1); ZVAL_LONG(c1, 4); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", c1, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 4 TSRMLS_CC); } else { if (phalcon_compare_strict_long(fetch_mode, 3 TSRMLS_CC)) { PHALCON_INIT_VAR(c2); ZVAL_LONG(c2, 3); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", c2, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 3 TSRMLS_CC); } } } PHALCON_MM_RESTORE(); RETURN_NULL(); }
/** * Returns a slice of the resultset to show in the pagination * * @return \stdClass */ PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, getPaginate){ zval *items, *limit, *number_page, start = {}, lim = {}, slice = {}; long int i_limit, i_number_page, i_number, i_before, i_rowcount; long int i_total_pages, i_next; ldiv_t tp; items = phalcon_read_property(getThis(), SL("_data"), PH_NOISY); if (UNEXPECTED(Z_TYPE_P(items) != IS_ARRAY)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_paginator_exception_ce, "Invalid data for paginator"); return; } limit = phalcon_read_property(getThis(), SL("_limitRows"), PH_NOISY); number_page = phalcon_read_property(getThis(), SL("_page"), PH_NOISY); i_limit = phalcon_get_intval(limit); i_number_page = phalcon_get_intval(number_page); if (i_limit < 1) { /* This should never happen unless someone deliberately modified the properties of the object */ i_limit = 10; } if (!i_number_page) { i_number_page = 1; } i_number = (i_number_page - 1) * i_limit; i_before = (i_number_page == 1) ? 1 : (i_number_page - 1); i_rowcount = zend_hash_num_elements(Z_ARRVAL_P(items)); tp = ldiv(i_rowcount, i_limit); i_total_pages = tp.quot + (tp.rem ? 1 : 0); i_next = (i_number_page < i_total_pages) ? (i_number_page + 1) : i_total_pages; ZVAL_LONG(&start, i_number); ZVAL_LONG(&lim, i_limit); PHALCON_CALL_FUNCTIONW(&slice, "hash_pbkdf2", items, &start, &lim); object_init(return_value); phalcon_update_property_zval(return_value, SL("items"), &slice); phalcon_update_property_long(return_value, SL("before"), i_before); phalcon_update_property_long(return_value, SL("first"), 1); phalcon_update_property_long(return_value, SL("next"), i_next); phalcon_update_property_long(return_value, SL("last"), i_total_pages); phalcon_update_property_long(return_value, SL("current"), i_number_page); phalcon_update_property_long(return_value, SL("total_pages"), i_total_pages); phalcon_update_property_long(return_value, SL("total_items"), i_rowcount); }
/** * Rewinds the internal iterator */ PHP_METHOD(Phalcon_Forms_Form, rewind){ zval *elements, *elements_indexed; PHALCON_MM_GROW(); phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); PHALCON_OBS_VAR(elements); phalcon_read_property(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); PHALCON_INIT_VAR(elements_indexed); PHALCON_CALL_FUNC_PARAMS_1(elements_indexed, "array_values", elements); phalcon_update_property_zval(this_ptr, SL("_elementsIndexed"), elements_indexed TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon\Mvc\Model\Resultset\Complex constructor * * @param array $columnsTypes * @param Phalcon\Db\ResultInterface $result * @param Phalcon\Cache\BackendInterface $cache */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, __construct){ zval *columns_types, *result, *cache = NULL, *fetch_assoc; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &columns_types, &result, &cache); if (!cache) { cache = PHALCON_GLOBAL(z_null); } /** * Column types, tell the resultset how to build the result */ phalcon_update_property_this(this_ptr, SL("_columnTypes"), columns_types TSRMLS_CC); /** * Valid resultsets are Phalcon\Db\ResultInterface instances * FIXME: or Phalcon\Db\Result\Pdo? */ phalcon_update_property_this(this_ptr, SL("_result"), result TSRMLS_CC); /** * Update the related cache if any */ if (Z_TYPE_P(cache) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_cache"), cache TSRMLS_CC); } /** * Resultsets type 1 are traversed one-by-one */ phalcon_update_property_long(this_ptr, SL("_type"), PHALCON_MVC_MODEL_RESULTSET_TYPE_PARTIAL TSRMLS_CC); /** * If the database result is an object, change it to fetch assoc */ if (Z_TYPE_P(result) == IS_OBJECT) { PHALCON_INIT_VAR(fetch_assoc); ZVAL_LONG(fetch_assoc, PDO_FETCH_ASSOC); PHALCON_CALL_METHOD(NULL, result, "setfetchmode", fetch_assoc); } PHALCON_MM_RESTORE(); }
/** * Phalcon_Model_Resultset constructor * * @param Phalcon_Model_Base $model * @param Phalcon_Model_Result $result */ PHP_METHOD(Phalcon_Model_Resultset, __construct){ zval *model = NULL, *result = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &model, &result) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_zval(this_ptr, "_model", strlen("_model"), model TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_result", strlen("_result"), result TSRMLS_CC); phalcon_update_property_long(this_ptr, "_type", strlen("_type"), 1 TSRMLS_CC); PHALCON_MM_RESTORE(); }
PHP_METHOD(Phalcon_Internal_TestTemp, e13a){ zval *a = NULL; zval *i0 = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(i0); object_init(i0); PHALCON_CPY_WRT(a, i0); phalcon_update_property_long(a, "uno", strlen("uno"), 1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, a, "uno", sizeof("uno")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_RETURN_CHECK_CTOR(t0); }
PHP_METHOD(Phalcon_Internal_TestParent, mp2){ zval *v0 = NULL, *v1 = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &v0, &v1) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_long(this_ptr, "_pp0", strlen("_pp0"), 0 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_add_function(r0, v0, v1 TSRMLS_CC); PHALCON_RETURN_CTOR(r0); }
/** * Unserializing a resultset will allow to only works on the rows present in the saved state * * @param string $data */ PHP_METHOD(Phalcon_Model_Resultset, unserialize){ zval *data = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &data) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_long(this_ptr, "_type", strlen("_type"), 0 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_FUNC_PARAMS_1(r0, "unserialize", data, 0x058); phalcon_update_property_zval(this_ptr, "_rows", strlen("_rows"), r0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon_Model_Resultset constructor * * @param Phalcon_Model_Base $model * @param resource $resultResource */ PHP_METHOD(Phalcon_Model_Resultset, __construct){ zval *model = NULL, *result_resource = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &model, &result_resource) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_zval(this_ptr, "_model", strlen("_model"), model TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD(r0, model, "getconnection", PHALCON_NO_CHECK); phalcon_update_property_zval(this_ptr, "_connection", strlen("_connection"), r0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_resultResource", strlen("_resultResource"), result_resource TSRMLS_CC); phalcon_update_property_long(this_ptr, "_type", strlen("_type"), 1 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Unserializing a resultset will allow to only works on the rows present in the saved state * * @param string $data */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, unserialize){ zval *data, *resultset, *rows, *cache, *column_types; zval *hydrate_mode; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &data); phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); PHALCON_INIT_VAR(resultset); phalcon_unserialize(resultset, data TSRMLS_CC); if (Z_TYPE_P(resultset) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); return; } PHALCON_OBS_VAR(rows); phalcon_array_fetch_string(&rows, resultset, SL("rows"), PH_NOISY); phalcon_update_property_this(this_ptr, SL("_rows"), rows TSRMLS_CC); PHALCON_OBS_VAR(cache); phalcon_array_fetch_string(&cache, resultset, SL("cache"), PH_NOISY); phalcon_update_property_this(this_ptr, SL("_cache"), cache TSRMLS_CC); PHALCON_OBS_VAR(column_types); phalcon_array_fetch_string(&column_types, resultset, SL("columnTypes"), PH_NOISY); phalcon_update_property_this(this_ptr, SL("_columnTypes"), column_types TSRMLS_CC); PHALCON_OBS_VAR(hydrate_mode); phalcon_array_fetch_string(&hydrate_mode, resultset, SL("hydrateMode"), PH_NOISY); phalcon_update_property_this(this_ptr, SL("_hydrateMode"), hydrate_mode TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Returns a slice of the resultset to show in the pagination * * @return stdClass */ PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){ zval *show = NULL, *config = NULL, *items = NULL, *page_number = NULL, *zero = NULL, *one = NULL; zval *smaller = NULL, *n = NULL, *page = NULL, *last_show_page = NULL, *start = NULL; zval *last_page = NULL, *possible_pages = NULL, *total_pages = NULL; zval *compare = NULL, *page_items = NULL, *i = NULL, *valid = NULL, *current = NULL, *maximum_pages = NULL; zval *next = NULL, *additional_page = NULL, *before = NULL, *remainder = NULL; zval *pages_total = NULL; zval *r0 = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(show); phalcon_read_property(&show, this_ptr, SL("_limitRows"), PH_NOISY_CC); PHALCON_INIT_VAR(config); phalcon_read_property(&config, this_ptr, SL("_config"), PH_NOISY_CC); PHALCON_INIT_VAR(items); phalcon_array_fetch_string(&items, config, SL("data"), PH_NOISY_CC); PHALCON_INIT_VAR(page_number); phalcon_read_property(&page_number, this_ptr, SL("_page"), PH_NOISY_CC); if (Z_TYPE_P(page_number) == IS_NULL) { PHALCON_INIT_VAR(page_number); ZVAL_LONG(page_number, 1); } PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_INIT_VAR(smaller); is_smaller_function(smaller, show, zero TSRMLS_CC); if (Z_TYPE_P(smaller) == IS_BOOL && Z_BVAL_P(smaller)) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less"); return; } PHALCON_INIT_VAR(n); phalcon_fast_count(n, items TSRMLS_CC); PHALCON_INIT_VAR(page); object_init(page); PHALCON_INIT_VAR(last_show_page); sub_function(last_show_page, page_number, one TSRMLS_CC); PHALCON_INIT_VAR(start); mul_function(start, show, last_show_page TSRMLS_CC); PHALCON_INIT_VAR(last_page); sub_function(last_page, n, one TSRMLS_CC); PHALCON_INIT_VAR(possible_pages); div_function(possible_pages, last_page, show TSRMLS_CC); PHALCON_INIT_VAR(total_pages); PHALCON_CALL_FUNC_PARAMS_1(total_pages, "ceil", possible_pages); if (Z_TYPE_P(items) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator"); return; } if (Z_TYPE_P(page_number) == IS_NULL) { PHALCON_INIT_VAR(page_number); ZVAL_LONG(page_number, 0); } PHALCON_INIT_VAR(compare); is_smaller_function(compare, start, zero TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less"); return; } PHALCON_INIT_VAR(page_items); array_init(page_items); PHALCON_INIT_VAR(compare); is_smaller_function(compare, zero, n TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_INIT_VAR(compare); is_smaller_or_equal_function(compare, start, n TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(items, "seek", start, PH_NO_CHECK); } else { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(items, "seek", one, PH_NO_CHECK); PHALCON_INIT_VAR(page_number); ZVAL_LONG(page_number, 1); } PHALCON_INIT_VAR(i); ZVAL_LONG(i, 1); ws_e435_0: PHALCON_INIT_VAR(r0); PHALCON_CALL_METHOD(r0, items, "valid", PH_NO_CHECK); PHALCON_CPY_WRT(valid, r0); if (Z_TYPE_P(valid) != IS_BOOL || (Z_TYPE_P(valid) == IS_BOOL && !Z_BVAL_P(valid))) { goto we_e435_0; } PHALCON_INIT_VAR(current); PHALCON_CALL_METHOD(current, items, "current", PH_NO_CHECK); phalcon_array_append(&page_items, current, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(compare); is_smaller_or_equal_function(compare, show, i TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { goto we_e435_0; } PHALCON_SEPARATE(i); increment_function(i); goto ws_e435_0; we_e435_0: if(0){} } phalcon_update_property_zval(page, SL("items"), page_items TSRMLS_CC); phalcon_update_property_long(page, SL("first"), 1 TSRMLS_CC); PHALCON_INIT_VAR(maximum_pages); phalcon_add_function(maximum_pages, start, show TSRMLS_CC); PHALCON_INIT_VAR(compare); is_smaller_function(compare, maximum_pages, n TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 1); PHALCON_INIT_VAR(next); phalcon_add_function(next, page_number, t0 TSRMLS_CC); } else { PHALCON_INIT_VAR(compare); is_equal_function(compare, maximum_pages, n TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_CPY_WRT(next, n); } else { PHALCON_INIT_VAR(possible_pages); div_function(possible_pages, n, show TSRMLS_CC); PHALCON_INIT_VAR(additional_page); phalcon_add_function(additional_page, possible_pages, one TSRMLS_CC); PHALCON_INIT_VAR(next); PHALCON_CALL_FUNC_PARAMS_1(next, "intval", additional_page); } } PHALCON_INIT_VAR(compare); is_smaller_function(compare, total_pages, next TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_CPY_WRT(next, total_pages); } phalcon_update_property_zval(page, SL("next"), next TSRMLS_CC); PHALCON_INIT_VAR(compare); is_smaller_function(compare, one, page_number TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_INIT_VAR(before); sub_function(before, page_number, one TSRMLS_CC); } else { PHALCON_INIT_VAR(before); ZVAL_LONG(before, 1); } phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); phalcon_update_property_zval(page, SL("current"), page_number TSRMLS_CC); PHALCON_INIT_VAR(remainder); mod_function(remainder, n, show TSRMLS_CC); PHALCON_INIT_VAR(possible_pages); div_function(possible_pages, n, show TSRMLS_CC); if (!phalcon_compare_strict_long(remainder, 0 TSRMLS_CC)) { PHALCON_INIT_VAR(next); phalcon_add_function(next, possible_pages, one TSRMLS_CC); PHALCON_INIT_VAR(pages_total); PHALCON_CALL_FUNC_PARAMS_1(pages_total, "intval", possible_pages); } else { PHALCON_CPY_WRT(pages_total, possible_pages); } phalcon_update_property_zval(page, SL("last"), pages_total TSRMLS_CC); phalcon_update_property_zval(page, SL("total_pages"), pages_total TSRMLS_CC); RETURN_CTOR(page); }
/** * Phalcon\Mvc\Model\Resultset\Simple constructor * * @param array $columnMap * @param Phalcon\Mvc\ModelInterface $model * @param Phalcon\Db\Result\Pdo $result * @param Phalcon\Cache\BackendInterface $cache * @param boolean $keepSnapshots */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, __construct){ zval *column_map, *model, *result, *cache = NULL, *keep_snapshots = NULL; zval *fetch_assoc, *limit, *row_count, *big_resultset; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|zz", &column_map, &model, &result, &cache, &keep_snapshots) == FAILURE) { RETURN_MM_NULL(); } if (!cache) { PHALCON_INIT_VAR(cache); } if (!keep_snapshots) { PHALCON_INIT_VAR(keep_snapshots); } phalcon_update_property_zval(this_ptr, SL("_model"), model TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_result"), result TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_cache"), cache TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_columnMap"), column_map TSRMLS_CC); if (Z_TYPE_P(result) != IS_OBJECT) { RETURN_MM_NULL(); } /** * Use only fetch assoc */ PHALCON_INIT_VAR(fetch_assoc); ZVAL_LONG(fetch_assoc, 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(result, "setfetchmode", fetch_assoc); PHALCON_INIT_VAR(limit); ZVAL_LONG(limit, 32); PHALCON_INIT_VAR(row_count); PHALCON_CALL_METHOD(row_count, result, "numrows"); /** * Check if it's a big resultset */ PHALCON_INIT_VAR(big_resultset); is_smaller_function(big_resultset, limit, row_count TSRMLS_CC); if (PHALCON_IS_TRUE(big_resultset)) { phalcon_update_property_long(this_ptr, SL("_type"), 1 TSRMLS_CC); } else { phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); } /** * Update the row-count */ phalcon_update_property_zval(this_ptr, SL("_count"), row_count TSRMLS_CC); /** * Set if the returned resultset must keep the record snapshots */ phalcon_update_property_zval(this_ptr, SL("_keepSnapshots"), keep_snapshots TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Cache the actual view render to certain level * * @param boolean|array $options */ PHP_METHOD(Phalcon_Mvc_View, cache){ zval *options = NULL, *view_options = NULL, *cache_options = NULL; zval *value = NULL, *key = NULL, *cache_level = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!options) { PHALCON_ALLOC_ZVAL_MM(options); ZVAL_BOOL(options, 1); } if (Z_TYPE_P(options) == IS_ARRAY) { PHALCON_INIT_VAR(view_options); phalcon_read_property(&view_options, this_ptr, SL("_options"), PH_NOISY_CC); eval_int = phalcon_array_isset_string(view_options, SL("cache")+1); if (eval_int) { PHALCON_INIT_VAR(cache_options); phalcon_array_fetch_string(&cache_options, view_options, SL("cache"), PH_NOISY_CC); } else { PHALCON_INIT_VAR(cache_options); array_init(cache_options); } if (!phalcon_valid_foreach(options TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(options); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_ecde_4: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_ecde_4; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); phalcon_array_update_zval(&cache_options, key, &value, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_4; fee_ecde_4: eval_int = phalcon_array_isset_string(cache_options, SL("level")+1); if (eval_int) { PHALCON_INIT_VAR(cache_level); phalcon_array_fetch_string(&cache_level, cache_options, SL("level"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_cacheLevel"), cache_level TSRMLS_CC); } else { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); } phalcon_update_property_zval(view_options, SL("cache"), cache_options TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_options"), view_options TSRMLS_CC); } else { if (zend_is_true(options)) { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); } else { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); } } PHALCON_MM_RESTORE(); }
/** * Rewinds the internal iterator */ PHP_METHOD(Phalcon_Assets_Collection, rewind){ phalcon_update_property_long(getThis(), SL("_position"), 0); }
/** * Cache the actual view render to certain level * * @param boolean|array $options */ PHP_METHOD(Phalcon_Mvc_View, cache){ zval *options = NULL, *view_options = NULL, *cache_options = NULL; zval *value = NULL, *key = NULL, *cache_level; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &options); if (!options) { PHALCON_INIT_VAR(options); ZVAL_BOOL(options, 1); } if (Z_TYPE_P(options) == IS_ARRAY) { PHALCON_OBS_VAR(view_options); phalcon_read_property_this(&view_options, this_ptr, SL("_options"), PH_NOISY_CC); if (Z_TYPE_P(view_options) != IS_ARRAY) { PHALCON_INIT_NVAR(view_options); array_init(view_options); } /** * Get the default cache options */ if (phalcon_array_isset_string(view_options, SS("cache"))) { PHALCON_OBS_VAR(cache_options); phalcon_array_fetch_string(&cache_options, view_options, SL("cache"), PH_NOISY_CC); } else { PHALCON_INIT_NVAR(cache_options); array_init(cache_options); } if (!phalcon_is_iterable(options, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); phalcon_array_update_zval(&cache_options, key, &value, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); } /** * Check if the user has defined a default cache level or use 5 as default */ if (phalcon_array_isset_string(cache_options, SS("level"))) { PHALCON_OBS_VAR(cache_level); phalcon_array_fetch_string(&cache_level, cache_options, SL("level"), PH_NOISY_CC); phalcon_update_property_this(this_ptr, SL("_cacheLevel"), cache_level TSRMLS_CC); } else { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); } phalcon_array_update_string(&view_options, SL("cache"), &cache_options, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_options"), view_options TSRMLS_CC); } else { /** * If 'options' isn't an array we enable the cache with the default options */ if (zend_is_true(options)) { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); } else { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); } } PHALCON_MM_RESTORE(); }
/** * Returns a slice of the resultset to show in the pagination * * @return stdClass */ PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){ zval *v0 = NULL, *v1 = NULL, *v2 = NULL, *v3 = NULL, *v4 = NULL, *v5 = NULL, *v6 = NULL; zval *v7 = NULL, *v8 = NULL, *v9 = NULL, *v10 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL, *t10 = NULL, *t11 = NULL, *t12 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL; zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL, *r19 = NULL, *r20 = NULL; zval *r21 = NULL, *r22 = NULL, *r23 = NULL, *r24 = NULL, *r25 = NULL, *r26 = NULL, *r27 = NULL; zval *r28 = NULL; zval *i0 = NULL, *i1 = NULL, *i2 = NULL; zval *a0 = NULL; zval *p2[] = { NULL }, *p3[] = { NULL }, *p4[] = { NULL }, *p5[] = { NULL }; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_limitRows", sizeof("_limitRows")-1, PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_CPY_WRT(v0, t0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_config", sizeof("_config")-1, PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, t1, "data", strlen("data"), PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_CPY_WRT(v1, r0); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_page", sizeof("_page")-1, PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_CPY_WRT(v2, t2); if (Z_TYPE_P(v2) == IS_NULL) { PHALCON_INIT_VAR(v2); ZVAL_LONG(v2, 1); } PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "count", v1, 0x008); PHALCON_CPY_WRT(v3, r1); PHALCON_ALLOC_ZVAL_MM(i0); object_init(i0); PHALCON_CPY_WRT(v4, i0); PHALCON_INIT_VAR(t3); ZVAL_LONG(t3, 1); PHALCON_ALLOC_ZVAL_MM(r2); sub_function(r2, v2, t3 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r3); mul_function(r3, v0, r2 TSRMLS_CC); PHALCON_CPY_WRT(v5, r3); PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_INIT_VAR(t4); ZVAL_LONG(t4, 1); PHALCON_ALLOC_ZVAL_MM(r5); sub_function(r5, v3, t4 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r6); div_function(r6, r5, v0 TSRMLS_CC); Z_ADDREF_P(r6); PHALCON_CALL_FUNC_PARAMS_1(r4, "ceil", r6, 0x00D); Z_DELREF_P(r6); PHALCON_CPY_WRT(v6, r4); if (Z_TYPE_P(v1) != IS_OBJECT) { PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_paginator_exception_class_entry); PHALCON_INIT_VAR(p2[0]); ZVAL_STRING(p2[0], "Invalid data for paginator", 1); PHALCON_CALL_METHOD_PARAMS_NORETURN(i1, "__construct", 1, p2, PHALCON_CALL_CHECK); zend_throw_exception_object(i1 TSRMLS_CC); Z_ADDREF_P(i1); PHALCON_MM_RESTORE(); return; } if (Z_TYPE_P(v2) == IS_NULL) { PHALCON_INIT_VAR(v2); ZVAL_LONG(v2, 0); } PHALCON_INIT_VAR(t5); ZVAL_LONG(t5, 0); PHALCON_INIT_VAR(r7); is_smaller_function(r7, v5, t5 TSRMLS_CC); if (zend_is_true(r7)) { PHALCON_ALLOC_ZVAL_MM(i2); object_init_ex(i2, phalcon_paginator_exception_class_entry); PHALCON_INIT_VAR(p3[0]); ZVAL_STRING(p3[0], "The start page number is zero or less", 1); PHALCON_CALL_METHOD_PARAMS_NORETURN(i2, "__construct", 1, p3, PHALCON_CALL_CHECK); zend_throw_exception_object(i2 TSRMLS_CC); Z_ADDREF_P(i2); PHALCON_MM_RESTORE(); return; } PHALCON_INIT_VAR(a0); array_init(a0); phalcon_update_property_zval(v4, "items", strlen("items"), a0 TSRMLS_CC); PHALCON_INIT_VAR(t6); ZVAL_LONG(t6, 0); PHALCON_INIT_VAR(r8); is_smaller_function(r8, t6, v3 TSRMLS_CC); if (zend_is_true(r8)) { PHALCON_INIT_VAR(r9); is_smaller_or_equal_function(r9, v5, v3 TSRMLS_CC); if (zend_is_true(r9)) { Z_ADDREF_P(v5); p4[0] = v5; PHALCON_CALL_METHOD_PARAMS_NORETURN(v1, "seek", 1, p4, PHALCON_CALL_DEFAULT); Z_DELREF_P(p4[0]); } else { PHALCON_INIT_VAR(p5[0]); ZVAL_LONG(p5[0], 1); PHALCON_CALL_METHOD_PARAMS_NORETURN(v1, "seek", 1, p5, PHALCON_CALL_DEFAULT); PHALCON_INIT_VAR(v2); ZVAL_LONG(v2, 1); } PHALCON_INIT_VAR(v7); ZVAL_LONG(v7, 1); ws_e435_0: PHALCON_INIT_VAR(r10); PHALCON_CALL_METHOD(r10, v1, "valid", PHALCON_CALL_DEFAULT); if (!zend_is_true(r10)) { goto we_e435_0; } PHALCON_INIT_VAR(r11); PHALCON_CALL_METHOD(r11, v1, "current", PHALCON_CALL_DEFAULT); PHALCON_INIT_VAR(t7); phalcon_read_property(&t7, v4, "items", sizeof("items")-1, PHALCON_NOISY_FETCH TSRMLS_CC); Z_ADDREF_P(r11); phalcon_array_append(t7, r11 TSRMLS_CC); phalcon_update_property_zval(v4, "items", strlen("items"), t7 TSRMLS_CC); PHALCON_INIT_VAR(r12); is_smaller_or_equal_function(r12, v0, v7 TSRMLS_CC); if (zend_is_true(r12)) { goto we_e435_0; } PHALCON_SEPARATE(v7); increment_function(v7); goto ws_e435_0; we_e435_0: if(0) { }; } phalcon_update_property_long(v4, "first", strlen("first"), 1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r13); phalcon_add_function(r13, v5, v0 TSRMLS_CC); PHALCON_INIT_VAR(r14); is_smaller_function(r14, r13, v3 TSRMLS_CC); if (zend_is_true(r14)) { PHALCON_INIT_VAR(t8); ZVAL_LONG(t8, 1); PHALCON_ALLOC_ZVAL_MM(r15); phalcon_add_function(r15, v2, t8 TSRMLS_CC); PHALCON_CPY_WRT(v8, r15); } else { PHALCON_ALLOC_ZVAL_MM(r16); phalcon_add_function(r16, v5, v0 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r17); is_equal_function(r17, r16, v3 TSRMLS_CC); if (zend_is_true(r17)) { PHALCON_CPY_WRT(v8, v3); } else { PHALCON_ALLOC_ZVAL_MM(r18); PHALCON_ALLOC_ZVAL_MM(r19); div_function(r19, v3, v0 TSRMLS_CC); PHALCON_CALL_FUNC_PARAMS_1(r18, "intval", r19, 0x00E); PHALCON_INIT_VAR(t9); ZVAL_LONG(t9, 1); PHALCON_ALLOC_ZVAL_MM(r20); phalcon_add_function(r20, r18, t9 TSRMLS_CC); PHALCON_CPY_WRT(v8, r20); } } PHALCON_INIT_VAR(r21); is_smaller_function(r21, v6, v8 TSRMLS_CC); if (zend_is_true(r21)) { PHALCON_CPY_WRT(v8, v6); } phalcon_update_property_zval(v4, "next", strlen("next"), v8 TSRMLS_CC); PHALCON_INIT_VAR(t10); ZVAL_LONG(t10, 1); PHALCON_INIT_VAR(r22); is_smaller_function(r22, t10, v2 TSRMLS_CC); if (zend_is_true(r22)) { PHALCON_INIT_VAR(t11); ZVAL_LONG(t11, 1); PHALCON_ALLOC_ZVAL_MM(r23); sub_function(r23, v2, t11 TSRMLS_CC); PHALCON_CPY_WRT(v9, r23); } else { PHALCON_INIT_VAR(v9); ZVAL_LONG(v9, 1); } phalcon_update_property_zval(v4, "before", strlen("before"), v9 TSRMLS_CC); phalcon_update_property_zval(v4, "current", strlen("current"), v2 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r24); mod_function(r24, v3, v0 TSRMLS_CC); if (zend_is_true(r24)) { PHALCON_ALLOC_ZVAL_MM(r25); PHALCON_ALLOC_ZVAL_MM(r26); div_function(r26, v3, v0 TSRMLS_CC); PHALCON_CALL_FUNC_PARAMS_1(r25, "intval", r26, 0x00E); PHALCON_INIT_VAR(t12); ZVAL_LONG(t12, 1); PHALCON_ALLOC_ZVAL_MM(r27); phalcon_add_function(r27, r25, t12 TSRMLS_CC); PHALCON_CPY_WRT(v10, r27); } else { PHALCON_ALLOC_ZVAL_MM(r28); div_function(r28, v3, v0 TSRMLS_CC); PHALCON_CPY_WRT(v10, r28); } phalcon_update_property_zval(v4, "last", strlen("last"), v10 TSRMLS_CC); phalcon_update_property_zval(v4, "total_pages", strlen("total_pages"), v10 TSRMLS_CC); PHALCON_RETURN_CTOR(v4); }
/** * Rewinds the internal iterator */ PHP_METHOD(Phalcon_Validation_Message_Group, rewind){ phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); }
/** * Returns a slice of the resultset to show in the pagination * * @return stdClass */ PHP_METHOD(Phalcon_Paginator_Adapter_Sql, getPaginate){ zval db = {}, sql = {}, total_sql = {}, bind = {}, limit = {}, number_page = {}, number = {}, fetch_mode = {}, items = {}, row = {}, rowcount = {}; long int i_limit, i_number_page, i_number, i_before, i_rowcount; long int i_total_pages, i_next; ldiv_t tp; phalcon_return_property(&db, getThis(), SL("_db")); phalcon_return_property(&sql, getThis(), SL("_sql")); phalcon_return_property(&total_sql, getThis(), SL("_total_sql")); phalcon_return_property(&bind, getThis(), SL("_bind")); phalcon_return_property(&limit, getThis(), SL("_limitRows")); phalcon_return_property(&number_page, getThis(), SL("_page")); phalcon_return_property(&fetch_mode, getThis(), SL("_fetchMode")); i_limit = phalcon_get_intval(&limit); i_number_page = phalcon_get_intval(&number_page); if (i_limit < 1) { /* This should never happen unless someone deliberately modified the properties of the object */ i_limit = 10; } if (!i_number_page) { i_number_page = 1; } i_number = (i_number_page - 1) * i_limit; i_before = (i_number_page == 1) ? 1 : (i_number_page - 1); PHALCON_CALL_METHODW(&row, &db, "fetchone", &total_sql, &fetch_mode, &bind); phalcon_return_property(&rowcount, &row, SL("rowcount")); PHALCON_SEPARATE(&bind); /* Set the limit clause avoiding negative offsets */ if (i_number < i_limit) { phalcon_array_update_str(&bind, SL("limit"), &limit, PH_COPY); phalcon_array_update_str_long(&bind, SL("offset"), 0, 0); } else { ZVAL_LONG(&number, i_number); phalcon_array_update_str(&bind, SL("limit"), &limit, PH_COPY); phalcon_array_update_str(&bind, SL("offset"), &number, PH_COPY); } PHALCON_CALL_METHODW(&items, &db, "fetchall", &sql, &fetch_mode, &bind); i_rowcount = phalcon_get_intval(&rowcount); tp = ldiv(i_rowcount, i_limit); i_total_pages = tp.quot + (tp.rem ? 1 : 0); i_next = (i_number_page < i_total_pages) ? (i_number_page + 1) : i_total_pages; object_init(return_value); phalcon_update_property_zval(return_value, SL("items"), &items); phalcon_update_property_long(return_value, SL("before"), i_before); phalcon_update_property_long(return_value, SL("first"), 1); phalcon_update_property_long(return_value, SL("next"), i_next); phalcon_update_property_long(return_value, SL("last"), i_total_pages); phalcon_update_property_long(return_value, SL("current"), i_number_page); phalcon_update_property_long(return_value, SL("total_pages"), i_total_pages); phalcon_update_property_long(return_value, SL("total_items"), i_rowcount); }