idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
51,300 | public function validateValidItem ( ) { if ( ! $ this -> value ) { return ; } $ this -> getValueList ( ) ; $ values = explode ( $ this -> separator , $ this -> value ) ; foreach ( $ values as $ v ) { if ( ! isset ( $ this -> value_list [ $ v ] ) ) { $ this -> displayFieldError ( "Value $v is not one of the offered values" ) ; return $ this -> validate ( ) ; } } } | Validate POSTed field value . |
51,301 | public function getValueList ( ) { try { if ( $ this -> model ) { $ id = $ this -> model -> id_field ; $ title = $ this -> model -> getElement ( $ this -> model -> title_field ) ; $ this -> value_list = array ( ) ; foreach ( $ this -> model as $ row ) { $ this -> value_list [ ( string ) $ row [ $ id ] ] = $ row [ $ title ] ; } } if ( $ this -> empty_text && ! isset ( $ this -> value_list [ $ this -> empty_value ] ) ) { $ this -> value_list = array ( $ this -> empty_value => $ this -> empty_text ) + $ this -> value_list ; } return $ this -> value_list ; } catch ( \ atk4 \ core \ Exception $ e ) { $ e -> addMoreInfo ( 'values_for_field' , $ this -> short_name ) ; throw $ e ; } } | Return value list . |
51,302 | public function normalize ( ) { $ data = $ this -> get ( ) ; if ( is_array ( $ data ) ) { $ data = implode ( $ this -> separator , $ data ) ; } $ data = trim ( $ data , $ this -> separator ) ; if ( ! $ data ) { $ data = null ; } if ( get_magic_quotes_gpc ( ) ) { $ this -> set ( stripslashes ( $ data ) ) ; } else { $ this -> set ( $ data ) ; } return parent :: normalize ( ) ; } | Normalize POSTed data . |
51,303 | public function send ( OutgoingMessage $ message ) { try { $ message = $ this -> mailer -> send ( [ 'text' => $ message -> getView ( ) ] , $ message -> getData ( ) , function ( $ email ) use ( $ message ) { $ this -> generateMessage ( $ email , $ message ) ; } ) ; } catch ( InvalidArgumentException $ e ) { $ message = $ this -> sendRaw ( $ message ) ; } return $ message ; } | Sends a SMS message via the mailer . |
51,304 | protected function generateMessage ( $ email , $ message ) { foreach ( $ message -> getToWithCarriers ( ) as $ number ) { $ email -> to ( $ this -> buildEmail ( $ number , $ message ) ) ; } if ( $ message -> getAttachImages ( ) ) { foreach ( $ message -> getAttachImages ( ) as $ image ) { $ email -> attach ( $ image ) ; } } $ email -> from ( $ message -> getFrom ( ) ) ; return $ email ; } | Generates the Laravel Message Object . |
51,305 | protected function sendRaw ( OutgoingMessage $ message ) { $ message = $ this -> mailer -> raw ( $ message -> getView ( ) , function ( $ email ) use ( $ message ) { $ this -> generateMessage ( $ email , $ message ) ; } ) ; return $ message ; } | Sends a SMS message via the mailer using the raw method . |
51,306 | protected function buildEmail ( $ number , OutgoingMessage $ message ) { if ( ! $ number [ 'carrier' ] ) { throw new \ InvalidArgumentException ( 'A carrier must be specified if using the E-Mail Driver.' ) ; } return $ number [ 'number' ] . '@' . $ this -> lookupGateway ( $ number [ 'carrier' ] , $ message -> isMMS ( ) ) ; } | Builds the email address of a number . |
51,307 | protected function lookupGateway ( $ carrier , $ mms ) { if ( $ mms ) { switch ( $ carrier ) { case 'att' : return 'mms.att.net' ; case 'airfiremobile' : throw new \ InvalidArgumentException ( 'Air Fire Mobile does not support Email Gateway MMS messages.' ) ; case 'alaskacommunicates' : return 'msg.acsalaska.com' ; case 'ameritech' : throw new \ InvalidArgumentException ( 'Ameritech does not support Email Gateway MMS messages.' ) ; case 'assurancewireless' : return 'vmobl.com' ; case 'boostmobile' : return 'myboostmobile.com' ; case 'cleartalk' : throw new \ InvalidArgumentException ( 'Clear Talk does not support Email Gateway MMS messages.' ) ; case 'cricket' : return 'mms.mycricket.com ' ; case 'metropcs' : return 'mymetropcs.com' ; case 'nextech' : throw new \ InvalidArgumentException ( 'NexTech does not support Email Gateway MMS messages.' ) ; case 'projectfi' : return 'msg.fi.google.com' ; case 'rogerswireless' : return 'mms.rogers.com' ; case 'unicel' : return 'utext.com' ; case 'verizonwireless' : return 'vzwpix.com' ; case 'virginmobile' : return 'vmpix.com' ; case 'tmobile' : return 'tmomail.net' ; case 'sprint' : return 'pm.sprint.com' ; case 'uscellular' : return 'mms.uscc.net' ; default : throw new \ InvalidArgumentException ( 'Carrier specified is not found.' ) ; } } else { switch ( $ carrier ) { case 'att' : return 'txt.att.net' ; case 'airfiremobile' : return 'sms.airfiremobile.com' ; case 'alaskacommunicates' : return 'msg.acsalaska.com' ; case 'ameritech' : return 'paging.acswireless.com' ; case 'assurancewireless' : return 'vmobl.com' ; case 'boostmobile' : return 'sms.myboostmobile.com' ; case 'cleartalk' : return 'sms.cleartalk.us' ; case 'cricket' : return 'sms.mycricket.com' ; case 'metropcs' : return 'mymetropcs.com' ; case 'nextech' : return 'sms.ntwls.net' ; case 'projectfi' : return 'msg.fi.google.com' ; case 'rogerswireless' : return 'sms.rogers.com' ; case 'unicel' : return 'utext.com' ; case 'verizonwireless' : return 'vtext.com' ; case 'virginmobile' : return 'vmobl.com' ; case 'tmobile' : return 'tmomail.net' ; case 'sprint' : return 'messaging.sprintpcs.com' ; case 'uscellular' : return 'email.uscc.net' ; default : throw new \ InvalidArgumentException ( 'Carrier specified is not found.' ) ; } } } | Finds the gateway based on the carrier and MMS . |
51,308 | protected function validateRequest ( ) { $ data = $ _POST ; ksort ( $ data ) ; $ url = $ this -> url ; foreach ( $ data as $ key => $ value ) { $ url = $ url . $ key . $ value ; } $ hmac = hash_hmac ( 'sha1' , $ url , $ this -> authToken , true ) ; if ( base64_encode ( $ hmac ) != $ _SERVER [ 'HTTP_X_TWILIO_SIGNATURE' ] ) { throw new \ InvalidArgumentException ( 'This request was not able to verify it came from Twilio.' ) ; } } | Checks if a message is authentic from Twilio . |
51,309 | public function sseMessageLine ( $ text , $ id = null ) { if ( ! is_null ( $ id ) ) { echo "id: $id\n" ; } $ text = explode ( "\n" , $ text ) ; $ text = 'data: ' . implode ( "\ndata: " , $ text ) . "\n\n" ; echo $ text ; flush ( ) ; } | Sends text through SSE channel . Text may contain newlines which will be transmitted proprely . Optionally you can specify ID also . |
51,310 | public function sseMessageJSON ( $ text , $ id = null ) { if ( ! is_null ( $ id ) ) { echo "id: $id\n" ; } $ text = 'data: ' . json_encode ( $ text ) . "\n\n" ; $ this -> _out_encoding = false ; echo $ text ; flush ( ) ; $ this -> _out_encoding = true ; } | Sends text or structured data through SSE channel encoded in JSON format . You may supply id argument . |
51,311 | public function jsEval ( $ str ) { if ( is_object ( $ str ) ) { $ str = $ str -> _render ( ) ; } $ data = [ 'js' => $ str ] ; $ this -> sseMessageJSON ( $ data ) ; } | Add ability to send javascript . |
51,312 | public function out ( $ str , $ opt = array ( ) ) { $ data = array_merge ( $ opt , [ 'text' => rtrim ( $ str , "\n" ) ] ) ; $ this -> sseMessageJSON ( $ data ) ; } | Displays output in the console . |
51,313 | public function rule_regex ( $ a ) { $ opt = array ( ) ; $ rule = $ this -> pullRule ( ) ; if ( $ rule [ 0 ] != '/' ) { $ rule = '/^' . $ rule . '*$/' ; } $ opt [ 'regexp' ] = $ rule ; if ( ! filter_var ( $ a , FILTER_VALIDATE_REGEXP , [ 'options' => $ opt ] ) ) { return $ this -> fail ( 'does not match the pattern' ) ; } } | Requires a regex pattern as the next rule in the chain . |
51,314 | public function rule_between ( $ a ) { $ min = $ this -> pullRule ( true ) ; $ max = $ this -> pullRule ( true ) ; if ( is_numeric ( $ a ) ) { if ( $ a < $ min || $ a > $ max ) { return $ this -> fail ( 'must be between {{arg1}} and {{arg2}}' , $ min , $ max ) ; } } else { return $ this -> fail ( 'Must be a numeric value' ) ; } } | Inclusive range check . |
51,315 | public function rule_decimal_places ( $ a ) { $ places = $ this -> pullRule ( ) ; $ pattern = sprintf ( '/^[0-9]+\.[0-9]{%s}$/' , $ places ) ; if ( ! preg_match ( $ pattern , $ a ) ) { return $ this -> fail ( 'Must have {{arg1}} decimal places' , $ places ) ; } } | Checks for a specific number of decimal places . |
51,316 | public function rule_bool ( $ a ) { $ a = strtolower ( $ a ) ; $ vals = array ( 'true' , 'false' , 't' , 'f' , 1 , 0 , 'yes' , 'no' , 'y' , 'n' ) ; if ( ! in_array ( $ a , $ vals ) ) { return $ this -> fail ( 'Must be a boolean value' ) ; } } | Validate for true|false|t|f|1|0|yes|no|y|n . |
51,317 | public function rule_true ( $ a ) { $ a = strtolower ( $ a ) ; $ vals = array ( 'true' , 't' , 1 , 'yes' , 'y' ) ; if ( ! in_array ( $ a , $ vals ) ) { return $ this -> fail ( 'Must be true' ) ; } } | Validate for true|t|1|yes|y . |
51,318 | public function rule_false ( $ a ) { $ a = strtolower ( $ a ) ; $ vals = array ( 'false' , 'f' , 0 , 'no' , 'n' ) ; if ( ! in_array ( $ a , $ vals ) ) { return $ this -> fail ( 'Must be false' ) ; } } | Validate for false|f|0|no|n . |
51,319 | public function validate_iso_date ( $ a ) { $ date = explode ( '-' , $ a ) ; $ msg = 'Must be date in format: YYYY-MMM-DD' ; if ( count ( $ date ) != 3 ) { return $ this -> fail ( $ msg ) ; } if ( strlen ( $ date [ 0 ] ) !== 4 || strlen ( $ date [ 1 ] ) !== 2 || strlen ( $ date [ 2 ] ) !== 2 ) { return $ this -> fail ( $ msg ) ; } if ( ! @ checkdate ( $ date [ 1 ] , $ date [ 2 ] , $ date [ 0 ] ) ) { return $ this -> fail ( $ msg ) ; } } | Validate for ISO date in format YYYY - MM - DD . |
51,320 | public function rule_iso_time ( $ a ) { $ pattern = "/^([0-9]{2}):([0-9]{2})(?::([0-9]{2})(?:(?:\.[0-9]{1,}))?)?$/" ; $ msg = 'Must be a valid ISO time' ; if ( preg_match ( $ pattern , $ a , $ matches ) ) { if ( $ matches [ 1 ] > 24 ) { return $ this -> fail ( $ msg ) ; } if ( $ matches [ 2 ] > 59 ) { return $ this -> fail ( $ msg ) ; } if ( isset ( $ matches [ 3 ] ) && $ matches [ 3 ] > 59 ) { return $ this -> fail ( $ msg ) ; } } else { return $ this -> fail ( $ msg ) ; } } | Validate for ISO time . |
51,321 | public function rule_credit_card ( $ a ) { $ msg = 'Not a valid card number' ; $ sum = 0 ; $ alt = false ; for ( $ i = strlen ( $ a ) - 1 ; $ i >= 0 ; -- $ i ) { $ n = substr ( $ a , $ i , 1 ) ; if ( $ alt ) { $ n *= 2 ; if ( $ n > 9 ) { $ n = ( $ n % 10 ) + 1 ; } } $ sum += $ n ; $ alt = ! $ alt ; } if ( ! ( $ sum % 10 == 0 ) ) { return $ this -> fail ( $ msg ) ; } else { $ stripped = str_replace ( '0' , '' , $ a ) ; if ( strlen ( $ stripped ) == 0 ) { return $ this -> fail ( $ msg ) ; } } } | Validate for credit card number . |
51,322 | protected function card_date_parser ( $ a , $ type ) { $ date = str_replace ( '/' , '' , $ a ) ; if ( ! preg_match ( '|^[0-9]{4}$|' , $ date ) ) { return false ; } $ month = substr ( $ date , 0 , 2 ) ; $ year = substr ( $ date , 2 , 2 ) ; if ( $ month > 12 ) { return false ; } $ parts = array ( date ( 'Y' ) , date ( 'm' ) , 1 ) ; $ now_datetime = new DateTime ( implode ( '-' , $ parts ) ) ; $ parts = array ( '20' . $ year , $ month , '1' ) ; $ card_datetime = new DateTime ( implode ( '-' , $ parts ) ) ; $ interval = $ now_datetime -> diff ( $ card_datetime ) ; $ days = $ interval -> format ( '%R%a days' ) ; if ( $ type == 'from' ) { if ( $ days <= 0 && $ days > - 3650 ) { return true ; } else { return false ; } } elseif ( $ type == 'to' ) { if ( $ days >= 0 && $ days < 3650 ) { return true ; } else { return false ; } } else { $ msg = "Bad date type '$type' in card-date validation" ; throw new Error ( $ msg ) ; } } | Helper for validating card to and from dates . |
51,323 | protected function prep_in_vals ( $ a ) { $ vals = $ this -> pullRule ( ) ; if ( is_array ( $ vals ) ) { return $ vals ; } $ vals = explode ( ',' , $ vals ) ; array_walk ( $ vals , function ( $ val ) { return trim ( $ val ) ; } ) ; return $ vals ; } | Explode and trim a comma - delmited list for the in and not_in rules . |
51,324 | public function _beforeInit ( ) { $ this -> pm = $ this -> add ( $ this -> pagemanager_class , $ this -> pagemanager_options ) ; $ this -> pm -> parseRequestedURL ( ) ; parent :: _beforeInit ( ) ; } | Executed before init this method will initialize PageManager and pathfinder . |
51,325 | public function init ( ) { $ this -> getLogger ( ) ; $ this -> sendHeaders ( ) ; $ this -> cleanMagicQuotes ( ) ; parent :: init ( ) ; $ this -> initializeTemplate ( ) ; if ( get_class ( $ this ) == 'App_Web' ) { $ this -> setConfig ( array ( 'url_postfix' => '.php' , 'url_prefix' => '' ) ) ; } } | Redefine this function instead of default constructor . |
51,326 | public function cleanMagicQuotes ( ) { if ( ! function_exists ( 'stripslashes_array' ) ) { function stripslashes_array ( & $ array , $ iterations = 0 ) { if ( $ iterations < 3 ) { foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { stripslashes_array ( $ array [ $ key ] , $ iterations + 1 ) ; } else { $ array [ $ key ] = stripslashes ( $ array [ $ key ] ) ; } } } } } if ( get_magic_quotes_gpc ( ) ) { stripslashes_array ( $ _GET ) ; stripslashes_array ( $ _POST ) ; stripslashes_array ( $ _COOKIE ) ; } } | Magic Quotes were a design error . Let s strip them if they are enabled . |
51,327 | public function destroySession ( ) { if ( $ this -> _is_session_initialized ) { $ _SESSION = array ( ) ; if ( isset ( $ _COOKIE [ $ this -> name ] ) ) { setcookie ( $ this -> name , '' , time ( ) - 42000 , '/' ) ; } session_destroy ( ) ; $ this -> _is_session_initialized = false ; } } | Completely destroy existing session . |
51,328 | public function main ( ) { try { $ this -> initLayout ( ) ; } catch ( Exception $ e ) { if ( ! ( $ e instanceof Exception_Stop ) ) { return $ this -> caughtException ( $ e ) ; } } try { $ this -> hook ( 'post-init' ) ; $ this -> hook ( 'afterInit' ) ; $ this -> hook ( 'pre-exec' ) ; $ this -> hook ( 'beforeExec' ) ; if ( isset ( $ _GET [ 'submit' ] ) && $ _POST ) { $ this -> hook ( 'submitted' ) ; } $ this -> hook ( 'post-submit' ) ; $ this -> hook ( 'afterSubmit' ) ; $ this -> execute ( ) ; } catch ( Exception $ e ) { $ this -> caughtException ( $ e ) ; } $ this -> hook ( 'saveDelayedModels' ) ; } | Call this method from your index file . It is the main method of Agile Toolkit . |
51,329 | public function execute ( ) { $ this -> rendered [ 'sub-elements' ] = array ( ) ; try { $ this -> hook ( 'pre-render' ) ; $ this -> hook ( 'beforeRender' ) ; $ this -> recursiveRender ( ) ; if ( isset ( $ _GET [ 'cut_object' ] ) ) { throw new BaseException ( "Unable to cut object with name='" . $ _GET [ 'cut_object' ] . "'. " . "It wasn't initialized" ) ; } if ( isset ( $ _GET [ 'cut_region' ] ) ) { if ( ! $ this -> cut_region_result ) { throw new BaseException ( "Unable to cut region with name='" . $ _GET [ 'cut_region' ] . "'" ) ; } echo $ this -> cut_region_result ; return ; } } catch ( Exception $ e ) { if ( $ e instanceof Exception_Stop ) { $ this -> hook ( 'cut-output' ) ; if ( isset ( $ e -> result ) ) { echo $ e -> result ; } $ this -> hook ( 'post-render-output' ) ; return ; } throw $ e ; } } | Main execution loop . |
51,330 | public function render ( ) { $ this -> hook ( 'pre-js-collection' ) ; if ( isset ( $ this -> app -> jquery ) && $ this -> app -> jquery ) { $ this -> app -> jquery -> getJS ( $ this ) ; } if ( ! ( $ this -> template ) ) { throw new BaseException ( 'You should specify template for APP object' ) ; } $ this -> hook ( 'pre-render-output' ) ; if ( headers_sent ( $ file , $ line ) ) { echo "<br />Direct output (echo or print) detected on $file:$line. <a target='_blank' " . "href='http://agiletoolkit.org/error/direct_output'>Use \$this->add('Text') instead</a>.<br />" ; } echo $ this -> template -> render ( ) ; $ this -> hook ( 'post-render-output' ) ; } | Renders all objects inside applications and echo all output to the browser . |
51,331 | public function redirect ( $ page = null , $ args = array ( ) ) { $ url = $ this -> url ( $ page , $ args ) ; if ( $ this -> app -> isAjaxOutput ( ) ) { if ( $ _GET [ 'cut_page' ] ) { echo '<script>' . $ this -> app -> js ( ) -> redirect ( $ url ) . '</script>Redirecting page...' ; exit ; } else { $ this -> app -> js ( ) -> redirect ( $ url ) -> execute ( ) ; } } header ( 'Location: ' . $ url ) ; exit ; } | Perform instant redirect to another page . |
51,332 | public function setTags ( $ t ) { if ( $ this -> app -> pathfinder && $ this -> app -> pathfinder -> atk_public ) { $ q = $ this -> app -> pathfinder -> atk_public -> getURL ( ) ; } else { $ q = 'http://www.agiletoolkit.org/' ; } $ t -> trySet ( 'atk_path' , $ q . '/' ) ; $ t -> trySet ( 'base_path' , $ q = $ this -> app -> pm -> base_path ) ; try { $ t -> eachTag ( $ tag = 'template' , array ( $ this , '_locateTemplate' ) ) ; $ t -> eachTag ( $ tag = 'public' , array ( $ this , '_locatePublic' ) ) ; $ t -> eachTag ( $ tag = 'js' , array ( $ this , '_locateJS' ) ) ; $ t -> eachTag ( $ tag = 'css' , array ( $ this , '_locateCSS' ) ) ; $ t -> eachTag ( $ tag = 'page' , array ( $ this , 'getBaseURL' ) ) ; } catch ( BaseException $ e ) { throw $ e -> addMoreInfo ( 'processing_tag' , $ tag ) -> addMoreInfo ( 'template' , $ t -> template_file ) ; } $ this -> hook ( 'set-tags' , array ( $ t ) ) ; } | Called on all templates in the system populates some system - wide tags . |
51,333 | public function addLayout ( $ name ) { if ( ! $ this -> template ) { return ; } if ( method_exists ( $ this , $ lfunc = 'layout_' . $ name ) ) { if ( $ this -> template -> is_set ( $ name ) ) { $ this -> $ lfunc ( ) ; } } return $ this ; } | Register new layout which if has method and tag in the template will be rendered . |
51,334 | public function layout_Content ( ) { $ page = str_replace ( '/' , '_' , $ this -> page ) ; if ( method_exists ( $ this , $ pagefunc = 'page_' . $ page ) ) { $ p = $ this -> add ( 'Page' , $ this -> page , 'Content' ) ; $ this -> $ pagefunc ( $ p ) ; } else { $ this -> app -> locate ( 'page' , str_replace ( '_' , '/' , $ this -> page ) . '.php' ) ; $ this -> add ( 'page_' . $ page , $ page , 'Content' ) ; } } | Default handling of Content page . To be replaced by App_Frontend This function initializes content . Content is page - dependant . |
51,335 | protected function import ( ) { $ query = '' ; while ( ! feof ( $ this -> file ) ) { $ line = fgets ( $ this -> file ) ; $ trim = trim ( $ line ) ; if ( $ trim === '' || strpos ( $ trim , '--' ) === 0 || strpos ( $ trim , '/*' ) === 0 ) { continue ; } if ( strpos ( $ trim , 'DELIMITER ' ) === 0 ) { $ this -> delimiter = substr ( $ trim , 10 ) ; continue ; } $ query .= $ line ; if ( substr ( $ trim , strlen ( $ this -> delimiter ) * - 1 ) === $ this -> delimiter ) { $ this -> pdo -> exec ( substr ( trim ( $ query ) , 0 , strlen ( $ this -> delimiter ) * - 1 ) ) ; $ query = '' ; } } } | Processes the SQL file . |
51,336 | public function addField ( $ name , $ actual_field = null ) { if ( $ this -> hasElement ( $ name ) ) { if ( $ name == $ this -> id_field ) { return $ this -> getElement ( $ name ) ; } throw $ this -> exception ( 'Field with this name is already defined' ) -> addMoreInfo ( 'field' , $ name ) ; } if ( $ name == 'deleted' && isset ( $ this -> app -> compat ) ) { $ f = $ this -> add ( 'Field_Deleted' , $ name ) ; return $ f -> enum ( array ( 'Y' , 'N' ) ) ; } $ f = $ this -> add ( $ this -> field_class , $ name ) ; if ( ! is_null ( $ actual_field ) ) { $ f -> actual ( $ actual_field ) ; } return $ f ; } | Adds field to model |
51,337 | public function initQuery ( ) { if ( ! $ this -> table ) { throw $ this -> exception ( '$table property must be defined' ) ; } $ this -> dsql = $ this -> db -> dsql ( ) ; $ this -> dsql -> debug ( $ this -> debug ) ; $ this -> dsql -> table ( $ this -> table , $ this -> table_alias ) ; $ this -> dsql -> default_field = $ this -> dsql -> expr ( '*,' . $ this -> dsql -> bt ( $ this -> table_alias ? : $ this -> table ) . '.' . $ this -> dsql -> bt ( $ this -> id_field ) ) ; $ this -> dsql -> id_field = $ this -> id_field ; return $ this ; } | Initializes base query for this model . |
51,338 | public function debug ( $ enabled = true ) { if ( $ enabled === true ) { $ this -> debug = $ enabled ; if ( $ this -> dsql ) { $ this -> dsql -> debug ( $ enabled ) ; } } else { parent :: debug ( $ enabled ) ; } return $ this ; } | Turns debugging mode on|off for this model . All database operations will be outputed . |
51,339 | public function fieldQuery ( $ field ) { $ query = $ this -> dsql ( ) -> del ( 'fields' ) ; if ( is_string ( $ field ) ) { $ field = $ this -> getElement ( $ field ) ; } $ field -> updateSelectQuery ( $ query ) ; return $ query ; } | Return query for a specific field . All other fields are ommitted . |
51,340 | public function titleQuery ( ) { $ query = $ this -> dsql ( ) -> del ( 'fields' ) ; $ el = $ this -> hasElement ( $ this -> title_field ) ; if ( $ this -> title_field && $ el ) { $ el -> updateSelectQuery ( $ query ) ; return $ query ; } return $ query -> field ( $ query -> concat ( 'Record #' , $ this -> getElement ( $ this -> id_field ) ) ) ; } | Returns query which selects title field |
51,341 | public function addExpression ( $ name , $ expression = null ) { $ f = $ this -> add ( 'Field_Expression' , $ name ) ; return $ f -> set ( $ expression ) ; } | Adds and returns SQL - calculated expression as a read - only field . |
51,342 | public function join ( $ foreign_table , $ master_field = null , $ join_kind = null , $ _foreign_alias = null , $ relation = null ) { if ( ! $ _foreign_alias ) { $ _foreign_alias = '_' . $ foreign_table [ 0 ] ; } $ _foreign_alias = $ this -> _unique ( $ this -> relations , $ _foreign_alias ) ; $ rel = $ this -> add ( 'SQL_Relation' , $ _foreign_alias ) ; return $ this -> relations [ $ _foreign_alias ] = $ rel -> set ( $ foreign_table , $ master_field , $ join_kind , $ relation ) ; } | Constructs model from multiple tables . Queries will join tables inserts updates and deletes will be applied on both tables |
51,343 | public function leftJoin ( $ foreign_table , $ master_field = null , $ join_kind = null , $ _foreign_alias = null , $ relation = null ) { if ( ! $ join_kind ) { $ join_kind = 'left' ; } $ res = $ this -> join ( $ foreign_table , $ master_field , $ join_kind , $ _foreign_alias , $ relation ) ; $ res -> delete_behaviour = 'ignore' ; return $ res ; } | Creates weak join between tables . The foreign table may be absent and will not be automatically deleted . |
51,344 | public function hasOne ( $ model , $ our_field = null , $ display_field = null , $ as_field = null ) { $ this -> _references [ null ] = $ model ; if ( ! $ our_field ) { if ( ! is_object ( $ model ) ) { $ tmp = $ this -> app -> normalizeClassName ( $ model , 'Model' ) ; $ tmp = new $ tmp ( ) ; } else { $ tmp = $ model ; } $ our_field = ( $ tmp -> table ) . '_id' ; } $ r = $ this -> add ( 'Field_Reference' , array ( 'name' => $ our_field , 'dereferenced_field' => $ as_field ) ) ; $ r -> setModel ( $ model , $ display_field ) ; $ r -> system ( true ) -> editable ( true ) ; return $ r ; } | Defines one to many association |
51,345 | public function hasMany ( $ model , $ their_field = null , $ our_field = null , $ as_field = null ) { if ( ! $ our_field ) { $ our_field = $ this -> id_field ; } if ( ! $ their_field ) { $ their_field = ( $ this -> table ) . '_id' ; } $ rel = $ this -> add ( 'SQL_Many' , $ as_field ? : $ model ) ; $ rel -> set ( $ model , $ their_field , $ our_field ) ; return $ rel ; } | Defines many to one association |
51,346 | public function containsOne ( $ field , $ model ) { if ( is_array ( $ field ) && $ field [ 0 ] ) { $ field [ 'name' ] = $ field [ 0 ] ; unset ( $ field [ 0 ] ) ; } if ( $ e = $ this -> hasElement ( is_string ( $ field ) ? $ field : $ field [ 'name' ] ) ) { $ e -> destroy ( ) ; } $ this -> add ( 'Relation_ContainsOne' , $ field ) -> setModel ( $ model ) ; } | Defines contained model for field |
51,347 | public function refSQL ( $ name , $ load = null ) { $ ref = $ this -> getElement ( $ name ) ; return $ ref -> refSQL ( $ load ) ; } | Returns Model with SQL join usable for subqueries . |
51,348 | public function setLimit ( $ count , $ offset = null ) { $ this -> _dsql ( ) -> limit ( $ count , $ offset ) ; return $ this ; } | Sets limit on query |
51,349 | public function setOrder ( $ field , $ desc = null ) { if ( ! $ field instanceof Field ) { if ( is_object ( $ field ) ) { $ this -> _dsql ( ) -> order ( $ field , $ desc ) ; return $ this ; } if ( is_string ( $ field ) && strpos ( $ field , ',' ) !== false ) { $ field = explode ( ',' , $ field ) ; } if ( is_array ( $ field ) ) { if ( ! is_null ( $ desc ) ) { throw $ this -> exception ( 'If first argument is array, second argument must not be used' ) ; } foreach ( array_reverse ( $ field ) as $ o ) { $ this -> setOrder ( $ o ) ; } return $ this ; } if ( is_null ( $ desc ) && is_string ( $ field ) && strpos ( $ field , ' ' ) !== false ) { list ( $ field , $ desc ) = array_map ( 'trim' , explode ( ' ' , trim ( $ field ) , 2 ) ) ; } $ field = $ this -> getElement ( $ field ) ; } $ this -> _dsql ( ) -> order ( $ field , $ desc ) ; return $ this ; } | Sets an order on the field . Field must be properly defined |
51,350 | public function getRows ( $ fields = null ) { $ this -> app -> pr -> start ( 'getRows/selecting' ) ; $ a = $ this -> selectQuery ( $ fields ) ; $ this -> app -> pr -> next ( 'getRows/fetching' ) ; $ a = $ a -> get ( ) ; $ this -> app -> pr -> stop ( ) ; return $ a ; } | Loads all matching data into array of hashes |
51,351 | public function sum ( $ field ) { $ q = $ this -> dsql ( ) -> del ( 'fields' ) -> del ( 'order' ) ; if ( ! is_array ( $ field ) ) { $ field = array ( $ field ) ; } foreach ( $ field as $ f ) { if ( ! is_object ( $ f ) ) { $ f = $ this -> getElement ( $ f ) ; } $ q -> field ( $ q -> sum ( $ f ) , $ f -> short_name ) ; } return $ q ; } | Returns dynamic query selecting sum of particular field or fields . |
51,352 | public function tryLoadRandom ( ) { $ id = $ this -> dsql ( ) -> order ( 'rand()' ) -> limit ( 1 ) -> field ( $ this -> getElement ( $ this -> id_field ) ) -> getOne ( ) ; if ( $ id ) { $ this -> load ( $ id ) ; } return $ this ; } | Loads random entry into model |
51,353 | public function tryLoad ( $ id ) { if ( is_null ( $ id ) ) { throw $ this -> exception ( 'Record ID must be specified, otherwise use loadAny()' ) ; } return $ this -> _load ( $ id , true ) ; } | Try to load a record by specified ID . Will not raise exception if record is not found |
51,354 | public function tryLoadBy ( $ field , $ cond = UNDEFINED , $ value = UNDEFINED ) { $ q = $ this -> dsql ; $ this -> dsql = $ this -> dsql ( ) ; $ this -> addCondition ( $ field , $ cond , $ value ) ; $ this -> tryLoadAny ( ) ; $ this -> dsql = $ q ; return $ this ; } | Attempt to load using a specified condition but will not fail if such record is not found |
51,355 | public function getBy ( $ field , $ cond = UNDEFINED , $ value = UNDEFINED ) { $ data = $ this -> data ; $ id = $ this -> id ; $ this -> tryLoadBy ( $ field , $ cond , $ value ) ; $ row = $ this -> data ; $ this -> data = $ data ; $ this -> id = $ id ; return $ row ; } | Loads data record and return array of that data . Will not affect currently loaded record . |
51,356 | protected function _load ( $ id , $ ignore_missing = false ) { $ this -> app -> pr -> start ( 'load/selectQuery' ) ; $ this -> unload ( ) ; $ load = $ this -> selectQuery ( ) ; $ this -> app -> pr -> next ( 'load/clone' ) ; $ p = '' ; if ( ! empty ( $ this -> relations ) ) { $ p = ( $ this -> table_alias ? : $ this -> table ) . '.' ; } $ this -> app -> pr -> next ( 'load/where' ) ; if ( ! is_null ( $ id ) ) { $ load -> where ( $ p . $ this -> id_field , $ id ) ; } $ this -> app -> pr -> next ( 'load/beforeLoad' ) ; $ this -> hook ( 'beforeLoad' , array ( $ load , $ id ) ) ; if ( ! $ this -> loaded ( ) ) { $ this -> app -> pr -> next ( 'load/get' ) ; $ s = $ load -> stmt ; $ l = $ load -> args [ 'limit' ] ; $ load -> stmt = null ; $ data = $ load -> limit ( 1 ) -> getHash ( ) ; $ load -> stmt = $ s ; $ load -> args [ 'limit' ] = $ l ; if ( ! is_null ( $ id ) ) { array_pop ( $ load -> args [ 'where' ] ) ; } $ this -> app -> pr -> next ( 'load/ending' ) ; $ this -> reset ( ) ; if ( @ ! $ data ) { if ( $ ignore_missing ) { return $ this ; } else { throw $ this -> exception ( 'Record could not be loaded' , 'Exception_NoRecord' ) -> addMoreInfo ( 'model' , $ this ) -> addMoreInfo ( 'id' , $ id ) ; } } $ this -> data = $ data ; $ this -> id = $ this -> data [ $ this -> id_field ] ; } $ this -> hook ( 'afterLoad' ) ; $ this -> app -> pr -> stop ( ) ; return $ this ; } | Internal loading funciton . Do not use . OK to override . |
51,357 | public function saveAndUnload ( ) { $ this -> _save_as = false ; $ this -> save ( ) ; $ this -> _save_as = null ; return $ this ; } | Save model into database and don t try to load it back |
51,358 | public function saveAs ( $ model ) { if ( is_string ( $ model ) ) { $ model = $ this -> app -> normalizeClassName ( $ model , 'Model' ) ; $ model = $ this -> add ( $ model ) ; } $ this -> _save_as = $ model ; $ res = $ this -> save ( ) ; $ this -> _save_as = null ; return $ res ; } | Save model into database and try to load it back as a new model of specified class . Instance of new class is returned . |
51,359 | public function save ( ) { $ this -> _dsql ( ) -> owner -> beginTransaction ( ) ; $ this -> hook ( 'beforeSave' ) ; if ( $ this -> loaded ( ) ) { $ res = $ this -> modify ( ) ; } else { $ res = $ this -> insert ( ) ; } $ res -> hook ( 'afterSave' ) ; $ this -> _dsql ( ) -> owner -> commit ( ) ; return $ res ; } | Save model into database and load it back . If for some reason it won t load whole operation is undone . |
51,360 | public function unload ( ) { if ( $ this -> _save_later ) { $ this -> _save_later = false ; $ this -> saveAndUnload ( ) ; } $ this -> hook ( 'beforeUnload' ) ; $ this -> id = null ; if ( $ this -> _save_later ) { $ this -> _save_later = false ; $ this -> saveAndUnload ( ) ; } if ( $ this -> loaded ( ) ) { $ this -> hook ( 'beforeUnload' ) ; } $ this -> data = $ this -> dirty = array ( ) ; $ this -> id = null ; $ this -> hook ( 'afterUnload' ) ; $ this -> hook ( 'afterUnload' ) ; return $ this ; } | forget currently loaded record and it s ID . Will not affect database |
51,361 | public function tryDelete ( $ id = null ) { if ( ! is_null ( $ id ) ) { $ this -> tryLoad ( $ id ) ; } if ( $ this -> loaded ( ) ) { $ this -> delete ( ) ; } return $ this ; } | Tries to delete record but does nothing if not found |
51,362 | public function delete ( $ id = null ) { if ( ! is_null ( $ id ) ) { $ this -> load ( $ id ) ; } if ( ! $ this -> loaded ( ) ) { throw $ this -> exception ( 'Unable to determine which record to delete' ) ; } $ tmp = $ this -> dsql ; $ this -> initQuery ( ) ; $ delete = $ this -> dsql -> where ( $ this -> id_field , $ this -> id ) ; $ delete -> owner -> beginTransaction ( ) ; $ this -> hook ( 'beforeDelete' , array ( $ delete ) ) ; $ delete -> delete ( ) ; $ this -> hook ( 'afterDelete' ) ; $ delete -> owner -> commit ( ) ; $ this -> dsql = $ tmp ; $ this -> unload ( ) ; return $ this ; } | Deletes record matching the ID |
51,363 | public function deleteAll ( ) { $ delete = $ this -> dsql ( ) ; $ delete -> owner -> beginTransaction ( ) ; $ this -> hook ( 'beforeDeleteAll' , array ( $ delete ) ) ; $ delete -> delete ( ) ; $ this -> hook ( 'afterDeleteAll' ) ; $ delete -> owner -> commit ( ) ; $ this -> reset ( ) ; return $ this ; } | Deletes all records matching this model . Use with caution . |
51,364 | public function set ( $ name , $ value = UNDEFINED ) { if ( is_array ( $ name ) ) { foreach ( $ name as $ key => $ val ) { $ this -> set ( $ key , $ val ) ; } return $ this ; } if ( $ name === false || $ name === null ) { return $ this -> reset ( ) ; } if ( $ this -> strict_fields && ! $ this -> hasElement ( $ name ) ) { throw $ this -> exception ( 'No such field' , 'Logic' ) -> addMoreInfo ( 'name' , $ name ) ; } if ( $ value !== UNDEFINED && ( is_object ( $ value ) || is_object ( $ this -> data [ $ name ] ) || is_array ( $ value ) || is_array ( $ this -> data [ $ name ] ) || ( string ) $ value != ( string ) $ this -> data [ $ name ] || $ value !== $ this -> data [ $ name ] || ! isset ( $ this -> data [ $ name ] ) ) ) { $ this -> data [ $ name ] = $ value ; $ this -> setDirty ( $ name ) ; } return $ this ; } | Override all methods to keep back - compatible |
51,365 | protected function processReceive ( $ rawMessage ) { $ rawMessage = $ rawMessage -> getSmsStatusResp ; $ incomingMessage = $ this -> createIncomingMessage ( ) ; $ incomingMessage -> setRaw ( $ rawMessage ) ; $ incomingMessage -> setFrom ( $ rawMessage -> shortcode ) ; $ incomingMessage -> setMessage ( null ) ; $ incomingMessage -> setId ( $ rawMessage -> id ) ; $ incomingMessage -> setTo ( null ) ; return $ incomingMessage ; } | Parse a response from messageId check and returns a Message . |
51,366 | protected function postRequest ( ) { $ response = $ this -> client -> post ( $ this -> buildUrl ( ) , [ 'auth' => $ this -> getAuth ( ) , 'json' => $ this -> getBody ( ) , 'headers' => [ 'Accept' => 'application/json' , ] , ] ) ; if ( $ response -> getStatusCode ( ) != 201 && $ response -> getStatusCode ( ) != 200 ) { throw new \ Exception ( 'Unable to request from API. HTTP Error: ' . $ response -> getStatusCode ( ) ) ; } return $ response ; } | Creates and sends a POST request to the requested URL . |
51,367 | protected function getRequest ( ) { $ url = $ this -> buildUrl ( $ this -> getBody ( ) ) ; $ response = $ this -> client -> get ( $ url , [ 'auth' => $ this -> getAuth ( ) , 'headers' => [ 'Accept' => 'application/json' , ] , ] ) ; if ( $ response -> getStatusCode ( ) != 201 && $ response -> getStatusCode ( ) != 200 ) { throw new \ Exception ( 'Unable to request from API.' ) ; } return $ response ; } | Creates and sends a GET request to the requested URL . |
51,368 | private function generateMessageBody ( $ from , $ number , $ composeMessage ) { $ aux = [ 'from' => $ from , 'to' => $ number [ 'number' ] , 'msg' => $ composeMessage , 'callbackOption' => $ this -> callbackOption , ] ; if ( ! is_null ( $ number [ 'carrier' ] ) ) { $ aux [ 'id' ] = $ number [ 'carrier' ] ; } return $ aux ; } | Message body generator based on the attributes . |
51,369 | public function parseRequestedURL ( ) { $ url = $ this -> app -> getConfig ( 'atk/base_url' , null ) ; if ( is_null ( $ url ) ) { $ url = 'http' ; $ https = ( isset ( $ _SERVER [ 'HTTPS' ] ) && $ _SERVER [ 'HTTPS' ] == 'on' ) || $ _SERVER [ 'SERVER_PORT' ] == 443 ; if ( $ https ) { $ url .= 's' ; } $ url .= '://' . $ _SERVER [ 'SERVER_NAME' ] ; if ( ( $ _SERVER [ 'SERVER_PORT' ] == '80' && ! $ https ) || ( $ _SERVER [ 'SERVER_PORT' ] == '443' && $ https ) ) { ; } else { $ url .= ':' . $ _SERVER [ 'SERVER_PORT' ] ; } } $ this -> base_url = $ url ; $ path = $ this -> unix_dirname ( $ _SERVER [ 'SCRIPT_NAME' ] ) ; if ( substr ( $ path , - 1 ) != '/' ) { $ path .= '/' ; } $ this -> base_path = $ path ; if ( isset ( $ _GET [ 'page' ] ) ) { $ page = $ _GET [ 'page' ] ; $ this -> page = $ page ; } else { $ request_uri = $ this -> getRequestURI ( ) ; if ( strpos ( $ request_uri , $ path ) !== 0 ) { throw $ this -> exception ( 'URL matching problem' ) -> addMoreInfo ( 'RequestURI' , $ request_uri ) -> addMoreInfo ( 'BasePath' , $ path ) ; } $ page = substr ( $ request_uri , strlen ( $ path ) ) ; if ( ! $ page ) { $ page = 'index' ; } $ this -> page = $ page ; $ page = preg_replace ( '/\..*$/' , '' , $ page ) ; $ page = preg_replace ( '/\/$/' , '' , $ page ) ; $ page = str_replace ( '/' , '_' , $ page ) ; if ( substr ( $ page , - 1 ) == '_' ) { $ page = substr ( $ page , 0 , - 1 ) ; } } if ( strpos ( $ page , '.' ) !== false ) { throw $ this -> exception ( 'Page may not contain periods (.)' ) -> addMoreInfo ( 'page' , $ page ) ; } $ this -> app -> page = str_replace ( '/' , '_' , $ page ) ; $ this -> template_filename = $ this -> app -> page ; if ( substr ( $ this -> template_filename , - 1 ) == '/' ) { $ this -> template_filename .= 'index' ; } } | Detect server environment and tries to guess absolute and relative URLs to your application . |
51,370 | protected function outputOne ( $ data ) { if ( is_object ( $ data ) ) { $ data = $ data -> get ( ) ; } if ( $ data [ '_id' ] ) { $ data = array ( 'id' => ( string ) $ data [ '_id' ] ) + $ data ; } unset ( $ data [ '_id' ] ) ; foreach ( $ data as $ key => $ val ) { if ( $ val instanceof MongoID ) { $ data [ $ key ] = ( string ) $ val ; } } return $ data ; } | Generic method for returning single record item of data which can be used for filtering or cleaning up . |
51,371 | protected function outputMany ( $ data ) { if ( is_object ( $ data ) ) { $ data = $ data -> getRows ( ) ; } $ output = array ( ) ; foreach ( $ data as $ row ) { $ output [ ] = $ this -> outputOne ( $ row ) ; } return $ output ; } | Generic outptu filtering method for multiple records of data . |
51,372 | protected function _input ( $ data , $ filter = true ) { if ( is_array ( $ filter ) ) { $ data = array_intersect_key ( $ data , array_flip ( $ filter ) ) ; } unset ( $ data [ 'id' ] ) ; unset ( $ data [ '_id' ] ) ; unset ( $ data [ 'user_id' ] ) ; unset ( $ data [ 'user' ] ) ; return $ data ; } | Filtering input data . |
51,373 | public function put_post ( $ data ) { $ m = $ this -> model ; if ( $ m -> loaded ( ) ) { if ( ! $ this -> allow_edit ) { throw $ this -> exception ( 'Editing is not allowed' ) ; } $ data = $ this -> _input ( $ data , $ this -> allow_edit ) ; } else { if ( ! $ this -> allow_add ) { throw $ this -> exception ( 'Adding is not allowed' ) ; } $ data = $ this -> _input ( $ data , $ this -> allow_add ) ; } return $ this -> outputOne ( $ m -> set ( $ data ) -> save ( ) -> get ( ) ) ; } | Because it s not really defined which of the two is used for updating the resource Agile Toolkit will support put_post identically . Both of the requests are idempotent . |
51,374 | protected function output ( ) { ob_start ( ) ; $ writer = PHPExcel_IOFactory :: createWriter ( $ this -> PhpExcel , 'Excel2007' ) ; if ( ! isset ( $ writer ) ) { throw new Exception ( 'Excel writer not found' ) ; } $ writer -> setPreCalculateFormulas ( false ) ; $ writer -> setIncludeCharts ( true ) ; $ writer -> save ( 'php://output' ) ; $ output = ob_get_clean ( ) ; return $ output ; } | Generates the binary excel data |
51,375 | public function getFilename ( ) { if ( isset ( $ this -> viewVars [ '_filename' ] ) ) { return $ this -> viewVars [ '_filename' ] . '.xlsx' ; } return Inflector :: slug ( str_replace ( '.xlsx' , '' , $ this -> request -> url ) ) . '.xlsx' ; } | Gets the filename |
51,376 | protected function makeMessages ( $ rawMessages ) { $ incomingMessages = [ ] ; foreach ( $ rawMessages as $ rawMessage ) { $ incomingMessages [ ] = $ this -> processReceive ( $ rawMessage ) ; } return $ incomingMessages ; } | Creates many IncomingMessage objects . |
51,377 | public function addColumn ( $ width = 'auto' ) { $ c = $ this -> add ( 'View' ) ; if ( is_numeric ( $ width ) ) { $ this -> mode = 'grid' ; $ c -> addClass ( 'atk-col-' . $ width ) ; return $ c ; } elseif ( substr ( $ width , - 1 ) == '%' ) { $ this -> mode = 'pct' ; $ c -> addStyle ( 'width' , $ width ) ; } $ this -> template -> trySet ( 'row_class' , 'atk-cells' ) ; $ c -> addClass ( 'atk-cell' ) ; return $ c ; } | Adds new column to the set . Argument can be numeric for 12GS percent for flexi design or omitted for equal columns . |
51,378 | public function link ( $ page , $ args = array ( ) ) { if ( $ this -> links [ $ page ] ) { throw $ this -> exception ( 'This page is already linked' ) -> addMoreInfo ( 'page' , $ page ) ; } $ this -> links [ $ page ] = $ args ; return $ this ; } | Link method creates a bi - directional link between a URL and a page along with some GET parameters . This method is entirely tranpsarent and can be added for pages which are already developed at any time . |
51,379 | public function route ( ) { $ this -> app -> page_orig = $ this -> app -> page ; foreach ( $ this -> links as $ page => $ args ) { $ page = str_replace ( '/' , '_' , $ page ) ; if ( $ this -> app -> page == $ page ) { return $ this ; } $ page .= '_' ; if ( substr ( $ this -> app -> page , 0 , strlen ( $ page ) ) == $ page ) { $ rest = explode ( '_' , substr ( $ this -> app -> page , strlen ( $ page ) ) ) ; reset ( $ args ) ; foreach ( $ rest as $ arg ) { list ( $ key , $ match ) = @ each ( $ args ) ; if ( is_numeric ( $ key ) || is_null ( $ key ) ) { $ key = $ match ; } else { if ( ! preg_match ( $ match , $ arg ) ) { break 2 ; } } $ _GET [ $ key ] = $ arg ; } $ this -> app -> page = substr ( $ page , 0 , - 1 ) ; return $ this ; } } $ r = $ _SERVER [ 'REQUEST_URI' ] ; foreach ( $ this -> rules as $ rule ) { if ( preg_match ( '/' . $ rule [ 0 ] . '/' , $ r , $ t ) ) { $ this -> app -> page = $ rule [ 1 ] ; if ( $ rule [ 2 ] ) { foreach ( $ rule [ 2 ] as $ k => $ v ) { $ _GET [ $ v ] = $ t [ $ k + 1 ] ; } } } } } | Perform the necessary changes in the APP s page . After this you can still get the orginal page in app - > page_orig . |
51,380 | public function addDefaultIncludes ( ) { $ this -> addInclude ( 'start-atk4' ) ; if ( $ v = $ this -> app -> getConfig ( 'js/versions/jqueryui' , null ) ) { $ v = 'jquery-ui-' . $ v ; } else { $ v = $ this -> app -> getConfig ( 'js/jqueryui' , 'jquery-ui-1.11.4.min' ) ; } $ this -> addInclude ( $ v ) ; $ this -> addInclude ( 'ui.atk4_loader' ) ; $ this -> addInclude ( 'ui.atk4_notify' ) ; $ this -> addInclude ( 'atk4_univ_basic' ) ; $ this -> addInclude ( 'atk4_univ_jui' ) ; } | Adds default includes |
51,381 | public function addOnReady ( $ js ) { if ( $ js instanceof jQuery_Chain ) { $ js = $ js -> getString ( ) ; } if ( ! $ this -> atk4_initialised ) { return parent :: addOnReady ( $ js ) ; } $ this -> app -> template -> appendHTML ( 'document_ready' , "$.atk4(function(){ " . $ js . "; });\n" ) ; return $ this ; } | Adds JS chain to DOM onReady event |
51,382 | protected function lock ( ) { $ this -> tables -> execute ( ) ; $ table = array ( ) ; while ( $ a = $ this -> tables -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ table [ ] = current ( $ a ) ; } return ! $ table || $ this -> pdo -> exec ( 'LOCK TABLES `' . implode ( '` WRITE, `' , $ table ) . '` WRITE' ) ; } | Locks all tables . |
51,383 | protected function open ( $ filename , $ flags ) { if ( is_file ( $ filename ) === false || ( $ this -> file = fopen ( $ filename , $ flags ) ) === false ) { throw new Exception ( 'Unable to open the target file.' ) ; } } | Opens a file for writing . |
51,384 | protected function write ( $ string , $ format = true ) { if ( $ format ) { $ string .= $ this -> delimiter ; } $ string .= "\n" ; if ( fwrite ( $ this -> file , $ string , strlen ( $ string ) ) === false ) { throw new Exception ( 'Unable to write ' . strlen ( $ string ) . ' bytes to the dumpfile.' ) ; } } | Writes a line to the file . |
51,385 | protected function move ( ) { if ( $ this -> compress ) { $ gzip = new Compress ( $ this -> config ) ; $ gzip -> pack ( $ this -> temp , $ this -> config -> file ) ; unlink ( $ this -> temp ) ; return true ; } if ( @ rename ( $ this -> temp , $ this -> config -> file ) ) { return true ; } if ( @ copy ( $ this -> temp , $ this -> config -> file ) && unlink ( $ this -> temp ) ) { return true ; } throw new Exception ( 'Unable to move the temporary file.' ) ; } | Moves a temporary file to the final location . |
51,386 | protected function getDelimiter ( $ delimiter = ';' , $ query = null ) { while ( 1 ) { if ( $ query === null || strpos ( $ query , $ delimiter ) === false ) { return $ delimiter ; } $ delimiter .= $ delimiter ; } } | Gets a SQL delimiter . |
51,387 | public function setModel ( $ model , $ fields = null , $ grid_fields = null ) { $ model = parent :: setModel ( $ model ) ; if ( ! isset ( $ this -> entity_name ) ) { if ( ! isset ( $ model -> caption ) ) { $ class = get_class ( $ this -> model ) ; $ class = substr ( strrchr ( $ class , '\\' ) ? : ' ' . $ class , 1 ) ; $ this -> entity_name = str_replace ( array ( 'Model_' , '_' ) , array ( '' , ' ' ) , $ class ) ; } else { $ this -> entity_name = $ model -> caption ; } } if ( ! $ this -> isEditing ( ) ) { $ this -> configureGrid ( is_null ( $ grid_fields ) ? $ fields : $ grid_fields ) ; } if ( $ this -> allow_add ) { if ( $ this -> configureAdd ( $ fields ) ) { return $ model ; } } elseif ( isset ( $ this -> add_button ) ) { $ this -> add_button -> destroy ( ) ; } if ( $ this -> allow_edit ) { if ( $ this -> configureEdit ( $ fields ) ) { return $ model ; } } if ( $ this -> allow_del ) { $ this -> configureDel ( ) ; } return $ model ; } | Assign model to your CRUD and specify list of fields to use from model . |
51,388 | public function addAction ( $ method_name , $ options = array ( ) ) { if ( ! $ this -> model ) { throw $ this -> exception ( 'Must set CRUD model first' ) ; } if ( $ options == 'toolbar' ) { $ options = array ( 'column' => false , 'toolbar' => true ) ; } if ( $ options == 'column' ) { $ options = array ( 'toolbar' => false , 'column' => true ) ; } $ descr = isset ( $ options [ 'descr' ] ) ? $ options [ 'descr' ] : ucwords ( str_replace ( '_' , ' ' , $ method_name ) ) ; $ icon = isset ( $ options [ 'icon' ] ) ? $ options [ 'icon' ] : 'target' ; $ show_toolbar = isset ( $ options [ 'toolbar' ] ) ? $ options [ 'toolbar' ] : true ; $ show_column = isset ( $ options [ 'column' ] ) ? $ options [ 'column' ] : true ; if ( $ this -> isEditing ( $ method_name ) ) { $ c = $ this -> virtual_page -> getPage ( ) -> add ( 'View_Console' ) ; $ self = $ this ; $ c -> set ( function ( $ c ) use ( $ show_toolbar , $ show_column , $ options , $ self , $ method_name ) { if ( $ show_toolbar && ! $ self -> id ) { $ self -> model -> unload ( ) ; } elseif ( $ show_column && $ self -> id ) { $ c -> out ( 'Loading record ' . $ self -> id , array ( 'class' => 'atk-effect-info' ) ) ; $ self -> model -> load ( $ self -> id ) ; } else { return ; } $ ret = $ self -> model -> $ method_name ( ) ; $ c -> out ( 'Returned: ' . json_encode ( $ ret , JSON_UNESCAPED_UNICODE ) , array ( 'class' => 'atk-effect-success' ) ) ; } ) ; return ; } elseif ( $ this -> isEditing ( ) ) { return ; } $ frame_options = array_merge ( array ( ) , $ this -> frame_options ? : array ( ) ) ; if ( $ show_column ) { $ this -> virtual_page -> addColumn ( $ method_name , $ descr . ' ' . $ this -> entity_name , array ( 'descr' => $ descr , 'icon' => $ icon ) , $ this -> grid ) ; } if ( $ show_toolbar ) { $ button = $ this -> addButton ( array ( $ descr , 'icon' => $ icon ) ) ; $ button -> js ( 'click' ) -> univ ( ) -> frameURL ( $ this -> app -> _ ( $ this -> entity_name . '::' . $ descr ) , $ this -> virtual_page -> getURL ( $ method_name ) , $ frame_options ) ; } } | Assuming that your model contains a certain method this allows you to create a frame which will pop you a new frame with a form representing model method arguments . Once the form is submitted the action will be evaluated . |
51,389 | protected function configureAdd ( $ fields = null ) { if ( $ this -> isEditing ( 'add' ) ) { $ this -> model -> unload ( ) ; $ m = $ this -> form -> setModel ( $ this -> model , $ fields ) ; $ this -> form -> addSubmit ( 'Add' ) ; $ this -> form -> onSubmit ( array ( $ this , 'formSubmit' ) ) ; return $ m ; } elseif ( $ this -> isEditing ( ) ) { return ; } $ this -> add_button -> js ( 'click' ) -> univ ( ) -> frameURL ( $ this -> app -> _ ( $ this -> entity_name === false ? 'New Record' : 'Adding new ' . $ this -> entity_name ) , $ this -> virtual_page -> getURL ( 'add' ) , $ this -> frame_options ) ; if ( $ this -> entity_name !== false ) { $ this -> add_button -> setIcon ( 'plus' ) -> setHTML ( 'Add ' . htmlspecialchars ( $ this -> entity_name ) ) ; } } | Configures necessary components when CRUD is in the adding mode . |
51,390 | protected function configureEdit ( $ fields = null ) { if ( $ this -> isEditing ( 'edit' ) ) { $ m = $ this -> form -> setModel ( $ this -> model , $ fields ) ; $ m -> load ( $ this -> id ) ; $ this -> form -> addSubmit ( ) ; $ this -> form -> onSubmit ( array ( $ this , 'formSubmit' ) ) ; return $ m ; } elseif ( $ this -> isEditing ( ) ) { return ; } $ this -> virtual_page -> addColumn ( 'edit' , 'Editing ' . $ this -> entity_name , array ( 'descr' => 'Edit' , 'icon' => 'pencil' ) , $ this -> grid ) ; } | Configures necessary components when CRUD is in the editing mode . |
51,391 | protected function formSubmit ( $ form ) { try { $ form -> save ( ) ; $ self = $ this ; $ this -> app -> addHook ( 'pre-render' , function ( ) use ( $ self ) { $ self -> formSubmitSuccess ( ) -> execute ( ) ; } ) ; } catch ( Exception_ValidityCheck $ e ) { $ form -> displayError ( $ e -> getField ( ) , $ e -> getMessage ( ) ) ; } } | Called after on post - init hook when form is submitted . |
51,392 | public function formSubmitSuccess ( ) { return $ this -> form -> js ( null , $ this -> js ( ) -> trigger ( 'reload' ) ) -> univ ( ) -> closeDialog ( ) ; } | Returns JavaScript action which should be executed on form successfull submission . |
51,393 | public function addLocation ( $ contents , $ obsolete = UNDEFINED ) { if ( $ obsolete !== UNDEFINED ) { throw $ this -> exception ( 'Use a single argument for addLocation' ) ; } return $ this -> pathfinder -> addLocation ( $ contents ) ; } | Add new location with additional resources . |
51,394 | public function url ( $ page = null , $ arguments = array ( ) ) { if ( is_object ( $ page ) && $ page instanceof URL ) { return $ page -> setArguments ( $ arguments ) ; } if ( is_array ( $ page ) ) { $ p = $ page [ 0 ] ; unset ( $ page [ 0 ] ) ; $ arguments = $ page ; $ page = $ p ; } $ url = $ this -> add ( 'URL' ) ; unset ( $ this -> elements [ $ url -> short_name ] ) ; if ( strpos ( $ page , 'http://' ) === 0 || strpos ( $ page , 'https://' ) === 0 ) { $ url -> setURL ( $ page ) ; } else { $ url -> setPage ( $ page ) ; } return $ url -> setArguments ( $ arguments ) ; } | Generates URL for specified page . Useful for building links on pages or emails . Returns URL object . |
51,395 | public function getLogger ( $ class_name = UNDEFINED ) { if ( is_null ( $ this -> logger ) ) { $ this -> logger = $ this -> add ( $ class_name === UNDEFINED ? $ this -> logger_class : $ class_name ) ; } return $ this -> logger ; } | Initialize logger or return existing one . |
51,396 | public function caughtException ( $ e ) { $ this -> hook ( 'caught-exception' , array ( $ e ) ) ; echo get_class ( $ e ) , ': ' . $ e -> getMessage ( ) ; exit ; } | Is executed if exception is raised during execution . Re - define to have custom handling of exceptions system - wide . |
51,397 | public function getConfig ( $ path , $ default_value = UNDEFINED ) { $ parts = explode ( '/' , $ path ) ; $ current_position = $ this -> config ; foreach ( $ parts as $ part ) { if ( ! array_key_exists ( $ part , $ current_position ) ) { if ( $ default_value !== UNDEFINED ) { return $ default_value ; } throw $ this -> exception ( 'Configuration parameter is missing in config.php' , 'NotConfigured' ) -> addMoreInfo ( 'config_files_loaded' , $ this -> config_files_loaded ) -> addMoreInfo ( 'missign_line' , " \$config['" . implode ( "']['" , explode ( '/' , $ path ) ) . "']" ) ; } else { $ current_position = $ current_position [ $ part ] ; } } return $ current_position ; } | Load config if necessary and look up corresponding setting . |
51,398 | public function getVersion ( $ of = 'atk' ) { if ( ! $ this -> version_cache ) { $ f = $ this -> app -> pathfinder -> atk_location -> base_path . DIRECTORY_SEPARATOR . 'VERSION' ; if ( file_exists ( $ f ) ) { $ this -> version_cache = trim ( file_get_contents ( $ f ) ) ; } else { $ this -> version_cache = '4.0.1' ; } } return $ this -> version_cache ; } | Determine version of Agile Toolkit or specified plug - in . |
51,399 | public function requires ( $ addon = 'atk' , $ v , $ location = null ) { $ cv = $ this -> getVersion ( $ addon ) ; if ( version_compare ( $ cv , $ v ) < 0 ) { if ( $ addon == 'atk' ) { $ e = $ this -> exception ( 'Agile Toolkit version is too old' ) ; } else { $ e = $ this -> exception ( 'Add-on is outdated' ) -> addMoreInfo ( 'addon' , $ addon ) ; } $ e -> addMoreInfo ( 'required' , $ v ) -> addMoreInfo ( 'you have' , $ cv ) ; if ( $ location !== null ) { $ e -> addMoreInfo ( 'download_location' , $ location ) ; } throw $ e ; } if ( $ addon == 'atk' ) { if ( version_compare ( $ v , '4.2' ) < 0 && version_compare ( $ v , '4.1.4' ) >= 0 ) { $ this -> add ( 'Controller_Compat' ) ; return true ; } } return true ; } | Verifies version . Should be used by addons . For speed improvement redefine this into empty function . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.