@@ -45,7 +45,7 @@ |
||
| 45 | 45 | * @param $mailer_name |
| 46 | 46 | * @param array $params |
| 47 | 47 | * @param array $options |
| 48 | - * @return mixed |
|
| 48 | + * @return boolean |
|
| 49 | 49 | */ |
| 50 | 50 | public static function deliver($mailer_name, $params=[], $options=[]) |
| 51 | 51 | { |
@@ -1,172 +1,172 @@ |
||
| 1 | 1 | <?php namespace Myth\Mail; |
| 2 | 2 | /** |
| 3 | - * Sprint |
|
| 4 | - * |
|
| 5 | - * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
| 6 | - * |
|
| 7 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 8 | - * of this software and associated documentation files (the "Software"), to deal |
|
| 9 | - * in the Software without restriction, including without limitation the rights |
|
| 10 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 11 | - * copies of the Software, and to permit persons to whom the Software is |
|
| 12 | - * furnished to do so, subject to the following conditions: |
|
| 13 | - * |
|
| 14 | - * The above copyright notice and this permission notice shall be included in |
|
| 15 | - * all copies or substantial portions of the Software. |
|
| 16 | - * |
|
| 17 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 18 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 19 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 20 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 21 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 22 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 23 | - * THE SOFTWARE. |
|
| 24 | - * |
|
| 25 | - * @package Sprint |
|
| 26 | - * @author Lonnie Ezell |
|
| 27 | - * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
| 28 | - * @license http://opensource.org/licenses/MIT (MIT) |
|
| 29 | - * @link http://sprintphp.com |
|
| 30 | - * @since Version 1.0 |
|
| 31 | - */ |
|
| 3 | + * Sprint |
|
| 4 | + * |
|
| 5 | + * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
| 6 | + * |
|
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
|
| 9 | + * in the Software without restriction, including without limitation the rights |
|
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
|
| 12 | + * furnished to do so, subject to the following conditions: |
|
| 13 | + * |
|
| 14 | + * The above copyright notice and this permission notice shall be included in |
|
| 15 | + * all copies or substantial portions of the Software. |
|
| 16 | + * |
|
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 23 | + * THE SOFTWARE. |
|
| 24 | + * |
|
| 25 | + * @package Sprint |
|
| 26 | + * @author Lonnie Ezell |
|
| 27 | + * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
| 28 | + * @license http://opensource.org/licenses/MIT (MIT) |
|
| 29 | + * @link http://sprintphp.com |
|
| 30 | + * @since Version 1.0 |
|
| 31 | + */ |
|
| 32 | 32 | |
| 33 | 33 | class Mail { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Sends an email, using an existing Mailer, which can |
|
| 37 | - * be found in application/mailers/. The mailer is the one responsible |
|
| 38 | - * for determining whether the email will be sent immediately or queued |
|
| 39 | - * to be sent later. |
|
| 40 | - * |
|
| 41 | - * The $mailer_name must include both the mailer name as well as the |
|
| 42 | - * task, separated by a single colon: |
|
| 43 | - * 'UserMailer:newUser' |
|
| 44 | - * |
|
| 45 | - * @param $mailer_name |
|
| 46 | - * @param array $params |
|
| 47 | - * @param array $options |
|
| 48 | - * @return mixed |
|
| 49 | - */ |
|
| 50 | - public static function deliver($mailer_name, $params=[], $options=[]) |
|
| 51 | - { |
|
| 52 | - // Protect users from themselves here. |
|
| 53 | - str_replace('::', ':', $mailer_name); |
|
| 54 | - |
|
| 55 | - // Try to load our mailer class. |
|
| 56 | - list($class, $method) = explode(':', $mailer_name); |
|
| 57 | - |
|
| 58 | - if (! is_file(APPPATH .'mailers/'. $class .'.php')) |
|
| 59 | - { |
|
| 60 | - throw new \RuntimeException( sprintf( lang('mail.cant_find_mailer'), $class) ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - require_once APPPATH .'mailers/'. $class .'.php'; |
|
| 64 | - |
|
| 65 | - if (! class_exists($class, false)) |
|
| 66 | - { |
|
| 67 | - throw new \RuntimeException( sprintf( lang('errors.cant_instantiate'), $class) ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $mailer = new $class( $options ); |
|
| 71 | - |
|
| 72 | - if (! method_exists($mailer, $method)) |
|
| 73 | - { |
|
| 74 | - throw new \BadMethodCallException( sprintf( lang('mail.invalid_mailer_method'), $class, $method) ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // try to deliver the mail, but don't send back the contents |
|
| 78 | - // since we don't want to force the mailers to return anything. |
|
| 79 | - if (call_user_func_array([$mailer, $method], $params) ) |
|
| 80 | - { |
|
| 81 | - return true; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - //-------------------------------------------------------------------- |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Adds an item to the email queue to be sent out next time. |
|
| 91 | - * |
|
| 92 | - * @param string $mailer_name |
|
| 93 | - * @param array $params |
|
| 94 | - * @param array $options |
|
| 95 | - * @param \Myth\Mail\Queue $queue |
|
| 96 | - * |
|
| 97 | - * @return mixed |
|
| 98 | - */ |
|
| 99 | - public static function queue($mailer_name, $params=[], $options=[], &$queue=null) |
|
| 100 | - { |
|
| 101 | - $data = [ |
|
| 102 | - 'mailer' => $mailer_name, |
|
| 103 | - 'params' => serialize($params), |
|
| 104 | - 'options' => serialize($options) |
|
| 105 | - ]; |
|
| 106 | - |
|
| 107 | - if (empty($queue)) |
|
| 108 | - { |
|
| 109 | - $queue = new \Myth\Mail\Queue(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return $queue->insert($data); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - //-------------------------------------------------------------------- |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Processes the Email queue sending out emails in chunks. |
|
| 119 | - * Typically used in a cronjob to send out all queued emails. |
|
| 120 | - * |
|
| 121 | - * @param int $chunk_size // How many emails to send per batch. |
|
| 122 | - * @return string // The output of the cronjob... |
|
| 123 | - */ |
|
| 124 | - public static function process($chunk_size=50, &$db=null) |
|
| 125 | - { |
|
| 126 | - if (empty($db)) |
|
| 127 | - { |
|
| 128 | - $db = new \Myth\Mail\Queue(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // Grab our batch of emails to process |
|
| 132 | - $queue = $db->find_many_by('sent', 0); |
|
| 133 | - |
|
| 134 | - if (! $queue) |
|
| 135 | - { |
|
| 136 | - // We didn't have an error, we simply |
|
| 137 | - // didn't have anything to do. |
|
| 138 | - return true; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $output = 'Started processing email Queue at '. date('Y-m-d H:i:s') .".\n\n"; |
|
| 142 | - |
|
| 143 | - foreach ($queue as $item) |
|
| 144 | - { |
|
| 145 | - try { |
|
| 146 | - if (! Mail::deliver($item->mailer, unserialize($item->params), unserialize($item->options))) { |
|
| 147 | - $output .= '[FAILED] '; |
|
| 148 | - } else { |
|
| 149 | - $data = [ |
|
| 150 | - 'sent' => 1, |
|
| 151 | - 'sent_on' => date('Y-m-d H:i:s') |
|
| 152 | - ]; |
|
| 153 | - |
|
| 154 | - $db->update($item->id, $data); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $output .= "ID: {$item->id}, Mailer: {$item->mailer}. \n"; |
|
| 158 | - } |
|
| 159 | - catch (\Exception $e) |
|
| 160 | - { |
|
| 161 | - $output .= "[EXCEPTION] ". $e->getMessage() ."\n"; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $output .= "Done processing email Queue at ". date('H:i:s') .".\n"; |
|
| 166 | - |
|
| 167 | - return $output; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - //-------------------------------------------------------------------- |
|
| 35 | + /** |
|
| 36 | + * Sends an email, using an existing Mailer, which can |
|
| 37 | + * be found in application/mailers/. The mailer is the one responsible |
|
| 38 | + * for determining whether the email will be sent immediately or queued |
|
| 39 | + * to be sent later. |
|
| 40 | + * |
|
| 41 | + * The $mailer_name must include both the mailer name as well as the |
|
| 42 | + * task, separated by a single colon: |
|
| 43 | + * 'UserMailer:newUser' |
|
| 44 | + * |
|
| 45 | + * @param $mailer_name |
|
| 46 | + * @param array $params |
|
| 47 | + * @param array $options |
|
| 48 | + * @return mixed |
|
| 49 | + */ |
|
| 50 | + public static function deliver($mailer_name, $params=[], $options=[]) |
|
| 51 | + { |
|
| 52 | + // Protect users from themselves here. |
|
| 53 | + str_replace('::', ':', $mailer_name); |
|
| 54 | + |
|
| 55 | + // Try to load our mailer class. |
|
| 56 | + list($class, $method) = explode(':', $mailer_name); |
|
| 57 | + |
|
| 58 | + if (! is_file(APPPATH .'mailers/'. $class .'.php')) |
|
| 59 | + { |
|
| 60 | + throw new \RuntimeException( sprintf( lang('mail.cant_find_mailer'), $class) ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + require_once APPPATH .'mailers/'. $class .'.php'; |
|
| 64 | + |
|
| 65 | + if (! class_exists($class, false)) |
|
| 66 | + { |
|
| 67 | + throw new \RuntimeException( sprintf( lang('errors.cant_instantiate'), $class) ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $mailer = new $class( $options ); |
|
| 71 | + |
|
| 72 | + if (! method_exists($mailer, $method)) |
|
| 73 | + { |
|
| 74 | + throw new \BadMethodCallException( sprintf( lang('mail.invalid_mailer_method'), $class, $method) ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // try to deliver the mail, but don't send back the contents |
|
| 78 | + // since we don't want to force the mailers to return anything. |
|
| 79 | + if (call_user_func_array([$mailer, $method], $params) ) |
|
| 80 | + { |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + //-------------------------------------------------------------------- |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Adds an item to the email queue to be sent out next time. |
|
| 91 | + * |
|
| 92 | + * @param string $mailer_name |
|
| 93 | + * @param array $params |
|
| 94 | + * @param array $options |
|
| 95 | + * @param \Myth\Mail\Queue $queue |
|
| 96 | + * |
|
| 97 | + * @return mixed |
|
| 98 | + */ |
|
| 99 | + public static function queue($mailer_name, $params=[], $options=[], &$queue=null) |
|
| 100 | + { |
|
| 101 | + $data = [ |
|
| 102 | + 'mailer' => $mailer_name, |
|
| 103 | + 'params' => serialize($params), |
|
| 104 | + 'options' => serialize($options) |
|
| 105 | + ]; |
|
| 106 | + |
|
| 107 | + if (empty($queue)) |
|
| 108 | + { |
|
| 109 | + $queue = new \Myth\Mail\Queue(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return $queue->insert($data); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + //-------------------------------------------------------------------- |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Processes the Email queue sending out emails in chunks. |
|
| 119 | + * Typically used in a cronjob to send out all queued emails. |
|
| 120 | + * |
|
| 121 | + * @param int $chunk_size // How many emails to send per batch. |
|
| 122 | + * @return string // The output of the cronjob... |
|
| 123 | + */ |
|
| 124 | + public static function process($chunk_size=50, &$db=null) |
|
| 125 | + { |
|
| 126 | + if (empty($db)) |
|
| 127 | + { |
|
| 128 | + $db = new \Myth\Mail\Queue(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // Grab our batch of emails to process |
|
| 132 | + $queue = $db->find_many_by('sent', 0); |
|
| 133 | + |
|
| 134 | + if (! $queue) |
|
| 135 | + { |
|
| 136 | + // We didn't have an error, we simply |
|
| 137 | + // didn't have anything to do. |
|
| 138 | + return true; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $output = 'Started processing email Queue at '. date('Y-m-d H:i:s') .".\n\n"; |
|
| 142 | + |
|
| 143 | + foreach ($queue as $item) |
|
| 144 | + { |
|
| 145 | + try { |
|
| 146 | + if (! Mail::deliver($item->mailer, unserialize($item->params), unserialize($item->options))) { |
|
| 147 | + $output .= '[FAILED] '; |
|
| 148 | + } else { |
|
| 149 | + $data = [ |
|
| 150 | + 'sent' => 1, |
|
| 151 | + 'sent_on' => date('Y-m-d H:i:s') |
|
| 152 | + ]; |
|
| 153 | + |
|
| 154 | + $db->update($item->id, $data); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $output .= "ID: {$item->id}, Mailer: {$item->mailer}. \n"; |
|
| 158 | + } |
|
| 159 | + catch (\Exception $e) |
|
| 160 | + { |
|
| 161 | + $output .= "[EXCEPTION] ". $e->getMessage() ."\n"; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $output .= "Done processing email Queue at ". date('H:i:s') .".\n"; |
|
| 166 | + |
|
| 167 | + return $output; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + //-------------------------------------------------------------------- |
|
| 171 | 171 | |
| 172 | 172 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param array $options |
| 48 | 48 | * @return mixed |
| 49 | 49 | */ |
| 50 | - public static function deliver($mailer_name, $params=[], $options=[]) |
|
| 50 | + public static function deliver($mailer_name, $params = [], $options = []) |
|
| 51 | 51 | { |
| 52 | 52 | // Protect users from themselves here. |
| 53 | 53 | str_replace('::', ':', $mailer_name); |
@@ -55,28 +55,28 @@ discard block |
||
| 55 | 55 | // Try to load our mailer class. |
| 56 | 56 | list($class, $method) = explode(':', $mailer_name); |
| 57 | 57 | |
| 58 | - if (! is_file(APPPATH .'mailers/'. $class .'.php')) |
|
| 58 | + if ( ! is_file(APPPATH.'mailers/'.$class.'.php')) |
|
| 59 | 59 | { |
| 60 | - throw new \RuntimeException( sprintf( lang('mail.cant_find_mailer'), $class) ); |
|
| 60 | + throw new \RuntimeException(sprintf(lang('mail.cant_find_mailer'), $class)); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - require_once APPPATH .'mailers/'. $class .'.php'; |
|
| 63 | + require_once APPPATH.'mailers/'.$class.'.php'; |
|
| 64 | 64 | |
| 65 | - if (! class_exists($class, false)) |
|
| 65 | + if ( ! class_exists($class, false)) |
|
| 66 | 66 | { |
| 67 | - throw new \RuntimeException( sprintf( lang('errors.cant_instantiate'), $class) ); |
|
| 67 | + throw new \RuntimeException(sprintf(lang('errors.cant_instantiate'), $class)); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $mailer = new $class( $options ); |
|
| 70 | + $mailer = new $class($options); |
|
| 71 | 71 | |
| 72 | - if (! method_exists($mailer, $method)) |
|
| 72 | + if ( ! method_exists($mailer, $method)) |
|
| 73 | 73 | { |
| 74 | - throw new \BadMethodCallException( sprintf( lang('mail.invalid_mailer_method'), $class, $method) ); |
|
| 74 | + throw new \BadMethodCallException(sprintf(lang('mail.invalid_mailer_method'), $class, $method)); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // try to deliver the mail, but don't send back the contents |
| 78 | 78 | // since we don't want to force the mailers to return anything. |
| 79 | - if (call_user_func_array([$mailer, $method], $params) ) |
|
| 79 | + if (call_user_func_array([$mailer, $method], $params)) |
|
| 80 | 80 | { |
| 81 | 81 | return true; |
| 82 | 82 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @return mixed |
| 98 | 98 | */ |
| 99 | - public static function queue($mailer_name, $params=[], $options=[], &$queue=null) |
|
| 99 | + public static function queue($mailer_name, $params = [], $options = [], &$queue = null) |
|
| 100 | 100 | { |
| 101 | 101 | $data = [ |
| 102 | 102 | 'mailer' => $mailer_name, |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param int $chunk_size // How many emails to send per batch. |
| 122 | 122 | * @return string // The output of the cronjob... |
| 123 | 123 | */ |
| 124 | - public static function process($chunk_size=50, &$db=null) |
|
| 124 | + public static function process($chunk_size = 50, &$db = null) |
|
| 125 | 125 | { |
| 126 | 126 | if (empty($db)) |
| 127 | 127 | { |
@@ -131,19 +131,19 @@ discard block |
||
| 131 | 131 | // Grab our batch of emails to process |
| 132 | 132 | $queue = $db->find_many_by('sent', 0); |
| 133 | 133 | |
| 134 | - if (! $queue) |
|
| 134 | + if ( ! $queue) |
|
| 135 | 135 | { |
| 136 | 136 | // We didn't have an error, we simply |
| 137 | 137 | // didn't have anything to do. |
| 138 | 138 | return true; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $output = 'Started processing email Queue at '. date('Y-m-d H:i:s') .".\n\n"; |
|
| 141 | + $output = 'Started processing email Queue at '.date('Y-m-d H:i:s').".\n\n"; |
|
| 142 | 142 | |
| 143 | 143 | foreach ($queue as $item) |
| 144 | 144 | { |
| 145 | 145 | try { |
| 146 | - if (! Mail::deliver($item->mailer, unserialize($item->params), unserialize($item->options))) { |
|
| 146 | + if ( ! Mail::deliver($item->mailer, unserialize($item->params), unserialize($item->options))) { |
|
| 147 | 147 | $output .= '[FAILED] '; |
| 148 | 148 | } else { |
| 149 | 149 | $data = [ |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | catch (\Exception $e) |
| 160 | 160 | { |
| 161 | - $output .= "[EXCEPTION] ". $e->getMessage() ."\n"; |
|
| 161 | + $output .= "[EXCEPTION] ".$e->getMessage()."\n"; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - $output .= "Done processing email Queue at ". date('H:i:s') .".\n"; |
|
| 165 | + $output .= "Done processing email Queue at ".date('H:i:s').".\n"; |
|
| 166 | 166 | |
| 167 | 167 | return $output; |
| 168 | 168 | } |
@@ -155,8 +155,7 @@ |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $output .= "ID: {$item->id}, Mailer: {$item->mailer}. \n"; |
| 158 | - } |
|
| 159 | - catch (\Exception $e) |
|
| 158 | + } catch (\Exception $e) |
|
| 160 | 159 | { |
| 161 | 160 | $output .= "[EXCEPTION] ". $e->getMessage() ."\n"; |
| 162 | 161 | } |
@@ -740,7 +740,6 @@ discard block |
||
| 740 | 740 | * $this->update_by($wheres, $data); |
| 741 | 741 | * $this->update_by('user_id', 15, $data); |
| 742 | 742 | * |
| 743 | - * @param array $data An array of data pairs to update |
|
| 744 | 743 | * @param one or more WHERE-acceptable entries. |
| 745 | 744 | * @return bool |
| 746 | 745 | */ |
@@ -1119,7 +1118,7 @@ discard block |
||
| 1119 | 1118 | * |
| 1120 | 1119 | * @param $field |
| 1121 | 1120 | * |
| 1122 | - * @return mixed |
|
| 1121 | + * @return CIDbModel |
|
| 1123 | 1122 | */ |
| 1124 | 1123 | public function protect($field) |
| 1125 | 1124 | { |
@@ -1380,6 +1379,7 @@ discard block |
||
| 1380 | 1379 | * |
| 1381 | 1380 | * @param array $data An array of validation rules |
| 1382 | 1381 | * @param string $type Either 'update' or 'insert'. |
| 1382 | + * @param boolean $skip_validation |
|
| 1383 | 1383 | * @return array/bool The original data or FALSE |
| 1384 | 1384 | */ |
| 1385 | 1385 | public function validate($data, $type = 'update', $skip_validation = null) |
@@ -1,34 +1,34 @@ discard block |
||
| 1 | 1 | <?php namespace Myth\Models; |
| 2 | 2 | /** |
| 3 | - * Sprint |
|
| 4 | - * |
|
| 5 | - * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
| 6 | - * |
|
| 7 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 8 | - * of this software and associated documentation files (the "Software"), to deal |
|
| 9 | - * in the Software without restriction, including without limitation the rights |
|
| 10 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 11 | - * copies of the Software, and to permit persons to whom the Software is |
|
| 12 | - * furnished to do so, subject to the following conditions: |
|
| 13 | - * |
|
| 14 | - * The above copyright notice and this permission notice shall be included in |
|
| 15 | - * all copies or substantial portions of the Software. |
|
| 16 | - * |
|
| 17 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 18 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 19 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 20 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 21 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 22 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 23 | - * THE SOFTWARE. |
|
| 24 | - * |
|
| 25 | - * @package Sprint |
|
| 26 | - * @author Lonnie Ezell |
|
| 27 | - * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
| 28 | - * @license http://opensource.org/licenses/MIT (MIT) |
|
| 29 | - * @link http://sprintphp.com |
|
| 30 | - * @since Version 1.0 |
|
| 31 | - */ |
|
| 3 | + * Sprint |
|
| 4 | + * |
|
| 5 | + * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
| 6 | + * |
|
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
|
| 9 | + * in the Software without restriction, including without limitation the rights |
|
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
|
| 12 | + * furnished to do so, subject to the following conditions: |
|
| 13 | + * |
|
| 14 | + * The above copyright notice and this permission notice shall be included in |
|
| 15 | + * all copies or substantial portions of the Software. |
|
| 16 | + * |
|
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 23 | + * THE SOFTWARE. |
|
| 24 | + * |
|
| 25 | + * @package Sprint |
|
| 26 | + * @author Lonnie Ezell |
|
| 27 | + * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
| 28 | + * @license http://opensource.org/licenses/MIT (MIT) |
|
| 29 | + * @link http://sprintphp.com |
|
| 30 | + * @since Version 1.0 |
|
| 31 | + */ |
|
| 32 | 32 | |
| 33 | 33 | //-------------------------------------------------------------------- |
| 34 | 34 | |
@@ -102,1479 +102,1479 @@ discard block |
||
| 102 | 102 | class CIDbModel |
| 103 | 103 | { |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * The model's default table name. |
|
| 107 | - * |
|
| 108 | - * @var string; |
|
| 109 | - */ |
|
| 110 | - protected $table_name; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * The model's default primary key. |
|
| 114 | - * |
|
| 115 | - * @var string |
|
| 116 | - */ |
|
| 117 | - protected $primary_key = 'id'; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The type of date/time field used for created_on and modified_on fields. |
|
| 121 | - * Valid types are: 'int', 'datetime', 'date' |
|
| 122 | - * |
|
| 123 | - * @var string |
|
| 124 | - * @access protected |
|
| 125 | - */ |
|
| 126 | - protected $date_format = 'datetime'; |
|
| 127 | - |
|
| 128 | - /* |
|
| 105 | + /** |
|
| 106 | + * The model's default table name. |
|
| 107 | + * |
|
| 108 | + * @var string; |
|
| 109 | + */ |
|
| 110 | + protected $table_name; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * The model's default primary key. |
|
| 114 | + * |
|
| 115 | + * @var string |
|
| 116 | + */ |
|
| 117 | + protected $primary_key = 'id'; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The type of date/time field used for created_on and modified_on fields. |
|
| 121 | + * Valid types are: 'int', 'datetime', 'date' |
|
| 122 | + * |
|
| 123 | + * @var string |
|
| 124 | + * @access protected |
|
| 125 | + */ |
|
| 126 | + protected $date_format = 'datetime'; |
|
| 127 | + |
|
| 128 | + /* |
|
| 129 | 129 | Var: $log_user |
| 130 | 130 | If TRUE, will log user id for 'created_by', 'modified_by' and 'deleted_by'. |
| 131 | 131 | |
| 132 | 132 | Access: |
| 133 | 133 | Protected |
| 134 | 134 | */ |
| 135 | - protected $log_user = FALSE; |
|
| 135 | + protected $log_user = FALSE; |
|
| 136 | 136 | |
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Whether or not to auto-fill a 'created_on' field on inserts. |
|
| 141 | - * |
|
| 142 | - * @var boolean |
|
| 143 | - * @access protected |
|
| 144 | - */ |
|
| 145 | - protected $set_created = TRUE; |
|
| 139 | + /** |
|
| 140 | + * Whether or not to auto-fill a 'created_on' field on inserts. |
|
| 141 | + * |
|
| 142 | + * @var boolean |
|
| 143 | + * @access protected |
|
| 144 | + */ |
|
| 145 | + protected $set_created = TRUE; |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Field name to use to the created time column in the DB table. |
|
| 149 | - * |
|
| 150 | - * @var string |
|
| 151 | - * @access protected |
|
| 152 | - */ |
|
| 153 | - protected $created_field = 'created_on'; |
|
| 147 | + /** |
|
| 148 | + * Field name to use to the created time column in the DB table. |
|
| 149 | + * |
|
| 150 | + * @var string |
|
| 151 | + * @access protected |
|
| 152 | + */ |
|
| 153 | + protected $created_field = 'created_on'; |
|
| 154 | 154 | |
| 155 | - /* |
|
| 155 | + /* |
|
| 156 | 156 | Var: $created_by_field |
| 157 | 157 | Field name to use to the created by column in the DB table. |
| 158 | 158 | |
| 159 | 159 | Access: |
| 160 | 160 | Protected |
| 161 | 161 | */ |
| 162 | - protected $created_by_field = 'created_by'; |
|
| 162 | + protected $created_by_field = 'created_by'; |
|
| 163 | 163 | |
| 164 | 164 | |
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Whether or not to auto-fill a 'modified_on' field on updates. |
|
| 168 | - * |
|
| 169 | - * @var boolean |
|
| 170 | - * @access protected |
|
| 171 | - */ |
|
| 172 | - protected $set_modified = TRUE; |
|
| 166 | + /** |
|
| 167 | + * Whether or not to auto-fill a 'modified_on' field on updates. |
|
| 168 | + * |
|
| 169 | + * @var boolean |
|
| 170 | + * @access protected |
|
| 171 | + */ |
|
| 172 | + protected $set_modified = TRUE; |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * Field name to use to the modified time column in the DB table. |
|
| 176 | - * |
|
| 177 | - * @var string |
|
| 178 | - * @access protected |
|
| 179 | - */ |
|
| 180 | - protected $modified_field = 'modified_on'; |
|
| 174 | + /** |
|
| 175 | + * Field name to use to the modified time column in the DB table. |
|
| 176 | + * |
|
| 177 | + * @var string |
|
| 178 | + * @access protected |
|
| 179 | + */ |
|
| 180 | + protected $modified_field = 'modified_on'; |
|
| 181 | 181 | |
| 182 | - /* |
|
| 182 | + /* |
|
| 183 | 183 | Var: $modified_by_field |
| 184 | 184 | Field name to use to the modified by column in the DB table. |
| 185 | 185 | |
| 186 | 186 | Access: |
| 187 | 187 | Protected |
| 188 | 188 | */ |
| 189 | - protected $modified_by_field = 'modified_by'; |
|
| 189 | + protected $modified_by_field = 'modified_by'; |
|
| 190 | 190 | |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Support for soft_deletes. |
|
| 194 | - */ |
|
| 195 | - protected $soft_deletes = FALSE; |
|
| 196 | - protected $soft_delete_key = 'deleted'; |
|
| 197 | - protected $temp_with_deleted = FALSE; |
|
| 192 | + /** |
|
| 193 | + * Support for soft_deletes. |
|
| 194 | + */ |
|
| 195 | + protected $soft_deletes = FALSE; |
|
| 196 | + protected $soft_delete_key = 'deleted'; |
|
| 197 | + protected $temp_with_deleted = FALSE; |
|
| 198 | 198 | |
| 199 | - /* |
|
| 199 | + /* |
|
| 200 | 200 | Var: $deleted_by_field |
| 201 | 201 | Field name to use for the deleted by column in the DB table. |
| 202 | 202 | |
| 203 | 203 | Access: |
| 204 | 204 | Protected |
| 205 | 205 | */ |
| 206 | - protected $deleted_by_field = 'deleted_by'; |
|
| 206 | + protected $deleted_by_field = 'deleted_by'; |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Various callbacks available to the class. They are simple lists of |
|
| 212 | - * method names (methods will be ran on $this). |
|
| 213 | - */ |
|
| 214 | - protected $before_insert = array(); |
|
| 215 | - protected $after_insert = array(); |
|
| 216 | - protected $before_update = array(); |
|
| 217 | - protected $after_update = array(); |
|
| 218 | - protected $before_find = array(); |
|
| 219 | - protected $after_find = array(); |
|
| 220 | - protected $before_delete = array(); |
|
| 221 | - protected $after_delete = array(); |
|
| 210 | + /** |
|
| 211 | + * Various callbacks available to the class. They are simple lists of |
|
| 212 | + * method names (methods will be ran on $this). |
|
| 213 | + */ |
|
| 214 | + protected $before_insert = array(); |
|
| 215 | + protected $after_insert = array(); |
|
| 216 | + protected $before_update = array(); |
|
| 217 | + protected $after_update = array(); |
|
| 218 | + protected $before_find = array(); |
|
| 219 | + protected $after_find = array(); |
|
| 220 | + protected $before_delete = array(); |
|
| 221 | + protected $after_delete = array(); |
|
| 222 | 222 | |
| 223 | - protected $callback_parameters = array(); |
|
| 223 | + protected $callback_parameters = array(); |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | 226 | |
| 227 | - /* |
|
| 227 | + /* |
|
| 228 | 228 | If TRUE, inserts will return the last_insert_id. However, |
| 229 | 229 | this can potentially slow down large imports drastically |
| 230 | 230 | so you can turn it off with the return_insert_id(false) method. |
| 231 | 231 | */ |
| 232 | - protected $return_insert_id = true; |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * By default, we return items as objects. You can change this for the |
|
| 236 | - * entire class by setting this value to 'array' instead of 'object'. |
|
| 237 | - * Alternatively, you can do it on a per-instance basis using the |
|
| 238 | - * 'as_array()' and 'as_object()' methods. |
|
| 239 | - */ |
|
| 240 | - protected $return_type = 'object'; |
|
| 241 | - protected $temp_return_type = NULL; |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Protected, non-modifiable attributes |
|
| 245 | - */ |
|
| 246 | - protected $protected_attributes = array(); |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * An array of validation rules. This needs to be the same format |
|
| 252 | - * as validation rules passed to the Form_validation library. |
|
| 253 | - */ |
|
| 254 | - protected $validation_rules = array(); |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Optionally skip the validation. Used in conjunction with |
|
| 258 | - * skip_validation() to skip data validation for any future calls. |
|
| 259 | - */ |
|
| 260 | - protected $skip_validation = FALSE; |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * An array of extra rules to add to validation rules during inserts only. |
|
| 264 | - * Often used for adding 'required' rules to fields on insert, but not udpates. |
|
| 265 | - * |
|
| 266 | - * array( 'username' => 'required|strip_tags' ); |
|
| 267 | - * @var array |
|
| 268 | - */ |
|
| 269 | - protected $insert_validate_rules = array(); |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * @var Array Columns for the model's database fields |
|
| 275 | - * |
|
| 276 | - * This can be set to avoid a database call if using $this->prep_data() |
|
| 277 | - */ |
|
| 278 | - protected $fields = array(); |
|
| 279 | - |
|
| 280 | - //-------------------------------------------------------------------- |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Does basic setup. Can pass the database connection into the constructor |
|
| 284 | - * to use that $db instead of the global CI one. |
|
| 285 | - * |
|
| 286 | - * @param object $db // A database/driver instance |
|
| 287 | - * @param object $form_validation // A form_validation library instance |
|
| 288 | - */ |
|
| 289 | - public function __construct($db = null, $form_validation = null) |
|
| 290 | - { |
|
| 291 | - // Always protect our attributes |
|
| 292 | - array_unshift($this->before_insert, 'protect_attributes'); |
|
| 293 | - array_unshift($this->before_update, 'protect_attributes'); |
|
| 294 | - |
|
| 295 | - // Check our auto-set features and make sure they are part of |
|
| 296 | - // our observer system. |
|
| 297 | - if ($this->set_created === true) array_unshift($this->before_insert, 'created_on'); |
|
| 298 | - if ($this->set_modified === true) array_unshift($this->before_update, 'modified_on'); |
|
| 299 | - |
|
| 300 | - // Make sure our temp return type is correct. |
|
| 301 | - $this->temp_return_type = $this->return_type; |
|
| 302 | - |
|
| 303 | - // Make sure our database is loaded |
|
| 304 | - if (!is_null($db)) { |
|
| 305 | - $this->db = $db; |
|
| 306 | - } |
|
| 307 | - else { |
|
| 308 | - // Auto Init the damn database.... |
|
| 309 | - $this->load->database(); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - // Do we have a form_validation library? |
|
| 313 | - if (! is_null($form_validation)) { |
|
| 314 | - $this->form_validation = $form_validation; |
|
| 315 | - } |
|
| 316 | - else { |
|
| 317 | - $this->load->library('form_validation'); |
|
| 318 | - } |
|
| 232 | + protected $return_insert_id = true; |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * By default, we return items as objects. You can change this for the |
|
| 236 | + * entire class by setting this value to 'array' instead of 'object'. |
|
| 237 | + * Alternatively, you can do it on a per-instance basis using the |
|
| 238 | + * 'as_array()' and 'as_object()' methods. |
|
| 239 | + */ |
|
| 240 | + protected $return_type = 'object'; |
|
| 241 | + protected $temp_return_type = NULL; |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Protected, non-modifiable attributes |
|
| 245 | + */ |
|
| 246 | + protected $protected_attributes = array(); |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * An array of validation rules. This needs to be the same format |
|
| 252 | + * as validation rules passed to the Form_validation library. |
|
| 253 | + */ |
|
| 254 | + protected $validation_rules = array(); |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Optionally skip the validation. Used in conjunction with |
|
| 258 | + * skip_validation() to skip data validation for any future calls. |
|
| 259 | + */ |
|
| 260 | + protected $skip_validation = FALSE; |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * An array of extra rules to add to validation rules during inserts only. |
|
| 264 | + * Often used for adding 'required' rules to fields on insert, but not udpates. |
|
| 265 | + * |
|
| 266 | + * array( 'username' => 'required|strip_tags' ); |
|
| 267 | + * @var array |
|
| 268 | + */ |
|
| 269 | + protected $insert_validate_rules = array(); |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * @var Array Columns for the model's database fields |
|
| 275 | + * |
|
| 276 | + * This can be set to avoid a database call if using $this->prep_data() |
|
| 277 | + */ |
|
| 278 | + protected $fields = array(); |
|
| 279 | + |
|
| 280 | + //-------------------------------------------------------------------- |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Does basic setup. Can pass the database connection into the constructor |
|
| 284 | + * to use that $db instead of the global CI one. |
|
| 285 | + * |
|
| 286 | + * @param object $db // A database/driver instance |
|
| 287 | + * @param object $form_validation // A form_validation library instance |
|
| 288 | + */ |
|
| 289 | + public function __construct($db = null, $form_validation = null) |
|
| 290 | + { |
|
| 291 | + // Always protect our attributes |
|
| 292 | + array_unshift($this->before_insert, 'protect_attributes'); |
|
| 293 | + array_unshift($this->before_update, 'protect_attributes'); |
|
| 294 | + |
|
| 295 | + // Check our auto-set features and make sure they are part of |
|
| 296 | + // our observer system. |
|
| 297 | + if ($this->set_created === true) array_unshift($this->before_insert, 'created_on'); |
|
| 298 | + if ($this->set_modified === true) array_unshift($this->before_update, 'modified_on'); |
|
| 299 | + |
|
| 300 | + // Make sure our temp return type is correct. |
|
| 301 | + $this->temp_return_type = $this->return_type; |
|
| 302 | + |
|
| 303 | + // Make sure our database is loaded |
|
| 304 | + if (!is_null($db)) { |
|
| 305 | + $this->db = $db; |
|
| 306 | + } |
|
| 307 | + else { |
|
| 308 | + // Auto Init the damn database.... |
|
| 309 | + $this->load->database(); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + // Do we have a form_validation library? |
|
| 313 | + if (! is_null($form_validation)) { |
|
| 314 | + $this->form_validation = $form_validation; |
|
| 315 | + } |
|
| 316 | + else { |
|
| 317 | + $this->load->library('form_validation'); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - log_message('debug', 'CIDbModel Class Initialized'); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - //-------------------------------------------------------------------- |
|
| 324 | - |
|
| 325 | - //-------------------------------------------------------------------- |
|
| 326 | - // CRUD Methods |
|
| 327 | - //-------------------------------------------------------------------- |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * A simple way to grab the first result of a search only. |
|
| 331 | - */ |
|
| 332 | - public function first() |
|
| 333 | - { |
|
| 334 | - $rows = $this->limit(1, 0)->find_all(); |
|
| 335 | - |
|
| 336 | - if (is_array($rows) && count($rows)) { |
|
| 337 | - return $rows[0]; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - return $rows; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - //-------------------------------------------------------------------- |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Finds a single record based on it's primary key. Will ignore deleted rows. |
|
| 348 | - * |
|
| 349 | - * @param mixed $id The primary_key value of the object to retrieve. |
|
| 350 | - * @return object |
|
| 351 | - */ |
|
| 352 | - public function find($id) |
|
| 353 | - { |
|
| 354 | - $this->trigger('before_find', ['id' => $id, 'method' => 'find']); |
|
| 355 | - |
|
| 356 | - // Ignore any soft-deleted rows |
|
| 357 | - if ($this->soft_deletes) { |
|
| 358 | - // We only need to modify the where statement if |
|
| 359 | - // temp_with_deleted is false. |
|
| 360 | - if ($this->temp_with_deleted !== true) { |
|
| 361 | - $this->db->where($this->soft_delete_key, false); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $this->temp_with_deleted = false; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - $this->db->where($this->primary_key, $id); |
|
| 368 | - $row = $this->db->get($this->table_name); |
|
| 369 | - $row = $this->temp_return_type == 'array' ? $row->row_array() : $row->row(0, $this->temp_return_type); |
|
| 370 | - |
|
| 371 | - if ( ! empty($row)) |
|
| 372 | - { |
|
| 373 | - $row = $this->trigger('after_find', ['id' => $id, 'method' => 'find', 'fields' => $row]); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - // Reset our return type |
|
| 377 | - $this->temp_return_type = $this->return_type; |
|
| 378 | - |
|
| 379 | - return $row; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - //-------------------------------------------------------------------- |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Fetch a single record based on an arbitrary WHERE call. Can be |
|
| 386 | - * any valid value to $this->db->where(). Will not pull in deleted rows |
|
| 387 | - * if using soft deletes. |
|
| 388 | - * |
|
| 389 | - * @return object |
|
| 390 | - */ |
|
| 391 | - public function find_by() |
|
| 392 | - { |
|
| 393 | - $where = func_get_args(); |
|
| 394 | - $this->_set_where($where); |
|
| 395 | - |
|
| 396 | - // Ignore any soft-deleted rows |
|
| 397 | - if ($this->soft_deletes) { |
|
| 398 | - // We only need to modify the where statement if |
|
| 399 | - // temp_with_deleted is false. |
|
| 400 | - if ($this->temp_with_deleted !== true) { |
|
| 401 | - $this->db->where($this->soft_delete_key, false); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - $this->temp_with_deleted = false; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - $this->trigger('before_find', ['method' => 'find_by', 'fields' => $where]); |
|
| 408 | - |
|
| 409 | - $row = $this->db->get($this->table_name); |
|
| 410 | - $row = $this->temp_return_type == 'array' ? $row->row_array() : $row->row(0, $this->temp_return_type); |
|
| 411 | - |
|
| 412 | - if ( ! empty($row)) |
|
| 413 | - { |
|
| 414 | - $row = $this->trigger('after_find', ['method' => 'find_by', 'fields' => $row]); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // Reset our return type |
|
| 418 | - $this->temp_return_type = $this->return_type; |
|
| 419 | - |
|
| 420 | - return $row; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - //-------------------------------------------------------------------- |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Retrieves a number of items based on an array of primary_values passed in. |
|
| 427 | - * |
|
| 428 | - * @param array $values An array of primary key values to find. |
|
| 429 | - * |
|
| 430 | - * @return object or FALSE |
|
| 431 | - */ |
|
| 432 | - public function find_many($values) |
|
| 433 | - { |
|
| 434 | - $this->db->where_in($this->primary_key, $values); |
|
| 435 | - |
|
| 436 | - return $this->find_all(); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - //-------------------------------------------------------------------- |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Retrieves a number of items based on an arbitrary WHERE call. Can be |
|
| 443 | - * any set of parameters valid to $db->where. |
|
| 444 | - * |
|
| 445 | - * @return object or FALSE |
|
| 446 | - */ |
|
| 447 | - public function find_many_by() |
|
| 448 | - { |
|
| 449 | - $where = func_get_args(); |
|
| 450 | - $this->_set_where($where); |
|
| 451 | - |
|
| 452 | - return $this->find_all(); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - //-------------------------------------------------------------------- |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Fetch all of the records in the table. Can be used with scoped calls |
|
| 459 | - * to restrict the results. |
|
| 460 | - * |
|
| 461 | - * @return object or FALSE |
|
| 462 | - */ |
|
| 463 | - public function find_all() |
|
| 464 | - { |
|
| 465 | - $this->trigger('before_find', ['method' => 'find_all']); |
|
| 466 | - |
|
| 467 | - // Ignore any soft-deleted rows |
|
| 468 | - if ($this->soft_deletes) { |
|
| 469 | - // We only need to modify the where statement if |
|
| 470 | - // temp_with_deleted is false. |
|
| 471 | - if ($this->temp_with_deleted !== true) { |
|
| 472 | - $this->db->where($this->soft_delete_key, false); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - $this->temp_with_deleted = false; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $rows = $this->db->get($this->table_name); |
|
| 479 | - $rows = $this->temp_return_type == 'array' ? $rows->result_array() : $rows->result($this->temp_return_type); |
|
| 480 | - |
|
| 481 | - if (is_array($rows)) { |
|
| 482 | - foreach ($rows as $key => &$row) { |
|
| 483 | - $row = $this->trigger('after_find', ['method' => 'find_all', 'fields' => $row] ); |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - // Reset our return type |
|
| 488 | - $this->temp_return_type = $this->return_type; |
|
| 489 | - |
|
| 490 | - return $rows; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - //-------------------------------------------------------------------- |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Inserts data into the database. |
|
| 497 | - * |
|
| 498 | - * @param array $data An array of key/value pairs to insert to database. |
|
| 499 | - * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 500 | - * @return mixed The primary_key value of the inserted record, or FALSE. |
|
| 501 | - */ |
|
| 502 | - public function insert($data, $skip_validation = null) |
|
| 503 | - { |
|
| 504 | - $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 505 | - |
|
| 506 | - if ($skip_validation === FALSE) { |
|
| 507 | - $data = $this->validate($data, 'insert', $skip_validation); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - if ($data !== FALSE) { |
|
| 511 | - $data = $this->trigger('before_insert', ['method' => 'insert', 'fields' => $data]); |
|
| 512 | - |
|
| 513 | - $this->db->insert($this->table_name, $this->prep_data($data) ); |
|
| 514 | - |
|
| 515 | - if ($this->return_insert_id) { |
|
| 516 | - $id = $this->db->insert_id(); |
|
| 517 | - |
|
| 518 | - $this->trigger('after_insert', ['id' => $id, 'fields' => $data, 'method' => 'insert']); |
|
| 519 | - |
|
| 520 | - return $id; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - return TRUE; |
|
| 524 | - } else { |
|
| 525 | - return FALSE; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - //-------------------------------------------------------------------- |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Inserts multiple rows into the database at once. Takes an associative |
|
| 533 | - * array of value pairs. |
|
| 534 | - * |
|
| 535 | - * $data = array( |
|
| 536 | - * array( |
|
| 537 | - * 'title' => 'My title' |
|
| 538 | - * ), |
|
| 539 | - * array( |
|
| 540 | - * 'title' => 'My Other Title' |
|
| 541 | - * ) |
|
| 542 | - * ); |
|
| 543 | - * |
|
| 544 | - * @param array $data An associate array of rows to insert |
|
| 545 | - * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 546 | - * @return bool |
|
| 547 | - */ |
|
| 548 | - public function insert_batch($data, $skip_validation = null) |
|
| 549 | - { |
|
| 550 | - $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 551 | - |
|
| 552 | - if ($skip_validation === FALSE) { |
|
| 553 | - $data = $this->validate($data, 'insert', $skip_validation); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - if ($data !== FALSE) { |
|
| 557 | - $data['batch'] = true; |
|
| 558 | - $data = $this->trigger('before_insert', ['method' => 'insert_batch', 'fields' => $data] ); |
|
| 559 | - unset($data['batch']); |
|
| 560 | - |
|
| 561 | - return $this->db->insert_batch($this->table_name, $data); |
|
| 562 | - } else { |
|
| 563 | - return FALSE; |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - //-------------------------------------------------------------------- |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Performs the SQL standard for a combined DELETE + INSERT, using |
|
| 571 | - * PRIMARY and UNIQUE keys to determine which row to replace. |
|
| 572 | - * |
|
| 573 | - * See CI's documentation for the replace method. We simply wrap |
|
| 574 | - * our validation and triggers around their method. |
|
| 575 | - * |
|
| 576 | - * @param $data |
|
| 577 | - * @param null $skip_validation |
|
| 578 | - * @return bool |
|
| 579 | - */ |
|
| 580 | - public function replace($data, $skip_validation=null) |
|
| 581 | - { |
|
| 582 | - $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 583 | - |
|
| 584 | - if ($skip_validation === FALSE) { |
|
| 585 | - $data = $this->validate($data, 'insert', $skip_validation); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - if ($data !== FALSE) { |
|
| 589 | - $this->db->replace($this->table_name, $this->prep_data($data)); |
|
| 590 | - |
|
| 591 | - if ($this->return_insert_id) { |
|
| 592 | - $id = $this->db->insert_id(); |
|
| 593 | - |
|
| 594 | - $this->trigger('after_insert', ['id' => $id, 'fields' => $data, 'method'=>'replace']); |
|
| 595 | - |
|
| 596 | - return $id; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - return TRUE; |
|
| 600 | - } else { |
|
| 601 | - return FALSE; |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - //-------------------------------------------------------------------- |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Updates an existing record in the database. |
|
| 610 | - * |
|
| 611 | - * @param mixed $id The primary_key value of the record to update. |
|
| 612 | - * @param array $data An array of value pairs to update in the record. |
|
| 613 | - * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 614 | - * @return bool |
|
| 615 | - */ |
|
| 616 | - public function update($id, $data, $skip_validation = null) |
|
| 617 | - { |
|
| 618 | - $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 619 | - |
|
| 620 | - if ($skip_validation === FALSE) { |
|
| 621 | - $data = $this->validate($data); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // Will be false if it didn't validate. |
|
| 625 | - if ($data !== FALSE) { |
|
| 320 | + log_message('debug', 'CIDbModel Class Initialized'); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + //-------------------------------------------------------------------- |
|
| 324 | + |
|
| 325 | + //-------------------------------------------------------------------- |
|
| 326 | + // CRUD Methods |
|
| 327 | + //-------------------------------------------------------------------- |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * A simple way to grab the first result of a search only. |
|
| 331 | + */ |
|
| 332 | + public function first() |
|
| 333 | + { |
|
| 334 | + $rows = $this->limit(1, 0)->find_all(); |
|
| 335 | + |
|
| 336 | + if (is_array($rows) && count($rows)) { |
|
| 337 | + return $rows[0]; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + return $rows; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + //-------------------------------------------------------------------- |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Finds a single record based on it's primary key. Will ignore deleted rows. |
|
| 348 | + * |
|
| 349 | + * @param mixed $id The primary_key value of the object to retrieve. |
|
| 350 | + * @return object |
|
| 351 | + */ |
|
| 352 | + public function find($id) |
|
| 353 | + { |
|
| 354 | + $this->trigger('before_find', ['id' => $id, 'method' => 'find']); |
|
| 355 | + |
|
| 356 | + // Ignore any soft-deleted rows |
|
| 357 | + if ($this->soft_deletes) { |
|
| 358 | + // We only need to modify the where statement if |
|
| 359 | + // temp_with_deleted is false. |
|
| 360 | + if ($this->temp_with_deleted !== true) { |
|
| 361 | + $this->db->where($this->soft_delete_key, false); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $this->temp_with_deleted = false; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + $this->db->where($this->primary_key, $id); |
|
| 368 | + $row = $this->db->get($this->table_name); |
|
| 369 | + $row = $this->temp_return_type == 'array' ? $row->row_array() : $row->row(0, $this->temp_return_type); |
|
| 370 | + |
|
| 371 | + if ( ! empty($row)) |
|
| 372 | + { |
|
| 373 | + $row = $this->trigger('after_find', ['id' => $id, 'method' => 'find', 'fields' => $row]); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + // Reset our return type |
|
| 377 | + $this->temp_return_type = $this->return_type; |
|
| 378 | + |
|
| 379 | + return $row; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + //-------------------------------------------------------------------- |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Fetch a single record based on an arbitrary WHERE call. Can be |
|
| 386 | + * any valid value to $this->db->where(). Will not pull in deleted rows |
|
| 387 | + * if using soft deletes. |
|
| 388 | + * |
|
| 389 | + * @return object |
|
| 390 | + */ |
|
| 391 | + public function find_by() |
|
| 392 | + { |
|
| 393 | + $where = func_get_args(); |
|
| 394 | + $this->_set_where($where); |
|
| 395 | + |
|
| 396 | + // Ignore any soft-deleted rows |
|
| 397 | + if ($this->soft_deletes) { |
|
| 398 | + // We only need to modify the where statement if |
|
| 399 | + // temp_with_deleted is false. |
|
| 400 | + if ($this->temp_with_deleted !== true) { |
|
| 401 | + $this->db->where($this->soft_delete_key, false); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + $this->temp_with_deleted = false; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + $this->trigger('before_find', ['method' => 'find_by', 'fields' => $where]); |
|
| 408 | + |
|
| 409 | + $row = $this->db->get($this->table_name); |
|
| 410 | + $row = $this->temp_return_type == 'array' ? $row->row_array() : $row->row(0, $this->temp_return_type); |
|
| 411 | + |
|
| 412 | + if ( ! empty($row)) |
|
| 413 | + { |
|
| 414 | + $row = $this->trigger('after_find', ['method' => 'find_by', 'fields' => $row]); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // Reset our return type |
|
| 418 | + $this->temp_return_type = $this->return_type; |
|
| 419 | + |
|
| 420 | + return $row; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + //-------------------------------------------------------------------- |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Retrieves a number of items based on an array of primary_values passed in. |
|
| 427 | + * |
|
| 428 | + * @param array $values An array of primary key values to find. |
|
| 429 | + * |
|
| 430 | + * @return object or FALSE |
|
| 431 | + */ |
|
| 432 | + public function find_many($values) |
|
| 433 | + { |
|
| 434 | + $this->db->where_in($this->primary_key, $values); |
|
| 435 | + |
|
| 436 | + return $this->find_all(); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + //-------------------------------------------------------------------- |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Retrieves a number of items based on an arbitrary WHERE call. Can be |
|
| 443 | + * any set of parameters valid to $db->where. |
|
| 444 | + * |
|
| 445 | + * @return object or FALSE |
|
| 446 | + */ |
|
| 447 | + public function find_many_by() |
|
| 448 | + { |
|
| 449 | + $where = func_get_args(); |
|
| 450 | + $this->_set_where($where); |
|
| 451 | + |
|
| 452 | + return $this->find_all(); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + //-------------------------------------------------------------------- |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Fetch all of the records in the table. Can be used with scoped calls |
|
| 459 | + * to restrict the results. |
|
| 460 | + * |
|
| 461 | + * @return object or FALSE |
|
| 462 | + */ |
|
| 463 | + public function find_all() |
|
| 464 | + { |
|
| 465 | + $this->trigger('before_find', ['method' => 'find_all']); |
|
| 466 | + |
|
| 467 | + // Ignore any soft-deleted rows |
|
| 468 | + if ($this->soft_deletes) { |
|
| 469 | + // We only need to modify the where statement if |
|
| 470 | + // temp_with_deleted is false. |
|
| 471 | + if ($this->temp_with_deleted !== true) { |
|
| 472 | + $this->db->where($this->soft_delete_key, false); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + $this->temp_with_deleted = false; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $rows = $this->db->get($this->table_name); |
|
| 479 | + $rows = $this->temp_return_type == 'array' ? $rows->result_array() : $rows->result($this->temp_return_type); |
|
| 480 | + |
|
| 481 | + if (is_array($rows)) { |
|
| 482 | + foreach ($rows as $key => &$row) { |
|
| 483 | + $row = $this->trigger('after_find', ['method' => 'find_all', 'fields' => $row] ); |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + // Reset our return type |
|
| 488 | + $this->temp_return_type = $this->return_type; |
|
| 489 | + |
|
| 490 | + return $rows; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + //-------------------------------------------------------------------- |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Inserts data into the database. |
|
| 497 | + * |
|
| 498 | + * @param array $data An array of key/value pairs to insert to database. |
|
| 499 | + * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 500 | + * @return mixed The primary_key value of the inserted record, or FALSE. |
|
| 501 | + */ |
|
| 502 | + public function insert($data, $skip_validation = null) |
|
| 503 | + { |
|
| 504 | + $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 505 | + |
|
| 506 | + if ($skip_validation === FALSE) { |
|
| 507 | + $data = $this->validate($data, 'insert', $skip_validation); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + if ($data !== FALSE) { |
|
| 511 | + $data = $this->trigger('before_insert', ['method' => 'insert', 'fields' => $data]); |
|
| 512 | + |
|
| 513 | + $this->db->insert($this->table_name, $this->prep_data($data) ); |
|
| 514 | + |
|
| 515 | + if ($this->return_insert_id) { |
|
| 516 | + $id = $this->db->insert_id(); |
|
| 517 | + |
|
| 518 | + $this->trigger('after_insert', ['id' => $id, 'fields' => $data, 'method' => 'insert']); |
|
| 519 | + |
|
| 520 | + return $id; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + return TRUE; |
|
| 524 | + } else { |
|
| 525 | + return FALSE; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + //-------------------------------------------------------------------- |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Inserts multiple rows into the database at once. Takes an associative |
|
| 533 | + * array of value pairs. |
|
| 534 | + * |
|
| 535 | + * $data = array( |
|
| 536 | + * array( |
|
| 537 | + * 'title' => 'My title' |
|
| 538 | + * ), |
|
| 539 | + * array( |
|
| 540 | + * 'title' => 'My Other Title' |
|
| 541 | + * ) |
|
| 542 | + * ); |
|
| 543 | + * |
|
| 544 | + * @param array $data An associate array of rows to insert |
|
| 545 | + * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 546 | + * @return bool |
|
| 547 | + */ |
|
| 548 | + public function insert_batch($data, $skip_validation = null) |
|
| 549 | + { |
|
| 550 | + $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 551 | + |
|
| 552 | + if ($skip_validation === FALSE) { |
|
| 553 | + $data = $this->validate($data, 'insert', $skip_validation); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + if ($data !== FALSE) { |
|
| 557 | + $data['batch'] = true; |
|
| 558 | + $data = $this->trigger('before_insert', ['method' => 'insert_batch', 'fields' => $data] ); |
|
| 559 | + unset($data['batch']); |
|
| 560 | + |
|
| 561 | + return $this->db->insert_batch($this->table_name, $data); |
|
| 562 | + } else { |
|
| 563 | + return FALSE; |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + //-------------------------------------------------------------------- |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Performs the SQL standard for a combined DELETE + INSERT, using |
|
| 571 | + * PRIMARY and UNIQUE keys to determine which row to replace. |
|
| 572 | + * |
|
| 573 | + * See CI's documentation for the replace method. We simply wrap |
|
| 574 | + * our validation and triggers around their method. |
|
| 575 | + * |
|
| 576 | + * @param $data |
|
| 577 | + * @param null $skip_validation |
|
| 578 | + * @return bool |
|
| 579 | + */ |
|
| 580 | + public function replace($data, $skip_validation=null) |
|
| 581 | + { |
|
| 582 | + $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 583 | + |
|
| 584 | + if ($skip_validation === FALSE) { |
|
| 585 | + $data = $this->validate($data, 'insert', $skip_validation); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + if ($data !== FALSE) { |
|
| 589 | + $this->db->replace($this->table_name, $this->prep_data($data)); |
|
| 590 | + |
|
| 591 | + if ($this->return_insert_id) { |
|
| 592 | + $id = $this->db->insert_id(); |
|
| 593 | + |
|
| 594 | + $this->trigger('after_insert', ['id' => $id, 'fields' => $data, 'method'=>'replace']); |
|
| 595 | + |
|
| 596 | + return $id; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + return TRUE; |
|
| 600 | + } else { |
|
| 601 | + return FALSE; |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + //-------------------------------------------------------------------- |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Updates an existing record in the database. |
|
| 610 | + * |
|
| 611 | + * @param mixed $id The primary_key value of the record to update. |
|
| 612 | + * @param array $data An array of value pairs to update in the record. |
|
| 613 | + * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 614 | + * @return bool |
|
| 615 | + */ |
|
| 616 | + public function update($id, $data, $skip_validation = null) |
|
| 617 | + { |
|
| 618 | + $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 619 | + |
|
| 620 | + if ($skip_validation === FALSE) { |
|
| 621 | + $data = $this->validate($data); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // Will be false if it didn't validate. |
|
| 625 | + if ($data !== FALSE) { |
|
| 626 | 626 | |
| 627 | - $data = $this->trigger('before_update', ['id' => $id, 'method' =>'update', 'fields' => $data] ); |
|
| 627 | + $data = $this->trigger('before_update', ['id' => $id, 'method' =>'update', 'fields' => $data] ); |
|
| 628 | 628 | |
| 629 | - $this->db->where($this->primary_key, $id); |
|
| 630 | - $this->db->set( $this->prep_data($data) ); |
|
| 631 | - $result = $this->db->update($this->table_name); |
|
| 632 | - |
|
| 633 | - $this->trigger('after_update', ['id' => $id, 'fields' => $data, 'result' => $result, 'method' => 'update']); |
|
| 634 | - |
|
| 635 | - return $result; |
|
| 636 | - } else { |
|
| 637 | - return FALSE; |
|
| 638 | - } |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - //-------------------------------------------------------------------- |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * Updates multiple records in the database at once. |
|
| 645 | - * |
|
| 646 | - * $data = array( |
|
| 647 | - * array( |
|
| 648 | - * 'title' => 'My title', |
|
| 649 | - * 'body' => 'body 1' |
|
| 650 | - * ), |
|
| 651 | - * array( |
|
| 652 | - * 'title' => 'Another Title', |
|
| 653 | - * 'body' => 'body 2' |
|
| 654 | - * ) |
|
| 655 | - * ); |
|
| 656 | - * |
|
| 657 | - * The $where_key should be the name of the column to match the record on. |
|
| 658 | - * If $where_key == 'title', then each record would be matched on that |
|
| 659 | - * 'title' value of the array. This does mean that the array key needs |
|
| 660 | - * to be provided with each row's data. |
|
| 661 | - * |
|
| 662 | - * @param array $data An associate array of row data to update. |
|
| 663 | - * @param string $where_key The column name to match on. |
|
| 664 | - * @return bool |
|
| 665 | - */ |
|
| 666 | - public function update_batch($data, $where_key) |
|
| 667 | - { |
|
| 668 | - foreach ($data as &$row) { |
|
| 669 | - $row = $this->trigger('before_update', ['method' => 'update_batch', 'fields' => $row] ); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - $result = $this->db->update_batch($this->table_name, $data, $where_key); |
|
| 673 | - |
|
| 674 | - foreach ($data as &$row) { |
|
| 675 | - $this->trigger('after_update', ['fields' => $data, 'result' => $result, 'method' => 'update_batch']); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - return $result; |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - //-------------------------------------------------------------------- |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Updates many records by an array of ids. |
|
| 685 | - * |
|
| 686 | - * While update_batch() allows modifying multiple, arbitrary rows of data |
|
| 687 | - * on each row, update_many() sets the same values for each row. |
|
| 688 | - * |
|
| 689 | - * $ids = array(1, 2, 3, 5, 12); |
|
| 690 | - * $data = array( |
|
| 691 | - * 'deleted_by' => 1 |
|
| 692 | - * ); |
|
| 693 | - * |
|
| 694 | - * $this->model->update_many($ids, $data); |
|
| 695 | - * |
|
| 696 | - * @param array $ids An array of primary_key values to update. |
|
| 697 | - * @param array $data An array of value pairs to modify in each row. |
|
| 698 | - * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 699 | - * @return bool |
|
| 700 | - */ |
|
| 701 | - public function update_many($ids, $data, $skip_validation = null) |
|
| 702 | - { |
|
| 703 | - if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 704 | - |
|
| 705 | - $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 706 | - |
|
| 707 | - if ($skip_validation === FALSE) { |
|
| 708 | - $data = $this->validate($data, 'update', $skip_validation); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - $data = $this->trigger('before_update', ['ids' => $ids, 'method' => 'update_many', 'fields' => $data]); |
|
| 712 | - |
|
| 713 | - // Will be false if it didn't validate. |
|
| 714 | - if ($data !== FALSE) { |
|
| 715 | - $this->db->where_in($this->primary_key, $ids); |
|
| 716 | - $this->db->set($data); |
|
| 717 | - $result = $this->db->update($this->table_name); |
|
| 718 | - |
|
| 719 | - $this->trigger('after_update', ['ids' => $ids, 'fields' => $data, 'result'=>$result, 'method' => 'update_many']); |
|
| 720 | - |
|
| 721 | - return $result; |
|
| 722 | - } else { |
|
| 723 | - return FALSE; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - //-------------------------------------------------------------------- |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Update records in the database using a standard WHERE clause. |
|
| 731 | - * |
|
| 732 | - * Your last parameter should be the $data array with values to update |
|
| 733 | - * on the rows. Any additional parameters should be provided to make up |
|
| 734 | - * a typical WHERE clause. This could be a single array, or a column name |
|
| 735 | - * and a value. |
|
| 736 | - * |
|
| 737 | - * $data = array('deleted_by' => 1); |
|
| 738 | - * $wheres = array('user_id' => 15); |
|
| 739 | - * |
|
| 740 | - * $this->update_by($wheres, $data); |
|
| 741 | - * $this->update_by('user_id', 15, $data); |
|
| 742 | - * |
|
| 743 | - * @param array $data An array of data pairs to update |
|
| 744 | - * @param one or more WHERE-acceptable entries. |
|
| 745 | - * @return bool |
|
| 746 | - */ |
|
| 747 | - public function update_by() |
|
| 748 | - { |
|
| 749 | - $args = func_get_args(); |
|
| 750 | - $data = array_pop($args); |
|
| 751 | - $this->_set_where($args); |
|
| 752 | - |
|
| 753 | - $data = $this->trigger('before_update', ['method' => 'update_by', 'fields' => $data]); |
|
| 754 | - |
|
| 755 | - // Will be false if it didn't validate. |
|
| 756 | - if ($this->validate($data) !== FALSE) { |
|
| 757 | - $this->db->set( $this->prep_data($data) ); |
|
| 758 | - $result = $this->db->update($this->table_name); |
|
| 759 | - |
|
| 760 | - $this->trigger('after_update', ['method' => 'update_by', 'fields' => $data, 'result' => $result] ); |
|
| 761 | - |
|
| 762 | - return $result; |
|
| 763 | - } else { |
|
| 764 | - return FALSE; |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - //-------------------------------------------------------------------- |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * Updates all records and sets the value pairs passed in the array. |
|
| 772 | - * |
|
| 773 | - * @param array $data An array of value pairs with the data to change. |
|
| 774 | - * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 775 | - * @return bool |
|
| 776 | - */ |
|
| 777 | - public function update_all($data, $skip_validation = FALSE) |
|
| 778 | - { |
|
| 779 | - $data = $this->trigger('before_update', ['method' => 'update_all', 'fields' => $data] ); |
|
| 780 | - |
|
| 781 | - $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 782 | - |
|
| 783 | - if ($skip_validation === FALSE) { |
|
| 784 | - $data = $this->validate($data); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - // Will be false if it didn't validate. |
|
| 788 | - if ($data !== FALSE) { |
|
| 789 | - $this->db->set( $this->prep_data($data) ); |
|
| 790 | - $result = $this->db->update($this->table_name); |
|
| 791 | - |
|
| 792 | - $this->trigger('after_update', ['method' => 'update_all', 'fields' => $data, 'result' => $result] ); |
|
| 793 | - |
|
| 794 | - return $result; |
|
| 795 | - } else { |
|
| 796 | - return FALSE; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - //-------------------------------------------------------------------- |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Increments the value of field for a given row, selected by the |
|
| 804 | - * primary key for the table. |
|
| 805 | - * |
|
| 806 | - * @param $id |
|
| 807 | - * @param $field |
|
| 808 | - * @param int $value |
|
| 809 | - * @return mixed |
|
| 810 | - */ |
|
| 811 | - public function increment($id, $field, $value=1) |
|
| 812 | - { |
|
| 813 | - $value = (int)abs($value); |
|
| 814 | - |
|
| 815 | - $this->db->where($this->primary_key, $id); |
|
| 816 | - $this->db->set($field, "{$field}+{$value}", false); |
|
| 817 | - |
|
| 818 | - return $this->db->update($this->table_name); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - //-------------------------------------------------------------------- |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Increments the value of field for a given row, selected by the |
|
| 825 | - * primary key for the table. |
|
| 826 | - * |
|
| 827 | - * @param $id |
|
| 828 | - * @param $field |
|
| 829 | - * @param int $value |
|
| 830 | - * @return mixed |
|
| 831 | - */ |
|
| 832 | - public function decrement($id, $field, $value=1) |
|
| 833 | - { |
|
| 834 | - $value = (int)abs($value); |
|
| 835 | - |
|
| 836 | - $this->db->where($this->primary_key, $id); |
|
| 837 | - $this->db->set($field, "{$field}-{$value}", false); |
|
| 838 | - |
|
| 839 | - return $this->db->update($this->table_name); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - //-------------------------------------------------------------------- |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * Deletes a row by it's primary key value. |
|
| 846 | - * |
|
| 847 | - * @param mixed $id The primary key value of the row to delete. |
|
| 848 | - * @return bool |
|
| 849 | - */ |
|
| 850 | - public function delete($id) |
|
| 851 | - { |
|
| 852 | - $this->trigger('before_delete', ['id' => $id, 'method' => 'delete'] ); |
|
| 853 | - |
|
| 854 | - $this->db->where($this->primary_key, $id); |
|
| 629 | + $this->db->where($this->primary_key, $id); |
|
| 630 | + $this->db->set( $this->prep_data($data) ); |
|
| 631 | + $result = $this->db->update($this->table_name); |
|
| 632 | + |
|
| 633 | + $this->trigger('after_update', ['id' => $id, 'fields' => $data, 'result' => $result, 'method' => 'update']); |
|
| 634 | + |
|
| 635 | + return $result; |
|
| 636 | + } else { |
|
| 637 | + return FALSE; |
|
| 638 | + } |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + //-------------------------------------------------------------------- |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * Updates multiple records in the database at once. |
|
| 645 | + * |
|
| 646 | + * $data = array( |
|
| 647 | + * array( |
|
| 648 | + * 'title' => 'My title', |
|
| 649 | + * 'body' => 'body 1' |
|
| 650 | + * ), |
|
| 651 | + * array( |
|
| 652 | + * 'title' => 'Another Title', |
|
| 653 | + * 'body' => 'body 2' |
|
| 654 | + * ) |
|
| 655 | + * ); |
|
| 656 | + * |
|
| 657 | + * The $where_key should be the name of the column to match the record on. |
|
| 658 | + * If $where_key == 'title', then each record would be matched on that |
|
| 659 | + * 'title' value of the array. This does mean that the array key needs |
|
| 660 | + * to be provided with each row's data. |
|
| 661 | + * |
|
| 662 | + * @param array $data An associate array of row data to update. |
|
| 663 | + * @param string $where_key The column name to match on. |
|
| 664 | + * @return bool |
|
| 665 | + */ |
|
| 666 | + public function update_batch($data, $where_key) |
|
| 667 | + { |
|
| 668 | + foreach ($data as &$row) { |
|
| 669 | + $row = $this->trigger('before_update', ['method' => 'update_batch', 'fields' => $row] ); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + $result = $this->db->update_batch($this->table_name, $data, $where_key); |
|
| 673 | + |
|
| 674 | + foreach ($data as &$row) { |
|
| 675 | + $this->trigger('after_update', ['fields' => $data, 'result' => $result, 'method' => 'update_batch']); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + return $result; |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + //-------------------------------------------------------------------- |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Updates many records by an array of ids. |
|
| 685 | + * |
|
| 686 | + * While update_batch() allows modifying multiple, arbitrary rows of data |
|
| 687 | + * on each row, update_many() sets the same values for each row. |
|
| 688 | + * |
|
| 689 | + * $ids = array(1, 2, 3, 5, 12); |
|
| 690 | + * $data = array( |
|
| 691 | + * 'deleted_by' => 1 |
|
| 692 | + * ); |
|
| 693 | + * |
|
| 694 | + * $this->model->update_many($ids, $data); |
|
| 695 | + * |
|
| 696 | + * @param array $ids An array of primary_key values to update. |
|
| 697 | + * @param array $data An array of value pairs to modify in each row. |
|
| 698 | + * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 699 | + * @return bool |
|
| 700 | + */ |
|
| 701 | + public function update_many($ids, $data, $skip_validation = null) |
|
| 702 | + { |
|
| 703 | + if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 704 | + |
|
| 705 | + $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 706 | + |
|
| 707 | + if ($skip_validation === FALSE) { |
|
| 708 | + $data = $this->validate($data, 'update', $skip_validation); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + $data = $this->trigger('before_update', ['ids' => $ids, 'method' => 'update_many', 'fields' => $data]); |
|
| 712 | + |
|
| 713 | + // Will be false if it didn't validate. |
|
| 714 | + if ($data !== FALSE) { |
|
| 715 | + $this->db->where_in($this->primary_key, $ids); |
|
| 716 | + $this->db->set($data); |
|
| 717 | + $result = $this->db->update($this->table_name); |
|
| 718 | + |
|
| 719 | + $this->trigger('after_update', ['ids' => $ids, 'fields' => $data, 'result'=>$result, 'method' => 'update_many']); |
|
| 720 | + |
|
| 721 | + return $result; |
|
| 722 | + } else { |
|
| 723 | + return FALSE; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + //-------------------------------------------------------------------- |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * Update records in the database using a standard WHERE clause. |
|
| 731 | + * |
|
| 732 | + * Your last parameter should be the $data array with values to update |
|
| 733 | + * on the rows. Any additional parameters should be provided to make up |
|
| 734 | + * a typical WHERE clause. This could be a single array, or a column name |
|
| 735 | + * and a value. |
|
| 736 | + * |
|
| 737 | + * $data = array('deleted_by' => 1); |
|
| 738 | + * $wheres = array('user_id' => 15); |
|
| 739 | + * |
|
| 740 | + * $this->update_by($wheres, $data); |
|
| 741 | + * $this->update_by('user_id', 15, $data); |
|
| 742 | + * |
|
| 743 | + * @param array $data An array of data pairs to update |
|
| 744 | + * @param one or more WHERE-acceptable entries. |
|
| 745 | + * @return bool |
|
| 746 | + */ |
|
| 747 | + public function update_by() |
|
| 748 | + { |
|
| 749 | + $args = func_get_args(); |
|
| 750 | + $data = array_pop($args); |
|
| 751 | + $this->_set_where($args); |
|
| 752 | + |
|
| 753 | + $data = $this->trigger('before_update', ['method' => 'update_by', 'fields' => $data]); |
|
| 754 | + |
|
| 755 | + // Will be false if it didn't validate. |
|
| 756 | + if ($this->validate($data) !== FALSE) { |
|
| 757 | + $this->db->set( $this->prep_data($data) ); |
|
| 758 | + $result = $this->db->update($this->table_name); |
|
| 759 | + |
|
| 760 | + $this->trigger('after_update', ['method' => 'update_by', 'fields' => $data, 'result' => $result] ); |
|
| 761 | + |
|
| 762 | + return $result; |
|
| 763 | + } else { |
|
| 764 | + return FALSE; |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + //-------------------------------------------------------------------- |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * Updates all records and sets the value pairs passed in the array. |
|
| 772 | + * |
|
| 773 | + * @param array $data An array of value pairs with the data to change. |
|
| 774 | + * @param array $skip_validation If TRUE, will skip validation of data for this call only. |
|
| 775 | + * @return bool |
|
| 776 | + */ |
|
| 777 | + public function update_all($data, $skip_validation = FALSE) |
|
| 778 | + { |
|
| 779 | + $data = $this->trigger('before_update', ['method' => 'update_all', 'fields' => $data] ); |
|
| 780 | + |
|
| 781 | + $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 782 | + |
|
| 783 | + if ($skip_validation === FALSE) { |
|
| 784 | + $data = $this->validate($data); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + // Will be false if it didn't validate. |
|
| 788 | + if ($data !== FALSE) { |
|
| 789 | + $this->db->set( $this->prep_data($data) ); |
|
| 790 | + $result = $this->db->update($this->table_name); |
|
| 791 | + |
|
| 792 | + $this->trigger('after_update', ['method' => 'update_all', 'fields' => $data, 'result' => $result] ); |
|
| 793 | + |
|
| 794 | + return $result; |
|
| 795 | + } else { |
|
| 796 | + return FALSE; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + //-------------------------------------------------------------------- |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Increments the value of field for a given row, selected by the |
|
| 804 | + * primary key for the table. |
|
| 805 | + * |
|
| 806 | + * @param $id |
|
| 807 | + * @param $field |
|
| 808 | + * @param int $value |
|
| 809 | + * @return mixed |
|
| 810 | + */ |
|
| 811 | + public function increment($id, $field, $value=1) |
|
| 812 | + { |
|
| 813 | + $value = (int)abs($value); |
|
| 814 | + |
|
| 815 | + $this->db->where($this->primary_key, $id); |
|
| 816 | + $this->db->set($field, "{$field}+{$value}", false); |
|
| 817 | + |
|
| 818 | + return $this->db->update($this->table_name); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + //-------------------------------------------------------------------- |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Increments the value of field for a given row, selected by the |
|
| 825 | + * primary key for the table. |
|
| 826 | + * |
|
| 827 | + * @param $id |
|
| 828 | + * @param $field |
|
| 829 | + * @param int $value |
|
| 830 | + * @return mixed |
|
| 831 | + */ |
|
| 832 | + public function decrement($id, $field, $value=1) |
|
| 833 | + { |
|
| 834 | + $value = (int)abs($value); |
|
| 835 | + |
|
| 836 | + $this->db->where($this->primary_key, $id); |
|
| 837 | + $this->db->set($field, "{$field}-{$value}", false); |
|
| 838 | + |
|
| 839 | + return $this->db->update($this->table_name); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + //-------------------------------------------------------------------- |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * Deletes a row by it's primary key value. |
|
| 846 | + * |
|
| 847 | + * @param mixed $id The primary key value of the row to delete. |
|
| 848 | + * @return bool |
|
| 849 | + */ |
|
| 850 | + public function delete($id) |
|
| 851 | + { |
|
| 852 | + $this->trigger('before_delete', ['id' => $id, 'method' => 'delete'] ); |
|
| 853 | + |
|
| 854 | + $this->db->where($this->primary_key, $id); |
|
| 855 | + |
|
| 856 | + if ($this->soft_deletes) { |
|
| 857 | + $sets = $this->log_user && is_object($this->authenticate) |
|
| 858 | + ? array($this->soft_delete_key => 1, $this->deleted_by_field => $this->authenticate->id()) |
|
| 859 | + : array($this->soft_delete_key => 1); |
|
| 860 | + |
|
| 861 | + $result = $this->db->update($this->table_name, $sets); |
|
| 862 | + } // Hard Delete |
|
| 863 | + else { |
|
| 864 | + $result = $this->db->delete($this->table_name); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + $this->trigger('after_delete', ['id' => $id, 'method' => 'delete', 'result' => $result] ); |
|
| 868 | + |
|
| 869 | + return $result; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + //-------------------------------------------------------------------- |
|
| 873 | + |
|
| 874 | + public function delete_by() |
|
| 875 | + { |
|
| 876 | + $where = func_get_args(); |
|
| 877 | + $this->_set_where($where); |
|
| 878 | + |
|
| 879 | + $where = $this->trigger('before_delete', ['method' => 'delete_by', 'fields' => $where]); |
|
| 880 | + |
|
| 881 | + if ($this->soft_deletes) { |
|
| 882 | + $sets = $this->log_user && is_object($this->authenticate) |
|
| 883 | + ? array($this->soft_delete_key => 1, $this->deleted_by_field => $this->authenticate->id()) |
|
| 884 | + : array($this->soft_delete_key => 1); |
|
| 885 | + |
|
| 886 | + $result = $this->db->update($this->table_name, $sets); |
|
| 887 | + } else { |
|
| 888 | + $result = $this->db->delete($this->table_name); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + $this->trigger('after_delete', ['method' => 'delete_by', 'fields' => $where, 'result' => $result] ); |
|
| 892 | + |
|
| 893 | + return $result; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + //-------------------------------------------------------------------- |
|
| 897 | + |
|
| 898 | + public function delete_many($ids) |
|
| 899 | + { |
|
| 900 | + if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 901 | + |
|
| 902 | + $ids = $this->trigger('before_delete', ['ids' => $ids, 'method' => 'delete_many'] ); |
|
| 903 | + |
|
| 904 | + $this->db->where_in($this->primary_key, $ids); |
|
| 905 | + |
|
| 906 | + if ($this->soft_deletes) { |
|
| 907 | + $sets = $this->log_user && is_object($this->authenticate) |
|
| 908 | + ? array($this->soft_delete_key => 1, $this->deleted_by_field => $this->authenticate->id()) |
|
| 909 | + : array($this->soft_delete_key => 1); |
|
| 910 | + |
|
| 911 | + $result = $this->db->update($this->table_name, $sets); |
|
| 912 | + } else { |
|
| 913 | + $result = $this->db->delete($this->table_name); |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + $this->trigger('after_delete', ['ids' => $ids, 'method' => 'delete_many', 'result' => $result]); |
|
| 855 | 917 | |
| 856 | - if ($this->soft_deletes) { |
|
| 857 | - $sets = $this->log_user && is_object($this->authenticate) |
|
| 858 | - ? array($this->soft_delete_key => 1, $this->deleted_by_field => $this->authenticate->id()) |
|
| 859 | - : array($this->soft_delete_key => 1); |
|
| 918 | + return $result; |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + //-------------------------------------------------------------------- |
|
| 922 | + |
|
| 923 | + //-------------------------------------------------------------------- |
|
| 924 | + // Scope Methods |
|
| 925 | + //-------------------------------------------------------------------- |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * Sets the value of the soft deletes flag. |
|
| 929 | + * |
|
| 930 | + * @param boolean $val If TRUE, should perform a soft delete. If FALSE, a hard delete. |
|
| 931 | + */ |
|
| 932 | + public function soft_delete($val = TRUE) |
|
| 933 | + { |
|
| 934 | + $this->soft_deletes = $val; |
|
| 860 | 935 | |
| 861 | - $result = $this->db->update($this->table_name, $sets); |
|
| 862 | - } // Hard Delete |
|
| 863 | - else { |
|
| 864 | - $result = $this->db->delete($this->table_name); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - $this->trigger('after_delete', ['id' => $id, 'method' => 'delete', 'result' => $result] ); |
|
| 868 | - |
|
| 869 | - return $result; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - //-------------------------------------------------------------------- |
|
| 873 | - |
|
| 874 | - public function delete_by() |
|
| 875 | - { |
|
| 876 | - $where = func_get_args(); |
|
| 877 | - $this->_set_where($where); |
|
| 878 | - |
|
| 879 | - $where = $this->trigger('before_delete', ['method' => 'delete_by', 'fields' => $where]); |
|
| 880 | - |
|
| 881 | - if ($this->soft_deletes) { |
|
| 882 | - $sets = $this->log_user && is_object($this->authenticate) |
|
| 883 | - ? array($this->soft_delete_key => 1, $this->deleted_by_field => $this->authenticate->id()) |
|
| 884 | - : array($this->soft_delete_key => 1); |
|
| 885 | - |
|
| 886 | - $result = $this->db->update($this->table_name, $sets); |
|
| 887 | - } else { |
|
| 888 | - $result = $this->db->delete($this->table_name); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - $this->trigger('after_delete', ['method' => 'delete_by', 'fields' => $where, 'result' => $result] ); |
|
| 892 | - |
|
| 893 | - return $result; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - //-------------------------------------------------------------------- |
|
| 897 | - |
|
| 898 | - public function delete_many($ids) |
|
| 899 | - { |
|
| 900 | - if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 901 | - |
|
| 902 | - $ids = $this->trigger('before_delete', ['ids' => $ids, 'method' => 'delete_many'] ); |
|
| 903 | - |
|
| 904 | - $this->db->where_in($this->primary_key, $ids); |
|
| 905 | - |
|
| 906 | - if ($this->soft_deletes) { |
|
| 907 | - $sets = $this->log_user && is_object($this->authenticate) |
|
| 908 | - ? array($this->soft_delete_key => 1, $this->deleted_by_field => $this->authenticate->id()) |
|
| 909 | - : array($this->soft_delete_key => 1); |
|
| 910 | - |
|
| 911 | - $result = $this->db->update($this->table_name, $sets); |
|
| 912 | - } else { |
|
| 913 | - $result = $this->db->delete($this->table_name); |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - $this->trigger('after_delete', ['ids' => $ids, 'method' => 'delete_many', 'result' => $result]); |
|
| 917 | - |
|
| 918 | - return $result; |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - //-------------------------------------------------------------------- |
|
| 922 | - |
|
| 923 | - //-------------------------------------------------------------------- |
|
| 924 | - // Scope Methods |
|
| 925 | - //-------------------------------------------------------------------- |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * Sets the value of the soft deletes flag. |
|
| 929 | - * |
|
| 930 | - * @param boolean $val If TRUE, should perform a soft delete. If FALSE, a hard delete. |
|
| 931 | - */ |
|
| 932 | - public function soft_delete($val = TRUE) |
|
| 933 | - { |
|
| 934 | - $this->soft_deletes = $val; |
|
| 935 | - |
|
| 936 | - return $this; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - //-------------------------------------------------------------------- |
|
| 940 | - |
|
| 941 | - /** |
|
| 942 | - * Temporarily sets our return type to an array. |
|
| 943 | - */ |
|
| 944 | - public function as_array() |
|
| 945 | - { |
|
| 946 | - $this->temp_return_type = 'array'; |
|
| 947 | - |
|
| 948 | - return $this; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - //-------------------------------------------------------------------- |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Temporarily sets our return type to an object. |
|
| 955 | - * |
|
| 956 | - * If $class is provided, the rows will be returned as objects that |
|
| 957 | - * are instances of that class. $class MUST be an fully qualified |
|
| 958 | - * class name, meaning that it must include the namespace, if applicable. |
|
| 959 | - * |
|
| 960 | - * @param string $class |
|
| 961 | - * @return $this |
|
| 962 | - */ |
|
| 963 | - public function as_object($class=null) |
|
| 964 | - { |
|
| 965 | - $this->temp_return_type = ! empty($class) ? $class : 'object'; |
|
| 966 | - |
|
| 967 | - return $this; |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - //-------------------------------------------------------------------- |
|
| 971 | - |
|
| 972 | - /** |
|
| 973 | - * Also fetches deleted items for this request only. |
|
| 974 | - */ |
|
| 975 | - public function with_deleted() |
|
| 976 | - { |
|
| 977 | - $this->temp_with_deleted = TRUE; |
|
| 978 | - |
|
| 979 | - return $this; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - //-------------------------------------------------------------------- |
|
| 983 | - |
|
| 984 | - /** |
|
| 985 | - * Returns whether the current setup will return |
|
| 986 | - * soft deleted rows. |
|
| 987 | - * |
|
| 988 | - * @return bool |
|
| 989 | - */ |
|
| 990 | - public function get_with_deleted() |
|
| 991 | - { |
|
| 992 | - return $this->temp_with_deleted; |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - //-------------------------------------------------------------------- |
|
| 996 | - |
|
| 997 | - |
|
| 998 | - /** |
|
| 999 | - * Sets the $skip_validation parameter. |
|
| 1000 | - * |
|
| 1001 | - * @param bool $skip |
|
| 1002 | - * @return $this |
|
| 1003 | - */ |
|
| 1004 | - public function skip_validation($skip = true) |
|
| 1005 | - { |
|
| 1006 | - $this->skip_validation = $skip; |
|
| 1007 | - |
|
| 1008 | - return $this; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - //-------------------------------------------------------------------- |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - //-------------------------------------------------------------------- |
|
| 1015 | - // Utility Methods |
|
| 1016 | - //-------------------------------------------------------------------- |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * Counts number of rows modified by an arbitrary WHERE call. |
|
| 1020 | - * @return INT |
|
| 1021 | - */ |
|
| 1022 | - public function count_by() |
|
| 1023 | - { |
|
| 1024 | - $where = func_get_args(); |
|
| 1025 | - $this->_set_where($where); |
|
| 1026 | - |
|
| 1027 | - return $this->db->count_all_results($this->table_name); |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - //-------------------------------------------------------------------- |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Counts total number of records, disregarding any previous conditions. |
|
| 1034 | - * |
|
| 1035 | - * @return int |
|
| 1036 | - */ |
|
| 1037 | - public function count_all() |
|
| 1038 | - { |
|
| 1039 | - return $this->db->count_all($this->table_name); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - //-------------------------------------------------------------------- |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * Getter for the table name. |
|
| 1046 | - * |
|
| 1047 | - * @return string The name of the table used by this class. |
|
| 1048 | - */ |
|
| 1049 | - public function table() |
|
| 1050 | - { |
|
| 1051 | - return $this->table_name; |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - //-------------------------------------------------------------------- |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * Set the return_insert_id value. |
|
| 1058 | - * |
|
| 1059 | - * @param boolean $return If TRUE, insert will return the insert_id. |
|
| 1060 | - */ |
|
| 1061 | - public function return_insert_id($return = true) |
|
| 1062 | - { |
|
| 1063 | - $this->return_insert_id = (bool)$return; |
|
| 1064 | - |
|
| 1065 | - return $this; |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - //-------------------------------------------------------------------- |
|
| 1069 | - |
|
| 1070 | - /** |
|
| 1071 | - * A convenience method to return only a single field of the specified row. |
|
| 1072 | - * |
|
| 1073 | - * @param mixed $id The primary_key value to match against. |
|
| 1074 | - * @param string $field The field to search for. |
|
| 1075 | - * |
|
| 1076 | - * @return bool|mixed The value of the field. |
|
| 1077 | - */ |
|
| 1078 | - public function get_field($id = NULL, $field = '') |
|
| 1079 | - { |
|
| 1080 | - $this->db->select($field); |
|
| 1081 | - $this->db->where($this->primary_key, $id); |
|
| 1082 | - $query = $this->db->get($this->table_name); |
|
| 1083 | - |
|
| 1084 | - if ($query && $query->num_rows() > 0) { |
|
| 1085 | - return $query->row()->$field; |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - return FALSE; |
|
| 1089 | - |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - //--------------------------------------------------------------- |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * Checks whether a field/value pair exists within the table. |
|
| 1096 | - * |
|
| 1097 | - * @param string $field The field to search for. |
|
| 1098 | - * @param string $value The value to match $field against. |
|
| 1099 | - * |
|
| 1100 | - * @return bool TRUE/FALSE |
|
| 1101 | - */ |
|
| 1102 | - public function is_unique($field, $value) |
|
| 1103 | - { |
|
| 1104 | - $this->db->where($field, $value); |
|
| 1105 | - $query = $this->db->get($this->table_name); |
|
| 1106 | - |
|
| 1107 | - if ($query && $query->num_rows() == 0) { |
|
| 1108 | - return TRUE; |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - return FALSE; |
|
| 1112 | - |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - //--------------------------------------------------------------- |
|
| 1116 | - |
|
| 1117 | - /** |
|
| 1118 | - * Adds a field to the protected_attributes array. |
|
| 1119 | - * |
|
| 1120 | - * @param $field |
|
| 1121 | - * |
|
| 1122 | - * @return mixed |
|
| 1123 | - */ |
|
| 1124 | - public function protect($field) |
|
| 1125 | - { |
|
| 1126 | - $this->protected_attributes[] = $field; |
|
| 1127 | - |
|
| 1128 | - return $this; |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - //-------------------------------------------------------------------- |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * Get the field names for this model's table. |
|
| 1135 | - * |
|
| 1136 | - * Returns the model's database fields stored in $this->fields |
|
| 1137 | - * if set, else it tries to retrieve the field list from |
|
| 1138 | - * $this->db->list_fields($this->table_name); |
|
| 1139 | - * |
|
| 1140 | - * @return array Returns the database fields for this model |
|
| 1141 | - */ |
|
| 1142 | - public function get_fields() |
|
| 1143 | - { |
|
| 1144 | - if (empty($this->fields)) { |
|
| 1145 | - $this->fields = $this->db->list_fields($this->table_name); |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - return $this->fields; |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - //-------------------------------------------------------------------- |
|
| 1152 | - |
|
| 1153 | - /** |
|
| 1154 | - * Extracts the model's fields (except the key and those handled by |
|
| 1155 | - * Observers) from the $post_data and returns an array of name => value pairs |
|
| 1156 | - * |
|
| 1157 | - * @param Array $post_data The post data, usually $this->input->post() when called from the controller |
|
| 1158 | - * |
|
| 1159 | - * @return Array An array of name => value pairs containing the data for the model's fields |
|
| 1160 | - */ |
|
| 1161 | - public function prep_data($post_data) |
|
| 1162 | - { |
|
| 1163 | - $data = array(); |
|
| 1164 | - $skippedFields = array(); |
|
| 1165 | - |
|
| 1166 | - if (empty($post_data)) |
|
| 1167 | - { |
|
| 1168 | - return []; |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - // Though the model doesn't support multiple keys well, $this->key |
|
| 1172 | - // could be an array or a string... |
|
| 1173 | - $skippedFields = array_merge($skippedFields, (array)$this->primary_key); |
|
| 1174 | - |
|
| 1175 | - // Remove any protected attributes |
|
| 1176 | - $skippedFields = array_merge($skippedFields, $this->protected_attributes); |
|
| 1177 | - |
|
| 1178 | - $fields = $this->get_fields(); |
|
| 1179 | - |
|
| 1180 | - // If the field is the primary key, one of the created/modified/deleted |
|
| 1181 | - // fields, or has not been set in the $post_data, skip it |
|
| 1182 | - foreach ($post_data as $field => $value) { |
|
| 1183 | - if (in_array($field, $skippedFields) || |
|
| 1184 | - ! in_array($field, $fields)) |
|
| 1185 | - { |
|
| 1186 | - continue; |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - $data[$field] = $value; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - return $data; |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - //-------------------------------------------------------------------- |
|
| 1196 | - |
|
| 1197 | - /** |
|
| 1198 | - * Returns the last query string, if available. Simply a wrapper for |
|
| 1199 | - * CodeIgniter's database method of the same name. |
|
| 1200 | - * |
|
| 1201 | - * @return string |
|
| 1202 | - */ |
|
| 1203 | - public function last_query () |
|
| 1204 | - { |
|
| 1205 | - return $this->db->last_query(); |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - //-------------------------------------------------------------------- |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * Returns the elapsed time for the last query that was executed, if |
|
| 1212 | - * available, or NULL if not available, like if debug mode is off. |
|
| 1213 | - * |
|
| 1214 | - * @return mixed |
|
| 1215 | - */ |
|
| 1216 | - public function last_query_time () |
|
| 1217 | - { |
|
| 1218 | - $times = $this->db->query_times; |
|
| 1219 | - |
|
| 1220 | - if (! is_array($this->db->query_times) || ! count($this->db->query_times)) |
|
| 1221 | - { |
|
| 1222 | - return null; |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - return end($times); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - //-------------------------------------------------------------------- |
|
| 1229 | - |
|
| 1230 | - //-------------------------------------------------------------------- |
|
| 1231 | - // Observers |
|
| 1232 | - //-------------------------------------------------------------------- |
|
| 1233 | - |
|
| 1234 | - /** |
|
| 1235 | - * Sets the created on date for the object based on the |
|
| 1236 | - * current date/time and date_format. Will not overwrite existing. |
|
| 1237 | - * |
|
| 1238 | - * @param array $row The array of data to be inserted |
|
| 1239 | - * |
|
| 1240 | - * @return array |
|
| 1241 | - */ |
|
| 1242 | - public function created_on($row) |
|
| 1243 | - { |
|
| 1244 | - if (empty($row['fields'])) |
|
| 1245 | - { |
|
| 1246 | - return null; |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - $row = $row['fields']; |
|
| 1250 | - |
|
| 1251 | - // Created_on |
|
| 1252 | - if (! array_key_exists($this->created_field, $row)) |
|
| 1253 | - { |
|
| 1254 | - $row[$this->created_field] = $this->set_date(); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - // Created by |
|
| 1258 | - if ($this->log_user && ! array_key_exists($this->created_by_field, $row) && is_object($this->authenticate)) |
|
| 1259 | - { |
|
| 1260 | - // If you're here because of an error with $this->authenticate |
|
| 1261 | - // not being available, it's likely due to you not using |
|
| 1262 | - // the AuthTrait and/or setting log_user after model is instantiated. |
|
| 1263 | - $row[$this->created_by_field] = (int)$this->authenticate->id(); |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - return $row; |
|
| 1267 | - } // end created_on() |
|
| 1268 | - |
|
| 1269 | - //-------------------------------------------------------------------- |
|
| 1270 | - |
|
| 1271 | - /** |
|
| 1272 | - * Sets the modified_on date for the object based on the |
|
| 1273 | - * current date/time and date_format. Will not overwrite existing. |
|
| 1274 | - * |
|
| 1275 | - * @param array $row The array of data to be inserted |
|
| 1276 | - * |
|
| 1277 | - * @return array |
|
| 1278 | - */ |
|
| 1279 | - public function modified_on($row) |
|
| 1280 | - { |
|
| 1281 | - if (empty($row['fields'])) |
|
| 1282 | - { |
|
| 1283 | - return null; |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - $row = $row['fields']; |
|
| 1287 | - |
|
| 1288 | - if (is_array($row) && ! array_key_exists($this->modified_field, $row)) |
|
| 1289 | - { |
|
| 1290 | - $row[$this->modified_field] = $this->set_date(); |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - // Modified by |
|
| 1294 | - if ($this->log_user && ! array_key_exists($this->modified_by_field, $row) && is_object($this->authenticate)) |
|
| 1295 | - { |
|
| 1296 | - // If you're here because of an error with $this->authenticate |
|
| 1297 | - // not being available, it's likely due to you not using |
|
| 1298 | - // the AuthTrait and/or setting log_user after model is instantiated. |
|
| 1299 | - $row[$this->modified_by_field] = $this->authenticate->id(); |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - return $row; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - //-------------------------------------------------------------------- |
|
| 1306 | - |
|
| 1307 | - //-------------------------------------------------------------------- |
|
| 1308 | - // Internal Methods |
|
| 1309 | - //-------------------------------------------------------------------- |
|
| 1310 | - |
|
| 1311 | - /** |
|
| 1312 | - * Set WHERE parameters |
|
| 1313 | - */ |
|
| 1314 | - protected function _set_where($params) |
|
| 1315 | - { |
|
| 1316 | - if (count($params) == 1) { |
|
| 1317 | - $this->db->where($params[0]); |
|
| 1318 | - } else { |
|
| 1319 | - $this->db->where($params[0], $params[1]); |
|
| 1320 | - } |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - //-------------------------------------------------------------------- |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * Triggers a model-specific event and call each of it's observers. |
|
| 1327 | - * |
|
| 1328 | - * @param string $event The name of the event to trigger |
|
| 1329 | - * @param mixed $data The data to be passed to the callback functions. |
|
| 1330 | - * |
|
| 1331 | - * @return mixed |
|
| 1332 | - */ |
|
| 1333 | - public function trigger($event, $data = false) |
|
| 1334 | - { |
|
| 1335 | - if (! isset($this->$event) || ! is_array($this->$event)) |
|
| 1336 | - { |
|
| 1337 | - if (isset($data['fields'])) |
|
| 1338 | - { |
|
| 1339 | - return $data['fields']; |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - return $data; |
|
| 1343 | - } |
|
| 1344 | - |
|
| 1345 | - foreach ($this->$event as $method) |
|
| 1346 | - { |
|
| 1347 | - if (strpos($method, '(')) |
|
| 1348 | - { |
|
| 1349 | - preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches); |
|
| 1350 | - $this->callback_parameters = explode(',', $matches[3]); |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - $data = call_user_func_array(array($this, $method), array($data)); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // In case no method called or method returned |
|
| 1357 | - // the entire data array, we typically just need the $fields |
|
| 1358 | - if (isset($data['fields'])) |
|
| 1359 | - { |
|
| 1360 | - return $data['fields']; |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - // A few methods might need to return 'ids' |
|
| 1364 | - if (isset($data['ids'])) |
|
| 1365 | - { |
|
| 1366 | - return $data['ids']; |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - return $data; |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - //-------------------------------------------------------------------- |
|
| 1373 | - |
|
| 1374 | - /** |
|
| 1375 | - * Validates the data passed into it based upon the form_validation rules |
|
| 1376 | - * setup in the $this->validate property. |
|
| 1377 | - * |
|
| 1378 | - * If $type == 'insert', any additional rules in the class var $insert_validate_rules |
|
| 1379 | - * for that field will be added to the rules. |
|
| 1380 | - * |
|
| 1381 | - * @param array $data An array of validation rules |
|
| 1382 | - * @param string $type Either 'update' or 'insert'. |
|
| 1383 | - * @return array/bool The original data or FALSE |
|
| 1384 | - */ |
|
| 1385 | - public function validate($data, $type = 'update', $skip_validation = null) |
|
| 1386 | - { |
|
| 1387 | - $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 1388 | - |
|
| 1389 | - if ($skip_validation) { |
|
| 1390 | - return $data; |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - // We need the database to be loaded up at this point in case |
|
| 1394 | - // we want to use callbacks that hit the database. |
|
| 1395 | - if (empty($this->db)) |
|
| 1396 | - { |
|
| 1397 | - $this->load->database(); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - if (!empty($this->validation_rules)) { |
|
| 1401 | - $this->form_validation->set_data($data); |
|
| 1402 | - |
|
| 1403 | - if (is_array($this->validation_rules)) { |
|
| 1404 | - // Any insert additions? |
|
| 1405 | - if ($type == 'insert' |
|
| 1406 | - && !empty($this->insert_validate_rules) |
|
| 1407 | - && is_array($this->insert_validate_rules) |
|
| 1408 | - ) { |
|
| 1409 | - foreach ($this->validation_rules as &$row) { |
|
| 1410 | - if (isset($this->insert_validate_rules[$row['field']])) { |
|
| 1411 | - $row ['rules'] .= '|' . $this->insert_validate_rules[$row['field']]; |
|
| 1412 | - } |
|
| 1413 | - } |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - $this->form_validation->set_rules($this->validation_rules); |
|
| 1417 | - |
|
| 1418 | - if ($this->form_validation->run('', $this) === TRUE) { |
|
| 1419 | - return $data; |
|
| 1420 | - } else { |
|
| 1421 | - return FALSE; |
|
| 1422 | - } |
|
| 1423 | - } else { |
|
| 1424 | - if ($this->form_validation->run($this->validate, $this) === TRUE) { |
|
| 1425 | - return $data; |
|
| 1426 | - } else { |
|
| 1427 | - return FALSE; |
|
| 1428 | - } |
|
| 1429 | - } |
|
| 1430 | - } else { |
|
| 1431 | - return $data; |
|
| 1432 | - } |
|
| 1433 | - } |
|
| 1434 | - |
|
| 1435 | - //-------------------------------------------------------------------- |
|
| 1436 | - |
|
| 1437 | - /** |
|
| 1438 | - * Protect attributes by removing them from $row array. Useful for |
|
| 1439 | - * removing id, or submit buttons names if you simply throw your $_POST |
|
| 1440 | - * array at your model. :) |
|
| 1441 | - * |
|
| 1442 | - * @param object /array $row The value pair item to remove. |
|
| 1443 | - */ |
|
| 1444 | - public function protect_attributes($row) |
|
| 1445 | - { |
|
| 1446 | - foreach ($this->protected_attributes as $attr) { |
|
| 1447 | - if (is_object($row)) { |
|
| 1448 | - unset($row->$attr); |
|
| 1449 | - } else { |
|
| 1450 | - unset($row[$attr]); |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - return $row; |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - //-------------------------------------------------------------------- |
|
| 1458 | - |
|
| 1459 | - /** |
|
| 1460 | - * A utility function to allow child models to use the type of |
|
| 1461 | - * date/time format that they prefer. This is primarily used for |
|
| 1462 | - * setting created_on and modified_on values, but can be used by |
|
| 1463 | - * inheriting classes. |
|
| 1464 | - * |
|
| 1465 | - * The available time formats are: |
|
| 1466 | - * * 'int' - Stores the date as an integer timestamp. |
|
| 1467 | - * * 'datetime' - Stores the date and time in the SQL datetime format. |
|
| 1468 | - * * 'date' - Stores teh date (only) in the SQL date format. |
|
| 1469 | - * |
|
| 1470 | - * @param mixed $user_date An optional PHP timestamp to be converted. |
|
| 1471 | - * |
|
| 1472 | - * @access protected |
|
| 1473 | - * |
|
| 1474 | - * @return int|null|string The current/user time converted to the proper format. |
|
| 1475 | - */ |
|
| 1476 | - protected function set_date($user_date = NULL) |
|
| 1477 | - { |
|
| 1478 | - $curr_date = !empty($user_date) ? $user_date : time(); |
|
| 1479 | - |
|
| 1480 | - switch ($this->date_format) { |
|
| 1481 | - case 'int': |
|
| 1482 | - return $curr_date; |
|
| 1483 | - break; |
|
| 1484 | - case 'datetime': |
|
| 1485 | - return date('Y-m-d H:i:s', $curr_date); |
|
| 1486 | - break; |
|
| 1487 | - case 'date': |
|
| 1488 | - return date('Y-m-d', $curr_date); |
|
| 1489 | - break; |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - }//end set_date() |
|
| 1493 | - |
|
| 1494 | - //-------------------------------------------------------------------- |
|
| 1495 | - |
|
| 1496 | - /** |
|
| 1497 | - * Returns an array containing the 'code' and 'message' of the |
|
| 1498 | - * database's error, as provided by CI's database drivers. |
|
| 1499 | - * |
|
| 1500 | - * @return mixed |
|
| 1501 | - */ |
|
| 1502 | - public function error($db_array_only=false) |
|
| 1503 | - { |
|
| 1504 | - // Send any validation errors if we have any. |
|
| 1505 | - if (function_exists('validation_errors') && validation_errors() && ! $db_array_only) |
|
| 1506 | - { |
|
| 1507 | - return validation_errors(); |
|
| 1508 | - } |
|
| 1509 | - |
|
| 1510 | - // No validation errors? Return the db error. |
|
| 1511 | - $error = $this->db->error(); |
|
| 1512 | - |
|
| 1513 | - if ($db_array_only) |
|
| 1514 | - { |
|
| 1515 | - return $error; |
|
| 1516 | - } |
|
| 1517 | - |
|
| 1518 | - if (! empty($error['code'])) |
|
| 1519 | - { |
|
| 1520 | - return "Database Error {$error['code']}: {$error['message']}."; |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - // No errors found. |
|
| 1524 | - return ''; |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - //-------------------------------------------------------------------- |
|
| 1528 | - |
|
| 1529 | - //-------------------------------------------------------------------- |
|
| 1530 | - // Magic Methods |
|
| 1531 | - //-------------------------------------------------------------------- |
|
| 1532 | - |
|
| 1533 | - /** |
|
| 1534 | - * __get magic |
|
| 1535 | - * |
|
| 1536 | - * Allows models to access CI's loaded classes using the same |
|
| 1537 | - * syntax as controllers. |
|
| 1538 | - * |
|
| 1539 | - * This is the same as what CI's model uses, but we keep it |
|
| 1540 | - * here since that's the ONLY thing that CI's model does. |
|
| 1541 | - * |
|
| 1542 | - * @param string $key |
|
| 1543 | - */ |
|
| 1544 | - public function __get($key) |
|
| 1545 | - { |
|
| 1546 | - // Give them first crack at any protected class vars |
|
| 1547 | - if (isset($this->$key)) |
|
| 1548 | - { |
|
| 1549 | - return $this->$key; |
|
| 1550 | - } |
|
| 1551 | - |
|
| 1552 | - // Debugging note: |
|
| 1553 | - // If you're here because you're getting an error message |
|
| 1554 | - // saying 'Undefined Property: system/core/Model.php', it's |
|
| 1555 | - // most likely a typo in your model code. |
|
| 1556 | - return get_instance()->$key; |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - //-------------------------------------------------------------------- |
|
| 1560 | - |
|
| 1561 | - /** |
|
| 1562 | - * Provide direct access to any of CodeIgniter's DB methods but |
|
| 1563 | - * make it look like it's part of the class, purely for convenience. |
|
| 1564 | - * |
|
| 1565 | - * @param $name |
|
| 1566 | - * @param $params |
|
| 1567 | - */ |
|
| 1568 | - public function __call($name, $params=null) |
|
| 1569 | - { |
|
| 1570 | - if (method_exists($this->db, $name)) |
|
| 1571 | - { |
|
| 1572 | - call_user_func_array([$this->db, $name], $params); |
|
| 1573 | - return $this; |
|
| 1574 | - } |
|
| 1575 | - } |
|
| 1576 | - |
|
| 1577 | - //-------------------------------------------------------------------- |
|
| 936 | + return $this; |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + //-------------------------------------------------------------------- |
|
| 940 | + |
|
| 941 | + /** |
|
| 942 | + * Temporarily sets our return type to an array. |
|
| 943 | + */ |
|
| 944 | + public function as_array() |
|
| 945 | + { |
|
| 946 | + $this->temp_return_type = 'array'; |
|
| 947 | + |
|
| 948 | + return $this; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + //-------------------------------------------------------------------- |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Temporarily sets our return type to an object. |
|
| 955 | + * |
|
| 956 | + * If $class is provided, the rows will be returned as objects that |
|
| 957 | + * are instances of that class. $class MUST be an fully qualified |
|
| 958 | + * class name, meaning that it must include the namespace, if applicable. |
|
| 959 | + * |
|
| 960 | + * @param string $class |
|
| 961 | + * @return $this |
|
| 962 | + */ |
|
| 963 | + public function as_object($class=null) |
|
| 964 | + { |
|
| 965 | + $this->temp_return_type = ! empty($class) ? $class : 'object'; |
|
| 966 | + |
|
| 967 | + return $this; |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + //-------------------------------------------------------------------- |
|
| 971 | + |
|
| 972 | + /** |
|
| 973 | + * Also fetches deleted items for this request only. |
|
| 974 | + */ |
|
| 975 | + public function with_deleted() |
|
| 976 | + { |
|
| 977 | + $this->temp_with_deleted = TRUE; |
|
| 978 | + |
|
| 979 | + return $this; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + //-------------------------------------------------------------------- |
|
| 983 | + |
|
| 984 | + /** |
|
| 985 | + * Returns whether the current setup will return |
|
| 986 | + * soft deleted rows. |
|
| 987 | + * |
|
| 988 | + * @return bool |
|
| 989 | + */ |
|
| 990 | + public function get_with_deleted() |
|
| 991 | + { |
|
| 992 | + return $this->temp_with_deleted; |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + //-------------------------------------------------------------------- |
|
| 996 | + |
|
| 997 | + |
|
| 998 | + /** |
|
| 999 | + * Sets the $skip_validation parameter. |
|
| 1000 | + * |
|
| 1001 | + * @param bool $skip |
|
| 1002 | + * @return $this |
|
| 1003 | + */ |
|
| 1004 | + public function skip_validation($skip = true) |
|
| 1005 | + { |
|
| 1006 | + $this->skip_validation = $skip; |
|
| 1007 | + |
|
| 1008 | + return $this; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + //-------------------------------------------------------------------- |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + //-------------------------------------------------------------------- |
|
| 1015 | + // Utility Methods |
|
| 1016 | + //-------------------------------------------------------------------- |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * Counts number of rows modified by an arbitrary WHERE call. |
|
| 1020 | + * @return INT |
|
| 1021 | + */ |
|
| 1022 | + public function count_by() |
|
| 1023 | + { |
|
| 1024 | + $where = func_get_args(); |
|
| 1025 | + $this->_set_where($where); |
|
| 1026 | + |
|
| 1027 | + return $this->db->count_all_results($this->table_name); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + //-------------------------------------------------------------------- |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * Counts total number of records, disregarding any previous conditions. |
|
| 1034 | + * |
|
| 1035 | + * @return int |
|
| 1036 | + */ |
|
| 1037 | + public function count_all() |
|
| 1038 | + { |
|
| 1039 | + return $this->db->count_all($this->table_name); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + //-------------------------------------------------------------------- |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * Getter for the table name. |
|
| 1046 | + * |
|
| 1047 | + * @return string The name of the table used by this class. |
|
| 1048 | + */ |
|
| 1049 | + public function table() |
|
| 1050 | + { |
|
| 1051 | + return $this->table_name; |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + //-------------------------------------------------------------------- |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * Set the return_insert_id value. |
|
| 1058 | + * |
|
| 1059 | + * @param boolean $return If TRUE, insert will return the insert_id. |
|
| 1060 | + */ |
|
| 1061 | + public function return_insert_id($return = true) |
|
| 1062 | + { |
|
| 1063 | + $this->return_insert_id = (bool)$return; |
|
| 1064 | + |
|
| 1065 | + return $this; |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + //-------------------------------------------------------------------- |
|
| 1069 | + |
|
| 1070 | + /** |
|
| 1071 | + * A convenience method to return only a single field of the specified row. |
|
| 1072 | + * |
|
| 1073 | + * @param mixed $id The primary_key value to match against. |
|
| 1074 | + * @param string $field The field to search for. |
|
| 1075 | + * |
|
| 1076 | + * @return bool|mixed The value of the field. |
|
| 1077 | + */ |
|
| 1078 | + public function get_field($id = NULL, $field = '') |
|
| 1079 | + { |
|
| 1080 | + $this->db->select($field); |
|
| 1081 | + $this->db->where($this->primary_key, $id); |
|
| 1082 | + $query = $this->db->get($this->table_name); |
|
| 1083 | + |
|
| 1084 | + if ($query && $query->num_rows() > 0) { |
|
| 1085 | + return $query->row()->$field; |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + return FALSE; |
|
| 1089 | + |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + //--------------------------------------------------------------- |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * Checks whether a field/value pair exists within the table. |
|
| 1096 | + * |
|
| 1097 | + * @param string $field The field to search for. |
|
| 1098 | + * @param string $value The value to match $field against. |
|
| 1099 | + * |
|
| 1100 | + * @return bool TRUE/FALSE |
|
| 1101 | + */ |
|
| 1102 | + public function is_unique($field, $value) |
|
| 1103 | + { |
|
| 1104 | + $this->db->where($field, $value); |
|
| 1105 | + $query = $this->db->get($this->table_name); |
|
| 1106 | + |
|
| 1107 | + if ($query && $query->num_rows() == 0) { |
|
| 1108 | + return TRUE; |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + return FALSE; |
|
| 1112 | + |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + //--------------------------------------------------------------- |
|
| 1116 | + |
|
| 1117 | + /** |
|
| 1118 | + * Adds a field to the protected_attributes array. |
|
| 1119 | + * |
|
| 1120 | + * @param $field |
|
| 1121 | + * |
|
| 1122 | + * @return mixed |
|
| 1123 | + */ |
|
| 1124 | + public function protect($field) |
|
| 1125 | + { |
|
| 1126 | + $this->protected_attributes[] = $field; |
|
| 1127 | + |
|
| 1128 | + return $this; |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + //-------------------------------------------------------------------- |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * Get the field names for this model's table. |
|
| 1135 | + * |
|
| 1136 | + * Returns the model's database fields stored in $this->fields |
|
| 1137 | + * if set, else it tries to retrieve the field list from |
|
| 1138 | + * $this->db->list_fields($this->table_name); |
|
| 1139 | + * |
|
| 1140 | + * @return array Returns the database fields for this model |
|
| 1141 | + */ |
|
| 1142 | + public function get_fields() |
|
| 1143 | + { |
|
| 1144 | + if (empty($this->fields)) { |
|
| 1145 | + $this->fields = $this->db->list_fields($this->table_name); |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + return $this->fields; |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + //-------------------------------------------------------------------- |
|
| 1152 | + |
|
| 1153 | + /** |
|
| 1154 | + * Extracts the model's fields (except the key and those handled by |
|
| 1155 | + * Observers) from the $post_data and returns an array of name => value pairs |
|
| 1156 | + * |
|
| 1157 | + * @param Array $post_data The post data, usually $this->input->post() when called from the controller |
|
| 1158 | + * |
|
| 1159 | + * @return Array An array of name => value pairs containing the data for the model's fields |
|
| 1160 | + */ |
|
| 1161 | + public function prep_data($post_data) |
|
| 1162 | + { |
|
| 1163 | + $data = array(); |
|
| 1164 | + $skippedFields = array(); |
|
| 1165 | + |
|
| 1166 | + if (empty($post_data)) |
|
| 1167 | + { |
|
| 1168 | + return []; |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + // Though the model doesn't support multiple keys well, $this->key |
|
| 1172 | + // could be an array or a string... |
|
| 1173 | + $skippedFields = array_merge($skippedFields, (array)$this->primary_key); |
|
| 1174 | + |
|
| 1175 | + // Remove any protected attributes |
|
| 1176 | + $skippedFields = array_merge($skippedFields, $this->protected_attributes); |
|
| 1177 | + |
|
| 1178 | + $fields = $this->get_fields(); |
|
| 1179 | + |
|
| 1180 | + // If the field is the primary key, one of the created/modified/deleted |
|
| 1181 | + // fields, or has not been set in the $post_data, skip it |
|
| 1182 | + foreach ($post_data as $field => $value) { |
|
| 1183 | + if (in_array($field, $skippedFields) || |
|
| 1184 | + ! in_array($field, $fields)) |
|
| 1185 | + { |
|
| 1186 | + continue; |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + $data[$field] = $value; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + return $data; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + //-------------------------------------------------------------------- |
|
| 1196 | + |
|
| 1197 | + /** |
|
| 1198 | + * Returns the last query string, if available. Simply a wrapper for |
|
| 1199 | + * CodeIgniter's database method of the same name. |
|
| 1200 | + * |
|
| 1201 | + * @return string |
|
| 1202 | + */ |
|
| 1203 | + public function last_query () |
|
| 1204 | + { |
|
| 1205 | + return $this->db->last_query(); |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + //-------------------------------------------------------------------- |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * Returns the elapsed time for the last query that was executed, if |
|
| 1212 | + * available, or NULL if not available, like if debug mode is off. |
|
| 1213 | + * |
|
| 1214 | + * @return mixed |
|
| 1215 | + */ |
|
| 1216 | + public function last_query_time () |
|
| 1217 | + { |
|
| 1218 | + $times = $this->db->query_times; |
|
| 1219 | + |
|
| 1220 | + if (! is_array($this->db->query_times) || ! count($this->db->query_times)) |
|
| 1221 | + { |
|
| 1222 | + return null; |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return end($times); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + //-------------------------------------------------------------------- |
|
| 1229 | + |
|
| 1230 | + //-------------------------------------------------------------------- |
|
| 1231 | + // Observers |
|
| 1232 | + //-------------------------------------------------------------------- |
|
| 1233 | + |
|
| 1234 | + /** |
|
| 1235 | + * Sets the created on date for the object based on the |
|
| 1236 | + * current date/time and date_format. Will not overwrite existing. |
|
| 1237 | + * |
|
| 1238 | + * @param array $row The array of data to be inserted |
|
| 1239 | + * |
|
| 1240 | + * @return array |
|
| 1241 | + */ |
|
| 1242 | + public function created_on($row) |
|
| 1243 | + { |
|
| 1244 | + if (empty($row['fields'])) |
|
| 1245 | + { |
|
| 1246 | + return null; |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + $row = $row['fields']; |
|
| 1250 | + |
|
| 1251 | + // Created_on |
|
| 1252 | + if (! array_key_exists($this->created_field, $row)) |
|
| 1253 | + { |
|
| 1254 | + $row[$this->created_field] = $this->set_date(); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + // Created by |
|
| 1258 | + if ($this->log_user && ! array_key_exists($this->created_by_field, $row) && is_object($this->authenticate)) |
|
| 1259 | + { |
|
| 1260 | + // If you're here because of an error with $this->authenticate |
|
| 1261 | + // not being available, it's likely due to you not using |
|
| 1262 | + // the AuthTrait and/or setting log_user after model is instantiated. |
|
| 1263 | + $row[$this->created_by_field] = (int)$this->authenticate->id(); |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + return $row; |
|
| 1267 | + } // end created_on() |
|
| 1268 | + |
|
| 1269 | + //-------------------------------------------------------------------- |
|
| 1270 | + |
|
| 1271 | + /** |
|
| 1272 | + * Sets the modified_on date for the object based on the |
|
| 1273 | + * current date/time and date_format. Will not overwrite existing. |
|
| 1274 | + * |
|
| 1275 | + * @param array $row The array of data to be inserted |
|
| 1276 | + * |
|
| 1277 | + * @return array |
|
| 1278 | + */ |
|
| 1279 | + public function modified_on($row) |
|
| 1280 | + { |
|
| 1281 | + if (empty($row['fields'])) |
|
| 1282 | + { |
|
| 1283 | + return null; |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + $row = $row['fields']; |
|
| 1287 | + |
|
| 1288 | + if (is_array($row) && ! array_key_exists($this->modified_field, $row)) |
|
| 1289 | + { |
|
| 1290 | + $row[$this->modified_field] = $this->set_date(); |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + // Modified by |
|
| 1294 | + if ($this->log_user && ! array_key_exists($this->modified_by_field, $row) && is_object($this->authenticate)) |
|
| 1295 | + { |
|
| 1296 | + // If you're here because of an error with $this->authenticate |
|
| 1297 | + // not being available, it's likely due to you not using |
|
| 1298 | + // the AuthTrait and/or setting log_user after model is instantiated. |
|
| 1299 | + $row[$this->modified_by_field] = $this->authenticate->id(); |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + return $row; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + //-------------------------------------------------------------------- |
|
| 1306 | + |
|
| 1307 | + //-------------------------------------------------------------------- |
|
| 1308 | + // Internal Methods |
|
| 1309 | + //-------------------------------------------------------------------- |
|
| 1310 | + |
|
| 1311 | + /** |
|
| 1312 | + * Set WHERE parameters |
|
| 1313 | + */ |
|
| 1314 | + protected function _set_where($params) |
|
| 1315 | + { |
|
| 1316 | + if (count($params) == 1) { |
|
| 1317 | + $this->db->where($params[0]); |
|
| 1318 | + } else { |
|
| 1319 | + $this->db->where($params[0], $params[1]); |
|
| 1320 | + } |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + //-------------------------------------------------------------------- |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * Triggers a model-specific event and call each of it's observers. |
|
| 1327 | + * |
|
| 1328 | + * @param string $event The name of the event to trigger |
|
| 1329 | + * @param mixed $data The data to be passed to the callback functions. |
|
| 1330 | + * |
|
| 1331 | + * @return mixed |
|
| 1332 | + */ |
|
| 1333 | + public function trigger($event, $data = false) |
|
| 1334 | + { |
|
| 1335 | + if (! isset($this->$event) || ! is_array($this->$event)) |
|
| 1336 | + { |
|
| 1337 | + if (isset($data['fields'])) |
|
| 1338 | + { |
|
| 1339 | + return $data['fields']; |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + return $data; |
|
| 1343 | + } |
|
| 1344 | + |
|
| 1345 | + foreach ($this->$event as $method) |
|
| 1346 | + { |
|
| 1347 | + if (strpos($method, '(')) |
|
| 1348 | + { |
|
| 1349 | + preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches); |
|
| 1350 | + $this->callback_parameters = explode(',', $matches[3]); |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + $data = call_user_func_array(array($this, $method), array($data)); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // In case no method called or method returned |
|
| 1357 | + // the entire data array, we typically just need the $fields |
|
| 1358 | + if (isset($data['fields'])) |
|
| 1359 | + { |
|
| 1360 | + return $data['fields']; |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + // A few methods might need to return 'ids' |
|
| 1364 | + if (isset($data['ids'])) |
|
| 1365 | + { |
|
| 1366 | + return $data['ids']; |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + return $data; |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + //-------------------------------------------------------------------- |
|
| 1373 | + |
|
| 1374 | + /** |
|
| 1375 | + * Validates the data passed into it based upon the form_validation rules |
|
| 1376 | + * setup in the $this->validate property. |
|
| 1377 | + * |
|
| 1378 | + * If $type == 'insert', any additional rules in the class var $insert_validate_rules |
|
| 1379 | + * for that field will be added to the rules. |
|
| 1380 | + * |
|
| 1381 | + * @param array $data An array of validation rules |
|
| 1382 | + * @param string $type Either 'update' or 'insert'. |
|
| 1383 | + * @return array/bool The original data or FALSE |
|
| 1384 | + */ |
|
| 1385 | + public function validate($data, $type = 'update', $skip_validation = null) |
|
| 1386 | + { |
|
| 1387 | + $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
|
| 1388 | + |
|
| 1389 | + if ($skip_validation) { |
|
| 1390 | + return $data; |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + // We need the database to be loaded up at this point in case |
|
| 1394 | + // we want to use callbacks that hit the database. |
|
| 1395 | + if (empty($this->db)) |
|
| 1396 | + { |
|
| 1397 | + $this->load->database(); |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + if (!empty($this->validation_rules)) { |
|
| 1401 | + $this->form_validation->set_data($data); |
|
| 1402 | + |
|
| 1403 | + if (is_array($this->validation_rules)) { |
|
| 1404 | + // Any insert additions? |
|
| 1405 | + if ($type == 'insert' |
|
| 1406 | + && !empty($this->insert_validate_rules) |
|
| 1407 | + && is_array($this->insert_validate_rules) |
|
| 1408 | + ) { |
|
| 1409 | + foreach ($this->validation_rules as &$row) { |
|
| 1410 | + if (isset($this->insert_validate_rules[$row['field']])) { |
|
| 1411 | + $row ['rules'] .= '|' . $this->insert_validate_rules[$row['field']]; |
|
| 1412 | + } |
|
| 1413 | + } |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + $this->form_validation->set_rules($this->validation_rules); |
|
| 1417 | + |
|
| 1418 | + if ($this->form_validation->run('', $this) === TRUE) { |
|
| 1419 | + return $data; |
|
| 1420 | + } else { |
|
| 1421 | + return FALSE; |
|
| 1422 | + } |
|
| 1423 | + } else { |
|
| 1424 | + if ($this->form_validation->run($this->validate, $this) === TRUE) { |
|
| 1425 | + return $data; |
|
| 1426 | + } else { |
|
| 1427 | + return FALSE; |
|
| 1428 | + } |
|
| 1429 | + } |
|
| 1430 | + } else { |
|
| 1431 | + return $data; |
|
| 1432 | + } |
|
| 1433 | + } |
|
| 1434 | + |
|
| 1435 | + //-------------------------------------------------------------------- |
|
| 1436 | + |
|
| 1437 | + /** |
|
| 1438 | + * Protect attributes by removing them from $row array. Useful for |
|
| 1439 | + * removing id, or submit buttons names if you simply throw your $_POST |
|
| 1440 | + * array at your model. :) |
|
| 1441 | + * |
|
| 1442 | + * @param object /array $row The value pair item to remove. |
|
| 1443 | + */ |
|
| 1444 | + public function protect_attributes($row) |
|
| 1445 | + { |
|
| 1446 | + foreach ($this->protected_attributes as $attr) { |
|
| 1447 | + if (is_object($row)) { |
|
| 1448 | + unset($row->$attr); |
|
| 1449 | + } else { |
|
| 1450 | + unset($row[$attr]); |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + return $row; |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + //-------------------------------------------------------------------- |
|
| 1458 | + |
|
| 1459 | + /** |
|
| 1460 | + * A utility function to allow child models to use the type of |
|
| 1461 | + * date/time format that they prefer. This is primarily used for |
|
| 1462 | + * setting created_on and modified_on values, but can be used by |
|
| 1463 | + * inheriting classes. |
|
| 1464 | + * |
|
| 1465 | + * The available time formats are: |
|
| 1466 | + * * 'int' - Stores the date as an integer timestamp. |
|
| 1467 | + * * 'datetime' - Stores the date and time in the SQL datetime format. |
|
| 1468 | + * * 'date' - Stores teh date (only) in the SQL date format. |
|
| 1469 | + * |
|
| 1470 | + * @param mixed $user_date An optional PHP timestamp to be converted. |
|
| 1471 | + * |
|
| 1472 | + * @access protected |
|
| 1473 | + * |
|
| 1474 | + * @return int|null|string The current/user time converted to the proper format. |
|
| 1475 | + */ |
|
| 1476 | + protected function set_date($user_date = NULL) |
|
| 1477 | + { |
|
| 1478 | + $curr_date = !empty($user_date) ? $user_date : time(); |
|
| 1479 | + |
|
| 1480 | + switch ($this->date_format) { |
|
| 1481 | + case 'int': |
|
| 1482 | + return $curr_date; |
|
| 1483 | + break; |
|
| 1484 | + case 'datetime': |
|
| 1485 | + return date('Y-m-d H:i:s', $curr_date); |
|
| 1486 | + break; |
|
| 1487 | + case 'date': |
|
| 1488 | + return date('Y-m-d', $curr_date); |
|
| 1489 | + break; |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + }//end set_date() |
|
| 1493 | + |
|
| 1494 | + //-------------------------------------------------------------------- |
|
| 1495 | + |
|
| 1496 | + /** |
|
| 1497 | + * Returns an array containing the 'code' and 'message' of the |
|
| 1498 | + * database's error, as provided by CI's database drivers. |
|
| 1499 | + * |
|
| 1500 | + * @return mixed |
|
| 1501 | + */ |
|
| 1502 | + public function error($db_array_only=false) |
|
| 1503 | + { |
|
| 1504 | + // Send any validation errors if we have any. |
|
| 1505 | + if (function_exists('validation_errors') && validation_errors() && ! $db_array_only) |
|
| 1506 | + { |
|
| 1507 | + return validation_errors(); |
|
| 1508 | + } |
|
| 1509 | + |
|
| 1510 | + // No validation errors? Return the db error. |
|
| 1511 | + $error = $this->db->error(); |
|
| 1512 | + |
|
| 1513 | + if ($db_array_only) |
|
| 1514 | + { |
|
| 1515 | + return $error; |
|
| 1516 | + } |
|
| 1517 | + |
|
| 1518 | + if (! empty($error['code'])) |
|
| 1519 | + { |
|
| 1520 | + return "Database Error {$error['code']}: {$error['message']}."; |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + // No errors found. |
|
| 1524 | + return ''; |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + //-------------------------------------------------------------------- |
|
| 1528 | + |
|
| 1529 | + //-------------------------------------------------------------------- |
|
| 1530 | + // Magic Methods |
|
| 1531 | + //-------------------------------------------------------------------- |
|
| 1532 | + |
|
| 1533 | + /** |
|
| 1534 | + * __get magic |
|
| 1535 | + * |
|
| 1536 | + * Allows models to access CI's loaded classes using the same |
|
| 1537 | + * syntax as controllers. |
|
| 1538 | + * |
|
| 1539 | + * This is the same as what CI's model uses, but we keep it |
|
| 1540 | + * here since that's the ONLY thing that CI's model does. |
|
| 1541 | + * |
|
| 1542 | + * @param string $key |
|
| 1543 | + */ |
|
| 1544 | + public function __get($key) |
|
| 1545 | + { |
|
| 1546 | + // Give them first crack at any protected class vars |
|
| 1547 | + if (isset($this->$key)) |
|
| 1548 | + { |
|
| 1549 | + return $this->$key; |
|
| 1550 | + } |
|
| 1551 | + |
|
| 1552 | + // Debugging note: |
|
| 1553 | + // If you're here because you're getting an error message |
|
| 1554 | + // saying 'Undefined Property: system/core/Model.php', it's |
|
| 1555 | + // most likely a typo in your model code. |
|
| 1556 | + return get_instance()->$key; |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + //-------------------------------------------------------------------- |
|
| 1560 | + |
|
| 1561 | + /** |
|
| 1562 | + * Provide direct access to any of CodeIgniter's DB methods but |
|
| 1563 | + * make it look like it's part of the class, purely for convenience. |
|
| 1564 | + * |
|
| 1565 | + * @param $name |
|
| 1566 | + * @param $params |
|
| 1567 | + */ |
|
| 1568 | + public function __call($name, $params=null) |
|
| 1569 | + { |
|
| 1570 | + if (method_exists($this->db, $name)) |
|
| 1571 | + { |
|
| 1572 | + call_user_func_array([$this->db, $name], $params); |
|
| 1573 | + return $this; |
|
| 1574 | + } |
|
| 1575 | + } |
|
| 1576 | + |
|
| 1577 | + //-------------------------------------------------------------------- |
|
| 1578 | 1578 | |
| 1579 | 1579 | |
| 1580 | 1580 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | $this->temp_return_type = $this->return_type; |
| 302 | 302 | |
| 303 | 303 | // Make sure our database is loaded |
| 304 | - if (!is_null($db)) { |
|
| 304 | + if ( ! is_null($db)) { |
|
| 305 | 305 | $this->db = $db; |
| 306 | 306 | } |
| 307 | 307 | else { |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // Do we have a form_validation library? |
| 313 | - if (! is_null($form_validation)) { |
|
| 313 | + if ( ! is_null($form_validation)) { |
|
| 314 | 314 | $this->form_validation = $form_validation; |
| 315 | 315 | } |
| 316 | 316 | else { |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | |
| 481 | 481 | if (is_array($rows)) { |
| 482 | 482 | foreach ($rows as $key => &$row) { |
| 483 | - $row = $this->trigger('after_find', ['method' => 'find_all', 'fields' => $row] ); |
|
| 483 | + $row = $this->trigger('after_find', ['method' => 'find_all', 'fields' => $row]); |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | if ($data !== FALSE) { |
| 511 | 511 | $data = $this->trigger('before_insert', ['method' => 'insert', 'fields' => $data]); |
| 512 | 512 | |
| 513 | - $this->db->insert($this->table_name, $this->prep_data($data) ); |
|
| 513 | + $this->db->insert($this->table_name, $this->prep_data($data)); |
|
| 514 | 514 | |
| 515 | 515 | if ($this->return_insert_id) { |
| 516 | 516 | $id = $this->db->insert_id(); |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | if ($data !== FALSE) { |
| 557 | 557 | $data['batch'] = true; |
| 558 | - $data = $this->trigger('before_insert', ['method' => 'insert_batch', 'fields' => $data] ); |
|
| 558 | + $data = $this->trigger('before_insert', ['method' => 'insert_batch', 'fields' => $data]); |
|
| 559 | 559 | unset($data['batch']); |
| 560 | 560 | |
| 561 | 561 | return $this->db->insert_batch($this->table_name, $data); |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | * @param null $skip_validation |
| 578 | 578 | * @return bool |
| 579 | 579 | */ |
| 580 | - public function replace($data, $skip_validation=null) |
|
| 580 | + public function replace($data, $skip_validation = null) |
|
| 581 | 581 | { |
| 582 | 582 | $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
| 583 | 583 | |
@@ -624,10 +624,10 @@ discard block |
||
| 624 | 624 | // Will be false if it didn't validate. |
| 625 | 625 | if ($data !== FALSE) { |
| 626 | 626 | |
| 627 | - $data = $this->trigger('before_update', ['id' => $id, 'method' =>'update', 'fields' => $data] ); |
|
| 627 | + $data = $this->trigger('before_update', ['id' => $id, 'method' =>'update', 'fields' => $data]); |
|
| 628 | 628 | |
| 629 | 629 | $this->db->where($this->primary_key, $id); |
| 630 | - $this->db->set( $this->prep_data($data) ); |
|
| 630 | + $this->db->set($this->prep_data($data)); |
|
| 631 | 631 | $result = $this->db->update($this->table_name); |
| 632 | 632 | |
| 633 | 633 | $this->trigger('after_update', ['id' => $id, 'fields' => $data, 'result' => $result, 'method' => 'update']); |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | public function update_batch($data, $where_key) |
| 667 | 667 | { |
| 668 | 668 | foreach ($data as &$row) { |
| 669 | - $row = $this->trigger('before_update', ['method' => 'update_batch', 'fields' => $row] ); |
|
| 669 | + $row = $this->trigger('before_update', ['method' => 'update_batch', 'fields' => $row]); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | $result = $this->db->update_batch($this->table_name, $data, $where_key); |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | */ |
| 701 | 701 | public function update_many($ids, $data, $skip_validation = null) |
| 702 | 702 | { |
| 703 | - if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 703 | + if ( ! is_array($ids) || count($ids) == 0) return NULL; |
|
| 704 | 704 | |
| 705 | 705 | $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
| 706 | 706 | |
@@ -754,10 +754,10 @@ discard block |
||
| 754 | 754 | |
| 755 | 755 | // Will be false if it didn't validate. |
| 756 | 756 | if ($this->validate($data) !== FALSE) { |
| 757 | - $this->db->set( $this->prep_data($data) ); |
|
| 757 | + $this->db->set($this->prep_data($data)); |
|
| 758 | 758 | $result = $this->db->update($this->table_name); |
| 759 | 759 | |
| 760 | - $this->trigger('after_update', ['method' => 'update_by', 'fields' => $data, 'result' => $result] ); |
|
| 760 | + $this->trigger('after_update', ['method' => 'update_by', 'fields' => $data, 'result' => $result]); |
|
| 761 | 761 | |
| 762 | 762 | return $result; |
| 763 | 763 | } else { |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | */ |
| 777 | 777 | public function update_all($data, $skip_validation = FALSE) |
| 778 | 778 | { |
| 779 | - $data = $this->trigger('before_update', ['method' => 'update_all', 'fields' => $data] ); |
|
| 779 | + $data = $this->trigger('before_update', ['method' => 'update_all', 'fields' => $data]); |
|
| 780 | 780 | |
| 781 | 781 | $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
| 782 | 782 | |
@@ -786,10 +786,10 @@ discard block |
||
| 786 | 786 | |
| 787 | 787 | // Will be false if it didn't validate. |
| 788 | 788 | if ($data !== FALSE) { |
| 789 | - $this->db->set( $this->prep_data($data) ); |
|
| 789 | + $this->db->set($this->prep_data($data)); |
|
| 790 | 790 | $result = $this->db->update($this->table_name); |
| 791 | 791 | |
| 792 | - $this->trigger('after_update', ['method' => 'update_all', 'fields' => $data, 'result' => $result] ); |
|
| 792 | + $this->trigger('after_update', ['method' => 'update_all', 'fields' => $data, 'result' => $result]); |
|
| 793 | 793 | |
| 794 | 794 | return $result; |
| 795 | 795 | } else { |
@@ -808,9 +808,9 @@ discard block |
||
| 808 | 808 | * @param int $value |
| 809 | 809 | * @return mixed |
| 810 | 810 | */ |
| 811 | - public function increment($id, $field, $value=1) |
|
| 811 | + public function increment($id, $field, $value = 1) |
|
| 812 | 812 | { |
| 813 | - $value = (int)abs($value); |
|
| 813 | + $value = (int) abs($value); |
|
| 814 | 814 | |
| 815 | 815 | $this->db->where($this->primary_key, $id); |
| 816 | 816 | $this->db->set($field, "{$field}+{$value}", false); |
@@ -829,9 +829,9 @@ discard block |
||
| 829 | 829 | * @param int $value |
| 830 | 830 | * @return mixed |
| 831 | 831 | */ |
| 832 | - public function decrement($id, $field, $value=1) |
|
| 832 | + public function decrement($id, $field, $value = 1) |
|
| 833 | 833 | { |
| 834 | - $value = (int)abs($value); |
|
| 834 | + $value = (int) abs($value); |
|
| 835 | 835 | |
| 836 | 836 | $this->db->where($this->primary_key, $id); |
| 837 | 837 | $this->db->set($field, "{$field}-{$value}", false); |
@@ -849,7 +849,7 @@ discard block |
||
| 849 | 849 | */ |
| 850 | 850 | public function delete($id) |
| 851 | 851 | { |
| 852 | - $this->trigger('before_delete', ['id' => $id, 'method' => 'delete'] ); |
|
| 852 | + $this->trigger('before_delete', ['id' => $id, 'method' => 'delete']); |
|
| 853 | 853 | |
| 854 | 854 | $this->db->where($this->primary_key, $id); |
| 855 | 855 | |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | $result = $this->db->delete($this->table_name); |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | - $this->trigger('after_delete', ['id' => $id, 'method' => 'delete', 'result' => $result] ); |
|
| 867 | + $this->trigger('after_delete', ['id' => $id, 'method' => 'delete', 'result' => $result]); |
|
| 868 | 868 | |
| 869 | 869 | return $result; |
| 870 | 870 | } |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | $result = $this->db->delete($this->table_name); |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - $this->trigger('after_delete', ['method' => 'delete_by', 'fields' => $where, 'result' => $result] ); |
|
| 891 | + $this->trigger('after_delete', ['method' => 'delete_by', 'fields' => $where, 'result' => $result]); |
|
| 892 | 892 | |
| 893 | 893 | return $result; |
| 894 | 894 | } |
@@ -897,9 +897,9 @@ discard block |
||
| 897 | 897 | |
| 898 | 898 | public function delete_many($ids) |
| 899 | 899 | { |
| 900 | - if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 900 | + if ( ! is_array($ids) || count($ids) == 0) return NULL; |
|
| 901 | 901 | |
| 902 | - $ids = $this->trigger('before_delete', ['ids' => $ids, 'method' => 'delete_many'] ); |
|
| 902 | + $ids = $this->trigger('before_delete', ['ids' => $ids, 'method' => 'delete_many']); |
|
| 903 | 903 | |
| 904 | 904 | $this->db->where_in($this->primary_key, $ids); |
| 905 | 905 | |
@@ -960,7 +960,7 @@ discard block |
||
| 960 | 960 | * @param string $class |
| 961 | 961 | * @return $this |
| 962 | 962 | */ |
| 963 | - public function as_object($class=null) |
|
| 963 | + public function as_object($class = null) |
|
| 964 | 964 | { |
| 965 | 965 | $this->temp_return_type = ! empty($class) ? $class : 'object'; |
| 966 | 966 | |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | */ |
| 1061 | 1061 | public function return_insert_id($return = true) |
| 1062 | 1062 | { |
| 1063 | - $this->return_insert_id = (bool)$return; |
|
| 1063 | + $this->return_insert_id = (bool) $return; |
|
| 1064 | 1064 | |
| 1065 | 1065 | return $this; |
| 1066 | 1066 | } |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | |
| 1171 | 1171 | // Though the model doesn't support multiple keys well, $this->key |
| 1172 | 1172 | // could be an array or a string... |
| 1173 | - $skippedFields = array_merge($skippedFields, (array)$this->primary_key); |
|
| 1173 | + $skippedFields = array_merge($skippedFields, (array) $this->primary_key); |
|
| 1174 | 1174 | |
| 1175 | 1175 | // Remove any protected attributes |
| 1176 | 1176 | $skippedFields = array_merge($skippedFields, $this->protected_attributes); |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | * |
| 1201 | 1201 | * @return string |
| 1202 | 1202 | */ |
| 1203 | - public function last_query () |
|
| 1203 | + public function last_query() |
|
| 1204 | 1204 | { |
| 1205 | 1205 | return $this->db->last_query(); |
| 1206 | 1206 | } |
@@ -1213,11 +1213,11 @@ discard block |
||
| 1213 | 1213 | * |
| 1214 | 1214 | * @return mixed |
| 1215 | 1215 | */ |
| 1216 | - public function last_query_time () |
|
| 1216 | + public function last_query_time() |
|
| 1217 | 1217 | { |
| 1218 | 1218 | $times = $this->db->query_times; |
| 1219 | 1219 | |
| 1220 | - if (! is_array($this->db->query_times) || ! count($this->db->query_times)) |
|
| 1220 | + if ( ! is_array($this->db->query_times) || ! count($this->db->query_times)) |
|
| 1221 | 1221 | { |
| 1222 | 1222 | return null; |
| 1223 | 1223 | } |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | $row = $row['fields']; |
| 1250 | 1250 | |
| 1251 | 1251 | // Created_on |
| 1252 | - if (! array_key_exists($this->created_field, $row)) |
|
| 1252 | + if ( ! array_key_exists($this->created_field, $row)) |
|
| 1253 | 1253 | { |
| 1254 | 1254 | $row[$this->created_field] = $this->set_date(); |
| 1255 | 1255 | } |
@@ -1260,7 +1260,7 @@ discard block |
||
| 1260 | 1260 | // If you're here because of an error with $this->authenticate |
| 1261 | 1261 | // not being available, it's likely due to you not using |
| 1262 | 1262 | // the AuthTrait and/or setting log_user after model is instantiated. |
| 1263 | - $row[$this->created_by_field] = (int)$this->authenticate->id(); |
|
| 1263 | + $row[$this->created_by_field] = (int) $this->authenticate->id(); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | return $row; |
@@ -1332,7 +1332,7 @@ discard block |
||
| 1332 | 1332 | */ |
| 1333 | 1333 | public function trigger($event, $data = false) |
| 1334 | 1334 | { |
| 1335 | - if (! isset($this->$event) || ! is_array($this->$event)) |
|
| 1335 | + if ( ! isset($this->$event) || ! is_array($this->$event)) |
|
| 1336 | 1336 | { |
| 1337 | 1337 | if (isset($data['fields'])) |
| 1338 | 1338 | { |
@@ -1397,18 +1397,18 @@ discard block |
||
| 1397 | 1397 | $this->load->database(); |
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | - if (!empty($this->validation_rules)) { |
|
| 1400 | + if ( ! empty($this->validation_rules)) { |
|
| 1401 | 1401 | $this->form_validation->set_data($data); |
| 1402 | 1402 | |
| 1403 | 1403 | if (is_array($this->validation_rules)) { |
| 1404 | 1404 | // Any insert additions? |
| 1405 | 1405 | if ($type == 'insert' |
| 1406 | - && !empty($this->insert_validate_rules) |
|
| 1406 | + && ! empty($this->insert_validate_rules) |
|
| 1407 | 1407 | && is_array($this->insert_validate_rules) |
| 1408 | 1408 | ) { |
| 1409 | 1409 | foreach ($this->validation_rules as &$row) { |
| 1410 | 1410 | if (isset($this->insert_validate_rules[$row['field']])) { |
| 1411 | - $row ['rules'] .= '|' . $this->insert_validate_rules[$row['field']]; |
|
| 1411 | + $row ['rules'] .= '|'.$this->insert_validate_rules[$row['field']]; |
|
| 1412 | 1412 | } |
| 1413 | 1413 | } |
| 1414 | 1414 | } |
@@ -1475,7 +1475,7 @@ discard block |
||
| 1475 | 1475 | */ |
| 1476 | 1476 | protected function set_date($user_date = NULL) |
| 1477 | 1477 | { |
| 1478 | - $curr_date = !empty($user_date) ? $user_date : time(); |
|
| 1478 | + $curr_date = ! empty($user_date) ? $user_date : time(); |
|
| 1479 | 1479 | |
| 1480 | 1480 | switch ($this->date_format) { |
| 1481 | 1481 | case 'int': |
@@ -1499,7 +1499,7 @@ discard block |
||
| 1499 | 1499 | * |
| 1500 | 1500 | * @return mixed |
| 1501 | 1501 | */ |
| 1502 | - public function error($db_array_only=false) |
|
| 1502 | + public function error($db_array_only = false) |
|
| 1503 | 1503 | { |
| 1504 | 1504 | // Send any validation errors if we have any. |
| 1505 | 1505 | if (function_exists('validation_errors') && validation_errors() && ! $db_array_only) |
@@ -1515,7 +1515,7 @@ discard block |
||
| 1515 | 1515 | return $error; |
| 1516 | 1516 | } |
| 1517 | 1517 | |
| 1518 | - if (! empty($error['code'])) |
|
| 1518 | + if ( ! empty($error['code'])) |
|
| 1519 | 1519 | { |
| 1520 | 1520 | return "Database Error {$error['code']}: {$error['message']}."; |
| 1521 | 1521 | } |
@@ -1565,7 +1565,7 @@ discard block |
||
| 1565 | 1565 | * @param $name |
| 1566 | 1566 | * @param $params |
| 1567 | 1567 | */ |
| 1568 | - public function __call($name, $params=null) |
|
| 1568 | + public function __call($name, $params = null) |
|
| 1569 | 1569 | { |
| 1570 | 1570 | if (method_exists($this->db, $name)) |
| 1571 | 1571 | { |
@@ -294,8 +294,12 @@ discard block |
||
| 294 | 294 | |
| 295 | 295 | // Check our auto-set features and make sure they are part of |
| 296 | 296 | // our observer system. |
| 297 | - if ($this->set_created === true) array_unshift($this->before_insert, 'created_on'); |
|
| 298 | - if ($this->set_modified === true) array_unshift($this->before_update, 'modified_on'); |
|
| 297 | + if ($this->set_created === true) { |
|
| 298 | + array_unshift($this->before_insert, 'created_on'); |
|
| 299 | + } |
|
| 300 | + if ($this->set_modified === true) { |
|
| 301 | + array_unshift($this->before_update, 'modified_on'); |
|
| 302 | + } |
|
| 299 | 303 | |
| 300 | 304 | // Make sure our temp return type is correct. |
| 301 | 305 | $this->temp_return_type = $this->return_type; |
@@ -303,8 +307,7 @@ discard block |
||
| 303 | 307 | // Make sure our database is loaded |
| 304 | 308 | if (!is_null($db)) { |
| 305 | 309 | $this->db = $db; |
| 306 | - } |
|
| 307 | - else { |
|
| 310 | + } else { |
|
| 308 | 311 | // Auto Init the damn database.... |
| 309 | 312 | $this->load->database(); |
| 310 | 313 | } |
@@ -312,8 +315,7 @@ discard block |
||
| 312 | 315 | // Do we have a form_validation library? |
| 313 | 316 | if (! is_null($form_validation)) { |
| 314 | 317 | $this->form_validation = $form_validation; |
| 315 | - } |
|
| 316 | - else { |
|
| 318 | + } else { |
|
| 317 | 319 | $this->load->library('form_validation'); |
| 318 | 320 | } |
| 319 | 321 | |
@@ -700,7 +702,9 @@ discard block |
||
| 700 | 702 | */ |
| 701 | 703 | public function update_many($ids, $data, $skip_validation = null) |
| 702 | 704 | { |
| 703 | - if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 705 | + if (!is_array($ids) || count($ids) == 0) { |
|
| 706 | + return NULL; |
|
| 707 | + } |
|
| 704 | 708 | |
| 705 | 709 | $skip_validation = is_null($skip_validation) ? $this->skip_validation : $skip_validation; |
| 706 | 710 | |
@@ -897,7 +901,9 @@ discard block |
||
| 897 | 901 | |
| 898 | 902 | public function delete_many($ids) |
| 899 | 903 | { |
| 900 | - if (!is_array($ids) || count($ids) == 0) return NULL; |
|
| 904 | + if (!is_array($ids) || count($ids) == 0) { |
|
| 905 | + return NULL; |
|
| 906 | + } |
|
| 901 | 907 | |
| 902 | 908 | $ids = $this->trigger('before_delete', ['ids' => $ids, 'method' => 'delete_many'] ); |
| 903 | 909 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | /** |
| 101 | 101 | * Load a module file |
| 102 | 102 | * |
| 103 | - * @param $file |
|
| 103 | + * @param string $file |
|
| 104 | 104 | * @param $path |
| 105 | 105 | * @param string $type |
| 106 | 106 | * @param bool $result |
@@ -333,8 +333,8 @@ discard block |
||
| 333 | 333 | /** |
| 334 | 334 | * Returns the path to the module and it's specified folder. |
| 335 | 335 | * |
| 336 | - * @param $module string The name of the module (must match the folder name) |
|
| 337 | - * @param $folder string The folder name to search for. (Optional) |
|
| 336 | + * @param string $module string The name of the module (must match the folder name) |
|
| 337 | + * @param string $folder string The folder name to search for. (Optional) |
|
| 338 | 338 | * |
| 339 | 339 | * @return string The path, relative to the front controller, or false if the folder was not found |
| 340 | 340 | */ |
@@ -37,20 +37,20 @@ discard block |
||
| 37 | 37 | * available within the Router class, before get_instance() is available we'll have to |
| 38 | 38 | * live with it for now. |
| 39 | 39 | */ |
| 40 | -include APPPATH . 'config/config.php'; |
|
| 40 | +include APPPATH.'config/config.php'; |
|
| 41 | 41 | |
| 42 | -if ( isset( $config ) ) |
|
| 42 | +if (isset($config)) |
|
| 43 | 43 | { |
| 44 | - if ( is_array( $config['modules_locations'] ) ) |
|
| 44 | + if (is_array($config['modules_locations'])) |
|
| 45 | 45 | { |
| 46 | 46 | Modules::$locations = $config['modules_locations']; |
| 47 | 47 | } |
| 48 | 48 | else |
| 49 | 49 | { |
| 50 | - Modules::$locations = array( APPPATH . 'modules/' => '../modules/' ); |
|
| 50 | + Modules::$locations = array(APPPATH.'modules/' => '../modules/'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - unset( $config ); |
|
| 53 | + unset($config); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -107,17 +107,17 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return bool |
| 109 | 109 | */ |
| 110 | - public static function load_file( $file, $path, $type = 'other', $result = TRUE ) |
|
| 110 | + public static function load_file($file, $path, $type = 'other', $result = TRUE) |
|
| 111 | 111 | { |
| 112 | 112 | |
| 113 | - $file = str_replace( '.php', '', $file ); |
|
| 114 | - $location = $path . $file . '.php'; |
|
| 113 | + $file = str_replace('.php', '', $file); |
|
| 114 | + $location = $path.$file.'.php'; |
|
| 115 | 115 | |
| 116 | - if ( $type === 'other' ) |
|
| 116 | + if ($type === 'other') |
|
| 117 | 117 | { |
| 118 | - if ( class_exists( $file, FALSE ) ) |
|
| 118 | + if (class_exists($file, FALSE)) |
|
| 119 | 119 | { |
| 120 | - log_message( 'debug', "File already loaded: {$location}" ); |
|
| 120 | + log_message('debug', "File already loaded: {$location}"); |
|
| 121 | 121 | |
| 122 | 122 | return $result; |
| 123 | 123 | } |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | /* load config or language array */ |
| 130 | 130 | include $location; |
| 131 | 131 | |
| 132 | - if ( ! isset( $$type ) OR ! is_array( $$type ) ) |
|
| 132 | + if ( ! isset($$type) OR ! is_array($$type)) |
|
| 133 | 133 | { |
| 134 | - show_error( "{$location} does not contain a valid {$type} array" ); |
|
| 134 | + show_error("{$location} does not contain a valid {$type} array"); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $result = $$type; |
| 138 | 138 | } |
| 139 | - log_message( 'debug', "File loaded: {$location}" ); |
|
| 139 | + log_message('debug', "File loaded: {$location}"); |
|
| 140 | 140 | |
| 141 | 141 | return $result; |
| 142 | 142 | } |
@@ -156,64 +156,64 @@ discard block |
||
| 156 | 156 | * |
| 157 | 157 | * @return array [ {full_path_to_file}, {file} ] or FALSE |
| 158 | 158 | */ |
| 159 | - public static function find( $file, $module, $base ) |
|
| 159 | + public static function find($file, $module, $base) |
|
| 160 | 160 | { |
| 161 | - if (! is_string($module) || ! is_string($file) || ! is_string($base)) |
|
| 161 | + if ( ! is_string($module) || ! is_string($file) || ! is_string($base)) |
|
| 162 | 162 | { |
| 163 | 163 | throw new \InvalidArgumentException('Argument must be a string for Modules::find()'); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // Find the actual file name. It will always be the last element. |
| 167 | - $segments = explode( '/', $file ); |
|
| 168 | - $file = array_pop( $segments ); |
|
| 169 | - $file_ext = ( pathinfo( $file, PATHINFO_EXTENSION ) ) ? $file : $file . '.php'; |
|
| 167 | + $segments = explode('/', $file); |
|
| 168 | + $file = array_pop($segments); |
|
| 169 | + $file_ext = (pathinfo($file, PATHINFO_EXTENSION)) ? $file : $file.'.php'; |
|
| 170 | 170 | |
| 171 | 171 | // Put the pieces back to get the path. |
| 172 | - $path = implode( '/', $segments ) . '/'; |
|
| 173 | - $base = rtrim( $base, '/' ) . '/'; |
|
| 172 | + $path = implode('/', $segments).'/'; |
|
| 173 | + $base = rtrim($base, '/').'/'; |
|
| 174 | 174 | |
| 175 | 175 | // Look in any possible module locations based on the string segments. |
| 176 | 176 | $modules = array(); |
| 177 | - if ( ! empty( $module ) ) |
|
| 177 | + if ( ! empty($module)) |
|
| 178 | 178 | { |
| 179 | - $modules[ $module ] = $path; |
|
| 179 | + $modules[$module] = $path; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // Collect the modules from the segments |
| 183 | - if ( ! empty( $segments ) ) |
|
| 183 | + if ( ! empty($segments)) |
|
| 184 | 184 | { |
| 185 | - $modules[ array_shift( $segments ) ] = ltrim( implode( '/', $segments ) . '/', '/' ); |
|
| 185 | + $modules[array_shift($segments)] = ltrim(implode('/', $segments).'/', '/'); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - foreach ( self::$locations as $location ) |
|
| 188 | + foreach (self::$locations as $location) |
|
| 189 | 189 | { |
| 190 | 190 | |
| 191 | - foreach ( $modules as $module => $subpath ) |
|
| 191 | + foreach ($modules as $module => $subpath) |
|
| 192 | 192 | { |
| 193 | 193 | // Combine the elements to make an actual path to the file |
| 194 | - $fullpath = str_replace( '//', '/', "{$location}{$module}/{$base}{$subpath}" ); |
|
| 194 | + $fullpath = str_replace('//', '/', "{$location}{$module}/{$base}{$subpath}"); |
|
| 195 | 195 | |
| 196 | 196 | // If it starts with a '/' assume it's a full path already |
| 197 | - if ( substr( $path, 0, 1 ) == '/' && strlen( $path ) > 1 ) |
|
| 197 | + if (substr($path, 0, 1) == '/' && strlen($path) > 1) |
|
| 198 | 198 | { |
| 199 | 199 | $fullpath = $path; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // Libraries are a special consideration since they are |
| 203 | 203 | // frequently ucfirst. |
| 204 | - if ( $base == 'libraries/' AND is_file( $fullpath . ucfirst( $file_ext ) ) ) |
|
| 204 | + if ($base == 'libraries/' AND is_file($fullpath.ucfirst($file_ext))) |
|
| 205 | 205 | { |
| 206 | - return array( $fullpath, ucfirst( $file ) ); |
|
| 206 | + return array($fullpath, ucfirst($file)); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if ( is_file( $fullpath . $file_ext ) ) |
|
| 209 | + if (is_file($fullpath.$file_ext)) |
|
| 210 | 210 | { |
| 211 | - return array( $fullpath, $file ); |
|
| 211 | + return array($fullpath, $file); |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - return array( FALSE, $file ); |
|
| 216 | + return array(FALSE, $file); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | //-------------------------------------------------------------------- |
@@ -225,33 +225,33 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public static function listModules() |
| 227 | 227 | { |
| 228 | - if ( ! function_exists( 'directory_map' ) ) |
|
| 228 | + if ( ! function_exists('directory_map')) |
|
| 229 | 229 | { |
| 230 | - require BASEPATH . 'helpers/directory_helper.php'; |
|
| 230 | + require BASEPATH.'helpers/directory_helper.php'; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | $map = array(); |
| 234 | 234 | |
| 235 | - foreach ( self::$locations as $folder ) |
|
| 235 | + foreach (self::$locations as $folder) |
|
| 236 | 236 | { |
| 237 | 237 | |
| 238 | - $dirs = directory_map( $folder, 1 ); |
|
| 239 | - if ( ! is_array( $dirs ) ) |
|
| 238 | + $dirs = directory_map($folder, 1); |
|
| 239 | + if ( ! is_array($dirs)) |
|
| 240 | 240 | { |
| 241 | 241 | $dirs = array(); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - $map = array_merge( $map, $dirs ); |
|
| 244 | + $map = array_merge($map, $dirs); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // Clean out any html or php files |
| 248 | - if ( $count = count( $map ) ) |
|
| 248 | + if ($count = count($map)) |
|
| 249 | 249 | { |
| 250 | - for ( $i = 0; $i < $count; $i ++ ) |
|
| 250 | + for ($i = 0; $i < $count; $i++) |
|
| 251 | 251 | { |
| 252 | - if ( strpos( $map[ $i ], '.html' ) !== FALSE || strpos( $map[ $i ], '.php' ) !== FALSE ) |
|
| 252 | + if (strpos($map[$i], '.html') !== FALSE || strpos($map[$i], '.php') !== FALSE) |
|
| 253 | 253 | { |
| 254 | - unset( $map[ $i ] ); |
|
| 254 | + unset($map[$i]); |
|
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | } |
@@ -278,17 +278,17 @@ discard block |
||
| 278 | 278 | * |
| 279 | 279 | * @return boolean |
| 280 | 280 | */ |
| 281 | - public static function controllerExists($controller, $module ) |
|
| 281 | + public static function controllerExists($controller, $module) |
|
| 282 | 282 | { |
| 283 | - if (! is_string($module) || ! is_string($controller)) |
|
| 283 | + if ( ! is_string($module) || ! is_string($controller)) |
|
| 284 | 284 | { |
| 285 | 285 | throw new \InvalidArgumentException('Argument must be a string for Modules::controllerExists()'); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Look in all module paths |
| 289 | - foreach ( self::$locations as $folder ) |
|
| 289 | + foreach (self::$locations as $folder) |
|
| 290 | 290 | { |
| 291 | - if ( is_file( "{$folder}{$module}/controllers/{$controller}.php" ) ) |
|
| 291 | + if (is_file("{$folder}{$module}/controllers/{$controller}.php")) |
|
| 292 | 292 | { |
| 293 | 293 | return TRUE; |
| 294 | 294 | } |
@@ -308,18 +308,18 @@ discard block |
||
| 308 | 308 | * |
| 309 | 309 | * @return string The full path to the file, or false if the file was not found |
| 310 | 310 | */ |
| 311 | - public static function filePath( $module, $folder, $file ) |
|
| 311 | + public static function filePath($module, $folder, $file) |
|
| 312 | 312 | { |
| 313 | - if (! is_string($module) || ! is_string($folder) || ! is_string($file)) |
|
| 313 | + if ( ! is_string($module) || ! is_string($folder) || ! is_string($file)) |
|
| 314 | 314 | { |
| 315 | 315 | throw new \InvalidArgumentException('Argument must be a string for Modules::filePath()'); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - foreach ( self::$locations as $location ) |
|
| 318 | + foreach (self::$locations as $location) |
|
| 319 | 319 | { |
| 320 | 320 | $test_file = "{$location}{$module}/{$folder}/{$file}"; |
| 321 | 321 | |
| 322 | - if ( is_file( $test_file ) ) |
|
| 322 | + if (is_file($test_file)) |
|
| 323 | 323 | { |
| 324 | 324 | return $test_file; |
| 325 | 325 | } |
@@ -338,23 +338,23 @@ discard block |
||
| 338 | 338 | * |
| 339 | 339 | * @return string The path, relative to the front controller, or false if the folder was not found |
| 340 | 340 | */ |
| 341 | - public static function path( $module, $folder = null ) |
|
| 341 | + public static function path($module, $folder = null) |
|
| 342 | 342 | { |
| 343 | - if (! is_string($module) || (! is_string($folder) && !is_null($folder) ) ) |
|
| 343 | + if ( ! is_string($module) || ( ! is_string($folder) && ! is_null($folder))) |
|
| 344 | 344 | { |
| 345 | 345 | throw new \InvalidArgumentException('Argument must be a string for Modules::path()'); |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - foreach ( self::$locations as $module_folder ) |
|
| 348 | + foreach (self::$locations as $module_folder) |
|
| 349 | 349 | { |
| 350 | - if ( is_dir( $module_folder . $module ) ) |
|
| 350 | + if (is_dir($module_folder.$module)) |
|
| 351 | 351 | { |
| 352 | - if ( ! empty( $folder ) && is_dir( "{$module_folder}{$module}/{$folder}" ) ) |
|
| 352 | + if ( ! empty($folder) && is_dir("{$module_folder}{$module}/{$folder}")) |
|
| 353 | 353 | { |
| 354 | 354 | return "{$module_folder}{$module}/{$folder}/"; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - return $module_folder . $module . '/'; |
|
| 357 | + return $module_folder.$module.'/'; |
|
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
@@ -372,58 +372,58 @@ discard block |
||
| 372 | 372 | * |
| 373 | 373 | * @return array An associative array, like: array('module_name' => array('folder' => array('file1', 'file2'))) |
| 374 | 374 | */ |
| 375 | - public static function files( $module_name = NULL, $module_folder = NULL ) |
|
| 375 | + public static function files($module_name = NULL, $module_folder = NULL) |
|
| 376 | 376 | { |
| 377 | - if ( ! function_exists( 'directory_map' ) ) |
|
| 377 | + if ( ! function_exists('directory_map')) |
|
| 378 | 378 | { |
| 379 | - require BASEPATH . 'helpers/directory_helper.php'; |
|
| 379 | + require BASEPATH.'helpers/directory_helper.php'; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | $files = array(); |
| 383 | 383 | |
| 384 | - foreach ( self::$locations as $path ) |
|
| 384 | + foreach (self::$locations as $path) |
|
| 385 | 385 | { |
| 386 | 386 | |
| 387 | 387 | // Only map the whole modules directory if $module_name isn't passed |
| 388 | - if ( empty( $module_name ) ) |
|
| 388 | + if (empty($module_name)) |
|
| 389 | 389 | { |
| 390 | - $modules = directory_map( $path ); |
|
| 390 | + $modules = directory_map($path); |
|
| 391 | 391 | } |
| 392 | 392 | // Only map the $module_name directory if it exists |
| 393 | - elseif ( is_dir( $path . $module_name ) ) |
|
| 393 | + elseif (is_dir($path.$module_name)) |
|
| 394 | 394 | { |
| 395 | - $path = $path . $module_name; |
|
| 396 | - $modules[ $module_name ] = directory_map( $path ); |
|
| 395 | + $path = $path.$module_name; |
|
| 396 | + $modules[$module_name] = directory_map($path); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // If the element is not an array, it's a file, so ignore it. |
| 400 | 400 | // Otherwise it is assumed to be a module. |
| 401 | - if ( empty( $modules ) || ! is_array( $modules ) ) |
|
| 401 | + if (empty($modules) || ! is_array($modules)) |
|
| 402 | 402 | { |
| 403 | 403 | continue; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - foreach ( $modules as $mod_name => $values ) |
|
| 406 | + foreach ($modules as $mod_name => $values) |
|
| 407 | 407 | { |
| 408 | - if ( is_array( $values ) ) |
|
| 408 | + if (is_array($values)) |
|
| 409 | 409 | { |
| 410 | 410 | // Add just the specified folder for this module |
| 411 | - if ( ! empty( $module_folder ) && isset( $values[ $module_folder .'/' ] ) && count( $values[ $module_folder .'/' ] ) ) |
|
| 411 | + if ( ! empty($module_folder) && isset($values[$module_folder.'/']) && count($values[$module_folder.'/'])) |
|
| 412 | 412 | { |
| 413 | - $files[ $mod_name ] = array( |
|
| 414 | - $module_folder .'/' => $values[ $module_folder .'/' ], |
|
| 413 | + $files[$mod_name] = array( |
|
| 414 | + $module_folder.'/' => $values[$module_folder.'/'], |
|
| 415 | 415 | ); |
| 416 | 416 | } |
| 417 | 417 | // Add the entire module |
| 418 | - elseif ( empty( $module_folder ) ) |
|
| 418 | + elseif (empty($module_folder)) |
|
| 419 | 419 | { |
| 420 | - $files[ $mod_name ] = $values; |
|
| 420 | + $files[$mod_name] = $values; |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - return count( $files ) ? $files : null; |
|
| 426 | + return count($files) ? $files : null; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | //-------------------------------------------------------------------- |
@@ -436,37 +436,37 @@ discard block |
||
| 436 | 436 | * |
| 437 | 437 | * @return array |
| 438 | 438 | */ |
| 439 | - public static function parse_routes( $module, $uri ) |
|
| 439 | + public static function parse_routes($module, $uri) |
|
| 440 | 440 | { |
| 441 | 441 | |
| 442 | 442 | /* load the route file */ |
| 443 | - if ( ! isset( self::$routes[ $module ] ) ) |
|
| 443 | + if ( ! isset(self::$routes[$module])) |
|
| 444 | 444 | { |
| 445 | - if ( list( $path ) = self::find( 'routes', $module, 'config/' ) AND $path ) |
|
| 445 | + if (list($path) = self::find('routes', $module, 'config/') AND $path) |
|
| 446 | 446 | { |
| 447 | - self::$routes[ $module ] = self::load_file( 'routes', $path, 'route' ); |
|
| 447 | + self::$routes[$module] = self::load_file('routes', $path, 'route'); |
|
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - if ( ! isset( self::$routes[ $module ] ) ) |
|
| 451 | + if ( ! isset(self::$routes[$module])) |
|
| 452 | 452 | { |
| 453 | 453 | return; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /* parse module routes */ |
| 457 | - foreach ( self::$routes[ $module ] as $key => $val ) |
|
| 457 | + foreach (self::$routes[$module] as $key => $val) |
|
| 458 | 458 | { |
| 459 | 459 | |
| 460 | - $key = str_replace( array( ':any', ':num' ), array( '.+', '[0-9]+' ), $key ); |
|
| 460 | + $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); |
|
| 461 | 461 | |
| 462 | - if ( preg_match( '#^' . $key . '$#', $uri ) ) |
|
| 462 | + if (preg_match('#^'.$key.'$#', $uri)) |
|
| 463 | 463 | { |
| 464 | - if ( strpos( $val, '$' ) !== FALSE AND strpos( $key, '(' ) !== FALSE ) |
|
| 464 | + if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) |
|
| 465 | 465 | { |
| 466 | - $val = preg_replace( '#^' . $key . '$#', $val, $uri ); |
|
| 466 | + $val = preg_replace('#^'.$key.'$#', $val, $uri); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - return explode( '/', $module . '/' . $val ); |
|
| 469 | + return explode('/', $module.'/'.$val); |
|
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | } |
@@ -482,17 +482,17 @@ discard block |
||
| 482 | 482 | * |
| 483 | 483 | * @param $class |
| 484 | 484 | */ |
| 485 | - public static function autoload( $class ) |
|
| 485 | + public static function autoload($class) |
|
| 486 | 486 | { |
| 487 | 487 | |
| 488 | 488 | /* don't autoload CI_ prefixed classes or those using the config subclass_prefix */ |
| 489 | - if ( strstr( $class, 'CI_' ) OR strstr( $class, config_item( 'subclass_prefix' ) ) ) |
|
| 489 | + if (strstr($class, 'CI_') OR strstr($class, config_item('subclass_prefix'))) |
|
| 490 | 490 | { |
| 491 | 491 | return; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | /* autoload core classes */ |
| 495 | - if ( is_file( $location = APPPATH . 'core/' . $class . '.php' ) ) |
|
| 495 | + if (is_file($location = APPPATH.'core/'.$class.'.php')) |
|
| 496 | 496 | { |
| 497 | 497 | include_once $location; |
| 498 | 498 | |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /* autoload library classes */ |
| 503 | - if ( is_file( $location = APPPATH . 'libraries/' . $class . '.php' ) ) |
|
| 503 | + if (is_file($location = APPPATH.'libraries/'.$class.'.php')) |
|
| 504 | 504 | { |
| 505 | 505 | include_once $location; |
| 506 | 506 | |
@@ -44,8 +44,7 @@ discard block |
||
| 44 | 44 | if ( is_array( $config['modules_locations'] ) ) |
| 45 | 45 | { |
| 46 | 46 | Modules::$locations = $config['modules_locations']; |
| 47 | - } |
|
| 48 | - else |
|
| 47 | + } else |
|
| 49 | 48 | { |
| 50 | 49 | Modules::$locations = array( APPPATH . 'modules/' => '../modules/' ); |
| 51 | 50 | } |
@@ -122,8 +121,7 @@ discard block |
||
| 122 | 121 | return $result; |
| 123 | 122 | } |
| 124 | 123 | include_once $location; |
| 125 | - } |
|
| 126 | - else |
|
| 124 | + } else |
|
| 127 | 125 | { |
| 128 | 126 | |
| 129 | 127 | /* load config or language array */ |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | * // Returns http://mysite.com/news |
| 195 | 195 | * site_url( Route::named('blog') ); |
| 196 | 196 | * |
| 197 | - * @param [type] $name [description] |
|
| 198 | - * @return [type] [description] |
|
| 197 | + * @param string $name [description] |
|
| 198 | + * @return string [description] |
|
| 199 | 199 | */ |
| 200 | 200 | public static function named($name) |
| 201 | 201 | { |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | /** |
| 280 | 280 | * Specifies a route that is only available to GET requests. |
| 281 | 281 | * |
| 282 | - * @param $from |
|
| 283 | - * @param $to |
|
| 282 | + * @param string $from |
|
| 283 | + * @param string $to |
|
| 284 | 284 | * @param array $options |
| 285 | 285 | */ |
| 286 | 286 | public function get($from, $to, $options = []) |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | /** |
| 296 | 296 | * Specifies a route that is only available to POST requests. |
| 297 | 297 | * |
| 298 | - * @param $from |
|
| 299 | - * @param $to |
|
| 298 | + * @param string $from |
|
| 299 | + * @param string $to |
|
| 300 | 300 | * @param array $options |
| 301 | 301 | */ |
| 302 | 302 | public function post($from, $to, $options = []) |
@@ -311,8 +311,8 @@ discard block |
||
| 311 | 311 | /** |
| 312 | 312 | * Specifies a route that is only available to PUT requests. |
| 313 | 313 | * |
| 314 | - * @param $from |
|
| 315 | - * @param $to |
|
| 314 | + * @param string $from |
|
| 315 | + * @param string $to |
|
| 316 | 316 | * @param array $options |
| 317 | 317 | */ |
| 318 | 318 | public function put($from, $to, $options = []) |
@@ -327,8 +327,8 @@ discard block |
||
| 327 | 327 | /** |
| 328 | 328 | * Specifies a route that is only available to DELETE requests. |
| 329 | 329 | * |
| 330 | - * @param $from |
|
| 331 | - * @param $to |
|
| 330 | + * @param string $from |
|
| 331 | + * @param string $to |
|
| 332 | 332 | * @param array $options |
| 333 | 333 | */ |
| 334 | 334 | public function delete($from, $to, $options = []) |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | /** |
| 376 | 376 | * Specifies a route that is only available to OPTIONS requests. |
| 377 | 377 | * |
| 378 | - * @param $from |
|
| 379 | - * @param $to |
|
| 378 | + * @param string $from |
|
| 379 | + * @param string $to |
|
| 380 | 380 | * @param array $options |
| 381 | 381 | */ |
| 382 | 382 | public function options($from, $to, $options = []) |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | * Limits the routes to a specified ENVIRONMENT or they won't run. |
| 501 | 501 | * |
| 502 | 502 | * @param $env |
| 503 | - * @param callable $callback |
|
| 503 | + * @param \Closure $callback |
|
| 504 | 504 | * |
| 505 | 505 | * @return bool|null |
| 506 | 506 | */ |
@@ -43,644 +43,644 @@ |
||
| 43 | 43 | class Route |
| 44 | 44 | { |
| 45 | 45 | |
| 46 | - // Our routes, ripe for the picking. |
|
| 47 | - public $routes = array(); |
|
| 48 | - |
|
| 49 | - // Holds key/value pairs of named routes |
|
| 50 | - public static $names = array(); |
|
| 51 | - |
|
| 52 | - // Used for grouping routes together. |
|
| 53 | - public $group = null; |
|
| 54 | - |
|
| 55 | - // Holds the 'areas' of the site. |
|
| 56 | - public static $areas = array(); |
|
| 57 | - |
|
| 58 | - // The default controller to use in case |
|
| 59 | - // 'default_controller' is not in the routes file. |
|
| 60 | - protected $default_home = 'home'; |
|
| 61 | - |
|
| 62 | - // The default constraint to use in route building |
|
| 63 | - protected $default_constraint = 'any'; |
|
| 64 | - |
|
| 65 | - protected $constraints = [ |
|
| 66 | - 'any' => '(:any)', |
|
| 67 | - 'num' => '(:num)', |
|
| 68 | - 'id' => '(:num)', |
|
| 69 | - 'name' => "([a-zA-Z']+)" |
|
| 70 | - ]; |
|
| 71 | - |
|
| 72 | - protected $current_subdomain = null; |
|
| 73 | - |
|
| 74 | - //-------------------------------------------------------------------- |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Combines the routes that we've defined with the Route class with the |
|
| 78 | - * routes passed in. This is intended to be used after all routes have been |
|
| 79 | - * defined to merge CI's default $route array with our routes. |
|
| 80 | - * |
|
| 81 | - * Example: |
|
| 82 | - * $route['default_controller'] = 'home'; |
|
| 83 | - * Route::resource('posts'); |
|
| 84 | - * $route = Route::map($route); |
|
| 85 | - * |
|
| 86 | - * @param array $routes |
|
| 87 | - * @internal param array $route The array to merge |
|
| 88 | - * @return array The merge route array. |
|
| 89 | - */ |
|
| 90 | - public function map($routes = array()) |
|
| 91 | - { |
|
| 92 | - $controller = isset($routes['default_controller']) ? $routes['default_controller'] : $this->default_home; |
|
| 93 | - |
|
| 94 | - $routes = array_merge($routes, $this->routes); |
|
| 95 | - |
|
| 96 | - foreach ($routes as $from => $to) { |
|
| 97 | - $routes[$from] = str_ireplace('{default_controller}', $controller, $to); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return $routes; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - //-------------------------------------------------------------------- |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * A single point to the basic routing. Can be used in place of CI's $route |
|
| 107 | - * array if desired. Used internally by many of the methods. |
|
| 108 | - * |
|
| 109 | - * Available options are currently: |
|
| 110 | - * 'as' - remembers the route via a name that can be called outside of it. |
|
| 111 | - * 'offset' - Offsets and parameters ($1, $2, etc) in routes by the specified amount. |
|
| 112 | - * Useful while doing versioning of API's, etc. |
|
| 113 | - * |
|
| 114 | - * Example: |
|
| 115 | - * $route->any('news', 'posts/index'); |
|
| 116 | - * |
|
| 117 | - * @param string $from |
|
| 118 | - * @param string $to |
|
| 119 | - * @param array $options |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - public function any($from, $to, $options = array()) |
|
| 123 | - { |
|
| 124 | - $this->create($from, $to, $options); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - //-------------------------------------------------------------------- |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Sets the default constraint to be used in the system. Typically |
|
| 131 | - * for use with the 'resources' method. |
|
| 132 | - * |
|
| 133 | - * @param $constraint |
|
| 134 | - */ |
|
| 135 | - public function setDefaultConstraint($constraint) |
|
| 136 | - { |
|
| 137 | - if (array_key_exists($constraint, $this->constraints)) { |
|
| 138 | - $this->default_constraint = $constraint; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - //-------------------------------------------------------------------- |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Registers a new constraint to be used internally. Useful for creating |
|
| 146 | - * very specific regex patterns, or simply to allow your routes to be |
|
| 147 | - * a tad more readable. |
|
| 148 | - * |
|
| 149 | - * Example: |
|
| 150 | - * $route->registerConstraint('hero', '(^.*)'); |
|
| 151 | - * |
|
| 152 | - * $route->any('home/{hero}', 'heroes/journey'); |
|
| 153 | - * |
|
| 154 | - * // Route then looks like: |
|
| 155 | - * $route['home/(^.*)'] = 'heroes/journey'; |
|
| 156 | - * |
|
| 157 | - * @param $name |
|
| 158 | - * @param $pattern |
|
| 159 | - * @param bool $overwrite |
|
| 160 | - */ |
|
| 161 | - public function registerConstraint($name, $pattern, $overwrite = false) |
|
| 162 | - { |
|
| 163 | - // Ensure consistency |
|
| 164 | - $name = trim($name, '{} '); |
|
| 165 | - $pattern = '(' . trim($pattern, '() ') . ')'; |
|
| 166 | - |
|
| 167 | - // Not here? Add it and leave... |
|
| 168 | - if (! array_key_exists($name, $this->constraints)) { |
|
| 169 | - $this->constraints[$name] = $pattern; |
|
| 170 | - |
|
| 171 | - return; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // Here? Then it exists. Should we overwrite it? |
|
| 175 | - if ($overwrite) { |
|
| 176 | - $this->constraints[$name] = $pattern; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - //-------------------------------------------------------------------- |
|
| 181 | - |
|
| 182 | - //-------------------------------------------------------------------- |
|
| 183 | - // Named Routes |
|
| 184 | - //-------------------------------------------------------------------- |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Returns the value of a named route. Useful for getting named |
|
| 188 | - * routes for use while building with site_url() or in templates |
|
| 189 | - * where you don't need to instantiate the route class. |
|
| 190 | - * |
|
| 191 | - * Example: |
|
| 192 | - * $route->any('news', 'posts/index', ['as' => 'blog']); |
|
| 193 | - * |
|
| 194 | - * // Returns http://mysite.com/news |
|
| 195 | - * site_url( Route::named('blog') ); |
|
| 196 | - * |
|
| 197 | - * @param [type] $name [description] |
|
| 198 | - * @return [type] [description] |
|
| 199 | - */ |
|
| 200 | - public static function named($name) |
|
| 201 | - { |
|
| 202 | - if (isset(self::$names[$name])) { |
|
| 203 | - return self::$names[$name]; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return null; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - //-------------------------------------------------------------------- |
|
| 210 | - |
|
| 211 | - //-------------------------------------------------------------------- |
|
| 212 | - // Grouping Routes |
|
| 213 | - //-------------------------------------------------------------------- |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Group a series of routes under a single URL segment. This is handy |
|
| 217 | - * for grouping items into an admin area, like: |
|
| 218 | - * |
|
| 219 | - * Example: |
|
| 220 | - * $route->group('admin', function() { |
|
| 221 | - * $route->resources('users'); |
|
| 222 | - * }); |
|
| 223 | - * |
|
| 224 | - * @param string $name The name to group/prefix the routes with. |
|
| 225 | - * @param \Closure $callback An anonymous function that allows you route inside of this group. |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - public function group($name, \Closure $callback) |
|
| 229 | - { |
|
| 230 | - $old_group = $this->group; |
|
| 231 | - |
|
| 232 | - // To register a route, we'll set a flag so that our router |
|
| 233 | - // so it will see the groupname. |
|
| 234 | - $this->group = ltrim($old_group . '/' . $name, '/'); |
|
| 235 | - |
|
| 236 | - call_user_func($callback); |
|
| 237 | - |
|
| 238 | - // Make sure to clear the group name so we don't accidentally |
|
| 239 | - // group any ones we didn't want to. |
|
| 240 | - $this->group = $old_group; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - //-------------------------------------------------------------------- |
|
| 244 | - |
|
| 245 | - //-------------------------------------------------------------------- |
|
| 246 | - // HTTP Verb-based routing |
|
| 247 | - //-------------------------------------------------------------------- |
|
| 248 | - // Routing works here because, as the routes config file is read in, |
|
| 249 | - // the various HTTP verb-based routes will only be added to the in-memory |
|
| 250 | - // routes if it is a call that should respond to that verb. |
|
| 251 | - // |
|
| 252 | - // The options array is typically used to pass in an 'as' or var, but may |
|
| 253 | - // be expanded in the future. See the docblock for 'any' method above for |
|
| 254 | - // current list of globally available options. |
|
| 255 | - // |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Specifies a single route to match for multiple HTTP Verbs. |
|
| 259 | - * |
|
| 260 | - * Example: |
|
| 261 | - * $route->match( ['get', 'post'], 'users/(:num)', 'users/$1); |
|
| 262 | - * |
|
| 263 | - * @param array $verbs |
|
| 264 | - * @param $from |
|
| 265 | - * @param $to |
|
| 266 | - * @param array $options |
|
| 267 | - */ |
|
| 268 | - public function match($verbs = [], $from, $to, $options = []) |
|
| 269 | - { |
|
| 270 | - foreach ($verbs as $verb) { |
|
| 271 | - $verb = strtolower($verb); |
|
| 272 | - |
|
| 273 | - $this->{$verb}($from, $to, $options); |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - //-------------------------------------------------------------------- |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Specifies a route that is only available to GET requests. |
|
| 281 | - * |
|
| 282 | - * @param $from |
|
| 283 | - * @param $to |
|
| 284 | - * @param array $options |
|
| 285 | - */ |
|
| 286 | - public function get($from, $to, $options = []) |
|
| 287 | - { |
|
| 288 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') { |
|
| 289 | - $this->create($from, $to, $options); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - //-------------------------------------------------------------------- |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Specifies a route that is only available to POST requests. |
|
| 297 | - * |
|
| 298 | - * @param $from |
|
| 299 | - * @param $to |
|
| 300 | - * @param array $options |
|
| 301 | - */ |
|
| 302 | - public function post($from, $to, $options = []) |
|
| 303 | - { |
|
| 304 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 305 | - $this->create($from, $to, $options); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - //-------------------------------------------------------------------- |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Specifies a route that is only available to PUT requests. |
|
| 313 | - * |
|
| 314 | - * @param $from |
|
| 315 | - * @param $to |
|
| 316 | - * @param array $options |
|
| 317 | - */ |
|
| 318 | - public function put($from, $to, $options = []) |
|
| 319 | - { |
|
| 320 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PUT') { |
|
| 321 | - $this->create($from, $to, $options); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - //-------------------------------------------------------------------- |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Specifies a route that is only available to DELETE requests. |
|
| 329 | - * |
|
| 330 | - * @param $from |
|
| 331 | - * @param $to |
|
| 332 | - * @param array $options |
|
| 333 | - */ |
|
| 334 | - public function delete($from, $to, $options = []) |
|
| 335 | - { |
|
| 336 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'DELETE') { |
|
| 337 | - $this->create($from, $to, $options); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - //-------------------------------------------------------------------- |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Specifies a route that is only available to HEAD requests. |
|
| 345 | - * |
|
| 346 | - * @param $from |
|
| 347 | - * @param $to |
|
| 348 | - * @param array $options |
|
| 349 | - */ |
|
| 350 | - public function head($from, $to, $options = []) |
|
| 351 | - { |
|
| 352 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') { |
|
| 353 | - $this->create($from, $to, $options); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - //-------------------------------------------------------------------- |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Specifies a route that is only available to PATCH requests. |
|
| 361 | - * |
|
| 362 | - * @param $from |
|
| 363 | - * @param $to |
|
| 364 | - * @param array $options |
|
| 365 | - */ |
|
| 366 | - public function patch($from, $to, $options = []) |
|
| 367 | - { |
|
| 368 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PATCH') { |
|
| 369 | - $this->create($from, $to, $options); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - //-------------------------------------------------------------------- |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Specifies a route that is only available to OPTIONS requests. |
|
| 377 | - * |
|
| 378 | - * @param $from |
|
| 379 | - * @param $to |
|
| 380 | - * @param array $options |
|
| 381 | - */ |
|
| 382 | - public function options($from, $to, $options = []) |
|
| 383 | - { |
|
| 384 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') { |
|
| 385 | - $this->create($from, $to, $options); |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - //-------------------------------------------------------------------- |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Creates a collections of HTTP-verb based routes for a controller. |
|
| 393 | - * |
|
| 394 | - * Possible Options: |
|
| 395 | - * 'controller' - Customize the name of the controller used in the 'to' route |
|
| 396 | - * 'module' - Prepend a module name to the generate 'to' routes |
|
| 397 | - * 'constraint' - The regex used by the Router. Defaults to '(:any)' |
|
| 398 | - * |
|
| 399 | - * Example: |
|
| 400 | - * $route->resources('photos'); |
|
| 401 | - * |
|
| 402 | - * // Generates the following routes: |
|
| 403 | - * HTTP Verb | Path | Action | Used for... |
|
| 404 | - * ----------+-------------+---------------+----------------- |
|
| 405 | - * GET /photos index display a list of photos |
|
| 406 | - * GET /photos/new creation_form return an HTML form for creating a new photo |
|
| 407 | - * GET /photos/{id} show display a specific photo |
|
| 408 | - * GET /photos/{id}/edit editing_form return an HTML form for editing the photo |
|
| 409 | - * POST /photos create create a new photo |
|
| 410 | - * PUT /photos/{id} update update an existing photo |
|
| 411 | - * DELETE /photos/{id}/delete delete delete an existing photo |
|
| 412 | - * |
|
| 413 | - * @param string $name The name of the controller to route to. |
|
| 414 | - * @param array $options An list of possible ways to customize the routing. |
|
| 415 | - */ |
|
| 416 | - public function resources($name, $options = []) |
|
| 417 | - { |
|
| 418 | - // In order to allow customization of the route the |
|
| 419 | - // resources are sent to, we need to have a new name |
|
| 420 | - // to store the values in. |
|
| 421 | - $new_name = $name; |
|
| 422 | - |
|
| 423 | - // If a new controller is specified, then we replace the |
|
| 424 | - // $name value with the name of the new controller. |
|
| 425 | - if (isset($options['controller'])) { |
|
| 426 | - $new_name = $options['controller']; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // If a new module was specified, simply put that path |
|
| 430 | - // in front of the controller. |
|
| 431 | - if (isset($options['module'])) { |
|
| 432 | - $new_name = $options['module'] . '/' . $new_name; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // In order to allow customization of allowed id values |
|
| 436 | - // we need someplace to store them. |
|
| 437 | - $id = isset($this->constraints[$this->default_constraint]) ? $this->constraints[$this->default_constraint] : |
|
| 438 | - '(:any)'; |
|
| 439 | - |
|
| 440 | - if (isset($options['constraint'])) { |
|
| 441 | - $id = $options['constraint']; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - $this->get($name, $new_name . '/list_all', $options); |
|
| 445 | - $this->get($name . '/' . $id, $new_name . '/show/$1', $options); |
|
| 446 | - $this->post($name, $new_name . '/create', $options); |
|
| 447 | - $this->put($name . '/' . $id, $new_name . '/update/$1', $options); |
|
| 448 | - $this->delete($name . '/' . $id, $new_name . '/delete/$1', $options); |
|
| 449 | - $this->options($name, $new_name . '/index', $options); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - //-------------------------------------------------------------------- |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Lets the system know about different 'areas' within the site, like |
|
| 456 | - * the admin area, that maps to certain controllers. |
|
| 457 | - * |
|
| 458 | - * @param string $area The name of the area. |
|
| 459 | - * @param string $controller The controller name to look for. |
|
| 460 | - * @param $options |
|
| 461 | - */ |
|
| 462 | - public function area($area, $controller = null, $options = []) |
|
| 463 | - { |
|
| 464 | - // No controller? Match the area name. |
|
| 465 | - $controller = is_null($controller) ? $area : $controller; |
|
| 466 | - |
|
| 467 | - // Save the area so we can recognize it later. |
|
| 468 | - self::$areas[$area] = $controller; |
|
| 469 | - |
|
| 470 | - // Create routes for this area. |
|
| 471 | - $this->create($area . '/(:any)/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4/$5', $options); |
|
| 472 | - $this->create($area . '/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4', $options); |
|
| 473 | - $this->create($area . '/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3', $options); |
|
| 474 | - $this->create($area . '/(:any)/(:any)', '$1/' . $controller . '/$2', $options); |
|
| 475 | - $this->create($area . '/(:any)', '$1/' . $controller, $options); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - //-------------------------------------------------------------------- |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * Returns the name of the area based on the controller name. |
|
| 482 | - * |
|
| 483 | - * @param string $controller The name of the controller |
|
| 484 | - * @return string The name of the corresponding area |
|
| 485 | - */ |
|
| 486 | - public static function getAreaName($controller) |
|
| 487 | - { |
|
| 488 | - foreach (self::$areas as $area => $cont) { |
|
| 489 | - if ($controller == $cont) { |
|
| 490 | - return $area; |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return null; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - //-------------------------------------------------------------------- |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Limits the routes to a specified ENVIRONMENT or they won't run. |
|
| 501 | - * |
|
| 502 | - * @param $env |
|
| 503 | - * @param callable $callback |
|
| 504 | - * |
|
| 505 | - * @return bool|null |
|
| 506 | - */ |
|
| 507 | - public function environment($env, \Closure $callback) |
|
| 508 | - { |
|
| 509 | - if (ENVIRONMENT == $env) |
|
| 510 | - { |
|
| 511 | - call_user_func($callback); |
|
| 512 | - return true; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return null; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - //-------------------------------------------------------------------- |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Allows you to easily block access to any number of routes by setting |
|
| 524 | - * that route to an empty path (''). |
|
| 525 | - * |
|
| 526 | - * Example: |
|
| 527 | - * Route::block('posts', 'photos/(:num)'); |
|
| 528 | - * |
|
| 529 | - * // Same as... |
|
| 530 | - * $route['posts'] = ''; |
|
| 531 | - * $route['photos/(:num)'] = ''; |
|
| 532 | - */ |
|
| 533 | - public function block() |
|
| 534 | - { |
|
| 535 | - $paths = func_get_args(); |
|
| 536 | - |
|
| 537 | - if (! is_array($paths) || ! count($paths)) { |
|
| 538 | - return; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - foreach ($paths as $path) { |
|
| 542 | - $this->create($path, ''); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - //-------------------------------------------------------------------- |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Empties all named and un-named routes from the system. |
|
| 550 | - * |
|
| 551 | - * @return void |
|
| 552 | - */ |
|
| 553 | - public function reset() |
|
| 554 | - { |
|
| 555 | - $this->routes = array(); |
|
| 556 | - $this->names = array(); |
|
| 557 | - $this->group = null; |
|
| 558 | - self::$areas = array(); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - //-------------------------------------------------------------------- |
|
| 562 | - |
|
| 563 | - //-------------------------------------------------------------------- |
|
| 564 | - // Private Methods |
|
| 565 | - //-------------------------------------------------------------------- |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Does the heavy lifting of creating an actual route. You must specify |
|
| 569 | - * the request method(s) that this route will work for. They can be separated |
|
| 570 | - * by a pipe character "|" if there is more than one. |
|
| 571 | - * |
|
| 572 | - * @param string $from |
|
| 573 | - * @param array $to |
|
| 574 | - * @param array $options |
|
| 575 | - * |
|
| 576 | - * @return array The built route. |
|
| 577 | - */ |
|
| 578 | - private function create($from, $to, $options = array()) |
|
| 579 | - { |
|
| 580 | - $prefix = is_null($this->group) ? '' : $this->group . '/'; |
|
| 581 | - |
|
| 582 | - $from = $prefix . $from; |
|
| 583 | - |
|
| 584 | - // Are we saving the name for this one? |
|
| 585 | - if (isset($options['as']) && !empty($options['as'])) { |
|
| 586 | - self::$names[$options['as']] = $from; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - // Limiting to subdomains? |
|
| 590 | - if (isset($options['subdomain']) && !empty($options['subdomain'])) { |
|
| 591 | - // If we don't match the current subdomain, then |
|
| 592 | - // we don't need to add the route. |
|
| 593 | - if (!$this->checkSubdomains($options['subdomain'])) { |
|
| 594 | - return; |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - // Are we offsetting the parameters? |
|
| 599 | - // If so, take care of them here in one |
|
| 600 | - // fell swoop. |
|
| 601 | - if (isset($options['offset'])) { |
|
| 602 | - // Get a constant string to work with. |
|
| 603 | - $to = preg_replace('/(\$\d+)/', '$X', $to); |
|
| 604 | - |
|
| 605 | - for ($i = (int)$options['offset'] + 1; $i < (int)$options['offset'] + 7; $i ++) { |
|
| 606 | - $to = preg_replace_callback( |
|
| 607 | - '/\$X/', |
|
| 608 | - function ($m) use ($i) { |
|
| 609 | - return '$' . $i; |
|
| 610 | - }, |
|
| 611 | - $to, |
|
| 612 | - 1 |
|
| 613 | - ); |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - // Convert any custom constraints to the CI/pattern equivalent |
|
| 618 | - foreach ($this->constraints as $name => $pattern) { |
|
| 619 | - $from = str_replace('{' . $name . '}', $pattern, $from); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - $this->routes[$from] = $to; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - //-------------------------------------------------------------------- |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Compares the subdomain(s) passed in against the current subdomain |
|
| 629 | - * on this page request. |
|
| 630 | - * |
|
| 631 | - * @param $subdomains |
|
| 632 | - * @return bool |
|
| 633 | - */ |
|
| 634 | - private function checkSubdomains($subdomains) |
|
| 635 | - { |
|
| 636 | - if (is_null($this->current_subdomain)) { |
|
| 637 | - $this->determineCurrentSubdomain(); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - if (!is_array($subdomains)) { |
|
| 641 | - $subdomains = array($subdomains); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - $matched = false; |
|
| 645 | - |
|
| 646 | - array_walk( |
|
| 647 | - $subdomains, |
|
| 648 | - function ($subdomain) use (&$matched) { |
|
| 649 | - if ($subdomain == $this->current_subdomain || $subdomain == '*') { |
|
| 650 | - $matched = true; |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - ); |
|
| 654 | - |
|
| 655 | - return $matched; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - //-------------------------------------------------------------------- |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Examines the HTTP_HOST to get a best match for the subdomain. It |
|
| 662 | - * won't be perfect, but should work for our needs. |
|
| 663 | - */ |
|
| 664 | - private function determineCurrentSubdomain() |
|
| 665 | - { |
|
| 666 | - $parsedUrl = parse_url($_SERVER['HTTP_HOST']); |
|
| 667 | - |
|
| 668 | - $host = explode('.', $parsedUrl['host']); |
|
| 669 | - |
|
| 670 | - // If we only have 2 parts, then we don't have a subdomain. |
|
| 671 | - // This won't be totally accurate, since URL's like example.co.uk |
|
| 672 | - // would still pass, but it helps to separate the chaff... |
|
| 673 | - if (!is_array($host) || count($host) == 2) { |
|
| 674 | - // Set it to false so we don't make it back here again. |
|
| 675 | - $this->current_subdomain = false; |
|
| 676 | - return; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - // Now, we'll simply take the first element of the array. This should |
|
| 680 | - // be fine even in cases like example.co.uk, since they won't be looking |
|
| 681 | - // for 'example' when they try to match the subdomain, in most all cases. |
|
| 682 | - $this->current_subdomain = array_shift($host); |
|
| 683 | - } |
|
| 684 | - //-------------------------------------------------------------------- |
|
| 46 | + // Our routes, ripe for the picking. |
|
| 47 | + public $routes = array(); |
|
| 48 | + |
|
| 49 | + // Holds key/value pairs of named routes |
|
| 50 | + public static $names = array(); |
|
| 51 | + |
|
| 52 | + // Used for grouping routes together. |
|
| 53 | + public $group = null; |
|
| 54 | + |
|
| 55 | + // Holds the 'areas' of the site. |
|
| 56 | + public static $areas = array(); |
|
| 57 | + |
|
| 58 | + // The default controller to use in case |
|
| 59 | + // 'default_controller' is not in the routes file. |
|
| 60 | + protected $default_home = 'home'; |
|
| 61 | + |
|
| 62 | + // The default constraint to use in route building |
|
| 63 | + protected $default_constraint = 'any'; |
|
| 64 | + |
|
| 65 | + protected $constraints = [ |
|
| 66 | + 'any' => '(:any)', |
|
| 67 | + 'num' => '(:num)', |
|
| 68 | + 'id' => '(:num)', |
|
| 69 | + 'name' => "([a-zA-Z']+)" |
|
| 70 | + ]; |
|
| 71 | + |
|
| 72 | + protected $current_subdomain = null; |
|
| 73 | + |
|
| 74 | + //-------------------------------------------------------------------- |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Combines the routes that we've defined with the Route class with the |
|
| 78 | + * routes passed in. This is intended to be used after all routes have been |
|
| 79 | + * defined to merge CI's default $route array with our routes. |
|
| 80 | + * |
|
| 81 | + * Example: |
|
| 82 | + * $route['default_controller'] = 'home'; |
|
| 83 | + * Route::resource('posts'); |
|
| 84 | + * $route = Route::map($route); |
|
| 85 | + * |
|
| 86 | + * @param array $routes |
|
| 87 | + * @internal param array $route The array to merge |
|
| 88 | + * @return array The merge route array. |
|
| 89 | + */ |
|
| 90 | + public function map($routes = array()) |
|
| 91 | + { |
|
| 92 | + $controller = isset($routes['default_controller']) ? $routes['default_controller'] : $this->default_home; |
|
| 93 | + |
|
| 94 | + $routes = array_merge($routes, $this->routes); |
|
| 95 | + |
|
| 96 | + foreach ($routes as $from => $to) { |
|
| 97 | + $routes[$from] = str_ireplace('{default_controller}', $controller, $to); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return $routes; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + //-------------------------------------------------------------------- |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * A single point to the basic routing. Can be used in place of CI's $route |
|
| 107 | + * array if desired. Used internally by many of the methods. |
|
| 108 | + * |
|
| 109 | + * Available options are currently: |
|
| 110 | + * 'as' - remembers the route via a name that can be called outside of it. |
|
| 111 | + * 'offset' - Offsets and parameters ($1, $2, etc) in routes by the specified amount. |
|
| 112 | + * Useful while doing versioning of API's, etc. |
|
| 113 | + * |
|
| 114 | + * Example: |
|
| 115 | + * $route->any('news', 'posts/index'); |
|
| 116 | + * |
|
| 117 | + * @param string $from |
|
| 118 | + * @param string $to |
|
| 119 | + * @param array $options |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + public function any($from, $to, $options = array()) |
|
| 123 | + { |
|
| 124 | + $this->create($from, $to, $options); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + //-------------------------------------------------------------------- |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Sets the default constraint to be used in the system. Typically |
|
| 131 | + * for use with the 'resources' method. |
|
| 132 | + * |
|
| 133 | + * @param $constraint |
|
| 134 | + */ |
|
| 135 | + public function setDefaultConstraint($constraint) |
|
| 136 | + { |
|
| 137 | + if (array_key_exists($constraint, $this->constraints)) { |
|
| 138 | + $this->default_constraint = $constraint; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + //-------------------------------------------------------------------- |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Registers a new constraint to be used internally. Useful for creating |
|
| 146 | + * very specific regex patterns, or simply to allow your routes to be |
|
| 147 | + * a tad more readable. |
|
| 148 | + * |
|
| 149 | + * Example: |
|
| 150 | + * $route->registerConstraint('hero', '(^.*)'); |
|
| 151 | + * |
|
| 152 | + * $route->any('home/{hero}', 'heroes/journey'); |
|
| 153 | + * |
|
| 154 | + * // Route then looks like: |
|
| 155 | + * $route['home/(^.*)'] = 'heroes/journey'; |
|
| 156 | + * |
|
| 157 | + * @param $name |
|
| 158 | + * @param $pattern |
|
| 159 | + * @param bool $overwrite |
|
| 160 | + */ |
|
| 161 | + public function registerConstraint($name, $pattern, $overwrite = false) |
|
| 162 | + { |
|
| 163 | + // Ensure consistency |
|
| 164 | + $name = trim($name, '{} '); |
|
| 165 | + $pattern = '(' . trim($pattern, '() ') . ')'; |
|
| 166 | + |
|
| 167 | + // Not here? Add it and leave... |
|
| 168 | + if (! array_key_exists($name, $this->constraints)) { |
|
| 169 | + $this->constraints[$name] = $pattern; |
|
| 170 | + |
|
| 171 | + return; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // Here? Then it exists. Should we overwrite it? |
|
| 175 | + if ($overwrite) { |
|
| 176 | + $this->constraints[$name] = $pattern; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + //-------------------------------------------------------------------- |
|
| 181 | + |
|
| 182 | + //-------------------------------------------------------------------- |
|
| 183 | + // Named Routes |
|
| 184 | + //-------------------------------------------------------------------- |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Returns the value of a named route. Useful for getting named |
|
| 188 | + * routes for use while building with site_url() or in templates |
|
| 189 | + * where you don't need to instantiate the route class. |
|
| 190 | + * |
|
| 191 | + * Example: |
|
| 192 | + * $route->any('news', 'posts/index', ['as' => 'blog']); |
|
| 193 | + * |
|
| 194 | + * // Returns http://mysite.com/news |
|
| 195 | + * site_url( Route::named('blog') ); |
|
| 196 | + * |
|
| 197 | + * @param [type] $name [description] |
|
| 198 | + * @return [type] [description] |
|
| 199 | + */ |
|
| 200 | + public static function named($name) |
|
| 201 | + { |
|
| 202 | + if (isset(self::$names[$name])) { |
|
| 203 | + return self::$names[$name]; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return null; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + //-------------------------------------------------------------------- |
|
| 210 | + |
|
| 211 | + //-------------------------------------------------------------------- |
|
| 212 | + // Grouping Routes |
|
| 213 | + //-------------------------------------------------------------------- |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Group a series of routes under a single URL segment. This is handy |
|
| 217 | + * for grouping items into an admin area, like: |
|
| 218 | + * |
|
| 219 | + * Example: |
|
| 220 | + * $route->group('admin', function() { |
|
| 221 | + * $route->resources('users'); |
|
| 222 | + * }); |
|
| 223 | + * |
|
| 224 | + * @param string $name The name to group/prefix the routes with. |
|
| 225 | + * @param \Closure $callback An anonymous function that allows you route inside of this group. |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + public function group($name, \Closure $callback) |
|
| 229 | + { |
|
| 230 | + $old_group = $this->group; |
|
| 231 | + |
|
| 232 | + // To register a route, we'll set a flag so that our router |
|
| 233 | + // so it will see the groupname. |
|
| 234 | + $this->group = ltrim($old_group . '/' . $name, '/'); |
|
| 235 | + |
|
| 236 | + call_user_func($callback); |
|
| 237 | + |
|
| 238 | + // Make sure to clear the group name so we don't accidentally |
|
| 239 | + // group any ones we didn't want to. |
|
| 240 | + $this->group = $old_group; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + //-------------------------------------------------------------------- |
|
| 244 | + |
|
| 245 | + //-------------------------------------------------------------------- |
|
| 246 | + // HTTP Verb-based routing |
|
| 247 | + //-------------------------------------------------------------------- |
|
| 248 | + // Routing works here because, as the routes config file is read in, |
|
| 249 | + // the various HTTP verb-based routes will only be added to the in-memory |
|
| 250 | + // routes if it is a call that should respond to that verb. |
|
| 251 | + // |
|
| 252 | + // The options array is typically used to pass in an 'as' or var, but may |
|
| 253 | + // be expanded in the future. See the docblock for 'any' method above for |
|
| 254 | + // current list of globally available options. |
|
| 255 | + // |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Specifies a single route to match for multiple HTTP Verbs. |
|
| 259 | + * |
|
| 260 | + * Example: |
|
| 261 | + * $route->match( ['get', 'post'], 'users/(:num)', 'users/$1); |
|
| 262 | + * |
|
| 263 | + * @param array $verbs |
|
| 264 | + * @param $from |
|
| 265 | + * @param $to |
|
| 266 | + * @param array $options |
|
| 267 | + */ |
|
| 268 | + public function match($verbs = [], $from, $to, $options = []) |
|
| 269 | + { |
|
| 270 | + foreach ($verbs as $verb) { |
|
| 271 | + $verb = strtolower($verb); |
|
| 272 | + |
|
| 273 | + $this->{$verb}($from, $to, $options); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + //-------------------------------------------------------------------- |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Specifies a route that is only available to GET requests. |
|
| 281 | + * |
|
| 282 | + * @param $from |
|
| 283 | + * @param $to |
|
| 284 | + * @param array $options |
|
| 285 | + */ |
|
| 286 | + public function get($from, $to, $options = []) |
|
| 287 | + { |
|
| 288 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') { |
|
| 289 | + $this->create($from, $to, $options); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + //-------------------------------------------------------------------- |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Specifies a route that is only available to POST requests. |
|
| 297 | + * |
|
| 298 | + * @param $from |
|
| 299 | + * @param $to |
|
| 300 | + * @param array $options |
|
| 301 | + */ |
|
| 302 | + public function post($from, $to, $options = []) |
|
| 303 | + { |
|
| 304 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 305 | + $this->create($from, $to, $options); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + //-------------------------------------------------------------------- |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Specifies a route that is only available to PUT requests. |
|
| 313 | + * |
|
| 314 | + * @param $from |
|
| 315 | + * @param $to |
|
| 316 | + * @param array $options |
|
| 317 | + */ |
|
| 318 | + public function put($from, $to, $options = []) |
|
| 319 | + { |
|
| 320 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PUT') { |
|
| 321 | + $this->create($from, $to, $options); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + //-------------------------------------------------------------------- |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Specifies a route that is only available to DELETE requests. |
|
| 329 | + * |
|
| 330 | + * @param $from |
|
| 331 | + * @param $to |
|
| 332 | + * @param array $options |
|
| 333 | + */ |
|
| 334 | + public function delete($from, $to, $options = []) |
|
| 335 | + { |
|
| 336 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'DELETE') { |
|
| 337 | + $this->create($from, $to, $options); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + //-------------------------------------------------------------------- |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Specifies a route that is only available to HEAD requests. |
|
| 345 | + * |
|
| 346 | + * @param $from |
|
| 347 | + * @param $to |
|
| 348 | + * @param array $options |
|
| 349 | + */ |
|
| 350 | + public function head($from, $to, $options = []) |
|
| 351 | + { |
|
| 352 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') { |
|
| 353 | + $this->create($from, $to, $options); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + //-------------------------------------------------------------------- |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Specifies a route that is only available to PATCH requests. |
|
| 361 | + * |
|
| 362 | + * @param $from |
|
| 363 | + * @param $to |
|
| 364 | + * @param array $options |
|
| 365 | + */ |
|
| 366 | + public function patch($from, $to, $options = []) |
|
| 367 | + { |
|
| 368 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PATCH') { |
|
| 369 | + $this->create($from, $to, $options); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + //-------------------------------------------------------------------- |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Specifies a route that is only available to OPTIONS requests. |
|
| 377 | + * |
|
| 378 | + * @param $from |
|
| 379 | + * @param $to |
|
| 380 | + * @param array $options |
|
| 381 | + */ |
|
| 382 | + public function options($from, $to, $options = []) |
|
| 383 | + { |
|
| 384 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') { |
|
| 385 | + $this->create($from, $to, $options); |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + //-------------------------------------------------------------------- |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Creates a collections of HTTP-verb based routes for a controller. |
|
| 393 | + * |
|
| 394 | + * Possible Options: |
|
| 395 | + * 'controller' - Customize the name of the controller used in the 'to' route |
|
| 396 | + * 'module' - Prepend a module name to the generate 'to' routes |
|
| 397 | + * 'constraint' - The regex used by the Router. Defaults to '(:any)' |
|
| 398 | + * |
|
| 399 | + * Example: |
|
| 400 | + * $route->resources('photos'); |
|
| 401 | + * |
|
| 402 | + * // Generates the following routes: |
|
| 403 | + * HTTP Verb | Path | Action | Used for... |
|
| 404 | + * ----------+-------------+---------------+----------------- |
|
| 405 | + * GET /photos index display a list of photos |
|
| 406 | + * GET /photos/new creation_form return an HTML form for creating a new photo |
|
| 407 | + * GET /photos/{id} show display a specific photo |
|
| 408 | + * GET /photos/{id}/edit editing_form return an HTML form for editing the photo |
|
| 409 | + * POST /photos create create a new photo |
|
| 410 | + * PUT /photos/{id} update update an existing photo |
|
| 411 | + * DELETE /photos/{id}/delete delete delete an existing photo |
|
| 412 | + * |
|
| 413 | + * @param string $name The name of the controller to route to. |
|
| 414 | + * @param array $options An list of possible ways to customize the routing. |
|
| 415 | + */ |
|
| 416 | + public function resources($name, $options = []) |
|
| 417 | + { |
|
| 418 | + // In order to allow customization of the route the |
|
| 419 | + // resources are sent to, we need to have a new name |
|
| 420 | + // to store the values in. |
|
| 421 | + $new_name = $name; |
|
| 422 | + |
|
| 423 | + // If a new controller is specified, then we replace the |
|
| 424 | + // $name value with the name of the new controller. |
|
| 425 | + if (isset($options['controller'])) { |
|
| 426 | + $new_name = $options['controller']; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // If a new module was specified, simply put that path |
|
| 430 | + // in front of the controller. |
|
| 431 | + if (isset($options['module'])) { |
|
| 432 | + $new_name = $options['module'] . '/' . $new_name; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // In order to allow customization of allowed id values |
|
| 436 | + // we need someplace to store them. |
|
| 437 | + $id = isset($this->constraints[$this->default_constraint]) ? $this->constraints[$this->default_constraint] : |
|
| 438 | + '(:any)'; |
|
| 439 | + |
|
| 440 | + if (isset($options['constraint'])) { |
|
| 441 | + $id = $options['constraint']; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + $this->get($name, $new_name . '/list_all', $options); |
|
| 445 | + $this->get($name . '/' . $id, $new_name . '/show/$1', $options); |
|
| 446 | + $this->post($name, $new_name . '/create', $options); |
|
| 447 | + $this->put($name . '/' . $id, $new_name . '/update/$1', $options); |
|
| 448 | + $this->delete($name . '/' . $id, $new_name . '/delete/$1', $options); |
|
| 449 | + $this->options($name, $new_name . '/index', $options); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + //-------------------------------------------------------------------- |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Lets the system know about different 'areas' within the site, like |
|
| 456 | + * the admin area, that maps to certain controllers. |
|
| 457 | + * |
|
| 458 | + * @param string $area The name of the area. |
|
| 459 | + * @param string $controller The controller name to look for. |
|
| 460 | + * @param $options |
|
| 461 | + */ |
|
| 462 | + public function area($area, $controller = null, $options = []) |
|
| 463 | + { |
|
| 464 | + // No controller? Match the area name. |
|
| 465 | + $controller = is_null($controller) ? $area : $controller; |
|
| 466 | + |
|
| 467 | + // Save the area so we can recognize it later. |
|
| 468 | + self::$areas[$area] = $controller; |
|
| 469 | + |
|
| 470 | + // Create routes for this area. |
|
| 471 | + $this->create($area . '/(:any)/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4/$5', $options); |
|
| 472 | + $this->create($area . '/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4', $options); |
|
| 473 | + $this->create($area . '/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3', $options); |
|
| 474 | + $this->create($area . '/(:any)/(:any)', '$1/' . $controller . '/$2', $options); |
|
| 475 | + $this->create($area . '/(:any)', '$1/' . $controller, $options); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + //-------------------------------------------------------------------- |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * Returns the name of the area based on the controller name. |
|
| 482 | + * |
|
| 483 | + * @param string $controller The name of the controller |
|
| 484 | + * @return string The name of the corresponding area |
|
| 485 | + */ |
|
| 486 | + public static function getAreaName($controller) |
|
| 487 | + { |
|
| 488 | + foreach (self::$areas as $area => $cont) { |
|
| 489 | + if ($controller == $cont) { |
|
| 490 | + return $area; |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return null; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + //-------------------------------------------------------------------- |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Limits the routes to a specified ENVIRONMENT or they won't run. |
|
| 501 | + * |
|
| 502 | + * @param $env |
|
| 503 | + * @param callable $callback |
|
| 504 | + * |
|
| 505 | + * @return bool|null |
|
| 506 | + */ |
|
| 507 | + public function environment($env, \Closure $callback) |
|
| 508 | + { |
|
| 509 | + if (ENVIRONMENT == $env) |
|
| 510 | + { |
|
| 511 | + call_user_func($callback); |
|
| 512 | + return true; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return null; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + //-------------------------------------------------------------------- |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Allows you to easily block access to any number of routes by setting |
|
| 524 | + * that route to an empty path (''). |
|
| 525 | + * |
|
| 526 | + * Example: |
|
| 527 | + * Route::block('posts', 'photos/(:num)'); |
|
| 528 | + * |
|
| 529 | + * // Same as... |
|
| 530 | + * $route['posts'] = ''; |
|
| 531 | + * $route['photos/(:num)'] = ''; |
|
| 532 | + */ |
|
| 533 | + public function block() |
|
| 534 | + { |
|
| 535 | + $paths = func_get_args(); |
|
| 536 | + |
|
| 537 | + if (! is_array($paths) || ! count($paths)) { |
|
| 538 | + return; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + foreach ($paths as $path) { |
|
| 542 | + $this->create($path, ''); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + //-------------------------------------------------------------------- |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Empties all named and un-named routes from the system. |
|
| 550 | + * |
|
| 551 | + * @return void |
|
| 552 | + */ |
|
| 553 | + public function reset() |
|
| 554 | + { |
|
| 555 | + $this->routes = array(); |
|
| 556 | + $this->names = array(); |
|
| 557 | + $this->group = null; |
|
| 558 | + self::$areas = array(); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + //-------------------------------------------------------------------- |
|
| 562 | + |
|
| 563 | + //-------------------------------------------------------------------- |
|
| 564 | + // Private Methods |
|
| 565 | + //-------------------------------------------------------------------- |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Does the heavy lifting of creating an actual route. You must specify |
|
| 569 | + * the request method(s) that this route will work for. They can be separated |
|
| 570 | + * by a pipe character "|" if there is more than one. |
|
| 571 | + * |
|
| 572 | + * @param string $from |
|
| 573 | + * @param array $to |
|
| 574 | + * @param array $options |
|
| 575 | + * |
|
| 576 | + * @return array The built route. |
|
| 577 | + */ |
|
| 578 | + private function create($from, $to, $options = array()) |
|
| 579 | + { |
|
| 580 | + $prefix = is_null($this->group) ? '' : $this->group . '/'; |
|
| 581 | + |
|
| 582 | + $from = $prefix . $from; |
|
| 583 | + |
|
| 584 | + // Are we saving the name for this one? |
|
| 585 | + if (isset($options['as']) && !empty($options['as'])) { |
|
| 586 | + self::$names[$options['as']] = $from; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + // Limiting to subdomains? |
|
| 590 | + if (isset($options['subdomain']) && !empty($options['subdomain'])) { |
|
| 591 | + // If we don't match the current subdomain, then |
|
| 592 | + // we don't need to add the route. |
|
| 593 | + if (!$this->checkSubdomains($options['subdomain'])) { |
|
| 594 | + return; |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + // Are we offsetting the parameters? |
|
| 599 | + // If so, take care of them here in one |
|
| 600 | + // fell swoop. |
|
| 601 | + if (isset($options['offset'])) { |
|
| 602 | + // Get a constant string to work with. |
|
| 603 | + $to = preg_replace('/(\$\d+)/', '$X', $to); |
|
| 604 | + |
|
| 605 | + for ($i = (int)$options['offset'] + 1; $i < (int)$options['offset'] + 7; $i ++) { |
|
| 606 | + $to = preg_replace_callback( |
|
| 607 | + '/\$X/', |
|
| 608 | + function ($m) use ($i) { |
|
| 609 | + return '$' . $i; |
|
| 610 | + }, |
|
| 611 | + $to, |
|
| 612 | + 1 |
|
| 613 | + ); |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + // Convert any custom constraints to the CI/pattern equivalent |
|
| 618 | + foreach ($this->constraints as $name => $pattern) { |
|
| 619 | + $from = str_replace('{' . $name . '}', $pattern, $from); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + $this->routes[$from] = $to; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + //-------------------------------------------------------------------- |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Compares the subdomain(s) passed in against the current subdomain |
|
| 629 | + * on this page request. |
|
| 630 | + * |
|
| 631 | + * @param $subdomains |
|
| 632 | + * @return bool |
|
| 633 | + */ |
|
| 634 | + private function checkSubdomains($subdomains) |
|
| 635 | + { |
|
| 636 | + if (is_null($this->current_subdomain)) { |
|
| 637 | + $this->determineCurrentSubdomain(); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + if (!is_array($subdomains)) { |
|
| 641 | + $subdomains = array($subdomains); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + $matched = false; |
|
| 645 | + |
|
| 646 | + array_walk( |
|
| 647 | + $subdomains, |
|
| 648 | + function ($subdomain) use (&$matched) { |
|
| 649 | + if ($subdomain == $this->current_subdomain || $subdomain == '*') { |
|
| 650 | + $matched = true; |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + ); |
|
| 654 | + |
|
| 655 | + return $matched; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + //-------------------------------------------------------------------- |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Examines the HTTP_HOST to get a best match for the subdomain. It |
|
| 662 | + * won't be perfect, but should work for our needs. |
|
| 663 | + */ |
|
| 664 | + private function determineCurrentSubdomain() |
|
| 665 | + { |
|
| 666 | + $parsedUrl = parse_url($_SERVER['HTTP_HOST']); |
|
| 667 | + |
|
| 668 | + $host = explode('.', $parsedUrl['host']); |
|
| 669 | + |
|
| 670 | + // If we only have 2 parts, then we don't have a subdomain. |
|
| 671 | + // This won't be totally accurate, since URL's like example.co.uk |
|
| 672 | + // would still pass, but it helps to separate the chaff... |
|
| 673 | + if (!is_array($host) || count($host) == 2) { |
|
| 674 | + // Set it to false so we don't make it back here again. |
|
| 675 | + $this->current_subdomain = false; |
|
| 676 | + return; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + // Now, we'll simply take the first element of the array. This should |
|
| 680 | + // be fine even in cases like example.co.uk, since they won't be looking |
|
| 681 | + // for 'example' when they try to match the subdomain, in most all cases. |
|
| 682 | + $this->current_subdomain = array_shift($host); |
|
| 683 | + } |
|
| 684 | + //-------------------------------------------------------------------- |
|
| 685 | 685 | |
| 686 | 686 | } |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | // Ensure consistency |
| 164 | 164 | $name = trim($name, '{} '); |
| 165 | - $pattern = '(' . trim($pattern, '() ') . ')'; |
|
| 165 | + $pattern = '('.trim($pattern, '() ').')'; |
|
| 166 | 166 | |
| 167 | 167 | // Not here? Add it and leave... |
| 168 | - if (! array_key_exists($name, $this->constraints)) { |
|
| 168 | + if ( ! array_key_exists($name, $this->constraints)) { |
|
| 169 | 169 | $this->constraints[$name] = $pattern; |
| 170 | 170 | |
| 171 | 171 | return; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | // To register a route, we'll set a flag so that our router |
| 233 | 233 | // so it will see the groupname. |
| 234 | - $this->group = ltrim($old_group . '/' . $name, '/'); |
|
| 234 | + $this->group = ltrim($old_group.'/'.$name, '/'); |
|
| 235 | 235 | |
| 236 | 236 | call_user_func($callback); |
| 237 | 237 | |
@@ -429,24 +429,23 @@ discard block |
||
| 429 | 429 | // If a new module was specified, simply put that path |
| 430 | 430 | // in front of the controller. |
| 431 | 431 | if (isset($options['module'])) { |
| 432 | - $new_name = $options['module'] . '/' . $new_name; |
|
| 432 | + $new_name = $options['module'].'/'.$new_name; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | // In order to allow customization of allowed id values |
| 436 | 436 | // we need someplace to store them. |
| 437 | - $id = isset($this->constraints[$this->default_constraint]) ? $this->constraints[$this->default_constraint] : |
|
| 438 | - '(:any)'; |
|
| 437 | + $id = isset($this->constraints[$this->default_constraint]) ? $this->constraints[$this->default_constraint] : '(:any)'; |
|
| 439 | 438 | |
| 440 | 439 | if (isset($options['constraint'])) { |
| 441 | 440 | $id = $options['constraint']; |
| 442 | 441 | } |
| 443 | 442 | |
| 444 | - $this->get($name, $new_name . '/list_all', $options); |
|
| 445 | - $this->get($name . '/' . $id, $new_name . '/show/$1', $options); |
|
| 446 | - $this->post($name, $new_name . '/create', $options); |
|
| 447 | - $this->put($name . '/' . $id, $new_name . '/update/$1', $options); |
|
| 448 | - $this->delete($name . '/' . $id, $new_name . '/delete/$1', $options); |
|
| 449 | - $this->options($name, $new_name . '/index', $options); |
|
| 443 | + $this->get($name, $new_name.'/list_all', $options); |
|
| 444 | + $this->get($name.'/'.$id, $new_name.'/show/$1', $options); |
|
| 445 | + $this->post($name, $new_name.'/create', $options); |
|
| 446 | + $this->put($name.'/'.$id, $new_name.'/update/$1', $options); |
|
| 447 | + $this->delete($name.'/'.$id, $new_name.'/delete/$1', $options); |
|
| 448 | + $this->options($name, $new_name.'/index', $options); |
|
| 450 | 449 | } |
| 451 | 450 | |
| 452 | 451 | //-------------------------------------------------------------------- |
@@ -468,11 +467,11 @@ discard block |
||
| 468 | 467 | self::$areas[$area] = $controller; |
| 469 | 468 | |
| 470 | 469 | // Create routes for this area. |
| 471 | - $this->create($area . '/(:any)/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4/$5', $options); |
|
| 472 | - $this->create($area . '/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4', $options); |
|
| 473 | - $this->create($area . '/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3', $options); |
|
| 474 | - $this->create($area . '/(:any)/(:any)', '$1/' . $controller . '/$2', $options); |
|
| 475 | - $this->create($area . '/(:any)', '$1/' . $controller, $options); |
|
| 470 | + $this->create($area.'/(:any)/(:any)/(:any)/(:any)/(:any)', '$1/'.$controller.'/$2/$3/$4/$5', $options); |
|
| 471 | + $this->create($area.'/(:any)/(:any)/(:any)/(:any)', '$1/'.$controller.'/$2/$3/$4', $options); |
|
| 472 | + $this->create($area.'/(:any)/(:any)/(:any)', '$1/'.$controller.'/$2/$3', $options); |
|
| 473 | + $this->create($area.'/(:any)/(:any)', '$1/'.$controller.'/$2', $options); |
|
| 474 | + $this->create($area.'/(:any)', '$1/'.$controller, $options); |
|
| 476 | 475 | } |
| 477 | 476 | |
| 478 | 477 | //-------------------------------------------------------------------- |
@@ -534,7 +533,7 @@ discard block |
||
| 534 | 533 | { |
| 535 | 534 | $paths = func_get_args(); |
| 536 | 535 | |
| 537 | - if (! is_array($paths) || ! count($paths)) { |
|
| 536 | + if ( ! is_array($paths) || ! count($paths)) { |
|
| 538 | 537 | return; |
| 539 | 538 | } |
| 540 | 539 | |
@@ -577,20 +576,20 @@ discard block |
||
| 577 | 576 | */ |
| 578 | 577 | private function create($from, $to, $options = array()) |
| 579 | 578 | { |
| 580 | - $prefix = is_null($this->group) ? '' : $this->group . '/'; |
|
| 579 | + $prefix = is_null($this->group) ? '' : $this->group.'/'; |
|
| 581 | 580 | |
| 582 | - $from = $prefix . $from; |
|
| 581 | + $from = $prefix.$from; |
|
| 583 | 582 | |
| 584 | 583 | // Are we saving the name for this one? |
| 585 | - if (isset($options['as']) && !empty($options['as'])) { |
|
| 584 | + if (isset($options['as']) && ! empty($options['as'])) { |
|
| 586 | 585 | self::$names[$options['as']] = $from; |
| 587 | 586 | } |
| 588 | 587 | |
| 589 | 588 | // Limiting to subdomains? |
| 590 | - if (isset($options['subdomain']) && !empty($options['subdomain'])) { |
|
| 589 | + if (isset($options['subdomain']) && ! empty($options['subdomain'])) { |
|
| 591 | 590 | // If we don't match the current subdomain, then |
| 592 | 591 | // we don't need to add the route. |
| 593 | - if (!$this->checkSubdomains($options['subdomain'])) { |
|
| 592 | + if ( ! $this->checkSubdomains($options['subdomain'])) { |
|
| 594 | 593 | return; |
| 595 | 594 | } |
| 596 | 595 | } |
@@ -602,11 +601,11 @@ discard block |
||
| 602 | 601 | // Get a constant string to work with. |
| 603 | 602 | $to = preg_replace('/(\$\d+)/', '$X', $to); |
| 604 | 603 | |
| 605 | - for ($i = (int)$options['offset'] + 1; $i < (int)$options['offset'] + 7; $i ++) { |
|
| 604 | + for ($i = (int) $options['offset'] + 1; $i < (int) $options['offset'] + 7; $i++) { |
|
| 606 | 605 | $to = preg_replace_callback( |
| 607 | 606 | '/\$X/', |
| 608 | - function ($m) use ($i) { |
|
| 609 | - return '$' . $i; |
|
| 607 | + function($m) use ($i) { |
|
| 608 | + return '$'.$i; |
|
| 610 | 609 | }, |
| 611 | 610 | $to, |
| 612 | 611 | 1 |
@@ -616,7 +615,7 @@ discard block |
||
| 616 | 615 | |
| 617 | 616 | // Convert any custom constraints to the CI/pattern equivalent |
| 618 | 617 | foreach ($this->constraints as $name => $pattern) { |
| 619 | - $from = str_replace('{' . $name . '}', $pattern, $from); |
|
| 618 | + $from = str_replace('{'.$name.'}', $pattern, $from); |
|
| 620 | 619 | } |
| 621 | 620 | |
| 622 | 621 | $this->routes[$from] = $to; |
@@ -637,7 +636,7 @@ discard block |
||
| 637 | 636 | $this->determineCurrentSubdomain(); |
| 638 | 637 | } |
| 639 | 638 | |
| 640 | - if (!is_array($subdomains)) { |
|
| 639 | + if ( ! is_array($subdomains)) { |
|
| 641 | 640 | $subdomains = array($subdomains); |
| 642 | 641 | } |
| 643 | 642 | |
@@ -645,7 +644,7 @@ discard block |
||
| 645 | 644 | |
| 646 | 645 | array_walk( |
| 647 | 646 | $subdomains, |
| 648 | - function ($subdomain) use (&$matched) { |
|
| 647 | + function($subdomain) use (&$matched) { |
|
| 649 | 648 | if ($subdomain == $this->current_subdomain || $subdomain == '*') { |
| 650 | 649 | $matched = true; |
| 651 | 650 | } |
@@ -670,7 +669,7 @@ discard block |
||
| 670 | 669 | // If we only have 2 parts, then we don't have a subdomain. |
| 671 | 670 | // This won't be totally accurate, since URL's like example.co.uk |
| 672 | 671 | // would still pass, but it helps to separate the chaff... |
| 673 | - if (!is_array($host) || count($host) == 2) { |
|
| 672 | + if ( ! is_array($host) || count($host) == 2) { |
|
| 674 | 673 | // Set it to false so we don't make it back here again. |
| 675 | 674 | $this->current_subdomain = false; |
| 676 | 675 | return; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param $alias |
| 40 | 40 | * @param null $value |
| 41 | 41 | * |
| 42 | - * @return mixed |
|
| 42 | + * @return MetaCollection |
|
| 43 | 43 | */ |
| 44 | 44 | public function set($alias, $value=null); |
| 45 | 45 | |
@@ -59,9 +59,8 @@ discard block |
||
| 59 | 59 | /** |
| 60 | 60 | * Renders out all defined meta tags. |
| 61 | 61 | * |
| 62 | - * @param array $show_tags |
|
| 63 | 62 | * |
| 64 | - * @return mixed |
|
| 63 | + * @return null|string |
|
| 65 | 64 | */ |
| 66 | 65 | public function renderTags(); |
| 67 | 66 | |
@@ -33,50 +33,50 @@ |
||
| 33 | 33 | |
| 34 | 34 | interface MetaInterface { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Sets a single meta item. |
|
| 38 | - * |
|
| 39 | - * @param $alias |
|
| 40 | - * @param null $value |
|
| 41 | - * |
|
| 42 | - * @return mixed |
|
| 43 | - */ |
|
| 44 | - public function set($alias, $value=null); |
|
| 36 | + /** |
|
| 37 | + * Sets a single meta item. |
|
| 38 | + * |
|
| 39 | + * @param $alias |
|
| 40 | + * @param null $value |
|
| 41 | + * |
|
| 42 | + * @return mixed |
|
| 43 | + */ |
|
| 44 | + public function set($alias, $value=null); |
|
| 45 | 45 | |
| 46 | - //-------------------------------------------------------------------- |
|
| 46 | + //-------------------------------------------------------------------- |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Returns a single meta item. |
|
| 50 | - * |
|
| 51 | - * @param $alias |
|
| 52 | - * |
|
| 53 | - * @return mixed |
|
| 54 | - */ |
|
| 55 | - public function get($alias); |
|
| 48 | + /** |
|
| 49 | + * Returns a single meta item. |
|
| 50 | + * |
|
| 51 | + * @param $alias |
|
| 52 | + * |
|
| 53 | + * @return mixed |
|
| 54 | + */ |
|
| 55 | + public function get($alias); |
|
| 56 | 56 | |
| 57 | - //-------------------------------------------------------------------- |
|
| 57 | + //-------------------------------------------------------------------- |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Renders out all defined meta tags. |
|
| 61 | - * |
|
| 62 | - * @param array $show_tags |
|
| 63 | - * |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function renderTags(); |
|
| 59 | + /** |
|
| 60 | + * Renders out all defined meta tags. |
|
| 61 | + * |
|
| 62 | + * @param array $show_tags |
|
| 63 | + * |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function renderTags(); |
|
| 67 | 67 | |
| 68 | - //-------------------------------------------------------------------- |
|
| 68 | + //-------------------------------------------------------------------- |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Registers a new HTTP Equivalent meta tag so it can be |
|
| 72 | - * rendered out properly. |
|
| 73 | - * |
|
| 74 | - * @param $name |
|
| 75 | - * |
|
| 76 | - * @return $this |
|
| 77 | - */ |
|
| 78 | - public function registerHTTPEquivTag($name); |
|
| 70 | + /** |
|
| 71 | + * Registers a new HTTP Equivalent meta tag so it can be |
|
| 72 | + * rendered out properly. |
|
| 73 | + * |
|
| 74 | + * @param $name |
|
| 75 | + * |
|
| 76 | + * @return $this |
|
| 77 | + */ |
|
| 78 | + public function registerHTTPEquivTag($name); |
|
| 79 | 79 | |
| 80 | - //-------------------------------------------------------------------- |
|
| 80 | + //-------------------------------------------------------------------- |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | * |
| 42 | 42 | * @return mixed |
| 43 | 43 | */ |
| 44 | - public function set($alias, $value=null); |
|
| 44 | + public function set($alias, $value = null); |
|
| 45 | 45 | |
| 46 | 46 | //-------------------------------------------------------------------- |
| 47 | 47 | |
@@ -73,7 +73,6 @@ discard block |
||
| 73 | 73 | * controller and is generally the last method called. |
| 74 | 74 | * |
| 75 | 75 | * @param string $layout If provided, will override the default layout. |
| 76 | - * @param int $cache_time The number of seconds to cache the output for. |
|
| 77 | 76 | * @return mixed |
| 78 | 77 | */ |
| 79 | 78 | public function render($layout = null) |
@@ -104,7 +103,6 @@ discard block |
||
| 104 | 103 | * Used within the template layout file to render the current content. |
| 105 | 104 | * This content is typically used to display the current view. |
| 106 | 105 | * |
| 107 | - * @param int $cache_time |
|
| 108 | 106 | * |
| 109 | 107 | * @return mixed |
| 110 | 108 | */ |
@@ -304,7 +302,7 @@ discard block |
||
| 304 | 302 | /** |
| 305 | 303 | * Returns the current theme. |
| 306 | 304 | * |
| 307 | - * @return mixed|string |
|
| 305 | + * @return string |
|
| 308 | 306 | */ |
| 309 | 307 | public function theme() |
| 310 | 308 | { |
@@ -343,7 +341,7 @@ discard block |
||
| 343 | 341 | /** |
| 344 | 342 | * Returns the current view. |
| 345 | 343 | * |
| 346 | - * @return mixed|string |
|
| 344 | + * @return string |
|
| 347 | 345 | */ |
| 348 | 346 | public function view() |
| 349 | 347 | { |
@@ -371,7 +369,7 @@ discard block |
||
| 371 | 369 | /** |
| 372 | 370 | * Returns the current layout. |
| 373 | 371 | * |
| 374 | - * @return mixed|string |
|
| 372 | + * @return string |
|
| 375 | 373 | */ |
| 376 | 374 | public function layout() |
| 377 | 375 | { |
@@ -425,7 +423,7 @@ discard block |
||
| 425 | 423 | * CodeIgniter's parser. |
| 426 | 424 | * |
| 427 | 425 | * @param bool $parse |
| 428 | - * @return mixed |
|
| 426 | + * @return ViewThemer |
|
| 429 | 427 | */ |
| 430 | 428 | public function parseViews($parse = false) |
| 431 | 429 | { |
@@ -444,7 +442,7 @@ discard block |
||
| 444 | 442 | * @param $alias The name the theme can be referenced by |
| 445 | 443 | * @param $path A new path where themes can be found. |
| 446 | 444 | * |
| 447 | - * @return mixed |
|
| 445 | + * @return ViewThemer |
|
| 448 | 446 | */ |
| 449 | 447 | public function addThemePath($alias, $path) |
| 450 | 448 | { |
@@ -525,7 +523,7 @@ discard block |
||
| 525 | 523 | * |
| 526 | 524 | * @param $name |
| 527 | 525 | * @param $postfix |
| 528 | - * @return $this|mixed |
|
| 526 | + * @return ViewThemer |
|
| 529 | 527 | */ |
| 530 | 528 | public function addVariant($name, $postfix) |
| 531 | 529 | { |
@@ -540,7 +538,7 @@ discard block |
||
| 540 | 538 | * Removes a variant from the system. |
| 541 | 539 | * |
| 542 | 540 | * @param $name |
| 543 | - * @return $this|mixed |
|
| 541 | + * @return ViewThemer |
|
| 544 | 542 | */ |
| 545 | 543 | public function removeVariant($name) |
| 546 | 544 | { |
@@ -35,70 +35,70 @@ discard block |
||
| 35 | 35 | class ViewThemer implements ThemerInterface |
| 36 | 36 | { |
| 37 | 37 | |
| 38 | - protected $theme = ''; |
|
| 38 | + protected $theme = ''; |
|
| 39 | 39 | |
| 40 | - protected $default_theme = null; |
|
| 40 | + protected $default_theme = null; |
|
| 41 | 41 | |
| 42 | 42 | protected $active_theme = null; |
| 43 | 43 | |
| 44 | - protected $layout = 'index'; |
|
| 44 | + protected $layout = 'index'; |
|
| 45 | 45 | |
| 46 | - protected $view = ''; |
|
| 46 | + protected $view = ''; |
|
| 47 | 47 | |
| 48 | - protected $vars = []; |
|
| 48 | + protected $vars = []; |
|
| 49 | 49 | |
| 50 | - protected $folders = []; |
|
| 50 | + protected $folders = []; |
|
| 51 | 51 | |
| 52 | - protected $variants = []; |
|
| 52 | + protected $variants = []; |
|
| 53 | 53 | |
| 54 | - protected $current_variant = ''; |
|
| 54 | + protected $current_variant = ''; |
|
| 55 | 55 | |
| 56 | 56 | protected $parse_views = false; |
| 57 | 57 | |
| 58 | - protected $ci; |
|
| 58 | + protected $ci; |
|
| 59 | 59 | |
| 60 | - //-------------------------------------------------------------------- |
|
| 60 | + //-------------------------------------------------------------------- |
|
| 61 | 61 | |
| 62 | - public function __construct($ci) |
|
| 63 | - { |
|
| 64 | - $this->ci = $ci; |
|
| 62 | + public function __construct($ci) |
|
| 63 | + { |
|
| 64 | + $this->ci = $ci; |
|
| 65 | 65 | |
| 66 | - $this->parse_views = config_item('theme.parse_views'); |
|
| 67 | - } |
|
| 66 | + $this->parse_views = config_item('theme.parse_views'); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - //-------------------------------------------------------------------- |
|
| 69 | + //-------------------------------------------------------------------- |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * The main entryway into rendering a view. This is called from the |
|
| 73 | - * controller and is generally the last method called. |
|
| 74 | - * |
|
| 75 | - * @param string $layout If provided, will override the default layout. |
|
| 76 | - * @param int $cache_time The number of seconds to cache the output for. |
|
| 77 | - * @return mixed |
|
| 78 | - */ |
|
| 79 | - public function render($layout = null) |
|
| 80 | - { |
|
| 81 | - // Make the template engine available within the views. |
|
| 82 | - $this->vars['themer'] = $this; |
|
| 71 | + /** |
|
| 72 | + * The main entryway into rendering a view. This is called from the |
|
| 73 | + * controller and is generally the last method called. |
|
| 74 | + * |
|
| 75 | + * @param string $layout If provided, will override the default layout. |
|
| 76 | + * @param int $cache_time The number of seconds to cache the output for. |
|
| 77 | + * @return mixed |
|
| 78 | + */ |
|
| 79 | + public function render($layout = null) |
|
| 80 | + { |
|
| 81 | + // Make the template engine available within the views. |
|
| 82 | + $this->vars['themer'] = $this; |
|
| 83 | 83 | |
| 84 | - // Render our current view content |
|
| 85 | - $this->vars['view_content'] = $this->content(); |
|
| 84 | + // Render our current view content |
|
| 85 | + $this->vars['view_content'] = $this->content(); |
|
| 86 | 86 | |
| 87 | - $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
| 87 | + $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
| 88 | 88 | |
| 89 | - if (! isset($this->folders[$theme])) { |
|
| 90 | - throw new \LogicException( sprintf( lang('theme.bad_folder'), $theme ) ); |
|
| 91 | - } |
|
| 89 | + if (! isset($this->folders[$theme])) { |
|
| 90 | + throw new \LogicException( sprintf( lang('theme.bad_folder'), $theme ) ); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $this->active_theme = $theme; |
|
| 93 | + $this->active_theme = $theme; |
|
| 94 | 94 | |
| 95 | - // Make the path available within views. |
|
| 96 | - $this->vars['theme_path'] = $this->folders[$theme]; |
|
| 95 | + // Make the path available within views. |
|
| 96 | + $this->vars['theme_path'] = $this->folders[$theme]; |
|
| 97 | 97 | |
| 98 | - return $this->display($this->folders[$theme] . '/' . $this->layout); |
|
| 99 | - } |
|
| 98 | + return $this->display($this->folders[$theme] . '/' . $this->layout); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - //-------------------------------------------------------------------- |
|
| 101 | + //-------------------------------------------------------------------- |
|
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * Used within the template layout file to render the current content. |
@@ -108,490 +108,490 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return mixed |
| 110 | 110 | */ |
| 111 | - public function content() |
|
| 112 | - { |
|
| 113 | - // Calc our view name based on current method/controller |
|
| 114 | - $dir = $this->ci->router->fetch_directory(); |
|
| 111 | + public function content() |
|
| 112 | + { |
|
| 113 | + // Calc our view name based on current method/controller |
|
| 114 | + $dir = $this->ci->router->fetch_directory(); |
|
| 115 | 115 | |
| 116 | - foreach (Modules::$locations as $key => $offset) { |
|
| 116 | + foreach (Modules::$locations as $key => $offset) { |
|
| 117 | 117 | |
| 118 | - if (stripos($dir, 'module') !== false) { |
|
| 118 | + if (stripos($dir, 'module') !== false) { |
|
| 119 | 119 | // $dir = str_replace($offset, '', $dir); |
| 120 | - $dir = str_replace('controllers/', '', $dir); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $module = $this->ci->router->fetch_module(); |
|
| 125 | - |
|
| 126 | - if (! empty($module) && substr($dir, -strlen($module .'/')) == $module . '/') { |
|
| 127 | - $dir = ''; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $view = ! empty($this->view) ? $this->view : |
|
| 131 | - $dir . $this->ci->router->fetch_class() . '/' . $this->ci->router->fetch_method(); |
|
| 132 | - |
|
| 133 | - return $this->display($view); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - //-------------------------------------------------------------------- |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Loads a view file. Useful to control caching. Intended for use |
|
| 140 | - * from within view files. |
|
| 141 | - * |
|
| 142 | - * You can specify that a view should belong to a theme by prefixing |
|
| 143 | - * the name of the theme and a colon to the view name. For example, |
|
| 144 | - * "admin:header" would try to display the "header.php" file within |
|
| 145 | - * the "admin" theme. |
|
| 146 | - * |
|
| 147 | - * If a variant has been specified, it will be added to the end |
|
| 148 | - * of the view name before looking for the file. |
|
| 149 | - * |
|
| 150 | - * @param string $view |
|
| 151 | - * @param array $data |
|
| 152 | - * @param int $cache_time Number of minutes to cache the page for |
|
| 153 | - * @param string $cache_name A custom name for the cached file. |
|
| 154 | - * @return mixed |
|
| 155 | - */ |
|
| 156 | - public function display($view, $data = array(), $cache_time = 0, $cache_name=null) |
|
| 157 | - { |
|
| 158 | - if (empty($cache_name)) |
|
| 159 | - { |
|
| 160 | - $cache_name = 'theme_view_' . $view . '_' . $this->ci->router->fetch_class() . '_' . $this->ci->router->fetch_method(); |
|
| 161 | - $cache_name = str_replace( '/', '_', $cache_name ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if ($cache_time == 0 || ! $output = $this->ci->cache->get($cache_name)) |
|
| 165 | - { |
|
| 166 | - $theme = NULL; |
|
| 167 | - $variant_view = NULL; |
|
| 168 | - |
|
| 169 | - // Pull out the theme from the view, if given. |
|
| 170 | - if ( strpos( $view, ':' ) !== FALSE ) |
|
| 171 | - { |
|
| 172 | - list( $theme, $view ) = explode( ':', $view ); |
|
| 173 | - |
|
| 174 | - $theme = str_replace('{theme}', $this->active_theme, $theme); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if ( ! empty( $theme ) && isset( $this->folders[ $theme ] ) ) |
|
| 178 | - { |
|
| 179 | - $view = rtrim( $this->folders[ $theme ], '/' ) . '/' . $view; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (! is_array($data)) |
|
| 183 | - { |
|
| 184 | - $data = []; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $data = array_merge( $this->vars, $data ); |
|
| 188 | - |
|
| 189 | - // if using a variant, add it to the view name. |
|
| 190 | - if ( ! empty( $this->current_variant ) ) |
|
| 191 | - { |
|
| 192 | - $variant_view = $view . $this->variants[ $this->current_variant ]; |
|
| 193 | - |
|
| 194 | - $output = $this->loadView($variant_view, $data); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // If that didn't find anything, then try it without a variant |
|
| 198 | - if ( empty( $output ) ) |
|
| 199 | - { |
|
| 200 | - $output = $this->loadView($view, $data); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - // Cache it |
|
| 204 | - if ((int)$cache_time > 0) |
|
| 205 | - { |
|
| 206 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Parse views? |
|
| 211 | - if ($this->parse_views) |
|
| 212 | - { |
|
| 213 | - $this->ci->load->library('parser'); |
|
| 214 | - |
|
| 215 | - // Any class objects will cause failure |
|
| 216 | - // so get rid of those bad boys.... |
|
| 217 | - unset($data['uikit'], $data['themer']); |
|
| 218 | - |
|
| 219 | - $output = $this->ci->parser->parse_string($output, $data, true); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return $output; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - //-------------------------------------------------------------------- |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Runs a callback method and returns the contents to the view. |
|
| 229 | - * |
|
| 230 | - * @param $command |
|
| 231 | - * @param int $cache_time |
|
| 232 | - * @param string $cache_name // Number of MINUTES to cache output |
|
| 233 | - * @return mixed|void |
|
| 234 | - */ |
|
| 235 | - public function call($command, $cache_time=0, $cache_name=null) |
|
| 236 | - { |
|
| 237 | - if (empty($cache_name)) |
|
| 238 | - { |
|
| 239 | - $cache_name = 'theme_call_' . md5( $command ); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if (! $output = $this->ci->cache->get($cache_name)) { |
|
| 243 | - $parts = explode(' ', $command); |
|
| 244 | - |
|
| 245 | - list($class, $method) = explode(':', array_shift($parts)); |
|
| 246 | - |
|
| 247 | - // Prepare our parameter list to send to the callback |
|
| 248 | - // by splitting $parts on equal signs. |
|
| 249 | - $params = array(); |
|
| 250 | - |
|
| 251 | - foreach ($parts as $part) { |
|
| 252 | - $p = explode('=', $part); |
|
| 253 | - |
|
| 254 | - if (empty($p[0]) || empty($p[1])) |
|
| 255 | - { |
|
| 256 | - continue; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $params[ $p[0] ] = $p[1]; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - // Let PHP try to autoload it through any available autoloaders |
|
| 263 | - // (including Composer and user's custom autoloaders). If we |
|
| 264 | - // don't find it, then assume it's a CI library that we can reach. |
|
| 265 | - if (class_exists($class)) { |
|
| 266 | - $class = new $class(); |
|
| 267 | - } else { |
|
| 268 | - $this->ci->load->library($class); |
|
| 269 | - $class =& $this->ci->$class; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - if (! method_exists($class, $method)) { |
|
| 273 | - throw new \RuntimeException( sprintf( lang('themer.bad_callback'), $class, $method ) ); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // Call the class with our parameters |
|
| 277 | - $output = $class->{$method}($params); |
|
| 278 | - |
|
| 279 | - // Cache it |
|
| 280 | - if ((int)$cache_time > 0) |
|
| 281 | - { |
|
| 282 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return $output; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - //-------------------------------------------------------------------- |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Sets the active theme to use. This theme should be |
|
| 293 | - * relative to one of the 'theme_paths' folders. |
|
| 294 | - * |
|
| 295 | - * @param $theme |
|
| 296 | - */ |
|
| 297 | - public function setTheme($theme) |
|
| 298 | - { |
|
| 299 | - $this->theme = $theme; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - //-------------------------------------------------------------------- |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Returns the current theme. |
|
| 306 | - * |
|
| 307 | - * @return mixed|string |
|
| 308 | - */ |
|
| 309 | - public function theme() |
|
| 310 | - { |
|
| 311 | - return $this->theme; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - //-------------------------------------------------------------------- |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Sets the default theme to use if another isn't specified. |
|
| 318 | - * |
|
| 319 | - * @param $theme |
|
| 320 | - * @return mixed|void |
|
| 321 | - */ |
|
| 322 | - public function setDefaultTheme($theme) |
|
| 323 | - { |
|
| 324 | - $this->default_theme = $theme; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - //-------------------------------------------------------------------- |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Sets the current view file to render. |
|
| 332 | - * |
|
| 333 | - * @param $file |
|
| 334 | - * @return mixed |
|
| 335 | - */ |
|
| 336 | - public function setView($file) |
|
| 337 | - { |
|
| 338 | - $this->view = $file; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - //-------------------------------------------------------------------- |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Returns the current view. |
|
| 345 | - * |
|
| 346 | - * @return mixed|string |
|
| 347 | - */ |
|
| 348 | - public function view() |
|
| 349 | - { |
|
| 350 | - return $this->view; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - //-------------------------------------------------------------------- |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Sets the current layout to be used. MUST be the name of one of |
|
| 357 | - * the layout files within the current theme. Case-sensitive. |
|
| 358 | - * |
|
| 359 | - * @param $file |
|
| 360 | - * @return mixed |
|
| 361 | - */ |
|
| 362 | - public function setLayout($file) |
|
| 363 | - { |
|
| 364 | - if (empty($file)) return; |
|
| 365 | - |
|
| 366 | - $this->layout = $file; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - //-------------------------------------------------------------------- |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Returns the current layout. |
|
| 373 | - * |
|
| 374 | - * @return mixed|string |
|
| 375 | - */ |
|
| 376 | - public function layout() |
|
| 377 | - { |
|
| 378 | - return $this->layout; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - //-------------------------------------------------------------------- |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Stores one or more pieces of data to be passed to the views when |
|
| 385 | - * they are rendered out. |
|
| 386 | - * |
|
| 387 | - * If both $key and $value are ! empty, then it will treat it as a |
|
| 388 | - * key/value pair. If $key is an array of key/value pairs, then $value |
|
| 389 | - * is ignored and each element of the array are made available to the |
|
| 390 | - * view as if it was a single $key/$value pair. |
|
| 391 | - * |
|
| 392 | - * @param string|array $key |
|
| 393 | - * @param mixed $value |
|
| 394 | - * @return $this |
|
| 395 | - */ |
|
| 396 | - public function set($key, $value = null) |
|
| 397 | - { |
|
| 398 | - if (is_array($key)) { |
|
| 399 | - $this->vars = array_merge($this->vars, $key); |
|
| 400 | - return; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - $this->vars[$key] = $value; |
|
| 404 | - |
|
| 405 | - return $this; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - //-------------------------------------------------------------------- |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Returns a value that has been previously set(). |
|
| 412 | - * |
|
| 413 | - * @param $key |
|
| 414 | - * @return mixed |
|
| 415 | - */ |
|
| 416 | - public function get($key) |
|
| 417 | - { |
|
| 418 | - return isset($this->vars[$key]) ? $this->vars[$key] : null; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - //-------------------------------------------------------------------- |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Determines whether or not the view should be parsed with the |
|
| 425 | - * CodeIgniter's parser. |
|
| 426 | - * |
|
| 427 | - * @param bool $parse |
|
| 428 | - * @return mixed |
|
| 429 | - */ |
|
| 430 | - public function parseViews($parse = false) |
|
| 431 | - { |
|
| 432 | - $this->parse_views = $parse; |
|
| 433 | - |
|
| 434 | - return $this; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - //-------------------------------------------------------------------- |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Theme paths allow you to have multiple locations for themes to be |
|
| 441 | - * stored. This might be used for separating themes for different sub- |
|
| 442 | - * applications, or a core theme and user-submitted themes. |
|
| 443 | - * |
|
| 444 | - * @param $alias The name the theme can be referenced by |
|
| 445 | - * @param $path A new path where themes can be found. |
|
| 446 | - * |
|
| 447 | - * @return mixed |
|
| 448 | - */ |
|
| 449 | - public function addThemePath($alias, $path) |
|
| 450 | - { |
|
| 451 | - $this->folders[$alias] = $path; |
|
| 452 | - |
|
| 453 | - return $this; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - //-------------------------------------------------------------------- |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Removes a single theme path. |
|
| 460 | - * |
|
| 461 | - * @param $alias |
|
| 462 | - * @return $this |
|
| 463 | - */ |
|
| 464 | - public function removeThemePath($alias) |
|
| 465 | - { |
|
| 466 | - unset($this->folders[$alias]); |
|
| 467 | - |
|
| 468 | - return $this; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - //-------------------------------------------------------------------- |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Returns the path to the active/default theme's folder. |
|
| 475 | - * |
|
| 476 | - * @return string|null |
|
| 477 | - */ |
|
| 478 | - public function getThemePath() |
|
| 479 | - { |
|
| 480 | - $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
| 481 | - |
|
| 482 | - if (! isset($this->folders[ $theme ])) |
|
| 483 | - { |
|
| 484 | - return null; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $this->folders[$theme]; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - //-------------------------------------------------------------------- |
|
| 491 | - |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - //-------------------------------------------------------------------- |
|
| 495 | - // Variants |
|
| 496 | - //-------------------------------------------------------------------- |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Sets the variant used when creating view names. These variants can |
|
| 500 | - * be anything, but by default are used to render specific templates |
|
| 501 | - * for desktop, tablet, and phone. The name of the variant is added |
|
| 502 | - * to the view name, joined by a "+" symbol. |
|
| 503 | - * |
|
| 504 | - * Example: |
|
| 505 | - * $this->setVariant('phone'); |
|
| 506 | - * $this->display('header'); |
|
| 507 | - * |
|
| 508 | - * Tries to display "views/header+phone.php" |
|
| 509 | - * |
|
| 510 | - * @param $variant |
|
| 511 | - * @return $this |
|
| 512 | - */ |
|
| 513 | - public function setVariant($variant) |
|
| 514 | - { |
|
| 515 | - if (isset($this->variants[$variant])) { |
|
| 516 | - $this->current_variant = $variant; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - return $this; |
|
| 520 | - } |
|
| 521 | - //-------------------------------------------------------------------- |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Adds a new variant to the system. |
|
| 525 | - * |
|
| 526 | - * @param $name |
|
| 527 | - * @param $postfix |
|
| 528 | - * @return $this|mixed |
|
| 529 | - */ |
|
| 530 | - public function addVariant($name, $postfix) |
|
| 531 | - { |
|
| 532 | - $this->variants[$name] = $postfix; |
|
| 533 | - |
|
| 534 | - return $this; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - //-------------------------------------------------------------------- |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Removes a variant from the system. |
|
| 541 | - * |
|
| 542 | - * @param $name |
|
| 543 | - * @return $this|mixed |
|
| 544 | - */ |
|
| 545 | - public function removeVariant($name) |
|
| 546 | - { |
|
| 547 | - if (isset($this->variants[$name])) { |
|
| 548 | - unset($this->variants[$name]); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - return $this; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - //-------------------------------------------------------------------- |
|
| 555 | - // Private Methods |
|
| 556 | - //-------------------------------------------------------------------- |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Handles the actual loading of a view file, and checks for any |
|
| 560 | - * overrides in themes, etc. |
|
| 561 | - * |
|
| 562 | - * @param $view |
|
| 563 | - * @param $data |
|
| 564 | - * |
|
| 565 | - * @return string |
|
| 566 | - */ |
|
| 567 | - private function loadView($view, $data) |
|
| 568 | - { |
|
| 569 | - // First - does it exist in the current theme? |
|
| 570 | - $theme = ! empty($this->active_theme) ? $this->active_theme : $this->default_theme; |
|
| 571 | - $theme = ! empty($this->folders[$theme]) ? $this->folders[$theme] : $theme; |
|
| 572 | - $theme = rtrim($theme, '/ ') .'/'; |
|
| 573 | - |
|
| 574 | - if (file_exists($theme ."{$view}.php")) |
|
| 575 | - { |
|
| 576 | - $output = $this->ci->load->view_path( $theme . $view, $data, TRUE ); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - // Next, if it's a real file with path, then load it |
|
| 580 | - elseif ( realpath( $view . '.php' ) ) |
|
| 581 | - { |
|
| 582 | - $output = $this->ci->load->view_path( $view, $data, TRUE ); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - // Otherwise, treat it as a standard view, which means |
|
| 586 | - // application/views will override any modules. (See HMVC/Loader) |
|
| 587 | - else |
|
| 588 | - { |
|
| 589 | - $output = $this->ci->load->view( $view, $data, TRUE ); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - return $output; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - //-------------------------------------------------------------------- |
|
| 120 | + $dir = str_replace('controllers/', '', $dir); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $module = $this->ci->router->fetch_module(); |
|
| 125 | + |
|
| 126 | + if (! empty($module) && substr($dir, -strlen($module .'/')) == $module . '/') { |
|
| 127 | + $dir = ''; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $view = ! empty($this->view) ? $this->view : |
|
| 131 | + $dir . $this->ci->router->fetch_class() . '/' . $this->ci->router->fetch_method(); |
|
| 132 | + |
|
| 133 | + return $this->display($view); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + //-------------------------------------------------------------------- |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Loads a view file. Useful to control caching. Intended for use |
|
| 140 | + * from within view files. |
|
| 141 | + * |
|
| 142 | + * You can specify that a view should belong to a theme by prefixing |
|
| 143 | + * the name of the theme and a colon to the view name. For example, |
|
| 144 | + * "admin:header" would try to display the "header.php" file within |
|
| 145 | + * the "admin" theme. |
|
| 146 | + * |
|
| 147 | + * If a variant has been specified, it will be added to the end |
|
| 148 | + * of the view name before looking for the file. |
|
| 149 | + * |
|
| 150 | + * @param string $view |
|
| 151 | + * @param array $data |
|
| 152 | + * @param int $cache_time Number of minutes to cache the page for |
|
| 153 | + * @param string $cache_name A custom name for the cached file. |
|
| 154 | + * @return mixed |
|
| 155 | + */ |
|
| 156 | + public function display($view, $data = array(), $cache_time = 0, $cache_name=null) |
|
| 157 | + { |
|
| 158 | + if (empty($cache_name)) |
|
| 159 | + { |
|
| 160 | + $cache_name = 'theme_view_' . $view . '_' . $this->ci->router->fetch_class() . '_' . $this->ci->router->fetch_method(); |
|
| 161 | + $cache_name = str_replace( '/', '_', $cache_name ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if ($cache_time == 0 || ! $output = $this->ci->cache->get($cache_name)) |
|
| 165 | + { |
|
| 166 | + $theme = NULL; |
|
| 167 | + $variant_view = NULL; |
|
| 168 | + |
|
| 169 | + // Pull out the theme from the view, if given. |
|
| 170 | + if ( strpos( $view, ':' ) !== FALSE ) |
|
| 171 | + { |
|
| 172 | + list( $theme, $view ) = explode( ':', $view ); |
|
| 173 | + |
|
| 174 | + $theme = str_replace('{theme}', $this->active_theme, $theme); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if ( ! empty( $theme ) && isset( $this->folders[ $theme ] ) ) |
|
| 178 | + { |
|
| 179 | + $view = rtrim( $this->folders[ $theme ], '/' ) . '/' . $view; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (! is_array($data)) |
|
| 183 | + { |
|
| 184 | + $data = []; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $data = array_merge( $this->vars, $data ); |
|
| 188 | + |
|
| 189 | + // if using a variant, add it to the view name. |
|
| 190 | + if ( ! empty( $this->current_variant ) ) |
|
| 191 | + { |
|
| 192 | + $variant_view = $view . $this->variants[ $this->current_variant ]; |
|
| 193 | + |
|
| 194 | + $output = $this->loadView($variant_view, $data); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // If that didn't find anything, then try it without a variant |
|
| 198 | + if ( empty( $output ) ) |
|
| 199 | + { |
|
| 200 | + $output = $this->loadView($view, $data); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + // Cache it |
|
| 204 | + if ((int)$cache_time > 0) |
|
| 205 | + { |
|
| 206 | + $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Parse views? |
|
| 211 | + if ($this->parse_views) |
|
| 212 | + { |
|
| 213 | + $this->ci->load->library('parser'); |
|
| 214 | + |
|
| 215 | + // Any class objects will cause failure |
|
| 216 | + // so get rid of those bad boys.... |
|
| 217 | + unset($data['uikit'], $data['themer']); |
|
| 218 | + |
|
| 219 | + $output = $this->ci->parser->parse_string($output, $data, true); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return $output; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + //-------------------------------------------------------------------- |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Runs a callback method and returns the contents to the view. |
|
| 229 | + * |
|
| 230 | + * @param $command |
|
| 231 | + * @param int $cache_time |
|
| 232 | + * @param string $cache_name // Number of MINUTES to cache output |
|
| 233 | + * @return mixed|void |
|
| 234 | + */ |
|
| 235 | + public function call($command, $cache_time=0, $cache_name=null) |
|
| 236 | + { |
|
| 237 | + if (empty($cache_name)) |
|
| 238 | + { |
|
| 239 | + $cache_name = 'theme_call_' . md5( $command ); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if (! $output = $this->ci->cache->get($cache_name)) { |
|
| 243 | + $parts = explode(' ', $command); |
|
| 244 | + |
|
| 245 | + list($class, $method) = explode(':', array_shift($parts)); |
|
| 246 | + |
|
| 247 | + // Prepare our parameter list to send to the callback |
|
| 248 | + // by splitting $parts on equal signs. |
|
| 249 | + $params = array(); |
|
| 250 | + |
|
| 251 | + foreach ($parts as $part) { |
|
| 252 | + $p = explode('=', $part); |
|
| 253 | + |
|
| 254 | + if (empty($p[0]) || empty($p[1])) |
|
| 255 | + { |
|
| 256 | + continue; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $params[ $p[0] ] = $p[1]; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + // Let PHP try to autoload it through any available autoloaders |
|
| 263 | + // (including Composer and user's custom autoloaders). If we |
|
| 264 | + // don't find it, then assume it's a CI library that we can reach. |
|
| 265 | + if (class_exists($class)) { |
|
| 266 | + $class = new $class(); |
|
| 267 | + } else { |
|
| 268 | + $this->ci->load->library($class); |
|
| 269 | + $class =& $this->ci->$class; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + if (! method_exists($class, $method)) { |
|
| 273 | + throw new \RuntimeException( sprintf( lang('themer.bad_callback'), $class, $method ) ); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // Call the class with our parameters |
|
| 277 | + $output = $class->{$method}($params); |
|
| 278 | + |
|
| 279 | + // Cache it |
|
| 280 | + if ((int)$cache_time > 0) |
|
| 281 | + { |
|
| 282 | + $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return $output; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + //-------------------------------------------------------------------- |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Sets the active theme to use. This theme should be |
|
| 293 | + * relative to one of the 'theme_paths' folders. |
|
| 294 | + * |
|
| 295 | + * @param $theme |
|
| 296 | + */ |
|
| 297 | + public function setTheme($theme) |
|
| 298 | + { |
|
| 299 | + $this->theme = $theme; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + //-------------------------------------------------------------------- |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Returns the current theme. |
|
| 306 | + * |
|
| 307 | + * @return mixed|string |
|
| 308 | + */ |
|
| 309 | + public function theme() |
|
| 310 | + { |
|
| 311 | + return $this->theme; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + //-------------------------------------------------------------------- |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Sets the default theme to use if another isn't specified. |
|
| 318 | + * |
|
| 319 | + * @param $theme |
|
| 320 | + * @return mixed|void |
|
| 321 | + */ |
|
| 322 | + public function setDefaultTheme($theme) |
|
| 323 | + { |
|
| 324 | + $this->default_theme = $theme; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + //-------------------------------------------------------------------- |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Sets the current view file to render. |
|
| 332 | + * |
|
| 333 | + * @param $file |
|
| 334 | + * @return mixed |
|
| 335 | + */ |
|
| 336 | + public function setView($file) |
|
| 337 | + { |
|
| 338 | + $this->view = $file; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + //-------------------------------------------------------------------- |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Returns the current view. |
|
| 345 | + * |
|
| 346 | + * @return mixed|string |
|
| 347 | + */ |
|
| 348 | + public function view() |
|
| 349 | + { |
|
| 350 | + return $this->view; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + //-------------------------------------------------------------------- |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Sets the current layout to be used. MUST be the name of one of |
|
| 357 | + * the layout files within the current theme. Case-sensitive. |
|
| 358 | + * |
|
| 359 | + * @param $file |
|
| 360 | + * @return mixed |
|
| 361 | + */ |
|
| 362 | + public function setLayout($file) |
|
| 363 | + { |
|
| 364 | + if (empty($file)) return; |
|
| 365 | + |
|
| 366 | + $this->layout = $file; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + //-------------------------------------------------------------------- |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Returns the current layout. |
|
| 373 | + * |
|
| 374 | + * @return mixed|string |
|
| 375 | + */ |
|
| 376 | + public function layout() |
|
| 377 | + { |
|
| 378 | + return $this->layout; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + //-------------------------------------------------------------------- |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Stores one or more pieces of data to be passed to the views when |
|
| 385 | + * they are rendered out. |
|
| 386 | + * |
|
| 387 | + * If both $key and $value are ! empty, then it will treat it as a |
|
| 388 | + * key/value pair. If $key is an array of key/value pairs, then $value |
|
| 389 | + * is ignored and each element of the array are made available to the |
|
| 390 | + * view as if it was a single $key/$value pair. |
|
| 391 | + * |
|
| 392 | + * @param string|array $key |
|
| 393 | + * @param mixed $value |
|
| 394 | + * @return $this |
|
| 395 | + */ |
|
| 396 | + public function set($key, $value = null) |
|
| 397 | + { |
|
| 398 | + if (is_array($key)) { |
|
| 399 | + $this->vars = array_merge($this->vars, $key); |
|
| 400 | + return; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + $this->vars[$key] = $value; |
|
| 404 | + |
|
| 405 | + return $this; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + //-------------------------------------------------------------------- |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Returns a value that has been previously set(). |
|
| 412 | + * |
|
| 413 | + * @param $key |
|
| 414 | + * @return mixed |
|
| 415 | + */ |
|
| 416 | + public function get($key) |
|
| 417 | + { |
|
| 418 | + return isset($this->vars[$key]) ? $this->vars[$key] : null; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + //-------------------------------------------------------------------- |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Determines whether or not the view should be parsed with the |
|
| 425 | + * CodeIgniter's parser. |
|
| 426 | + * |
|
| 427 | + * @param bool $parse |
|
| 428 | + * @return mixed |
|
| 429 | + */ |
|
| 430 | + public function parseViews($parse = false) |
|
| 431 | + { |
|
| 432 | + $this->parse_views = $parse; |
|
| 433 | + |
|
| 434 | + return $this; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + //-------------------------------------------------------------------- |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Theme paths allow you to have multiple locations for themes to be |
|
| 441 | + * stored. This might be used for separating themes for different sub- |
|
| 442 | + * applications, or a core theme and user-submitted themes. |
|
| 443 | + * |
|
| 444 | + * @param $alias The name the theme can be referenced by |
|
| 445 | + * @param $path A new path where themes can be found. |
|
| 446 | + * |
|
| 447 | + * @return mixed |
|
| 448 | + */ |
|
| 449 | + public function addThemePath($alias, $path) |
|
| 450 | + { |
|
| 451 | + $this->folders[$alias] = $path; |
|
| 452 | + |
|
| 453 | + return $this; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + //-------------------------------------------------------------------- |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Removes a single theme path. |
|
| 460 | + * |
|
| 461 | + * @param $alias |
|
| 462 | + * @return $this |
|
| 463 | + */ |
|
| 464 | + public function removeThemePath($alias) |
|
| 465 | + { |
|
| 466 | + unset($this->folders[$alias]); |
|
| 467 | + |
|
| 468 | + return $this; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + //-------------------------------------------------------------------- |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Returns the path to the active/default theme's folder. |
|
| 475 | + * |
|
| 476 | + * @return string|null |
|
| 477 | + */ |
|
| 478 | + public function getThemePath() |
|
| 479 | + { |
|
| 480 | + $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
| 481 | + |
|
| 482 | + if (! isset($this->folders[ $theme ])) |
|
| 483 | + { |
|
| 484 | + return null; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $this->folders[$theme]; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + //-------------------------------------------------------------------- |
|
| 491 | + |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + //-------------------------------------------------------------------- |
|
| 495 | + // Variants |
|
| 496 | + //-------------------------------------------------------------------- |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Sets the variant used when creating view names. These variants can |
|
| 500 | + * be anything, but by default are used to render specific templates |
|
| 501 | + * for desktop, tablet, and phone. The name of the variant is added |
|
| 502 | + * to the view name, joined by a "+" symbol. |
|
| 503 | + * |
|
| 504 | + * Example: |
|
| 505 | + * $this->setVariant('phone'); |
|
| 506 | + * $this->display('header'); |
|
| 507 | + * |
|
| 508 | + * Tries to display "views/header+phone.php" |
|
| 509 | + * |
|
| 510 | + * @param $variant |
|
| 511 | + * @return $this |
|
| 512 | + */ |
|
| 513 | + public function setVariant($variant) |
|
| 514 | + { |
|
| 515 | + if (isset($this->variants[$variant])) { |
|
| 516 | + $this->current_variant = $variant; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + return $this; |
|
| 520 | + } |
|
| 521 | + //-------------------------------------------------------------------- |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Adds a new variant to the system. |
|
| 525 | + * |
|
| 526 | + * @param $name |
|
| 527 | + * @param $postfix |
|
| 528 | + * @return $this|mixed |
|
| 529 | + */ |
|
| 530 | + public function addVariant($name, $postfix) |
|
| 531 | + { |
|
| 532 | + $this->variants[$name] = $postfix; |
|
| 533 | + |
|
| 534 | + return $this; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + //-------------------------------------------------------------------- |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Removes a variant from the system. |
|
| 541 | + * |
|
| 542 | + * @param $name |
|
| 543 | + * @return $this|mixed |
|
| 544 | + */ |
|
| 545 | + public function removeVariant($name) |
|
| 546 | + { |
|
| 547 | + if (isset($this->variants[$name])) { |
|
| 548 | + unset($this->variants[$name]); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + return $this; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + //-------------------------------------------------------------------- |
|
| 555 | + // Private Methods |
|
| 556 | + //-------------------------------------------------------------------- |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Handles the actual loading of a view file, and checks for any |
|
| 560 | + * overrides in themes, etc. |
|
| 561 | + * |
|
| 562 | + * @param $view |
|
| 563 | + * @param $data |
|
| 564 | + * |
|
| 565 | + * @return string |
|
| 566 | + */ |
|
| 567 | + private function loadView($view, $data) |
|
| 568 | + { |
|
| 569 | + // First - does it exist in the current theme? |
|
| 570 | + $theme = ! empty($this->active_theme) ? $this->active_theme : $this->default_theme; |
|
| 571 | + $theme = ! empty($this->folders[$theme]) ? $this->folders[$theme] : $theme; |
|
| 572 | + $theme = rtrim($theme, '/ ') .'/'; |
|
| 573 | + |
|
| 574 | + if (file_exists($theme ."{$view}.php")) |
|
| 575 | + { |
|
| 576 | + $output = $this->ci->load->view_path( $theme . $view, $data, TRUE ); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + // Next, if it's a real file with path, then load it |
|
| 580 | + elseif ( realpath( $view . '.php' ) ) |
|
| 581 | + { |
|
| 582 | + $output = $this->ci->load->view_path( $view, $data, TRUE ); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + // Otherwise, treat it as a standard view, which means |
|
| 586 | + // application/views will override any modules. (See HMVC/Loader) |
|
| 587 | + else |
|
| 588 | + { |
|
| 589 | + $output = $this->ci->load->view( $view, $data, TRUE ); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + return $output; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + //-------------------------------------------------------------------- |
|
| 596 | 596 | |
| 597 | 597 | } |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
| 88 | 88 | |
| 89 | - if (! isset($this->folders[$theme])) { |
|
| 90 | - throw new \LogicException( sprintf( lang('theme.bad_folder'), $theme ) ); |
|
| 89 | + if ( ! isset($this->folders[$theme])) { |
|
| 90 | + throw new \LogicException(sprintf(lang('theme.bad_folder'), $theme)); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $this->active_theme = $theme; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | // Make the path available within views. |
| 96 | 96 | $this->vars['theme_path'] = $this->folders[$theme]; |
| 97 | 97 | |
| 98 | - return $this->display($this->folders[$theme] . '/' . $this->layout); |
|
| 98 | + return $this->display($this->folders[$theme].'/'.$this->layout); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | //-------------------------------------------------------------------- |
@@ -123,12 +123,11 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $module = $this->ci->router->fetch_module(); |
| 125 | 125 | |
| 126 | - if (! empty($module) && substr($dir, -strlen($module .'/')) == $module . '/') { |
|
| 126 | + if ( ! empty($module) && substr($dir, -strlen($module.'/')) == $module.'/') { |
|
| 127 | 127 | $dir = ''; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - $view = ! empty($this->view) ? $this->view : |
|
| 131 | - $dir . $this->ci->router->fetch_class() . '/' . $this->ci->router->fetch_method(); |
|
| 130 | + $view = ! empty($this->view) ? $this->view : $dir.$this->ci->router->fetch_class().'/'.$this->ci->router->fetch_method(); |
|
| 132 | 131 | |
| 133 | 132 | return $this->display($view); |
| 134 | 133 | } |
@@ -153,12 +152,12 @@ discard block |
||
| 153 | 152 | * @param string $cache_name A custom name for the cached file. |
| 154 | 153 | * @return mixed |
| 155 | 154 | */ |
| 156 | - public function display($view, $data = array(), $cache_time = 0, $cache_name=null) |
|
| 155 | + public function display($view, $data = array(), $cache_time = 0, $cache_name = null) |
|
| 157 | 156 | { |
| 158 | 157 | if (empty($cache_name)) |
| 159 | 158 | { |
| 160 | - $cache_name = 'theme_view_' . $view . '_' . $this->ci->router->fetch_class() . '_' . $this->ci->router->fetch_method(); |
|
| 161 | - $cache_name = str_replace( '/', '_', $cache_name ); |
|
| 159 | + $cache_name = 'theme_view_'.$view.'_'.$this->ci->router->fetch_class().'_'.$this->ci->router->fetch_method(); |
|
| 160 | + $cache_name = str_replace('/', '_', $cache_name); |
|
| 162 | 161 | } |
| 163 | 162 | |
| 164 | 163 | if ($cache_time == 0 || ! $output = $this->ci->cache->get($cache_name)) |
@@ -167,43 +166,43 @@ discard block |
||
| 167 | 166 | $variant_view = NULL; |
| 168 | 167 | |
| 169 | 168 | // Pull out the theme from the view, if given. |
| 170 | - if ( strpos( $view, ':' ) !== FALSE ) |
|
| 169 | + if (strpos($view, ':') !== FALSE) |
|
| 171 | 170 | { |
| 172 | - list( $theme, $view ) = explode( ':', $view ); |
|
| 171 | + list($theme, $view) = explode(':', $view); |
|
| 173 | 172 | |
| 174 | 173 | $theme = str_replace('{theme}', $this->active_theme, $theme); |
| 175 | 174 | } |
| 176 | 175 | |
| 177 | - if ( ! empty( $theme ) && isset( $this->folders[ $theme ] ) ) |
|
| 176 | + if ( ! empty($theme) && isset($this->folders[$theme])) |
|
| 178 | 177 | { |
| 179 | - $view = rtrim( $this->folders[ $theme ], '/' ) . '/' . $view; |
|
| 178 | + $view = rtrim($this->folders[$theme], '/').'/'.$view; |
|
| 180 | 179 | } |
| 181 | 180 | |
| 182 | - if (! is_array($data)) |
|
| 181 | + if ( ! is_array($data)) |
|
| 183 | 182 | { |
| 184 | 183 | $data = []; |
| 185 | 184 | } |
| 186 | 185 | |
| 187 | - $data = array_merge( $this->vars, $data ); |
|
| 186 | + $data = array_merge($this->vars, $data); |
|
| 188 | 187 | |
| 189 | 188 | // if using a variant, add it to the view name. |
| 190 | - if ( ! empty( $this->current_variant ) ) |
|
| 189 | + if ( ! empty($this->current_variant)) |
|
| 191 | 190 | { |
| 192 | - $variant_view = $view . $this->variants[ $this->current_variant ]; |
|
| 191 | + $variant_view = $view.$this->variants[$this->current_variant]; |
|
| 193 | 192 | |
| 194 | 193 | $output = $this->loadView($variant_view, $data); |
| 195 | 194 | } |
| 196 | 195 | |
| 197 | 196 | // If that didn't find anything, then try it without a variant |
| 198 | - if ( empty( $output ) ) |
|
| 197 | + if (empty($output)) |
|
| 199 | 198 | { |
| 200 | 199 | $output = $this->loadView($view, $data); |
| 201 | 200 | } |
| 202 | 201 | |
| 203 | 202 | // Cache it |
| 204 | - if ((int)$cache_time > 0) |
|
| 203 | + if ((int) $cache_time > 0) |
|
| 205 | 204 | { |
| 206 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 205 | + $this->ci->cache->save($cache_name, $output, (int) $cache_time * 60); |
|
| 207 | 206 | } |
| 208 | 207 | } |
| 209 | 208 | |
@@ -232,14 +231,14 @@ discard block |
||
| 232 | 231 | * @param string $cache_name // Number of MINUTES to cache output |
| 233 | 232 | * @return mixed|void |
| 234 | 233 | */ |
| 235 | - public function call($command, $cache_time=0, $cache_name=null) |
|
| 234 | + public function call($command, $cache_time = 0, $cache_name = null) |
|
| 236 | 235 | { |
| 237 | 236 | if (empty($cache_name)) |
| 238 | 237 | { |
| 239 | - $cache_name = 'theme_call_' . md5( $command ); |
|
| 238 | + $cache_name = 'theme_call_'.md5($command); |
|
| 240 | 239 | } |
| 241 | 240 | |
| 242 | - if (! $output = $this->ci->cache->get($cache_name)) { |
|
| 241 | + if ( ! $output = $this->ci->cache->get($cache_name)) { |
|
| 243 | 242 | $parts = explode(' ', $command); |
| 244 | 243 | |
| 245 | 244 | list($class, $method) = explode(':', array_shift($parts)); |
@@ -256,7 +255,7 @@ discard block |
||
| 256 | 255 | continue; |
| 257 | 256 | } |
| 258 | 257 | |
| 259 | - $params[ $p[0] ] = $p[1]; |
|
| 258 | + $params[$p[0]] = $p[1]; |
|
| 260 | 259 | } |
| 261 | 260 | |
| 262 | 261 | // Let PHP try to autoload it through any available autoloaders |
@@ -266,20 +265,20 @@ discard block |
||
| 266 | 265 | $class = new $class(); |
| 267 | 266 | } else { |
| 268 | 267 | $this->ci->load->library($class); |
| 269 | - $class =& $this->ci->$class; |
|
| 268 | + $class = & $this->ci->$class; |
|
| 270 | 269 | } |
| 271 | 270 | |
| 272 | - if (! method_exists($class, $method)) { |
|
| 273 | - throw new \RuntimeException( sprintf( lang('themer.bad_callback'), $class, $method ) ); |
|
| 271 | + if ( ! method_exists($class, $method)) { |
|
| 272 | + throw new \RuntimeException(sprintf(lang('themer.bad_callback'), $class, $method)); |
|
| 274 | 273 | } |
| 275 | 274 | |
| 276 | 275 | // Call the class with our parameters |
| 277 | 276 | $output = $class->{$method}($params); |
| 278 | 277 | |
| 279 | 278 | // Cache it |
| 280 | - if ((int)$cache_time > 0) |
|
| 279 | + if ((int) $cache_time > 0) |
|
| 281 | 280 | { |
| 282 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 281 | + $this->ci->cache->save($cache_name, $output, (int) $cache_time * 60); |
|
| 283 | 282 | } |
| 284 | 283 | } |
| 285 | 284 | |
@@ -479,7 +478,7 @@ discard block |
||
| 479 | 478 | { |
| 480 | 479 | $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
| 481 | 480 | |
| 482 | - if (! isset($this->folders[ $theme ])) |
|
| 481 | + if ( ! isset($this->folders[$theme])) |
|
| 483 | 482 | { |
| 484 | 483 | return null; |
| 485 | 484 | } |
@@ -569,24 +568,24 @@ discard block |
||
| 569 | 568 | // First - does it exist in the current theme? |
| 570 | 569 | $theme = ! empty($this->active_theme) ? $this->active_theme : $this->default_theme; |
| 571 | 570 | $theme = ! empty($this->folders[$theme]) ? $this->folders[$theme] : $theme; |
| 572 | - $theme = rtrim($theme, '/ ') .'/'; |
|
| 571 | + $theme = rtrim($theme, '/ ').'/'; |
|
| 573 | 572 | |
| 574 | - if (file_exists($theme ."{$view}.php")) |
|
| 573 | + if (file_exists($theme."{$view}.php")) |
|
| 575 | 574 | { |
| 576 | - $output = $this->ci->load->view_path( $theme . $view, $data, TRUE ); |
|
| 575 | + $output = $this->ci->load->view_path($theme.$view, $data, TRUE); |
|
| 577 | 576 | } |
| 578 | 577 | |
| 579 | 578 | // Next, if it's a real file with path, then load it |
| 580 | - elseif ( realpath( $view . '.php' ) ) |
|
| 579 | + elseif (realpath($view.'.php')) |
|
| 581 | 580 | { |
| 582 | - $output = $this->ci->load->view_path( $view, $data, TRUE ); |
|
| 581 | + $output = $this->ci->load->view_path($view, $data, TRUE); |
|
| 583 | 582 | } |
| 584 | 583 | |
| 585 | 584 | // Otherwise, treat it as a standard view, which means |
| 586 | 585 | // application/views will override any modules. (See HMVC/Loader) |
| 587 | 586 | else |
| 588 | 587 | { |
| 589 | - $output = $this->ci->load->view( $view, $data, TRUE ); |
|
| 588 | + $output = $this->ci->load->view($view, $data, TRUE); |
|
| 590 | 589 | } |
| 591 | 590 | |
| 592 | 591 | return $output; |
@@ -361,7 +361,9 @@ |
||
| 361 | 361 | */ |
| 362 | 362 | public function setLayout($file) |
| 363 | 363 | { |
| 364 | - if (empty($file)) return; |
|
| 364 | + if (empty($file)) { |
|
| 365 | + return; |
|
| 366 | + } |
|
| 365 | 367 | |
| 366 | 368 | $this->layout = $file; |
| 367 | 369 | } |
@@ -91,7 +91,6 @@ discard block |
||
| 91 | 91 | * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
| 92 | 92 | * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
| 93 | 93 | * |
| 94 | - * @param array $attributes |
|
| 95 | 94 | * @return mixed |
| 96 | 95 | */ |
| 97 | 96 | abstract public function column($options=[], \Closure $c); |
@@ -107,7 +106,7 @@ discard block |
||
| 107 | 106 | * top of a page. |
| 108 | 107 | * |
| 109 | 108 | * @param array $options |
| 110 | - * @param callable $c |
|
| 109 | + * @param \Closure $c |
|
| 111 | 110 | * @return string |
| 112 | 111 | */ |
| 113 | 112 | abstract public function navbar($options=[], \Closure $c); |
@@ -133,7 +132,7 @@ discard block |
||
| 133 | 132 | * 'class' - An additional class to add |
| 134 | 133 | * |
| 135 | 134 | * @param array $options |
| 136 | - * @param callable $c |
|
| 135 | + * @param \Closure $c |
|
| 137 | 136 | * @return string |
| 138 | 137 | */ |
| 139 | 138 | abstract public function navbarRight($options=[], \Closure $c); |
@@ -157,7 +156,7 @@ discard block |
||
| 157 | 156 | * |
| 158 | 157 | * @param $title |
| 159 | 158 | * @param array $options |
| 160 | - * @param callable $c |
|
| 159 | + * @param \Closure $c |
|
| 161 | 160 | */ |
| 162 | 161 | abstract public function navDropdown($title,$options=[], \Closure $c); |
| 163 | 162 | |
@@ -176,7 +175,7 @@ discard block |
||
| 176 | 175 | * Creates a list of nav items to function as breadcrumbs for a site. |
| 177 | 176 | * |
| 178 | 177 | * @param array $options |
| 179 | - * @param callable $c |
|
| 178 | + * @param \Closure $c |
|
| 180 | 179 | * @return mixed |
| 181 | 180 | */ |
| 182 | 181 | abstract public function breadcrumb($options=[], \Closure $c); |
@@ -218,7 +217,7 @@ discard block |
||
| 218 | 217 | * Creates button groups wrapping HTML. |
| 219 | 218 | * |
| 220 | 219 | * @param $options |
| 221 | - * @param callable $c |
|
| 220 | + * @param \Closure $c |
|
| 222 | 221 | * @return mixed |
| 223 | 222 | */ |
| 224 | 223 | abstract public function buttonGroup($options, \Closure $c); |
@@ -227,7 +226,7 @@ discard block |
||
| 227 | 226 | * Creates the button bar wrapping HTML. |
| 228 | 227 | * |
| 229 | 228 | * @param $options |
| 230 | - * @param callable $c |
|
| 229 | + * @param \Closure $c |
|
| 231 | 230 | * @return mixed |
| 232 | 231 | */ |
| 233 | 232 | abstract public function buttonBar($options, \Closure $c); |
@@ -240,7 +239,7 @@ discard block |
||
| 240 | 239 | * @param string $style |
| 241 | 240 | * @param string $size |
| 242 | 241 | * @param array $options |
| 243 | - * @param callable $c |
|
| 242 | + * @param \Closure $c |
|
| 244 | 243 | * @return mixed |
| 245 | 244 | */ |
| 246 | 245 | abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
@@ -272,7 +271,7 @@ discard block |
||
| 272 | 271 | * |
| 273 | 272 | * @param $label_text |
| 274 | 273 | * @param array $options |
| 275 | - * @param callable $c |
|
| 274 | + * @param \Closure $c |
|
| 276 | 275 | * |
| 277 | 276 | * @return mixed |
| 278 | 277 | */ |
@@ -285,7 +284,7 @@ discard block |
||
| 285 | 284 | /** |
| 286 | 285 | * Helper method to run a Closure and collect the output of it. |
| 287 | 286 | * |
| 288 | - * @param callable $c |
|
| 287 | + * @param \Closure $c |
|
| 289 | 288 | * @return string |
| 290 | 289 | */ |
| 291 | 290 | protected function runClosure(\Closure $c) |
@@ -1,34 +1,34 @@ discard block |
||
| 1 | 1 | <?php namespace Myth\UIKits; |
| 2 | 2 | /** |
| 3 | - * Sprint |
|
| 4 | - * |
|
| 5 | - * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
| 6 | - * |
|
| 7 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 8 | - * of this software and associated documentation files (the "Software"), to deal |
|
| 9 | - * in the Software without restriction, including without limitation the rights |
|
| 10 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 11 | - * copies of the Software, and to permit persons to whom the Software is |
|
| 12 | - * furnished to do so, subject to the following conditions: |
|
| 13 | - * |
|
| 14 | - * The above copyright notice and this permission notice shall be included in |
|
| 15 | - * all copies or substantial portions of the Software. |
|
| 16 | - * |
|
| 17 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 18 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 19 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 20 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 21 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 22 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 23 | - * THE SOFTWARE. |
|
| 24 | - * |
|
| 25 | - * @package Sprint |
|
| 26 | - * @author Lonnie Ezell |
|
| 27 | - * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
| 28 | - * @license http://opensource.org/licenses/MIT (MIT) |
|
| 29 | - * @link http://sprintphp.com |
|
| 30 | - * @since Version 1.0 |
|
| 31 | - */ |
|
| 3 | + * Sprint |
|
| 4 | + * |
|
| 5 | + * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
| 6 | + * |
|
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
|
| 9 | + * in the Software without restriction, including without limitation the rights |
|
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
|
| 12 | + * furnished to do so, subject to the following conditions: |
|
| 13 | + * |
|
| 14 | + * The above copyright notice and this permission notice shall be included in |
|
| 15 | + * all copies or substantial portions of the Software. |
|
| 16 | + * |
|
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 23 | + * THE SOFTWARE. |
|
| 24 | + * |
|
| 25 | + * @package Sprint |
|
| 26 | + * @author Lonnie Ezell |
|
| 27 | + * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
| 28 | + * @license http://opensource.org/licenses/MIT (MIT) |
|
| 29 | + * @link http://sprintphp.com |
|
| 30 | + * @since Version 1.0 |
|
| 31 | + */ |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Class BaseUIKit |
@@ -38,228 +38,228 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | abstract class BaseUIKit { |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Bucket for methods to control their current state between method calls. |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - protected $states = []; |
|
| 46 | - |
|
| 47 | - protected $name = ''; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Attached to nav items that are considered active. |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $active_class = 'active'; |
|
| 54 | - |
|
| 55 | - //-------------------------------------------------------------------- |
|
| 56 | - |
|
| 57 | - public function name() |
|
| 58 | - { |
|
| 59 | - return $this->name; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - //-------------------------------------------------------------------- |
|
| 63 | - |
|
| 64 | - //-------------------------------------------------------------------- |
|
| 65 | - // Grids |
|
| 66 | - //-------------------------------------------------------------------- |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
| 70 | - * the class for it, but some frameworks use a completely different |
|
| 71 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 72 | - * |
|
| 73 | - * @param array $options |
|
| 74 | - * @return mixed |
|
| 75 | - */ |
|
| 76 | - abstract public function row($options=[], \Closure $c); |
|
| 77 | - |
|
| 78 | - //-------------------------------------------------------------------- |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Creates the CSS for a column in a grid. |
|
| 82 | - * |
|
| 83 | - * The attribute array is made up of key/value pairs with the |
|
| 84 | - * key being the size, and the value being the number of columns/offset |
|
| 85 | - * in a 12-column grid. |
|
| 86 | - * |
|
| 87 | - * Note that we currently DO NOT support offset columns. |
|
| 88 | - * |
|
| 89 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 90 | - * |
|
| 91 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 92 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 93 | - * |
|
| 94 | - * @param array $attributes |
|
| 95 | - * @return mixed |
|
| 96 | - */ |
|
| 97 | - abstract public function column($options=[], \Closure $c); |
|
| 98 | - |
|
| 99 | - //-------------------------------------------------------------------- |
|
| 100 | - |
|
| 101 | - //-------------------------------------------------------------------- |
|
| 102 | - // Navigation |
|
| 103 | - //-------------------------------------------------------------------- |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Generates the container code for a navbar, typically used along the |
|
| 107 | - * top of a page. |
|
| 108 | - * |
|
| 109 | - * @param array $options |
|
| 110 | - * @param callable $c |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - abstract public function navbar($options=[], \Closure $c); |
|
| 114 | - |
|
| 115 | - //-------------------------------------------------------------------- |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
| 119 | - * includes the code for the hamburger menu on small resolutions. |
|
| 120 | - * |
|
| 121 | - * @param $title |
|
| 122 | - * @param string $url |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - abstract public function navbarTitle($title, $url='#'); |
|
| 126 | - |
|
| 127 | - //-------------------------------------------------------------------- |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Creates a UL meant to pull to the right within the navbar. |
|
| 131 | - * |
|
| 132 | - * Available options: |
|
| 133 | - * 'class' - An additional class to add |
|
| 134 | - * |
|
| 135 | - * @param array $options |
|
| 136 | - * @param callable $c |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - abstract public function navbarRight($options=[], \Closure $c); |
|
| 140 | - |
|
| 141 | - //-------------------------------------------------------------------- |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Creates a single list item for use within a nav section. |
|
| 145 | - * |
|
| 146 | - * @param $title |
|
| 147 | - * @param $url |
|
| 148 | - * @param array $options |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 151 | - abstract public function navItem($title, $url, $options=[], $isActive=false); |
|
| 152 | - |
|
| 153 | - //-------------------------------------------------------------------- |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
| 157 | - * |
|
| 158 | - * @param $title |
|
| 159 | - * @param array $options |
|
| 160 | - * @param callable $c |
|
| 161 | - */ |
|
| 162 | - abstract public function navDropdown($title,$options=[], \Closure $c); |
|
| 163 | - |
|
| 164 | - //-------------------------------------------------------------------- |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Creates a divider for use within a nav list. |
|
| 168 | - * |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 171 | - abstract public function navDivider(); |
|
| 172 | - |
|
| 173 | - //-------------------------------------------------------------------- |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 177 | - * |
|
| 178 | - * @param array $options |
|
| 179 | - * @param callable $c |
|
| 180 | - * @return mixed |
|
| 181 | - */ |
|
| 182 | - abstract public function breadcrumb($options=[], \Closure $c); |
|
| 183 | - |
|
| 184 | - //-------------------------------------------------------------------- |
|
| 185 | - |
|
| 186 | - //-------------------------------------------------------------------- |
|
| 187 | - // Buttons |
|
| 188 | - //-------------------------------------------------------------------- |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Creates a simple button. |
|
| 192 | - * |
|
| 193 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 194 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 195 | - * |
|
| 196 | - * @param $title |
|
| 197 | - * @param string $style |
|
| 198 | - * @param array $options |
|
| 199 | - * @return mixed |
|
| 200 | - */ |
|
| 201 | - abstract public function button($title, $style='default', $size='default', $options=[]); |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Creates a simple link styled as a button. |
|
| 205 | - * |
|
| 206 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 207 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 208 | - * |
|
| 209 | - * @param $title |
|
| 210 | - * @param string $url |
|
| 211 | - * @param string $style |
|
| 212 | - * @param array $options |
|
| 213 | - * @return mixed |
|
| 214 | - */ |
|
| 215 | - abstract public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]); |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Creates button groups wrapping HTML. |
|
| 219 | - * |
|
| 220 | - * @param $options |
|
| 221 | - * @param callable $c |
|
| 222 | - * @return mixed |
|
| 223 | - */ |
|
| 224 | - abstract public function buttonGroup($options, \Closure $c); |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Creates the button bar wrapping HTML. |
|
| 228 | - * |
|
| 229 | - * @param $options |
|
| 230 | - * @param callable $c |
|
| 231 | - * @return mixed |
|
| 232 | - */ |
|
| 233 | - abstract public function buttonBar($options, \Closure $c); |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 237 | - * by some frameworks. |
|
| 238 | - * |
|
| 239 | - * @param $title |
|
| 240 | - * @param string $style |
|
| 241 | - * @param string $size |
|
| 242 | - * @param array $options |
|
| 243 | - * @param callable $c |
|
| 244 | - * @return mixed |
|
| 245 | - */ |
|
| 246 | - abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
|
| 247 | - |
|
| 248 | - //-------------------------------------------------------------------- |
|
| 249 | - // Notices |
|
| 250 | - //-------------------------------------------------------------------- |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Creates an 'alert-box' style of notice grid. |
|
| 254 | - * |
|
| 255 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 256 | - * |
|
| 257 | - * @param $content |
|
| 258 | - * @param string $style |
|
| 259 | - * @param bool $closable |
|
| 260 | - * @return mixed |
|
| 261 | - */ |
|
| 262 | - abstract public function notice($content, $style='success', $closable=true); |
|
| 41 | + /** |
|
| 42 | + * Bucket for methods to control their current state between method calls. |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + protected $states = []; |
|
| 46 | + |
|
| 47 | + protected $name = ''; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Attached to nav items that are considered active. |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $active_class = 'active'; |
|
| 54 | + |
|
| 55 | + //-------------------------------------------------------------------- |
|
| 56 | + |
|
| 57 | + public function name() |
|
| 58 | + { |
|
| 59 | + return $this->name; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + //-------------------------------------------------------------------- |
|
| 63 | + |
|
| 64 | + //-------------------------------------------------------------------- |
|
| 65 | + // Grids |
|
| 66 | + //-------------------------------------------------------------------- |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
| 70 | + * the class for it, but some frameworks use a completely different |
|
| 71 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 72 | + * |
|
| 73 | + * @param array $options |
|
| 74 | + * @return mixed |
|
| 75 | + */ |
|
| 76 | + abstract public function row($options=[], \Closure $c); |
|
| 77 | + |
|
| 78 | + //-------------------------------------------------------------------- |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Creates the CSS for a column in a grid. |
|
| 82 | + * |
|
| 83 | + * The attribute array is made up of key/value pairs with the |
|
| 84 | + * key being the size, and the value being the number of columns/offset |
|
| 85 | + * in a 12-column grid. |
|
| 86 | + * |
|
| 87 | + * Note that we currently DO NOT support offset columns. |
|
| 88 | + * |
|
| 89 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 90 | + * |
|
| 91 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 92 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 93 | + * |
|
| 94 | + * @param array $attributes |
|
| 95 | + * @return mixed |
|
| 96 | + */ |
|
| 97 | + abstract public function column($options=[], \Closure $c); |
|
| 98 | + |
|
| 99 | + //-------------------------------------------------------------------- |
|
| 100 | + |
|
| 101 | + //-------------------------------------------------------------------- |
|
| 102 | + // Navigation |
|
| 103 | + //-------------------------------------------------------------------- |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Generates the container code for a navbar, typically used along the |
|
| 107 | + * top of a page. |
|
| 108 | + * |
|
| 109 | + * @param array $options |
|
| 110 | + * @param callable $c |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + abstract public function navbar($options=[], \Closure $c); |
|
| 114 | + |
|
| 115 | + //-------------------------------------------------------------------- |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
| 119 | + * includes the code for the hamburger menu on small resolutions. |
|
| 120 | + * |
|
| 121 | + * @param $title |
|
| 122 | + * @param string $url |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + abstract public function navbarTitle($title, $url='#'); |
|
| 126 | + |
|
| 127 | + //-------------------------------------------------------------------- |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Creates a UL meant to pull to the right within the navbar. |
|
| 131 | + * |
|
| 132 | + * Available options: |
|
| 133 | + * 'class' - An additional class to add |
|
| 134 | + * |
|
| 135 | + * @param array $options |
|
| 136 | + * @param callable $c |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + abstract public function navbarRight($options=[], \Closure $c); |
|
| 140 | + |
|
| 141 | + //-------------------------------------------------------------------- |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Creates a single list item for use within a nav section. |
|
| 145 | + * |
|
| 146 | + * @param $title |
|
| 147 | + * @param $url |
|
| 148 | + * @param array $options |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | + abstract public function navItem($title, $url, $options=[], $isActive=false); |
|
| 152 | + |
|
| 153 | + //-------------------------------------------------------------------- |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
| 157 | + * |
|
| 158 | + * @param $title |
|
| 159 | + * @param array $options |
|
| 160 | + * @param callable $c |
|
| 161 | + */ |
|
| 162 | + abstract public function navDropdown($title,$options=[], \Closure $c); |
|
| 163 | + |
|
| 164 | + //-------------------------------------------------------------------- |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Creates a divider for use within a nav list. |
|
| 168 | + * |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | + abstract public function navDivider(); |
|
| 172 | + |
|
| 173 | + //-------------------------------------------------------------------- |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 177 | + * |
|
| 178 | + * @param array $options |
|
| 179 | + * @param callable $c |
|
| 180 | + * @return mixed |
|
| 181 | + */ |
|
| 182 | + abstract public function breadcrumb($options=[], \Closure $c); |
|
| 183 | + |
|
| 184 | + //-------------------------------------------------------------------- |
|
| 185 | + |
|
| 186 | + //-------------------------------------------------------------------- |
|
| 187 | + // Buttons |
|
| 188 | + //-------------------------------------------------------------------- |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Creates a simple button. |
|
| 192 | + * |
|
| 193 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 194 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 195 | + * |
|
| 196 | + * @param $title |
|
| 197 | + * @param string $style |
|
| 198 | + * @param array $options |
|
| 199 | + * @return mixed |
|
| 200 | + */ |
|
| 201 | + abstract public function button($title, $style='default', $size='default', $options=[]); |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Creates a simple link styled as a button. |
|
| 205 | + * |
|
| 206 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 207 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 208 | + * |
|
| 209 | + * @param $title |
|
| 210 | + * @param string $url |
|
| 211 | + * @param string $style |
|
| 212 | + * @param array $options |
|
| 213 | + * @return mixed |
|
| 214 | + */ |
|
| 215 | + abstract public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]); |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Creates button groups wrapping HTML. |
|
| 219 | + * |
|
| 220 | + * @param $options |
|
| 221 | + * @param callable $c |
|
| 222 | + * @return mixed |
|
| 223 | + */ |
|
| 224 | + abstract public function buttonGroup($options, \Closure $c); |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Creates the button bar wrapping HTML. |
|
| 228 | + * |
|
| 229 | + * @param $options |
|
| 230 | + * @param callable $c |
|
| 231 | + * @return mixed |
|
| 232 | + */ |
|
| 233 | + abstract public function buttonBar($options, \Closure $c); |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 237 | + * by some frameworks. |
|
| 238 | + * |
|
| 239 | + * @param $title |
|
| 240 | + * @param string $style |
|
| 241 | + * @param string $size |
|
| 242 | + * @param array $options |
|
| 243 | + * @param callable $c |
|
| 244 | + * @return mixed |
|
| 245 | + */ |
|
| 246 | + abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
|
| 247 | + |
|
| 248 | + //-------------------------------------------------------------------- |
|
| 249 | + // Notices |
|
| 250 | + //-------------------------------------------------------------------- |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Creates an 'alert-box' style of notice grid. |
|
| 254 | + * |
|
| 255 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 256 | + * |
|
| 257 | + * @param $content |
|
| 258 | + * @param string $style |
|
| 259 | + * @param bool $closable |
|
| 260 | + * @return mixed |
|
| 261 | + */ |
|
| 262 | + abstract public function notice($content, $style='success', $closable=true); |
|
| 263 | 263 | |
| 264 | 264 | //-------------------------------------------------------------------- |
| 265 | 265 | // Forms |
@@ -278,137 +278,137 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | abstract public function inputWrap($label_text, $options=[], \Closure $c); |
| 280 | 280 | |
| 281 | - //-------------------------------------------------------------------- |
|
| 282 | - // Utility Methods |
|
| 283 | - //-------------------------------------------------------------------- |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Helper method to run a Closure and collect the output of it. |
|
| 287 | - * |
|
| 288 | - * @param callable $c |
|
| 289 | - * @return string |
|
| 290 | - */ |
|
| 291 | - protected function runClosure(\Closure $c) |
|
| 292 | - { |
|
| 293 | - if (! is_callable($c)) return ''; |
|
| 294 | - |
|
| 295 | - ob_start(); |
|
| 296 | - $c(); |
|
| 297 | - $output = ob_get_contents(); |
|
| 298 | - ob_end_clean(); |
|
| 299 | - |
|
| 300 | - return $output; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - //-------------------------------------------------------------------- |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Provides a single method call to get the $classes, $id, and $attributes |
|
| 307 | - * from the options array. |
|
| 308 | - * |
|
| 309 | - * @param $options |
|
| 310 | - * @param string $initial_classes |
|
| 311 | - * @param bool $fullClassString |
|
| 312 | - * @return array |
|
| 313 | - */ |
|
| 314 | - protected function parseStandardOptions($options, $initial_classes='', $fullClassString=false) |
|
| 315 | - { |
|
| 316 | - return [ |
|
| 317 | - $this->buildClassString($initial_classes, $options, $fullClassString), |
|
| 318 | - $this->buildIdFromOptions($options), |
|
| 319 | - $this->buildAttributesFromOptions($options) |
|
| 320 | - ]; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - //-------------------------------------------------------------------- |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Sets the element that is to be considered the active item. This is |
|
| 327 | - * based on the navItem's $title so it must match, though it is NOT |
|
| 328 | - * case sensitive. |
|
| 329 | - * |
|
| 330 | - * @param $title |
|
| 331 | - * @return mixed |
|
| 332 | - */ |
|
| 333 | - public function setActiveNavItem($title) |
|
| 334 | - { |
|
| 335 | - $this->states['activeNavItem'] = strtolower($title); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - //-------------------------------------------------------------------- |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Combines an initial classes string with a 'class' item that |
|
| 342 | - * might be available within the options array. |
|
| 343 | - * |
|
| 344 | - * If 'buildEntireString' is TRUE will return the string with the 'class=""' portion. |
|
| 345 | - * Otherwise, just returns the raw classes. |
|
| 346 | - * |
|
| 347 | - * @param string $initial |
|
| 348 | - * @param array $options |
|
| 349 | - * @return array |
|
| 350 | - */ |
|
| 351 | - protected function buildClassString($initial, $options, $buildEntireString=false) |
|
| 352 | - { |
|
| 353 | - $classes = explode(' ', $initial); |
|
| 354 | - |
|
| 355 | - if (isset($options['class'])) |
|
| 356 | - { |
|
| 357 | - $classes = array_merge($classes, explode(' ', $options['class'])); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - if (isset($this->states['activeNavItem']) && isset($this->states['activeNavTitle']) && |
|
| 361 | - $this->states['activeNavItem'] == strtolower($this->states['activeNavTitle'])) |
|
| 362 | - { |
|
| 363 | - $classes[] = $this->active_class; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - $classes = implode(' ', $classes); |
|
| 367 | - |
|
| 368 | - // Substitute the active class for a placeholder. |
|
| 369 | - $classes = str_replace('{active}', $this->active_class, $classes); |
|
| 370 | - |
|
| 371 | - return $buildEntireString ? "class='{$classes}'" : $classes; |
|
| 372 | - } |
|
| 373 | - //-------------------------------------------------------------------- |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Checks the options array for an ID and returns the entire string. |
|
| 377 | - * |
|
| 378 | - * Example Return: |
|
| 379 | - * id='MyID' |
|
| 380 | - * |
|
| 381 | - * @param $options |
|
| 382 | - * @return string |
|
| 383 | - */ |
|
| 384 | - protected function buildIdFromOptions($options) |
|
| 385 | - { |
|
| 386 | - return isset($options['id']) ? "id='{$options['id']}'" : ' '; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - //-------------------------------------------------------------------- |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Parses out attributes from the options array. The attributes array |
|
| 393 | - * should all contain no key names, only values, so: |
|
| 394 | - * |
|
| 395 | - * 'attributes' => [ |
|
| 396 | - * 'style="width:100%", |
|
| 397 | - * 'required' |
|
| 398 | - * ] |
|
| 399 | - * |
|
| 400 | - * @param $options |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - protected function buildAttributesFromOptions($options) |
|
| 404 | - { |
|
| 405 | - if (isset($options['attributes']) && ! is_array($options['attributes'])) |
|
| 406 | - { |
|
| 407 | - $options['attributes'] = [ $options['attributes'] ]; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return isset($options['attributes']) ? implode($options['attributes']) : ''; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - //-------------------------------------------------------------------- |
|
| 281 | + //-------------------------------------------------------------------- |
|
| 282 | + // Utility Methods |
|
| 283 | + //-------------------------------------------------------------------- |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Helper method to run a Closure and collect the output of it. |
|
| 287 | + * |
|
| 288 | + * @param callable $c |
|
| 289 | + * @return string |
|
| 290 | + */ |
|
| 291 | + protected function runClosure(\Closure $c) |
|
| 292 | + { |
|
| 293 | + if (! is_callable($c)) return ''; |
|
| 294 | + |
|
| 295 | + ob_start(); |
|
| 296 | + $c(); |
|
| 297 | + $output = ob_get_contents(); |
|
| 298 | + ob_end_clean(); |
|
| 299 | + |
|
| 300 | + return $output; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + //-------------------------------------------------------------------- |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Provides a single method call to get the $classes, $id, and $attributes |
|
| 307 | + * from the options array. |
|
| 308 | + * |
|
| 309 | + * @param $options |
|
| 310 | + * @param string $initial_classes |
|
| 311 | + * @param bool $fullClassString |
|
| 312 | + * @return array |
|
| 313 | + */ |
|
| 314 | + protected function parseStandardOptions($options, $initial_classes='', $fullClassString=false) |
|
| 315 | + { |
|
| 316 | + return [ |
|
| 317 | + $this->buildClassString($initial_classes, $options, $fullClassString), |
|
| 318 | + $this->buildIdFromOptions($options), |
|
| 319 | + $this->buildAttributesFromOptions($options) |
|
| 320 | + ]; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + //-------------------------------------------------------------------- |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Sets the element that is to be considered the active item. This is |
|
| 327 | + * based on the navItem's $title so it must match, though it is NOT |
|
| 328 | + * case sensitive. |
|
| 329 | + * |
|
| 330 | + * @param $title |
|
| 331 | + * @return mixed |
|
| 332 | + */ |
|
| 333 | + public function setActiveNavItem($title) |
|
| 334 | + { |
|
| 335 | + $this->states['activeNavItem'] = strtolower($title); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + //-------------------------------------------------------------------- |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Combines an initial classes string with a 'class' item that |
|
| 342 | + * might be available within the options array. |
|
| 343 | + * |
|
| 344 | + * If 'buildEntireString' is TRUE will return the string with the 'class=""' portion. |
|
| 345 | + * Otherwise, just returns the raw classes. |
|
| 346 | + * |
|
| 347 | + * @param string $initial |
|
| 348 | + * @param array $options |
|
| 349 | + * @return array |
|
| 350 | + */ |
|
| 351 | + protected function buildClassString($initial, $options, $buildEntireString=false) |
|
| 352 | + { |
|
| 353 | + $classes = explode(' ', $initial); |
|
| 354 | + |
|
| 355 | + if (isset($options['class'])) |
|
| 356 | + { |
|
| 357 | + $classes = array_merge($classes, explode(' ', $options['class'])); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + if (isset($this->states['activeNavItem']) && isset($this->states['activeNavTitle']) && |
|
| 361 | + $this->states['activeNavItem'] == strtolower($this->states['activeNavTitle'])) |
|
| 362 | + { |
|
| 363 | + $classes[] = $this->active_class; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + $classes = implode(' ', $classes); |
|
| 367 | + |
|
| 368 | + // Substitute the active class for a placeholder. |
|
| 369 | + $classes = str_replace('{active}', $this->active_class, $classes); |
|
| 370 | + |
|
| 371 | + return $buildEntireString ? "class='{$classes}'" : $classes; |
|
| 372 | + } |
|
| 373 | + //-------------------------------------------------------------------- |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Checks the options array for an ID and returns the entire string. |
|
| 377 | + * |
|
| 378 | + * Example Return: |
|
| 379 | + * id='MyID' |
|
| 380 | + * |
|
| 381 | + * @param $options |
|
| 382 | + * @return string |
|
| 383 | + */ |
|
| 384 | + protected function buildIdFromOptions($options) |
|
| 385 | + { |
|
| 386 | + return isset($options['id']) ? "id='{$options['id']}'" : ' '; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + //-------------------------------------------------------------------- |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Parses out attributes from the options array. The attributes array |
|
| 393 | + * should all contain no key names, only values, so: |
|
| 394 | + * |
|
| 395 | + * 'attributes' => [ |
|
| 396 | + * 'style="width:100%", |
|
| 397 | + * 'required' |
|
| 398 | + * ] |
|
| 399 | + * |
|
| 400 | + * @param $options |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + protected function buildAttributesFromOptions($options) |
|
| 404 | + { |
|
| 405 | + if (isset($options['attributes']) && ! is_array($options['attributes'])) |
|
| 406 | + { |
|
| 407 | + $options['attributes'] = [ $options['attributes'] ]; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return isset($options['attributes']) ? implode($options['attributes']) : ''; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + //-------------------------------------------------------------------- |
|
| 414 | 414 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param array $options |
| 74 | 74 | * @return mixed |
| 75 | 75 | */ |
| 76 | - abstract public function row($options=[], \Closure $c); |
|
| 76 | + abstract public function row($options = [], \Closure $c); |
|
| 77 | 77 | |
| 78 | 78 | //-------------------------------------------------------------------- |
| 79 | 79 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param array $attributes |
| 95 | 95 | * @return mixed |
| 96 | 96 | */ |
| 97 | - abstract public function column($options=[], \Closure $c); |
|
| 97 | + abstract public function column($options = [], \Closure $c); |
|
| 98 | 98 | |
| 99 | 99 | //-------------------------------------------------------------------- |
| 100 | 100 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param callable $c |
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | - abstract public function navbar($options=[], \Closure $c); |
|
| 113 | + abstract public function navbar($options = [], \Closure $c); |
|
| 114 | 114 | |
| 115 | 115 | //-------------------------------------------------------------------- |
| 116 | 116 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param string $url |
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | - abstract public function navbarTitle($title, $url='#'); |
|
| 125 | + abstract public function navbarTitle($title, $url = '#'); |
|
| 126 | 126 | |
| 127 | 127 | //-------------------------------------------------------------------- |
| 128 | 128 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @param callable $c |
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | - abstract public function navbarRight($options=[], \Closure $c); |
|
| 139 | + abstract public function navbarRight($options = [], \Closure $c); |
|
| 140 | 140 | |
| 141 | 141 | //-------------------------------------------------------------------- |
| 142 | 142 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * @param array $options |
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | - abstract public function navItem($title, $url, $options=[], $isActive=false); |
|
| 151 | + abstract public function navItem($title, $url, $options = [], $isActive = false); |
|
| 152 | 152 | |
| 153 | 153 | //-------------------------------------------------------------------- |
| 154 | 154 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @param array $options |
| 160 | 160 | * @param callable $c |
| 161 | 161 | */ |
| 162 | - abstract public function navDropdown($title,$options=[], \Closure $c); |
|
| 162 | + abstract public function navDropdown($title, $options = [], \Closure $c); |
|
| 163 | 163 | |
| 164 | 164 | //-------------------------------------------------------------------- |
| 165 | 165 | |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param callable $c |
| 180 | 180 | * @return mixed |
| 181 | 181 | */ |
| 182 | - abstract public function breadcrumb($options=[], \Closure $c); |
|
| 182 | + abstract public function breadcrumb($options = [], \Closure $c); |
|
| 183 | 183 | |
| 184 | 184 | //-------------------------------------------------------------------- |
| 185 | 185 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @param array $options |
| 199 | 199 | * @return mixed |
| 200 | 200 | */ |
| 201 | - abstract public function button($title, $style='default', $size='default', $options=[]); |
|
| 201 | + abstract public function button($title, $style = 'default', $size = 'default', $options = []); |
|
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | 204 | * Creates a simple link styled as a button. |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @param array $options |
| 213 | 213 | * @return mixed |
| 214 | 214 | */ |
| 215 | - abstract public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]); |
|
| 215 | + abstract public function buttonLink($title, $url = '#', $style = 'default', $size = 'default', $options = []); |
|
| 216 | 216 | |
| 217 | 217 | /** |
| 218 | 218 | * Creates button groups wrapping HTML. |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @param callable $c |
| 244 | 244 | * @return mixed |
| 245 | 245 | */ |
| 246 | - abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
|
| 246 | + abstract public function buttonDropdown($title, $style = 'default', $size = 'default', $options = [], \Closure $c); |
|
| 247 | 247 | |
| 248 | 248 | //-------------------------------------------------------------------- |
| 249 | 249 | // Notices |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | * @param bool $closable |
| 260 | 260 | * @return mixed |
| 261 | 261 | */ |
| 262 | - abstract public function notice($content, $style='success', $closable=true); |
|
| 262 | + abstract public function notice($content, $style = 'success', $closable = true); |
|
| 263 | 263 | |
| 264 | 264 | //-------------------------------------------------------------------- |
| 265 | 265 | // Forms |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return mixed |
| 278 | 278 | */ |
| 279 | - abstract public function inputWrap($label_text, $options=[], \Closure $c); |
|
| 279 | + abstract public function inputWrap($label_text, $options = [], \Closure $c); |
|
| 280 | 280 | |
| 281 | 281 | //-------------------------------------------------------------------- |
| 282 | 282 | // Utility Methods |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | */ |
| 291 | 291 | protected function runClosure(\Closure $c) |
| 292 | 292 | { |
| 293 | - if (! is_callable($c)) return ''; |
|
| 293 | + if ( ! is_callable($c)) return ''; |
|
| 294 | 294 | |
| 295 | 295 | ob_start(); |
| 296 | 296 | $c(); |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @param bool $fullClassString |
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | - protected function parseStandardOptions($options, $initial_classes='', $fullClassString=false) |
|
| 314 | + protected function parseStandardOptions($options, $initial_classes = '', $fullClassString = false) |
|
| 315 | 315 | { |
| 316 | 316 | return [ |
| 317 | 317 | $this->buildClassString($initial_classes, $options, $fullClassString), |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | * @param array $options |
| 349 | 349 | * @return array |
| 350 | 350 | */ |
| 351 | - protected function buildClassString($initial, $options, $buildEntireString=false) |
|
| 351 | + protected function buildClassString($initial, $options, $buildEntireString = false) |
|
| 352 | 352 | { |
| 353 | 353 | $classes = explode(' ', $initial); |
| 354 | 354 | |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | { |
| 405 | 405 | if (isset($options['attributes']) && ! is_array($options['attributes'])) |
| 406 | 406 | { |
| 407 | - $options['attributes'] = [ $options['attributes'] ]; |
|
| 407 | + $options['attributes'] = [$options['attributes']]; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | return isset($options['attributes']) ? implode($options['attributes']) : ''; |
@@ -290,7 +290,9 @@ |
||
| 290 | 290 | */ |
| 291 | 291 | protected function runClosure(\Closure $c) |
| 292 | 292 | { |
| 293 | - if (! is_callable($c)) return ''; |
|
| 293 | + if (! is_callable($c)) { |
|
| 294 | + return ''; |
|
| 295 | + } |
|
| 294 | 296 | |
| 295 | 297 | ob_start(); |
| 296 | 298 | $c(); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * approach to rows and columns than the reference Bootstrap and Foundation. |
| 50 | 50 | * |
| 51 | 51 | * @param array $options |
| 52 | - * @return mixed |
|
| 52 | + * @return string |
|
| 53 | 53 | */ |
| 54 | 54 | public function row($options=[], \Closure $c) |
| 55 | 55 | { |
@@ -80,8 +80,7 @@ discard block |
||
| 80 | 80 | * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
| 81 | 81 | * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
| 82 | 82 | * |
| 83 | - * @param array $attributes |
|
| 84 | - * @return mixed |
|
| 83 | + * @return string |
|
| 85 | 84 | */ |
| 86 | 85 | public function column($options=[], \Closure $c) |
| 87 | 86 | { |
@@ -141,7 +140,7 @@ discard block |
||
| 141 | 140 | * top of a page. |
| 142 | 141 | * |
| 143 | 142 | * @param array $options |
| 144 | - * @param callable $c |
|
| 143 | + * @param \Closure $c |
|
| 145 | 144 | * @return string |
| 146 | 145 | */ |
| 147 | 146 | public function navbar($options=[], \Closure $c) |
@@ -218,7 +217,7 @@ discard block |
||
| 218 | 217 | * 'class' - An additional class to add |
| 219 | 218 | * |
| 220 | 219 | * @param array $options |
| 221 | - * @param callable $c |
|
| 220 | + * @param \Closure $c |
|
| 222 | 221 | * @return string |
| 223 | 222 | */ |
| 224 | 223 | public function navbarRight($options=[], \Closure $c) |
@@ -270,7 +269,7 @@ discard block |
||
| 270 | 269 | * |
| 271 | 270 | * @param $title |
| 272 | 271 | * @param array $options |
| 273 | - * @param callable $c |
|
| 272 | + * @param \Closure $c |
|
| 274 | 273 | */ |
| 275 | 274 | public function navDropdown($title,$options=[], \Closure $c) |
| 276 | 275 | { |
@@ -320,8 +319,8 @@ discard block |
||
| 320 | 319 | * Creates a list of nav items to function as breadcrumbs for a site. |
| 321 | 320 | * |
| 322 | 321 | * @param array $options |
| 323 | - * @param callable $c |
|
| 324 | - * @return mixed |
|
| 322 | + * @param \Closure $c |
|
| 323 | + * @return string |
|
| 325 | 324 | */ |
| 326 | 325 | public function breadcrumb($options=[], \Closure $c) |
| 327 | 326 | { |
@@ -401,9 +400,10 @@ discard block |
||
| 401 | 400 | * Helper method to render out our buttons in a DRY manner. |
| 402 | 401 | * |
| 403 | 402 | * @param $title |
| 404 | - * @param $style |
|
| 405 | - * @param $size |
|
| 403 | + * @param string $style |
|
| 404 | + * @param string $size |
|
| 406 | 405 | * @param $tag |
| 406 | + * @return \Closure |
|
| 407 | 407 | */ |
| 408 | 408 | protected function renderButtonElement($title, $style, $size, $options, $tag) |
| 409 | 409 | { |
@@ -473,8 +473,8 @@ discard block |
||
| 473 | 473 | * Creates button groups wrapping HTML. |
| 474 | 474 | * |
| 475 | 475 | * @param $options |
| 476 | - * @param callable $c |
|
| 477 | - * @return mixed |
|
| 476 | + * @param \Closure $c |
|
| 477 | + * @return string |
|
| 478 | 478 | */ |
| 479 | 479 | public function buttonGroup($options, \Closure $c) |
| 480 | 480 | { |
@@ -495,8 +495,8 @@ discard block |
||
| 495 | 495 | * Creates the button bar wrapping HTML. |
| 496 | 496 | * |
| 497 | 497 | * @param $options |
| 498 | - * @param callable $c |
|
| 499 | - * @return mixed |
|
| 498 | + * @param \Closure $c |
|
| 499 | + * @return string |
|
| 500 | 500 | */ |
| 501 | 501 | public function buttonBar($options, \Closure $c) |
| 502 | 502 | { |
@@ -523,8 +523,8 @@ discard block |
||
| 523 | 523 | * @param string $style |
| 524 | 524 | * @param string $size |
| 525 | 525 | * @param array $options |
| 526 | - * @param callable $c |
|
| 527 | - * @return mixed |
|
| 526 | + * @param \Closure $c |
|
| 527 | + * @return string |
|
| 528 | 528 | */ |
| 529 | 529 | public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
| 530 | 530 | { |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | * @param $content |
| 557 | 557 | * @param string $style |
| 558 | 558 | * @param bool $closable |
| 559 | - * @return mixed |
|
| 559 | + * @return string |
|
| 560 | 560 | */ |
| 561 | 561 | public function notice($content, $style='success', $closable=true, $options=[]) |
| 562 | 562 | { |
@@ -609,9 +609,9 @@ discard block |
||
| 609 | 609 | * |
| 610 | 610 | * @param $label_text |
| 611 | 611 | * @param array $options |
| 612 | - * @param callable $c |
|
| 612 | + * @param \Closure $c |
|
| 613 | 613 | * |
| 614 | - * @return mixed |
|
| 614 | + * @return string |
|
| 615 | 615 | */ |
| 616 | 616 | public function inputWrap($label_text, $options=[], \Closure $c) |
| 617 | 617 | { |
@@ -1,34 +1,34 @@ discard block |
||
| 1 | 1 | <?php namespace Myth\UIKits; |
| 2 | 2 | /** |
| 3 | - * Sprint |
|
| 4 | - * |
|
| 5 | - * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
| 6 | - * |
|
| 7 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 8 | - * of this software and associated documentation files (the "Software"), to deal |
|
| 9 | - * in the Software without restriction, including without limitation the rights |
|
| 10 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 11 | - * copies of the Software, and to permit persons to whom the Software is |
|
| 12 | - * furnished to do so, subject to the following conditions: |
|
| 13 | - * |
|
| 14 | - * The above copyright notice and this permission notice shall be included in |
|
| 15 | - * all copies or substantial portions of the Software. |
|
| 16 | - * |
|
| 17 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 18 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 19 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 20 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 21 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 22 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 23 | - * THE SOFTWARE. |
|
| 24 | - * |
|
| 25 | - * @package Sprint |
|
| 26 | - * @author Lonnie Ezell |
|
| 27 | - * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
| 28 | - * @license http://opensource.org/licenses/MIT (MIT) |
|
| 29 | - * @link http://sprintphp.com |
|
| 30 | - * @since Version 1.0 |
|
| 31 | - */ |
|
| 3 | + * Sprint |
|
| 4 | + * |
|
| 5 | + * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
| 6 | + * |
|
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
|
| 9 | + * in the Software without restriction, including without limitation the rights |
|
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
|
| 12 | + * furnished to do so, subject to the following conditions: |
|
| 13 | + * |
|
| 14 | + * The above copyright notice and this permission notice shall be included in |
|
| 15 | + * all copies or substantial portions of the Software. |
|
| 16 | + * |
|
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 23 | + * THE SOFTWARE. |
|
| 24 | + * |
|
| 25 | + * @package Sprint |
|
| 26 | + * @author Lonnie Ezell |
|
| 27 | + * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
| 28 | + * @license http://opensource.org/licenses/MIT (MIT) |
|
| 29 | + * @link http://sprintphp.com |
|
| 30 | + * @since Version 1.0 |
|
| 31 | + */ |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Class Bootstrap3UIKit |
@@ -37,168 +37,168 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | class Bootstrap extends BaseUIKit { |
| 39 | 39 | |
| 40 | - protected $name = 'Bootstrap3UIKit'; |
|
| 41 | - |
|
| 42 | - //-------------------------------------------------------------------- |
|
| 43 | - // Grid |
|
| 44 | - //-------------------------------------------------------------------- |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
| 48 | - * the class for it, but some frameworks use a completely different |
|
| 49 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 50 | - * |
|
| 51 | - * @param array $options |
|
| 52 | - * @return mixed |
|
| 53 | - */ |
|
| 54 | - public function row($options=[], \Closure $c) |
|
| 55 | - { |
|
| 56 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
| 57 | - |
|
| 58 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 59 | - |
|
| 60 | - $output .= $this->runClosure($c); |
|
| 61 | - |
|
| 62 | - $output .= "</div>\n"; |
|
| 63 | - |
|
| 64 | - return $output; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - //-------------------------------------------------------------------- |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Creates the CSS for a column in a grid. |
|
| 71 | - * |
|
| 72 | - * The attribute array is made up of key/value pairs with the |
|
| 73 | - * key being the size, and the value being the number of columns/offset |
|
| 74 | - * in a 12-column grid. |
|
| 75 | - * |
|
| 76 | - * Note that we currently DO NOT support offset columns. |
|
| 77 | - * |
|
| 78 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 79 | - * |
|
| 80 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 81 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 82 | - * |
|
| 83 | - * @param array $attributes |
|
| 84 | - * @return mixed |
|
| 85 | - */ |
|
| 86 | - public function column($options=[], \Closure $c) |
|
| 87 | - { |
|
| 88 | - // Build our classes |
|
| 89 | - $classes = ''; |
|
| 90 | - |
|
| 91 | - foreach ($options['sizes'] as $size => $value) |
|
| 92 | - { |
|
| 93 | - switch ($size) |
|
| 94 | - { |
|
| 95 | - case 's': |
|
| 96 | - $classes .= ' col-xs-'. $value; |
|
| 97 | - break; |
|
| 98 | - case 'm': |
|
| 99 | - $classes .= ' col-sm-'. $value; |
|
| 100 | - break; |
|
| 101 | - case 'l': |
|
| 102 | - $classes .= ' col-md-'. $value; |
|
| 103 | - break; |
|
| 104 | - case 'xl': |
|
| 105 | - $classes .= ' col-lg-'. $value; |
|
| 106 | - break; |
|
| 107 | - case 's-offset': |
|
| 108 | - $classes .= ' col-xs-offset-'. $value; |
|
| 109 | - break; |
|
| 110 | - case 'm-offset': |
|
| 111 | - $classes .= ' col-sm-offset-'. $value; |
|
| 112 | - break; |
|
| 113 | - case 'l-offset': |
|
| 114 | - $classes .= ' col-md-offset-'. $value; |
|
| 115 | - break; |
|
| 116 | - case 'xl-offset': |
|
| 117 | - $classes .= ' col-lg-offset-'. $value; |
|
| 118 | - break; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 123 | - |
|
| 124 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 125 | - |
|
| 126 | - $output .= $this->runClosure($c); |
|
| 127 | - |
|
| 128 | - $output .= "</div>\n"; |
|
| 129 | - |
|
| 130 | - return $output; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - //-------------------------------------------------------------------- |
|
| 134 | - |
|
| 135 | - //-------------------------------------------------------------------- |
|
| 136 | - // Navigation |
|
| 137 | - //-------------------------------------------------------------------- |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Generates the container code for a navbar, typically used along the |
|
| 141 | - * top of a page. |
|
| 142 | - * |
|
| 143 | - * @param array $options |
|
| 144 | - * @param callable $c |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 147 | - public function navbar($options=[], \Closure $c) |
|
| 148 | - { |
|
| 149 | - $output = ''; |
|
| 150 | - |
|
| 151 | - /* |
|
| 40 | + protected $name = 'Bootstrap3UIKit'; |
|
| 41 | + |
|
| 42 | + //-------------------------------------------------------------------- |
|
| 43 | + // Grid |
|
| 44 | + //-------------------------------------------------------------------- |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
| 48 | + * the class for it, but some frameworks use a completely different |
|
| 49 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 50 | + * |
|
| 51 | + * @param array $options |
|
| 52 | + * @return mixed |
|
| 53 | + */ |
|
| 54 | + public function row($options=[], \Closure $c) |
|
| 55 | + { |
|
| 56 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
| 57 | + |
|
| 58 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 59 | + |
|
| 60 | + $output .= $this->runClosure($c); |
|
| 61 | + |
|
| 62 | + $output .= "</div>\n"; |
|
| 63 | + |
|
| 64 | + return $output; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + //-------------------------------------------------------------------- |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Creates the CSS for a column in a grid. |
|
| 71 | + * |
|
| 72 | + * The attribute array is made up of key/value pairs with the |
|
| 73 | + * key being the size, and the value being the number of columns/offset |
|
| 74 | + * in a 12-column grid. |
|
| 75 | + * |
|
| 76 | + * Note that we currently DO NOT support offset columns. |
|
| 77 | + * |
|
| 78 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 79 | + * |
|
| 80 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 81 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 82 | + * |
|
| 83 | + * @param array $attributes |
|
| 84 | + * @return mixed |
|
| 85 | + */ |
|
| 86 | + public function column($options=[], \Closure $c) |
|
| 87 | + { |
|
| 88 | + // Build our classes |
|
| 89 | + $classes = ''; |
|
| 90 | + |
|
| 91 | + foreach ($options['sizes'] as $size => $value) |
|
| 92 | + { |
|
| 93 | + switch ($size) |
|
| 94 | + { |
|
| 95 | + case 's': |
|
| 96 | + $classes .= ' col-xs-'. $value; |
|
| 97 | + break; |
|
| 98 | + case 'm': |
|
| 99 | + $classes .= ' col-sm-'. $value; |
|
| 100 | + break; |
|
| 101 | + case 'l': |
|
| 102 | + $classes .= ' col-md-'. $value; |
|
| 103 | + break; |
|
| 104 | + case 'xl': |
|
| 105 | + $classes .= ' col-lg-'. $value; |
|
| 106 | + break; |
|
| 107 | + case 's-offset': |
|
| 108 | + $classes .= ' col-xs-offset-'. $value; |
|
| 109 | + break; |
|
| 110 | + case 'm-offset': |
|
| 111 | + $classes .= ' col-sm-offset-'. $value; |
|
| 112 | + break; |
|
| 113 | + case 'l-offset': |
|
| 114 | + $classes .= ' col-md-offset-'. $value; |
|
| 115 | + break; |
|
| 116 | + case 'xl-offset': |
|
| 117 | + $classes .= ' col-lg-offset-'. $value; |
|
| 118 | + break; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 123 | + |
|
| 124 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 125 | + |
|
| 126 | + $output .= $this->runClosure($c); |
|
| 127 | + |
|
| 128 | + $output .= "</div>\n"; |
|
| 129 | + |
|
| 130 | + return $output; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + //-------------------------------------------------------------------- |
|
| 134 | + |
|
| 135 | + //-------------------------------------------------------------------- |
|
| 136 | + // Navigation |
|
| 137 | + //-------------------------------------------------------------------- |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Generates the container code for a navbar, typically used along the |
|
| 141 | + * top of a page. |
|
| 142 | + * |
|
| 143 | + * @param array $options |
|
| 144 | + * @param callable $c |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | + public function navbar($options=[], \Closure $c) |
|
| 148 | + { |
|
| 149 | + $output = ''; |
|
| 150 | + |
|
| 151 | + /* |
|
| 152 | 152 | * Open the navbar |
| 153 | 153 | */ |
| 154 | - $classes = "navbar navbar-default "; |
|
| 155 | - |
|
| 156 | - foreach ($options as $option) |
|
| 157 | - { |
|
| 158 | - switch ($option) |
|
| 159 | - { |
|
| 160 | - case 'sticky-top': |
|
| 161 | - $classes .= " navbar-static-top"; |
|
| 162 | - break; |
|
| 163 | - case 'fixed': |
|
| 164 | - $classes .= " navbar-fixed-top"; |
|
| 165 | - break; |
|
| 166 | - case 'inverse': |
|
| 167 | - $classes .= " navbar-inverse"; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - list($class, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 172 | - |
|
| 173 | - $output .= "<nav {$class} {$id} {$attributes} role='navigation'> |
|
| 154 | + $classes = "navbar navbar-default "; |
|
| 155 | + |
|
| 156 | + foreach ($options as $option) |
|
| 157 | + { |
|
| 158 | + switch ($option) |
|
| 159 | + { |
|
| 160 | + case 'sticky-top': |
|
| 161 | + $classes .= " navbar-static-top"; |
|
| 162 | + break; |
|
| 163 | + case 'fixed': |
|
| 164 | + $classes .= " navbar-fixed-top"; |
|
| 165 | + break; |
|
| 166 | + case 'inverse': |
|
| 167 | + $classes .= " navbar-inverse"; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + list($class, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 172 | + |
|
| 173 | + $output .= "<nav {$class} {$id} {$attributes} role='navigation'> |
|
| 174 | 174 | <div class='container-fluid'>\n"; |
| 175 | 175 | |
| 176 | - /* |
|
| 176 | + /* |
|
| 177 | 177 | * Do any user content inside the bar |
| 178 | 178 | */ |
| 179 | - $output .= $this->runClosure($c); |
|
| 179 | + $output .= $this->runClosure($c); |
|
| 180 | 180 | |
| 181 | - /* |
|
| 181 | + /* |
|
| 182 | 182 | * Close out the navbar |
| 183 | 183 | */ |
| 184 | - $output .= "</div></nav>\n"; |
|
| 185 | - |
|
| 186 | - return $output; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - //-------------------------------------------------------------------- |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
| 193 | - * includes the code for the hamburger menu on small resolutions. |
|
| 194 | - * |
|
| 195 | - * @param $title |
|
| 196 | - * @param string $url |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function navbarTitle($title, $url='#') |
|
| 200 | - { |
|
| 201 | - return '<div class="navbar-header"> |
|
| 184 | + $output .= "</div></nav>\n"; |
|
| 185 | + |
|
| 186 | + return $output; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + //-------------------------------------------------------------------- |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
| 193 | + * includes the code for the hamburger menu on small resolutions. |
|
| 194 | + * |
|
| 195 | + * @param $title |
|
| 196 | + * @param string $url |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function navbarTitle($title, $url='#') |
|
| 200 | + { |
|
| 201 | + return '<div class="navbar-header"> |
|
| 202 | 202 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1"> |
| 203 | 203 | <span class="sr-only">Toggle navigation</span> |
| 204 | 204 | <span class="icon-bar"></span> |
@@ -207,396 +207,396 @@ discard block |
||
| 207 | 207 | </button> |
| 208 | 208 | <a class="navbar-brand" href="'. $url .'">'. $title .'</a> |
| 209 | 209 | </div>'; |
| 210 | - } |
|
| 211 | - |
|
| 212 | - //-------------------------------------------------------------------- |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Creates a UL meant to pull to the right within the navbar. |
|
| 216 | - * |
|
| 217 | - * Available options: |
|
| 218 | - * 'class' - An additional class to add |
|
| 219 | - * |
|
| 220 | - * @param array $options |
|
| 221 | - * @param callable $c |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - public function navbarRight($options=[], \Closure $c) |
|
| 225 | - { |
|
| 226 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav navbar-nav navbar-right', true); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + //-------------------------------------------------------------------- |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Creates a UL meant to pull to the right within the navbar. |
|
| 216 | + * |
|
| 217 | + * Available options: |
|
| 218 | + * 'class' - An additional class to add |
|
| 219 | + * |
|
| 220 | + * @param array $options |
|
| 221 | + * @param callable $c |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + public function navbarRight($options=[], \Closure $c) |
|
| 225 | + { |
|
| 226 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav navbar-nav navbar-right', true); |
|
| 227 | 227 | |
| 228 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 228 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 229 | 229 | |
| 230 | - $output .= $this->runClosure($c); |
|
| 230 | + $output .= $this->runClosure($c); |
|
| 231 | 231 | |
| 232 | - $output .= "</ul>\n"; |
|
| 232 | + $output .= "</ul>\n"; |
|
| 233 | 233 | |
| 234 | - return $output; |
|
| 235 | - } |
|
| 234 | + return $output; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - //-------------------------------------------------------------------- |
|
| 237 | + //-------------------------------------------------------------------- |
|
| 238 | 238 | |
| 239 | - public function nav() |
|
| 240 | - { |
|
| 239 | + public function nav() |
|
| 240 | + { |
|
| 241 | 241 | |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - //-------------------------------------------------------------------- |
|
| 244 | + //-------------------------------------------------------------------- |
|
| 245 | 245 | |
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * Creates a single list item for use within a nav section. |
|
| 249 | - * |
|
| 250 | - * @param $title |
|
| 251 | - * @param $url |
|
| 252 | - * @param array $options |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - public function navItem($title, $url='#', $options=[], $isActive=false) |
|
| 256 | - { |
|
| 257 | - $this->states['activeNavTitle'] = $title; |
|
| 247 | + /** |
|
| 248 | + * Creates a single list item for use within a nav section. |
|
| 249 | + * |
|
| 250 | + * @param $title |
|
| 251 | + * @param $url |
|
| 252 | + * @param array $options |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + public function navItem($title, $url='#', $options=[], $isActive=false) |
|
| 256 | + { |
|
| 257 | + $this->states['activeNavTitle'] = $title; |
|
| 258 | 258 | |
| 259 | - $class = $isActive ? $this->active_class : ''; |
|
| 259 | + $class = $isActive ? $this->active_class : ''; |
|
| 260 | 260 | |
| 261 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $class, true); |
|
| 261 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $class, true); |
|
| 262 | 262 | |
| 263 | - return " <li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>\n"; |
|
| 264 | - } |
|
| 263 | + return " <li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>\n"; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - //-------------------------------------------------------------------- |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
| 270 | - * |
|
| 271 | - * @param $title |
|
| 272 | - * @param array $options |
|
| 273 | - * @param callable $c |
|
| 274 | - */ |
|
| 275 | - public function navDropdown($title,$options=[], \Closure $c) |
|
| 276 | - { |
|
| 277 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'dropdown', true); |
|
| 278 | - |
|
| 279 | - $output = "\t<li {$classes} {$id} {$attributes}> |
|
| 266 | + //-------------------------------------------------------------------- |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
| 270 | + * |
|
| 271 | + * @param $title |
|
| 272 | + * @param array $options |
|
| 273 | + * @param callable $c |
|
| 274 | + */ |
|
| 275 | + public function navDropdown($title,$options=[], \Closure $c) |
|
| 276 | + { |
|
| 277 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'dropdown', true); |
|
| 278 | + |
|
| 279 | + $output = "\t<li {$classes} {$id} {$attributes}> |
|
| 280 | 280 | <a href='#' class='dropdown-toggle' data-toggle='dropdown'>{$title} <span class='caret'></span></a> |
| 281 | 281 | <ul class='dropdown-menu' role='menu'>\n"; |
| 282 | 282 | |
| 283 | - $output .= $this->runClosure($c); |
|
| 283 | + $output .= $this->runClosure($c); |
|
| 284 | + |
|
| 285 | + $output .= " </ul></li>\n"; |
|
| 286 | + |
|
| 287 | + return $output; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + //-------------------------------------------------------------------- |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Creates a divider for use within a nav list. |
|
| 294 | + * |
|
| 295 | + * @return string |
|
| 296 | + */ |
|
| 297 | + public function navDivider() |
|
| 298 | + { |
|
| 299 | + return "<li class=\"divider\"></li>\n"; |
|
| 300 | + } |
|
| 284 | 301 | |
| 285 | - $output .= " </ul></li>\n"; |
|
| 302 | + //-------------------------------------------------------------------- |
|
| 286 | 303 | |
| 287 | - return $output; |
|
| 288 | - } |
|
| 304 | + public function sideNav($options=[], \Closure $c) |
|
| 305 | + { |
|
| 306 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav nav-pills nav-stacked', true); |
|
| 289 | 307 | |
| 290 | - //-------------------------------------------------------------------- |
|
| 308 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 291 | 309 | |
| 292 | - /** |
|
| 293 | - * Creates a divider for use within a nav list. |
|
| 294 | - * |
|
| 295 | - * @return string |
|
| 296 | - */ |
|
| 297 | - public function navDivider() |
|
| 298 | - { |
|
| 299 | - return "<li class=\"divider\"></li>\n"; |
|
| 300 | - } |
|
| 310 | + $output .= $this->runClosure($c); |
|
| 301 | 311 | |
| 302 | - //-------------------------------------------------------------------- |
|
| 312 | + $output .= "</ul>\n"; |
|
| 303 | 313 | |
| 304 | - public function sideNav($options=[], \Closure $c) |
|
| 305 | - { |
|
| 306 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav nav-pills nav-stacked', true); |
|
| 314 | + return $output; |
|
| 315 | + } |
|
| 307 | 316 | |
| 308 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 309 | - |
|
| 310 | - $output .= $this->runClosure($c); |
|
| 311 | - |
|
| 312 | - $output .= "</ul>\n"; |
|
| 313 | - |
|
| 314 | - return $output; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - //-------------------------------------------------------------------- |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 321 | - * |
|
| 322 | - * @param array $options |
|
| 323 | - * @param callable $c |
|
| 324 | - * @return mixed |
|
| 325 | - */ |
|
| 326 | - public function breadcrumb($options=[], \Closure $c) |
|
| 327 | - { |
|
| 328 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumb', true); |
|
| 329 | - |
|
| 330 | - $output = "<ol {$classes} {$id} {$attributes}>\n"; |
|
| 331 | - |
|
| 332 | - $output .= $this->runClosure($c); |
|
| 333 | - |
|
| 334 | - $output .= "</ol>\n"; |
|
| 335 | - |
|
| 336 | - return $output; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - //-------------------------------------------------------------------- |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - //-------------------------------------------------------------------- |
|
| 343 | - |
|
| 344 | - //-------------------------------------------------------------------- |
|
| 345 | - // Tables |
|
| 346 | - //-------------------------------------------------------------------- |
|
| 347 | - |
|
| 348 | - public function table() |
|
| 349 | - { |
|
| 350 | - return 'table'; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - //-------------------------------------------------------------------- |
|
| 354 | - |
|
| 355 | - //-------------------------------------------------------------------- |
|
| 356 | - // Buttons |
|
| 357 | - //-------------------------------------------------------------------- |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Creates a simple button. |
|
| 361 | - * |
|
| 362 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 363 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 364 | - * |
|
| 365 | - * @param $title |
|
| 366 | - * @param string $style |
|
| 367 | - * @param array $options |
|
| 368 | - * @return mixed |
|
| 369 | - */ |
|
| 370 | - public function button($title, $style='default', $size='default', $options=[]) |
|
| 371 | - { |
|
| 372 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 373 | - |
|
| 374 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - //-------------------------------------------------------------------- |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Creates a simple link styled as a button. |
|
| 381 | - * |
|
| 382 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 383 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 384 | - * |
|
| 385 | - * @param $title |
|
| 386 | - * @param string $url |
|
| 387 | - * @param string $style |
|
| 388 | - * @param array $options |
|
| 389 | - * @return mixed |
|
| 390 | - */ |
|
| 391 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 392 | - { |
|
| 393 | - $tag = "<a href='{$url}' {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
| 394 | - |
|
| 395 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - //-------------------------------------------------------------------- |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Helper method to render out our buttons in a DRY manner. |
|
| 402 | - * |
|
| 403 | - * @param $title |
|
| 404 | - * @param $style |
|
| 405 | - * @param $size |
|
| 406 | - * @param $tag |
|
| 407 | - */ |
|
| 408 | - protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
| 409 | - { |
|
| 410 | - $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
| 411 | - $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
| 412 | - |
|
| 413 | - if (! in_array($style, $valid_styles)) |
|
| 414 | - { |
|
| 415 | - $style = 'default'; |
|
| 416 | - $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - $classes = 'btn '; |
|
| 420 | - |
|
| 421 | - // Sizes |
|
| 422 | - switch($size) |
|
| 423 | - { |
|
| 424 | - case 'small': |
|
| 425 | - $classes .= 'btn-sm '; |
|
| 426 | - break; |
|
| 427 | - case 'xsmall': |
|
| 428 | - $classes .= 'btn-xs '; |
|
| 429 | - break; |
|
| 430 | - case 'large': |
|
| 431 | - $classes .= 'btn-lg '; |
|
| 432 | - break; |
|
| 433 | - default: |
|
| 434 | - break; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // Styles |
|
| 438 | - switch ($style) |
|
| 439 | - { |
|
| 440 | - case 'primary': |
|
| 441 | - $classes .= 'btn-primary '; |
|
| 442 | - break; |
|
| 443 | - case 'success': |
|
| 444 | - $classes .= 'btn-success '; |
|
| 445 | - break; |
|
| 446 | - case 'info': |
|
| 447 | - $classes .= 'btn-info '; |
|
| 448 | - break; |
|
| 449 | - case 'warning': |
|
| 450 | - $classes .= 'btn-warning '; |
|
| 451 | - break; |
|
| 452 | - case 'danger': |
|
| 453 | - $classes .= 'btn-danger '; |
|
| 454 | - break; |
|
| 455 | - case 'default': |
|
| 456 | - $classes .= 'btn-default '; |
|
| 457 | - break; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 461 | - |
|
| 462 | - $tag = str_replace('{classes}', $classes, $tag); |
|
| 463 | - $tag = str_replace('{id}', $id, $tag); |
|
| 464 | - $tag = str_replace('{attributes}', $attributes, $tag); |
|
| 465 | - $tag = str_replace('{title}', $title, $tag); |
|
| 466 | - |
|
| 467 | - return $tag; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - //-------------------------------------------------------------------- |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Creates button groups wrapping HTML. |
|
| 474 | - * |
|
| 475 | - * @param $options |
|
| 476 | - * @param callable $c |
|
| 477 | - * @return mixed |
|
| 478 | - */ |
|
| 479 | - public function buttonGroup($options, \Closure $c) |
|
| 480 | - { |
|
| 481 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-group', true); |
|
| 482 | - |
|
| 483 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 484 | - |
|
| 485 | - $output .= $this->runClosure($c); |
|
| 486 | - |
|
| 487 | - $output .= "</div>\n"; |
|
| 488 | - |
|
| 489 | - return $output; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - //-------------------------------------------------------------------- |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Creates the button bar wrapping HTML. |
|
| 496 | - * |
|
| 497 | - * @param $options |
|
| 498 | - * @param callable $c |
|
| 499 | - * @return mixed |
|
| 500 | - */ |
|
| 501 | - public function buttonBar($options, \Closure $c) |
|
| 502 | - { |
|
| 503 | - $options['attributes'][] = 'role="toolbar"'; |
|
| 504 | - |
|
| 505 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-toolbar', true); |
|
| 506 | - |
|
| 507 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 508 | - |
|
| 509 | - $output .= $this->runClosure($c); |
|
| 510 | - |
|
| 511 | - $output .= "</div>\n"; |
|
| 512 | - |
|
| 513 | - return $output; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - //-------------------------------------------------------------------- |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 520 | - * by some frameworks. |
|
| 521 | - * |
|
| 522 | - * @param $title |
|
| 523 | - * @param string $style |
|
| 524 | - * @param string $size |
|
| 525 | - * @param array $options |
|
| 526 | - * @param callable $c |
|
| 527 | - * @return mixed |
|
| 528 | - */ |
|
| 529 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 530 | - { |
|
| 531 | - $tag = "<button type='button' {classes} data-toggle='dropdown'> |
|
| 317 | + //-------------------------------------------------------------------- |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 321 | + * |
|
| 322 | + * @param array $options |
|
| 323 | + * @param callable $c |
|
| 324 | + * @return mixed |
|
| 325 | + */ |
|
| 326 | + public function breadcrumb($options=[], \Closure $c) |
|
| 327 | + { |
|
| 328 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumb', true); |
|
| 329 | + |
|
| 330 | + $output = "<ol {$classes} {$id} {$attributes}>\n"; |
|
| 331 | + |
|
| 332 | + $output .= $this->runClosure($c); |
|
| 333 | + |
|
| 334 | + $output .= "</ol>\n"; |
|
| 335 | + |
|
| 336 | + return $output; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + //-------------------------------------------------------------------- |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + //-------------------------------------------------------------------- |
|
| 343 | + |
|
| 344 | + //-------------------------------------------------------------------- |
|
| 345 | + // Tables |
|
| 346 | + //-------------------------------------------------------------------- |
|
| 347 | + |
|
| 348 | + public function table() |
|
| 349 | + { |
|
| 350 | + return 'table'; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + //-------------------------------------------------------------------- |
|
| 354 | + |
|
| 355 | + //-------------------------------------------------------------------- |
|
| 356 | + // Buttons |
|
| 357 | + //-------------------------------------------------------------------- |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Creates a simple button. |
|
| 361 | + * |
|
| 362 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 363 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 364 | + * |
|
| 365 | + * @param $title |
|
| 366 | + * @param string $style |
|
| 367 | + * @param array $options |
|
| 368 | + * @return mixed |
|
| 369 | + */ |
|
| 370 | + public function button($title, $style='default', $size='default', $options=[]) |
|
| 371 | + { |
|
| 372 | + $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 373 | + |
|
| 374 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + //-------------------------------------------------------------------- |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Creates a simple link styled as a button. |
|
| 381 | + * |
|
| 382 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 383 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 384 | + * |
|
| 385 | + * @param $title |
|
| 386 | + * @param string $url |
|
| 387 | + * @param string $style |
|
| 388 | + * @param array $options |
|
| 389 | + * @return mixed |
|
| 390 | + */ |
|
| 391 | + public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 392 | + { |
|
| 393 | + $tag = "<a href='{$url}' {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
| 394 | + |
|
| 395 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + //-------------------------------------------------------------------- |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Helper method to render out our buttons in a DRY manner. |
|
| 402 | + * |
|
| 403 | + * @param $title |
|
| 404 | + * @param $style |
|
| 405 | + * @param $size |
|
| 406 | + * @param $tag |
|
| 407 | + */ |
|
| 408 | + protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
| 409 | + { |
|
| 410 | + $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
| 411 | + $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
| 412 | + |
|
| 413 | + if (! in_array($style, $valid_styles)) |
|
| 414 | + { |
|
| 415 | + $style = 'default'; |
|
| 416 | + $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + $classes = 'btn '; |
|
| 420 | + |
|
| 421 | + // Sizes |
|
| 422 | + switch($size) |
|
| 423 | + { |
|
| 424 | + case 'small': |
|
| 425 | + $classes .= 'btn-sm '; |
|
| 426 | + break; |
|
| 427 | + case 'xsmall': |
|
| 428 | + $classes .= 'btn-xs '; |
|
| 429 | + break; |
|
| 430 | + case 'large': |
|
| 431 | + $classes .= 'btn-lg '; |
|
| 432 | + break; |
|
| 433 | + default: |
|
| 434 | + break; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // Styles |
|
| 438 | + switch ($style) |
|
| 439 | + { |
|
| 440 | + case 'primary': |
|
| 441 | + $classes .= 'btn-primary '; |
|
| 442 | + break; |
|
| 443 | + case 'success': |
|
| 444 | + $classes .= 'btn-success '; |
|
| 445 | + break; |
|
| 446 | + case 'info': |
|
| 447 | + $classes .= 'btn-info '; |
|
| 448 | + break; |
|
| 449 | + case 'warning': |
|
| 450 | + $classes .= 'btn-warning '; |
|
| 451 | + break; |
|
| 452 | + case 'danger': |
|
| 453 | + $classes .= 'btn-danger '; |
|
| 454 | + break; |
|
| 455 | + case 'default': |
|
| 456 | + $classes .= 'btn-default '; |
|
| 457 | + break; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 461 | + |
|
| 462 | + $tag = str_replace('{classes}', $classes, $tag); |
|
| 463 | + $tag = str_replace('{id}', $id, $tag); |
|
| 464 | + $tag = str_replace('{attributes}', $attributes, $tag); |
|
| 465 | + $tag = str_replace('{title}', $title, $tag); |
|
| 466 | + |
|
| 467 | + return $tag; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + //-------------------------------------------------------------------- |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Creates button groups wrapping HTML. |
|
| 474 | + * |
|
| 475 | + * @param $options |
|
| 476 | + * @param callable $c |
|
| 477 | + * @return mixed |
|
| 478 | + */ |
|
| 479 | + public function buttonGroup($options, \Closure $c) |
|
| 480 | + { |
|
| 481 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-group', true); |
|
| 482 | + |
|
| 483 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 484 | + |
|
| 485 | + $output .= $this->runClosure($c); |
|
| 486 | + |
|
| 487 | + $output .= "</div>\n"; |
|
| 488 | + |
|
| 489 | + return $output; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + //-------------------------------------------------------------------- |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Creates the button bar wrapping HTML. |
|
| 496 | + * |
|
| 497 | + * @param $options |
|
| 498 | + * @param callable $c |
|
| 499 | + * @return mixed |
|
| 500 | + */ |
|
| 501 | + public function buttonBar($options, \Closure $c) |
|
| 502 | + { |
|
| 503 | + $options['attributes'][] = 'role="toolbar"'; |
|
| 504 | + |
|
| 505 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-toolbar', true); |
|
| 506 | + |
|
| 507 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 508 | + |
|
| 509 | + $output .= $this->runClosure($c); |
|
| 510 | + |
|
| 511 | + $output .= "</div>\n"; |
|
| 512 | + |
|
| 513 | + return $output; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + //-------------------------------------------------------------------- |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 520 | + * by some frameworks. |
|
| 521 | + * |
|
| 522 | + * @param $title |
|
| 523 | + * @param string $style |
|
| 524 | + * @param string $size |
|
| 525 | + * @param array $options |
|
| 526 | + * @param callable $c |
|
| 527 | + * @return mixed |
|
| 528 | + */ |
|
| 529 | + public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 530 | + { |
|
| 531 | + $tag = "<button type='button' {classes} data-toggle='dropdown'> |
|
| 532 | 532 | {title} <span class='caret'></span> |
| 533 | 533 | </button> |
| 534 | 534 | <ul class='dropdown-menu' role='menu'>"; |
| 535 | 535 | |
| 536 | - $output = $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 537 | - |
|
| 538 | - $output .= $this->runClosure($c); |
|
| 539 | - |
|
| 540 | - $output .= "</ul>\n"; |
|
| 541 | - |
|
| 542 | - return $output; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - //-------------------------------------------------------------------- |
|
| 546 | - |
|
| 547 | - //-------------------------------------------------------------------- |
|
| 548 | - // Notices |
|
| 549 | - //-------------------------------------------------------------------- |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Creates an 'alert-box' style of notice grid. |
|
| 553 | - * |
|
| 554 | - * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
| 555 | - * |
|
| 556 | - * @param $content |
|
| 557 | - * @param string $style |
|
| 558 | - * @param bool $closable |
|
| 559 | - * @return mixed |
|
| 560 | - */ |
|
| 561 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 562 | - { |
|
| 563 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert', false); |
|
| 564 | - |
|
| 565 | - // Styles |
|
| 566 | - switch ($style) |
|
| 567 | - { |
|
| 568 | - case 'success': |
|
| 569 | - $classes .= ' alert-success '; |
|
| 570 | - break; |
|
| 571 | - case 'info': |
|
| 572 | - $classes .= ' alert-info '; |
|
| 573 | - break; |
|
| 574 | - case 'warning': |
|
| 575 | - $classes .= ' alert-warning '; |
|
| 576 | - break; |
|
| 577 | - case 'danger': |
|
| 578 | - $classes .= ' alert-danger '; |
|
| 579 | - break; |
|
| 580 | - case 'default': |
|
| 581 | - $classes .= ' text-muted '; |
|
| 582 | - break; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - $output = "<div class='{$classes}'>\n"; |
|
| 586 | - |
|
| 587 | - $output .= "\t$content\n"; |
|
| 588 | - |
|
| 589 | - if ($closable) |
|
| 590 | - { |
|
| 591 | - $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - $output .= "</div>\n"; |
|
| 595 | - |
|
| 596 | - return $output; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - //-------------------------------------------------------------------- |
|
| 536 | + $output = $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 537 | + |
|
| 538 | + $output .= $this->runClosure($c); |
|
| 539 | + |
|
| 540 | + $output .= "</ul>\n"; |
|
| 541 | + |
|
| 542 | + return $output; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + //-------------------------------------------------------------------- |
|
| 546 | + |
|
| 547 | + //-------------------------------------------------------------------- |
|
| 548 | + // Notices |
|
| 549 | + //-------------------------------------------------------------------- |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Creates an 'alert-box' style of notice grid. |
|
| 553 | + * |
|
| 554 | + * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
| 555 | + * |
|
| 556 | + * @param $content |
|
| 557 | + * @param string $style |
|
| 558 | + * @param bool $closable |
|
| 559 | + * @return mixed |
|
| 560 | + */ |
|
| 561 | + public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 562 | + { |
|
| 563 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert', false); |
|
| 564 | + |
|
| 565 | + // Styles |
|
| 566 | + switch ($style) |
|
| 567 | + { |
|
| 568 | + case 'success': |
|
| 569 | + $classes .= ' alert-success '; |
|
| 570 | + break; |
|
| 571 | + case 'info': |
|
| 572 | + $classes .= ' alert-info '; |
|
| 573 | + break; |
|
| 574 | + case 'warning': |
|
| 575 | + $classes .= ' alert-warning '; |
|
| 576 | + break; |
|
| 577 | + case 'danger': |
|
| 578 | + $classes .= ' alert-danger '; |
|
| 579 | + break; |
|
| 580 | + case 'default': |
|
| 581 | + $classes .= ' text-muted '; |
|
| 582 | + break; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + $output = "<div class='{$classes}'>\n"; |
|
| 586 | + |
|
| 587 | + $output .= "\t$content\n"; |
|
| 588 | + |
|
| 589 | + if ($closable) |
|
| 590 | + { |
|
| 591 | + $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + $output .= "</div>\n"; |
|
| 595 | + |
|
| 596 | + return $output; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + //-------------------------------------------------------------------- |
|
| 600 | 600 | |
| 601 | 601 | //-------------------------------------------------------------------- |
| 602 | 602 | // Forms |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param array $options |
| 52 | 52 | * @return mixed |
| 53 | 53 | */ |
| 54 | - public function row($options=[], \Closure $c) |
|
| 54 | + public function row($options = [], \Closure $c) |
|
| 55 | 55 | { |
| 56 | 56 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
| 57 | 57 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param array $attributes |
| 84 | 84 | * @return mixed |
| 85 | 85 | */ |
| 86 | - public function column($options=[], \Closure $c) |
|
| 86 | + public function column($options = [], \Closure $c) |
|
| 87 | 87 | { |
| 88 | 88 | // Build our classes |
| 89 | 89 | $classes = ''; |
@@ -93,28 +93,28 @@ discard block |
||
| 93 | 93 | switch ($size) |
| 94 | 94 | { |
| 95 | 95 | case 's': |
| 96 | - $classes .= ' col-xs-'. $value; |
|
| 96 | + $classes .= ' col-xs-'.$value; |
|
| 97 | 97 | break; |
| 98 | 98 | case 'm': |
| 99 | - $classes .= ' col-sm-'. $value; |
|
| 99 | + $classes .= ' col-sm-'.$value; |
|
| 100 | 100 | break; |
| 101 | 101 | case 'l': |
| 102 | - $classes .= ' col-md-'. $value; |
|
| 102 | + $classes .= ' col-md-'.$value; |
|
| 103 | 103 | break; |
| 104 | 104 | case 'xl': |
| 105 | - $classes .= ' col-lg-'. $value; |
|
| 105 | + $classes .= ' col-lg-'.$value; |
|
| 106 | 106 | break; |
| 107 | 107 | case 's-offset': |
| 108 | - $classes .= ' col-xs-offset-'. $value; |
|
| 108 | + $classes .= ' col-xs-offset-'.$value; |
|
| 109 | 109 | break; |
| 110 | 110 | case 'm-offset': |
| 111 | - $classes .= ' col-sm-offset-'. $value; |
|
| 111 | + $classes .= ' col-sm-offset-'.$value; |
|
| 112 | 112 | break; |
| 113 | 113 | case 'l-offset': |
| 114 | - $classes .= ' col-md-offset-'. $value; |
|
| 114 | + $classes .= ' col-md-offset-'.$value; |
|
| 115 | 115 | break; |
| 116 | 116 | case 'xl-offset': |
| 117 | - $classes .= ' col-lg-offset-'. $value; |
|
| 117 | + $classes .= ' col-lg-offset-'.$value; |
|
| 118 | 118 | break; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param callable $c |
| 145 | 145 | * @return string |
| 146 | 146 | */ |
| 147 | - public function navbar($options=[], \Closure $c) |
|
| 147 | + public function navbar($options = [], \Closure $c) |
|
| 148 | 148 | { |
| 149 | 149 | $output = ''; |
| 150 | 150 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @param string $url |
| 197 | 197 | * @return string |
| 198 | 198 | */ |
| 199 | - public function navbarTitle($title, $url='#') |
|
| 199 | + public function navbarTitle($title, $url = '#') |
|
| 200 | 200 | { |
| 201 | 201 | return '<div class="navbar-header"> |
| 202 | 202 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1"> |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | <span class="icon-bar"></span> |
| 206 | 206 | <span class="icon-bar"></span> |
| 207 | 207 | </button> |
| 208 | - <a class="navbar-brand" href="'. $url .'">'. $title .'</a> |
|
| 208 | + <a class="navbar-brand" href="'. $url.'">'.$title.'</a> |
|
| 209 | 209 | </div>'; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * @param callable $c |
| 222 | 222 | * @return string |
| 223 | 223 | */ |
| 224 | - public function navbarRight($options=[], \Closure $c) |
|
| 224 | + public function navbarRight($options = [], \Closure $c) |
|
| 225 | 225 | { |
| 226 | 226 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav navbar-nav navbar-right', true); |
| 227 | 227 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param array $options |
| 253 | 253 | * @return string |
| 254 | 254 | */ |
| 255 | - public function navItem($title, $url='#', $options=[], $isActive=false) |
|
| 255 | + public function navItem($title, $url = '#', $options = [], $isActive = false) |
|
| 256 | 256 | { |
| 257 | 257 | $this->states['activeNavTitle'] = $title; |
| 258 | 258 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @param array $options |
| 273 | 273 | * @param callable $c |
| 274 | 274 | */ |
| 275 | - public function navDropdown($title,$options=[], \Closure $c) |
|
| 275 | + public function navDropdown($title, $options = [], \Closure $c) |
|
| 276 | 276 | { |
| 277 | 277 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'dropdown', true); |
| 278 | 278 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | //-------------------------------------------------------------------- |
| 303 | 303 | |
| 304 | - public function sideNav($options=[], \Closure $c) |
|
| 304 | + public function sideNav($options = [], \Closure $c) |
|
| 305 | 305 | { |
| 306 | 306 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav nav-pills nav-stacked', true); |
| 307 | 307 | |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | * @param callable $c |
| 324 | 324 | * @return mixed |
| 325 | 325 | */ |
| 326 | - public function breadcrumb($options=[], \Closure $c) |
|
| 326 | + public function breadcrumb($options = [], \Closure $c) |
|
| 327 | 327 | { |
| 328 | 328 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumb', true); |
| 329 | 329 | |
@@ -367,9 +367,9 @@ discard block |
||
| 367 | 367 | * @param array $options |
| 368 | 368 | * @return mixed |
| 369 | 369 | */ |
| 370 | - public function button($title, $style='default', $size='default', $options=[]) |
|
| 370 | + public function button($title, $style = 'default', $size = 'default', $options = []) |
|
| 371 | 371 | { |
| 372 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 372 | + $tag = "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 373 | 373 | |
| 374 | 374 | return $this->renderButtonElement($title, $style, $size, $options, $tag); |
| 375 | 375 | } |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * @param array $options |
| 389 | 389 | * @return mixed |
| 390 | 390 | */ |
| 391 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 391 | + public function buttonLink($title, $url = '#', $style = 'default', $size = 'default', $options = []) |
|
| 392 | 392 | { |
| 393 | 393 | $tag = "<a href='{$url}' {classes} {id} {attributes} role='button'>{$title}</a>"; |
| 394 | 394 | |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
| 411 | 411 | $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
| 412 | 412 | |
| 413 | - if (! in_array($style, $valid_styles)) |
|
| 413 | + if ( ! in_array($style, $valid_styles)) |
|
| 414 | 414 | { |
| 415 | 415 | $style = 'default'; |
| 416 | 416 | $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | $classes = 'btn '; |
| 420 | 420 | |
| 421 | 421 | // Sizes |
| 422 | - switch($size) |
|
| 422 | + switch ($size) |
|
| 423 | 423 | { |
| 424 | 424 | case 'small': |
| 425 | 425 | $classes .= 'btn-sm '; |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | * @param callable $c |
| 527 | 527 | * @return mixed |
| 528 | 528 | */ |
| 529 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 529 | + public function buttonDropdown($title, $style = 'default', $size = 'default', $options = [], \Closure $c) |
|
| 530 | 530 | { |
| 531 | 531 | $tag = "<button type='button' {classes} data-toggle='dropdown'> |
| 532 | 532 | {title} <span class='caret'></span> |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * @param bool $closable |
| 559 | 559 | * @return mixed |
| 560 | 560 | */ |
| 561 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 561 | + public function notice($content, $style = 'success', $closable = true, $options = []) |
|
| 562 | 562 | { |
| 563 | 563 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert', false); |
| 564 | 564 | |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | * |
| 614 | 614 | * @return mixed |
| 615 | 615 | */ |
| 616 | - public function inputWrap($label_text, $options=[], \Closure $c) |
|
| 616 | + public function inputWrap($label_text, $options = [], \Closure $c) |
|
| 617 | 617 | { |
| 618 | 618 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'form-group', true); |
| 619 | 619 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * approach to rows and columns than the reference Bootstrap and Foundation. |
| 57 | 57 | * |
| 58 | 58 | * @param array $options |
| 59 | - * @return mixed |
|
| 59 | + * @return string |
|
| 60 | 60 | */ |
| 61 | 61 | public function row($options=[], \Closure $c) |
| 62 | 62 | { |
@@ -87,8 +87,7 @@ discard block |
||
| 87 | 87 | * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
| 88 | 88 | * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
| 89 | 89 | * |
| 90 | - * @param array $attributes |
|
| 91 | - * @return mixed |
|
| 90 | + * @return string |
|
| 92 | 91 | */ |
| 93 | 92 | public function column($options=[], \Closure $c) |
| 94 | 93 | { |
@@ -152,7 +151,7 @@ discard block |
||
| 152 | 151 | * top of a page. |
| 153 | 152 | * |
| 154 | 153 | * @param array $options |
| 155 | - * @param callable $c |
|
| 154 | + * @param \Closure $c |
|
| 156 | 155 | * @return string |
| 157 | 156 | */ |
| 158 | 157 | public function navbar($options=[], \Closure $c) |
@@ -224,7 +223,7 @@ discard block |
||
| 224 | 223 | * 'class' - An additional class to add |
| 225 | 224 | * |
| 226 | 225 | * @param array $options |
| 227 | - * @param callable $c |
|
| 226 | + * @param \Closure $c |
|
| 228 | 227 | * @return string |
| 229 | 228 | */ |
| 230 | 229 | public function navbarRight($options=[], \Closure $c) |
@@ -263,7 +262,7 @@ discard block |
||
| 263 | 262 | * 'class' - An additional class to add |
| 264 | 263 | * |
| 265 | 264 | * @param array $options |
| 266 | - * @param callable $c |
|
| 265 | + * @param \Closure $c |
|
| 267 | 266 | * @return string |
| 268 | 267 | */ |
| 269 | 268 | public function navbarLeft($options=[], \Closure $c) |
@@ -331,7 +330,7 @@ discard block |
||
| 331 | 330 | * |
| 332 | 331 | * @param $title |
| 333 | 332 | * @param array $options |
| 334 | - * @param callable $c |
|
| 333 | + * @param \Closure $c |
|
| 335 | 334 | */ |
| 336 | 335 | public function navDropdown($title,$options=[], \Closure $c) |
| 337 | 336 | { |
@@ -389,8 +388,8 @@ discard block |
||
| 389 | 388 | * Creates a list of nav items to function as breadcrumbs for a site. |
| 390 | 389 | * |
| 391 | 390 | * @param array $options |
| 392 | - * @param callable $c |
|
| 393 | - * @return mixed |
|
| 391 | + * @param \Closure $c |
|
| 392 | + * @return string |
|
| 394 | 393 | */ |
| 395 | 394 | public function breadcrumb($options=[], \Closure $c) |
| 396 | 395 | { |
@@ -470,8 +469,8 @@ discard block |
||
| 470 | 469 | * Helper method to render out our buttons in a DRY manner. |
| 471 | 470 | * |
| 472 | 471 | * @param $title |
| 473 | - * @param $style |
|
| 474 | - * @param $size |
|
| 472 | + * @param string $style |
|
| 473 | + * @param string $size |
|
| 475 | 474 | * @param $tag |
| 476 | 475 | */ |
| 477 | 476 | protected function renderButtonElement($title, $style, $size, $options, $tag) |
@@ -547,8 +546,8 @@ discard block |
||
| 547 | 546 | * Creates button groups wrapping HTML. |
| 548 | 547 | * |
| 549 | 548 | * @param $options |
| 550 | - * @param callable $c |
|
| 551 | - * @return mixed |
|
| 549 | + * @param \Closure $c |
|
| 550 | + * @return string |
|
| 552 | 551 | */ |
| 553 | 552 | public function buttonGroup($options, \Closure $c) |
| 554 | 553 | { |
@@ -573,8 +572,8 @@ discard block |
||
| 573 | 572 | * Creates the button bar wrapping HTML. |
| 574 | 573 | * |
| 575 | 574 | * @param $options |
| 576 | - * @param callable $c |
|
| 577 | - * @return mixed |
|
| 575 | + * @param \Closure $c |
|
| 576 | + * @return string |
|
| 578 | 577 | */ |
| 579 | 578 | public function buttonBar($options, \Closure $c) |
| 580 | 579 | { |
@@ -599,8 +598,8 @@ discard block |
||
| 599 | 598 | * @param string $style |
| 600 | 599 | * @param string $size |
| 601 | 600 | * @param array $options |
| 602 | - * @param callable $c |
|
| 603 | - * @return mixed |
|
| 601 | + * @param \Closure $c |
|
| 602 | + * @return string |
|
| 604 | 603 | */ |
| 605 | 604 | public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
| 606 | 605 | { |
@@ -630,7 +629,7 @@ discard block |
||
| 630 | 629 | * @param $content |
| 631 | 630 | * @param string $style |
| 632 | 631 | * @param bool $closable |
| 633 | - * @return mixed |
|
| 632 | + * @return string |
|
| 634 | 633 | */ |
| 635 | 634 | public function notice($content, $style='success', $closable=true, $options=[]) |
| 636 | 635 | { |
@@ -37,639 +37,639 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class Foundation extends BaseUIKit { |
| 39 | 39 | |
| 40 | - //-------------------------------------------------------------------- |
|
| 41 | - |
|
| 42 | - public function name() |
|
| 43 | - { |
|
| 44 | - return 'Foundation5UIKit'; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - //-------------------------------------------------------------------- |
|
| 48 | - |
|
| 49 | - //-------------------------------------------------------------------- |
|
| 50 | - // Grid |
|
| 51 | - //-------------------------------------------------------------------- |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
| 55 | - * the class for it, but some frameworks use a completely different |
|
| 56 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 57 | - * |
|
| 58 | - * @param array $options |
|
| 59 | - * @return mixed |
|
| 60 | - */ |
|
| 61 | - public function row($options=[], \Closure $c) |
|
| 62 | - { |
|
| 63 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
| 64 | - |
|
| 65 | - $output = "<div {$classes} {$id} {$attributes}>"; |
|
| 66 | - |
|
| 67 | - $output .= $this->runClosure($c); |
|
| 68 | - |
|
| 69 | - $output .= "</div>"; |
|
| 70 | - |
|
| 71 | - return $output; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - //-------------------------------------------------------------------- |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Creates the CSS for a column in a grid. |
|
| 78 | - * |
|
| 79 | - * The attribute array is made up of key/value pairs with the |
|
| 80 | - * key being the size, and the value being the number of columns/offset |
|
| 81 | - * in a 12-column grid. |
|
| 82 | - * |
|
| 83 | - * Note that we currently DO NOT support offset columns. |
|
| 84 | - * |
|
| 85 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 86 | - * |
|
| 87 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 88 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 89 | - * |
|
| 90 | - * @param array $attributes |
|
| 91 | - * @return mixed |
|
| 92 | - */ |
|
| 93 | - public function column($options=[], \Closure $c) |
|
| 94 | - { |
|
| 95 | - // Build our classes |
|
| 96 | - $classes = ''; |
|
| 97 | - |
|
| 98 | - foreach ($options['sizes'] as $size => $value) |
|
| 99 | - { |
|
| 100 | - switch ($size) |
|
| 101 | - { |
|
| 102 | - case 's': |
|
| 103 | - $classes .= ' small-'. $value; |
|
| 104 | - break; |
|
| 105 | - case 'm': |
|
| 106 | - $classes .= ' medium-'. $value; |
|
| 107 | - break; |
|
| 108 | - case 'l': |
|
| 109 | - $classes .= ' large-'. $value; |
|
| 110 | - break; |
|
| 111 | - case 'xl': |
|
| 112 | - $classes .= ' large-'. $value; |
|
| 113 | - break; |
|
| 114 | - case 's-offset': |
|
| 115 | - $classes .= ' small-offset-'. $value; |
|
| 116 | - break; |
|
| 117 | - case 'm-offset': |
|
| 118 | - $classes .= ' medium-offset-'. $value; |
|
| 119 | - break; |
|
| 120 | - case 'l-offset': |
|
| 121 | - $classes .= ' large-offset-'. $value; |
|
| 122 | - break; |
|
| 123 | - case 'xl-offset': |
|
| 124 | - $classes .= ' large-offset-'. $value; |
|
| 125 | - break; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $classes = $this->buildClassString($classes .' columns', $options, true); |
|
| 130 | - |
|
| 131 | - $id = $this->buildIdFromOptions($options); |
|
| 132 | - |
|
| 133 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 134 | - |
|
| 135 | - $output = "<div {$classes} {$id} {$attributes}>"; |
|
| 136 | - |
|
| 137 | - $output .= $this->runClosure($c); |
|
| 138 | - |
|
| 139 | - $output .= "</div>"; |
|
| 140 | - |
|
| 141 | - return $output; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - //-------------------------------------------------------------------- |
|
| 145 | - |
|
| 146 | - //-------------------------------------------------------------------- |
|
| 147 | - // Navigation |
|
| 148 | - //-------------------------------------------------------------------- |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Generates the container code for a navbar, typically used along the |
|
| 152 | - * top of a page. |
|
| 153 | - * |
|
| 154 | - * @param array $options |
|
| 155 | - * @param callable $c |
|
| 156 | - * @return string |
|
| 157 | - */ |
|
| 158 | - public function navbar($options=[], \Closure $c) |
|
| 159 | - { |
|
| 160 | - $output = ''; |
|
| 161 | - |
|
| 162 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'top-bar ', true); |
|
| 163 | - |
|
| 164 | - foreach ($options as $option) |
|
| 165 | - { |
|
| 166 | - switch ($option) |
|
| 167 | - { |
|
| 168 | - case 'sticky-top': |
|
| 169 | - $classes .= " navbar-static-top"; |
|
| 170 | - break; |
|
| 171 | - case 'fixed': |
|
| 172 | - $classes .= " navbar-fixed-top"; |
|
| 173 | - break; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $output .= "<nav {$classes} {$id} {$attributes} data-topbar>"; |
|
| 178 | - |
|
| 179 | - /* |
|
| 40 | + //-------------------------------------------------------------------- |
|
| 41 | + |
|
| 42 | + public function name() |
|
| 43 | + { |
|
| 44 | + return 'Foundation5UIKit'; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + //-------------------------------------------------------------------- |
|
| 48 | + |
|
| 49 | + //-------------------------------------------------------------------- |
|
| 50 | + // Grid |
|
| 51 | + //-------------------------------------------------------------------- |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
| 55 | + * the class for it, but some frameworks use a completely different |
|
| 56 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 57 | + * |
|
| 58 | + * @param array $options |
|
| 59 | + * @return mixed |
|
| 60 | + */ |
|
| 61 | + public function row($options=[], \Closure $c) |
|
| 62 | + { |
|
| 63 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
| 64 | + |
|
| 65 | + $output = "<div {$classes} {$id} {$attributes}>"; |
|
| 66 | + |
|
| 67 | + $output .= $this->runClosure($c); |
|
| 68 | + |
|
| 69 | + $output .= "</div>"; |
|
| 70 | + |
|
| 71 | + return $output; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + //-------------------------------------------------------------------- |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Creates the CSS for a column in a grid. |
|
| 78 | + * |
|
| 79 | + * The attribute array is made up of key/value pairs with the |
|
| 80 | + * key being the size, and the value being the number of columns/offset |
|
| 81 | + * in a 12-column grid. |
|
| 82 | + * |
|
| 83 | + * Note that we currently DO NOT support offset columns. |
|
| 84 | + * |
|
| 85 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 86 | + * |
|
| 87 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 88 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 89 | + * |
|
| 90 | + * @param array $attributes |
|
| 91 | + * @return mixed |
|
| 92 | + */ |
|
| 93 | + public function column($options=[], \Closure $c) |
|
| 94 | + { |
|
| 95 | + // Build our classes |
|
| 96 | + $classes = ''; |
|
| 97 | + |
|
| 98 | + foreach ($options['sizes'] as $size => $value) |
|
| 99 | + { |
|
| 100 | + switch ($size) |
|
| 101 | + { |
|
| 102 | + case 's': |
|
| 103 | + $classes .= ' small-'. $value; |
|
| 104 | + break; |
|
| 105 | + case 'm': |
|
| 106 | + $classes .= ' medium-'. $value; |
|
| 107 | + break; |
|
| 108 | + case 'l': |
|
| 109 | + $classes .= ' large-'. $value; |
|
| 110 | + break; |
|
| 111 | + case 'xl': |
|
| 112 | + $classes .= ' large-'. $value; |
|
| 113 | + break; |
|
| 114 | + case 's-offset': |
|
| 115 | + $classes .= ' small-offset-'. $value; |
|
| 116 | + break; |
|
| 117 | + case 'm-offset': |
|
| 118 | + $classes .= ' medium-offset-'. $value; |
|
| 119 | + break; |
|
| 120 | + case 'l-offset': |
|
| 121 | + $classes .= ' large-offset-'. $value; |
|
| 122 | + break; |
|
| 123 | + case 'xl-offset': |
|
| 124 | + $classes .= ' large-offset-'. $value; |
|
| 125 | + break; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $classes = $this->buildClassString($classes .' columns', $options, true); |
|
| 130 | + |
|
| 131 | + $id = $this->buildIdFromOptions($options); |
|
| 132 | + |
|
| 133 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 134 | + |
|
| 135 | + $output = "<div {$classes} {$id} {$attributes}>"; |
|
| 136 | + |
|
| 137 | + $output .= $this->runClosure($c); |
|
| 138 | + |
|
| 139 | + $output .= "</div>"; |
|
| 140 | + |
|
| 141 | + return $output; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + //-------------------------------------------------------------------- |
|
| 145 | + |
|
| 146 | + //-------------------------------------------------------------------- |
|
| 147 | + // Navigation |
|
| 148 | + //-------------------------------------------------------------------- |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Generates the container code for a navbar, typically used along the |
|
| 152 | + * top of a page. |
|
| 153 | + * |
|
| 154 | + * @param array $options |
|
| 155 | + * @param callable $c |
|
| 156 | + * @return string |
|
| 157 | + */ |
|
| 158 | + public function navbar($options=[], \Closure $c) |
|
| 159 | + { |
|
| 160 | + $output = ''; |
|
| 161 | + |
|
| 162 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'top-bar ', true); |
|
| 163 | + |
|
| 164 | + foreach ($options as $option) |
|
| 165 | + { |
|
| 166 | + switch ($option) |
|
| 167 | + { |
|
| 168 | + case 'sticky-top': |
|
| 169 | + $classes .= " navbar-static-top"; |
|
| 170 | + break; |
|
| 171 | + case 'fixed': |
|
| 172 | + $classes .= " navbar-fixed-top"; |
|
| 173 | + break; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $output .= "<nav {$classes} {$id} {$attributes} data-topbar>"; |
|
| 178 | + |
|
| 179 | + /* |
|
| 180 | 180 | * Do any user content inside the bar |
| 181 | 181 | */ |
| 182 | - $output .= $this->runClosure($c); |
|
| 182 | + $output .= $this->runClosure($c); |
|
| 183 | 183 | |
| 184 | - if (isset($this->states['nav-section-open'])) |
|
| 185 | - { |
|
| 186 | - $output .= "</section>"; |
|
| 187 | - unset($this->states['nav-section-open']); |
|
| 188 | - } |
|
| 184 | + if (isset($this->states['nav-section-open'])) |
|
| 185 | + { |
|
| 186 | + $output .= "</section>"; |
|
| 187 | + unset($this->states['nav-section-open']); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /* |
|
| 190 | + /* |
|
| 191 | 191 | * Close out the navbar |
| 192 | 192 | */ |
| 193 | - $output .= '</nav>'; |
|
| 194 | - |
|
| 195 | - return $output; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - //-------------------------------------------------------------------- |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
| 202 | - * includes the code for the hamburger menu on small resolutions. |
|
| 203 | - * |
|
| 204 | - * @param $title |
|
| 205 | - * @param string $url |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function navbarTitle($title, $url='#') |
|
| 209 | - { |
|
| 210 | - return "<ul class='title-area'> |
|
| 193 | + $output .= '</nav>'; |
|
| 194 | + |
|
| 195 | + return $output; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + //-------------------------------------------------------------------- |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
| 202 | + * includes the code for the hamburger menu on small resolutions. |
|
| 203 | + * |
|
| 204 | + * @param $title |
|
| 205 | + * @param string $url |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function navbarTitle($title, $url='#') |
|
| 209 | + { |
|
| 210 | + return "<ul class='title-area'> |
|
| 211 | 211 | <li class='name'> |
| 212 | 212 | <h1><a href='{$url}'>{$title}</a></h1> |
| 213 | 213 | </li> |
| 214 | 214 | <li class='toggle-topbar menu-icon'><a href='#'><span>Menu</span></a></li> |
| 215 | 215 | </ul>"; |
| 216 | - } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - //-------------------------------------------------------------------- |
|
| 218 | + //-------------------------------------------------------------------- |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Creates a UL meant to pull to the right within the navbar. |
|
| 222 | - * |
|
| 223 | - * Available options: |
|
| 224 | - * 'class' - An additional class to add |
|
| 225 | - * |
|
| 226 | - * @param array $options |
|
| 227 | - * @param callable $c |
|
| 228 | - * @return string |
|
| 229 | - */ |
|
| 230 | - public function navbarRight($options=[], \Closure $c) |
|
| 231 | - { |
|
| 232 | - $output = ''; |
|
| 220 | + /** |
|
| 221 | + * Creates a UL meant to pull to the right within the navbar. |
|
| 222 | + * |
|
| 223 | + * Available options: |
|
| 224 | + * 'class' - An additional class to add |
|
| 225 | + * |
|
| 226 | + * @param array $options |
|
| 227 | + * @param callable $c |
|
| 228 | + * @return string |
|
| 229 | + */ |
|
| 230 | + public function navbarRight($options=[], \Closure $c) |
|
| 231 | + { |
|
| 232 | + $output = ''; |
|
| 233 | 233 | |
| 234 | - if (! isset($this->states['nav-section-open'])) |
|
| 235 | - { |
|
| 236 | - $output .= "<section class='top-bar-section'>\n"; |
|
| 237 | - $this->states['nav-section-open'] = true; |
|
| 238 | - } |
|
| 234 | + if (! isset($this->states['nav-section-open'])) |
|
| 235 | + { |
|
| 236 | + $output .= "<section class='top-bar-section'>\n"; |
|
| 237 | + $this->states['nav-section-open'] = true; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - // Class |
|
| 241 | - $classes = $this->buildClassString('right', $options); |
|
| 240 | + // Class |
|
| 241 | + $classes = $this->buildClassString('right', $options); |
|
| 242 | 242 | |
| 243 | - // ID |
|
| 244 | - $id = $this->buildIdFromOptions($options); |
|
| 243 | + // ID |
|
| 244 | + $id = $this->buildIdFromOptions($options); |
|
| 245 | 245 | |
| 246 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 246 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 247 | 247 | |
| 248 | - $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
| 248 | + $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
| 249 | 249 | |
| 250 | - $output .= $this->runClosure($c); |
|
| 250 | + $output .= $this->runClosure($c); |
|
| 251 | 251 | |
| 252 | - $output .= "</ul>\n"; |
|
| 252 | + $output .= "</ul>\n"; |
|
| 253 | 253 | |
| 254 | - return $output; |
|
| 255 | - } |
|
| 254 | + return $output; |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - //-------------------------------------------------------------------- |
|
| 257 | + //-------------------------------------------------------------------- |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Creates a UL meant to pull to the left within the navbar. |
|
| 261 | - * |
|
| 262 | - * Available options: |
|
| 263 | - * 'class' - An additional class to add |
|
| 264 | - * |
|
| 265 | - * @param array $options |
|
| 266 | - * @param callable $c |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - public function navbarLeft($options=[], \Closure $c) |
|
| 270 | - { |
|
| 271 | - $output = ''; |
|
| 259 | + /** |
|
| 260 | + * Creates a UL meant to pull to the left within the navbar. |
|
| 261 | + * |
|
| 262 | + * Available options: |
|
| 263 | + * 'class' - An additional class to add |
|
| 264 | + * |
|
| 265 | + * @param array $options |
|
| 266 | + * @param callable $c |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + public function navbarLeft($options=[], \Closure $c) |
|
| 270 | + { |
|
| 271 | + $output = ''; |
|
| 272 | 272 | |
| 273 | - if (! isset($this->states['nav-section-open'])) |
|
| 274 | - { |
|
| 275 | - $output .= "<section class='top-bar-section'>\n"; |
|
| 276 | - $this->states['nav-section-open'] = true; |
|
| 277 | - } |
|
| 273 | + if (! isset($this->states['nav-section-open'])) |
|
| 274 | + { |
|
| 275 | + $output .= "<section class='top-bar-section'>\n"; |
|
| 276 | + $this->states['nav-section-open'] = true; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - // Class |
|
| 280 | - $classes = $this->buildClassString('left', $options); |
|
| 279 | + // Class |
|
| 280 | + $classes = $this->buildClassString('left', $options); |
|
| 281 | 281 | |
| 282 | - // ID |
|
| 283 | - $id = $this->buildIdFromOptions($options); |
|
| 282 | + // ID |
|
| 283 | + $id = $this->buildIdFromOptions($options); |
|
| 284 | 284 | |
| 285 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 285 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 286 | 286 | |
| 287 | - $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
| 287 | + $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
| 288 | 288 | |
| 289 | - $output .= $this->runClosure($c); |
|
| 289 | + $output .= $this->runClosure($c); |
|
| 290 | 290 | |
| 291 | - $output .= "</ul>\n"; |
|
| 291 | + $output .= "</ul>\n"; |
|
| 292 | 292 | |
| 293 | - return $output; |
|
| 294 | - } |
|
| 293 | + return $output; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - //-------------------------------------------------------------------- |
|
| 296 | + //-------------------------------------------------------------------- |
|
| 297 | 297 | |
| 298 | - public function nav() |
|
| 299 | - { |
|
| 298 | + public function nav() |
|
| 299 | + { |
|
| 300 | 300 | |
| 301 | - } |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - //-------------------------------------------------------------------- |
|
| 303 | + //-------------------------------------------------------------------- |
|
| 304 | 304 | |
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Creates a single list item for use within a nav section. |
|
| 308 | - * |
|
| 309 | - * @param $title |
|
| 310 | - * @param $url |
|
| 311 | - * @param array $options |
|
| 312 | - * @return string |
|
| 313 | - */ |
|
| 314 | - public function navItem($title, $url='#', $options=[], $active=false) |
|
| 315 | - { |
|
| 316 | - $options['active'] = $active; |
|
| 306 | + /** |
|
| 307 | + * Creates a single list item for use within a nav section. |
|
| 308 | + * |
|
| 309 | + * @param $title |
|
| 310 | + * @param $url |
|
| 311 | + * @param array $options |
|
| 312 | + * @return string |
|
| 313 | + */ |
|
| 314 | + public function navItem($title, $url='#', $options=[], $active=false) |
|
| 315 | + { |
|
| 316 | + $options['active'] = $active; |
|
| 317 | 317 | |
| 318 | - $classes = $this->buildClassString('', $options, true); |
|
| 318 | + $classes = $this->buildClassString('', $options, true); |
|
| 319 | 319 | |
| 320 | - $id = $this->buildIdFromOptions($options); |
|
| 320 | + $id = $this->buildIdFromOptions($options); |
|
| 321 | 321 | |
| 322 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 322 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 323 | 323 | |
| 324 | - return "\t<li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>"; |
|
| 325 | - } |
|
| 324 | + return "\t<li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>"; |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - //-------------------------------------------------------------------- |
|
| 327 | + //-------------------------------------------------------------------- |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
| 331 | - * |
|
| 332 | - * @param $title |
|
| 333 | - * @param array $options |
|
| 334 | - * @param callable $c |
|
| 335 | - */ |
|
| 336 | - public function navDropdown($title,$options=[], \Closure $c) |
|
| 337 | - { |
|
| 338 | - $classes = $this->buildClassString('has-dropdown', $options, true); |
|
| 329 | + /** |
|
| 330 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
| 331 | + * |
|
| 332 | + * @param $title |
|
| 333 | + * @param array $options |
|
| 334 | + * @param callable $c |
|
| 335 | + */ |
|
| 336 | + public function navDropdown($title,$options=[], \Closure $c) |
|
| 337 | + { |
|
| 338 | + $classes = $this->buildClassString('has-dropdown', $options, true); |
|
| 339 | 339 | |
| 340 | - $id = $this->buildIdFromOptions($options); |
|
| 340 | + $id = $this->buildIdFromOptions($options); |
|
| 341 | 341 | |
| 342 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 342 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 343 | 343 | |
| 344 | - $output = "\t<li {$classes} {$id} {$attributes}> |
|
| 344 | + $output = "\t<li {$classes} {$id} {$attributes}> |
|
| 345 | 345 | <a href='#'>{$title}</a> |
| 346 | 346 | <ul class='dropdown'>"; |
| 347 | 347 | |
| 348 | - $output .= $this->runClosure($c); |
|
| 348 | + $output .= $this->runClosure($c); |
|
| 349 | 349 | |
| 350 | - $output .= "\t</ul></li>"; |
|
| 350 | + $output .= "\t</ul></li>"; |
|
| 351 | 351 | |
| 352 | - return $output; |
|
| 353 | - } |
|
| 352 | + return $output; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - //-------------------------------------------------------------------- |
|
| 355 | + //-------------------------------------------------------------------- |
|
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * Creates a divider for use within a nav list. |
|
| 359 | - * |
|
| 360 | - * @return string |
|
| 361 | - */ |
|
| 362 | - public function navDivider() |
|
| 363 | - { |
|
| 364 | - return '<li class="divider"></li>'; |
|
| 365 | - } |
|
| 357 | + /** |
|
| 358 | + * Creates a divider for use within a nav list. |
|
| 359 | + * |
|
| 360 | + * @return string |
|
| 361 | + */ |
|
| 362 | + public function navDivider() |
|
| 363 | + { |
|
| 364 | + return '<li class="divider"></li>'; |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - //-------------------------------------------------------------------- |
|
| 367 | + //-------------------------------------------------------------------- |
|
| 368 | 368 | |
| 369 | - public function sideNav($options=[], \Closure $c) |
|
| 370 | - { |
|
| 371 | - $classes = $this->buildClassString('side-nav', $options, true); |
|
| 369 | + public function sideNav($options=[], \Closure $c) |
|
| 370 | + { |
|
| 371 | + $classes = $this->buildClassString('side-nav', $options, true); |
|
| 372 | 372 | |
| 373 | - $id = $this->buildIdFromOptions($options); |
|
| 373 | + $id = $this->buildIdFromOptions($options); |
|
| 374 | 374 | |
| 375 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 375 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 376 | 376 | |
| 377 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 378 | - |
|
| 379 | - $output .= $this->runClosure($c); |
|
| 380 | - |
|
| 381 | - $output .= "</ul>\n"; |
|
| 382 | - |
|
| 383 | - return $output; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - //-------------------------------------------------------------------- |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 390 | - * |
|
| 391 | - * @param array $options |
|
| 392 | - * @param callable $c |
|
| 393 | - * @return mixed |
|
| 394 | - */ |
|
| 395 | - public function breadcrumb($options=[], \Closure $c) |
|
| 396 | - { |
|
| 397 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumbs', true); |
|
| 398 | - |
|
| 399 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 400 | - |
|
| 401 | - $output .= $this->runClosure($c); |
|
| 402 | - |
|
| 403 | - $output .= "</ul>\n"; |
|
| 404 | - |
|
| 405 | - return $output; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - //-------------------------------------------------------------------- |
|
| 409 | - |
|
| 410 | - //-------------------------------------------------------------------- |
|
| 411 | - // Tables |
|
| 412 | - //-------------------------------------------------------------------- |
|
| 413 | - |
|
| 414 | - public function table() |
|
| 415 | - { |
|
| 416 | - return 'table'; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - //-------------------------------------------------------------------- |
|
| 420 | - |
|
| 421 | - //-------------------------------------------------------------------- |
|
| 422 | - // Buttons |
|
| 423 | - //-------------------------------------------------------------------- |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Creates a simple button. |
|
| 427 | - * |
|
| 428 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 429 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 430 | - * |
|
| 431 | - * @param $title |
|
| 432 | - * @param string $style |
|
| 433 | - * @param array $options |
|
| 434 | - * @return mixed |
|
| 435 | - */ |
|
| 436 | - public function button($title, $style='default', $size='default', $options=[]) |
|
| 437 | - { |
|
| 438 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 439 | - |
|
| 440 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - //-------------------------------------------------------------------- |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Creates a simple link styled as a button. |
|
| 447 | - * |
|
| 448 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 449 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 450 | - * |
|
| 451 | - * @param $title |
|
| 452 | - * @param string $url |
|
| 453 | - * @param string $style |
|
| 454 | - * @param array $options |
|
| 455 | - * @return mixed |
|
| 456 | - */ |
|
| 457 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 458 | - { |
|
| 459 | - $class = isset($options['class']) ? $options['class'] .' button' : 'button'; |
|
| 460 | - $options['class'] = $class; |
|
| 461 | - |
|
| 462 | - $tag = "<a {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
| 463 | - |
|
| 464 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - //-------------------------------------------------------------------- |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Helper method to render out our buttons in a DRY manner. |
|
| 471 | - * |
|
| 472 | - * @param $title |
|
| 473 | - * @param $style |
|
| 474 | - * @param $size |
|
| 475 | - * @param $tag |
|
| 476 | - */ |
|
| 477 | - protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
| 478 | - { |
|
| 479 | - $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
| 480 | - $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
| 481 | - |
|
| 482 | - if (! in_array($style, $valid_styles)) |
|
| 483 | - { |
|
| 484 | - $style = 'default'; |
|
| 485 | - $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - $classes = 'btn '; |
|
| 489 | - |
|
| 490 | - // Sizes |
|
| 491 | - switch($size) |
|
| 492 | - { |
|
| 493 | - case 'small': |
|
| 494 | - $classes .= 'small '; |
|
| 495 | - break; |
|
| 496 | - case 'xsmall': |
|
| 497 | - $classes .= 'tiny '; |
|
| 498 | - break; |
|
| 499 | - case 'large': |
|
| 500 | - $classes .= 'large '; |
|
| 501 | - break; |
|
| 502 | - default: |
|
| 503 | - break; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - // Styles |
|
| 507 | - switch ($style) |
|
| 508 | - { |
|
| 509 | - case 'primary': |
|
| 510 | - $classes .= ''; |
|
| 511 | - break; |
|
| 512 | - case 'success': |
|
| 513 | - $classes .= 'success '; |
|
| 514 | - break; |
|
| 515 | - case 'info': |
|
| 516 | - $classes .= 'secondary '; |
|
| 517 | - break; |
|
| 518 | - case 'warning': |
|
| 519 | - $classes .= 'alert '; |
|
| 520 | - break; |
|
| 521 | - case 'danger': |
|
| 522 | - $classes .= 'alert '; |
|
| 523 | - break; |
|
| 524 | - case 'default': |
|
| 525 | - $classes .= 'secondary '; |
|
| 526 | - break; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 530 | - |
|
| 531 | - $tag = str_replace('{classes}', $classes, $tag); |
|
| 532 | - $tag = str_replace('{id}', $id, $tag); |
|
| 533 | - $tag = str_replace('{attributes}', $attributes, $tag); |
|
| 534 | - $tag = str_replace('{title}', $title, $tag); |
|
| 535 | - |
|
| 536 | - // If we're in a button group we need to wrap each item in li tags. |
|
| 537 | - if (isset($this->states['inButtonGroup'])) |
|
| 538 | - { |
|
| 539 | - $tag = '<li>'. $tag .'</li>'; |
|
| 540 | - } |
|
| 541 | - return $tag; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - //-------------------------------------------------------------------- |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Creates button groups wrapping HTML. |
|
| 548 | - * |
|
| 549 | - * @param $options |
|
| 550 | - * @param callable $c |
|
| 551 | - * @return mixed |
|
| 552 | - */ |
|
| 553 | - public function buttonGroup($options, \Closure $c) |
|
| 554 | - { |
|
| 555 | - $this->states['inButtonGroup'] = true; |
|
| 556 | - |
|
| 557 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-group', true); |
|
| 558 | - |
|
| 559 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 560 | - |
|
| 561 | - $output .= $this->runClosure($c); |
|
| 562 | - |
|
| 563 | - $output .= "</ul>\n"; |
|
| 564 | - |
|
| 565 | - unset($this->states['inButtonGroup']); |
|
| 566 | - |
|
| 567 | - return $output; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - //-------------------------------------------------------------------- |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Creates the button bar wrapping HTML. |
|
| 574 | - * |
|
| 575 | - * @param $options |
|
| 576 | - * @param callable $c |
|
| 577 | - * @return mixed |
|
| 578 | - */ |
|
| 579 | - public function buttonBar($options, \Closure $c) |
|
| 580 | - { |
|
| 581 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-bar', true); |
|
| 582 | - |
|
| 583 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 584 | - |
|
| 585 | - $output .= $this->runClosure($c); |
|
| 586 | - |
|
| 587 | - $output .= "</div>\n"; |
|
| 588 | - |
|
| 589 | - return $output; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - //-------------------------------------------------------------------- |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 596 | - * by some frameworks. |
|
| 597 | - * |
|
| 598 | - * @param $title |
|
| 599 | - * @param string $style |
|
| 600 | - * @param string $size |
|
| 601 | - * @param array $options |
|
| 602 | - * @param callable $c |
|
| 603 | - * @return mixed |
|
| 604 | - */ |
|
| 605 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 606 | - { |
|
| 607 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button split', true); |
|
| 608 | - |
|
| 609 | - $output = "<a href='#' {$classes} {$id} {$attributes}>{$title} <span data-dropdown='drop'></span></a><br>\n |
|
| 377 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 378 | + |
|
| 379 | + $output .= $this->runClosure($c); |
|
| 380 | + |
|
| 381 | + $output .= "</ul>\n"; |
|
| 382 | + |
|
| 383 | + return $output; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + //-------------------------------------------------------------------- |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 390 | + * |
|
| 391 | + * @param array $options |
|
| 392 | + * @param callable $c |
|
| 393 | + * @return mixed |
|
| 394 | + */ |
|
| 395 | + public function breadcrumb($options=[], \Closure $c) |
|
| 396 | + { |
|
| 397 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumbs', true); |
|
| 398 | + |
|
| 399 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 400 | + |
|
| 401 | + $output .= $this->runClosure($c); |
|
| 402 | + |
|
| 403 | + $output .= "</ul>\n"; |
|
| 404 | + |
|
| 405 | + return $output; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + //-------------------------------------------------------------------- |
|
| 409 | + |
|
| 410 | + //-------------------------------------------------------------------- |
|
| 411 | + // Tables |
|
| 412 | + //-------------------------------------------------------------------- |
|
| 413 | + |
|
| 414 | + public function table() |
|
| 415 | + { |
|
| 416 | + return 'table'; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + //-------------------------------------------------------------------- |
|
| 420 | + |
|
| 421 | + //-------------------------------------------------------------------- |
|
| 422 | + // Buttons |
|
| 423 | + //-------------------------------------------------------------------- |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Creates a simple button. |
|
| 427 | + * |
|
| 428 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 429 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 430 | + * |
|
| 431 | + * @param $title |
|
| 432 | + * @param string $style |
|
| 433 | + * @param array $options |
|
| 434 | + * @return mixed |
|
| 435 | + */ |
|
| 436 | + public function button($title, $style='default', $size='default', $options=[]) |
|
| 437 | + { |
|
| 438 | + $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 439 | + |
|
| 440 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + //-------------------------------------------------------------------- |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Creates a simple link styled as a button. |
|
| 447 | + * |
|
| 448 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 449 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 450 | + * |
|
| 451 | + * @param $title |
|
| 452 | + * @param string $url |
|
| 453 | + * @param string $style |
|
| 454 | + * @param array $options |
|
| 455 | + * @return mixed |
|
| 456 | + */ |
|
| 457 | + public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 458 | + { |
|
| 459 | + $class = isset($options['class']) ? $options['class'] .' button' : 'button'; |
|
| 460 | + $options['class'] = $class; |
|
| 461 | + |
|
| 462 | + $tag = "<a {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
| 463 | + |
|
| 464 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + //-------------------------------------------------------------------- |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Helper method to render out our buttons in a DRY manner. |
|
| 471 | + * |
|
| 472 | + * @param $title |
|
| 473 | + * @param $style |
|
| 474 | + * @param $size |
|
| 475 | + * @param $tag |
|
| 476 | + */ |
|
| 477 | + protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
| 478 | + { |
|
| 479 | + $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
| 480 | + $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
| 481 | + |
|
| 482 | + if (! in_array($style, $valid_styles)) |
|
| 483 | + { |
|
| 484 | + $style = 'default'; |
|
| 485 | + $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + $classes = 'btn '; |
|
| 489 | + |
|
| 490 | + // Sizes |
|
| 491 | + switch($size) |
|
| 492 | + { |
|
| 493 | + case 'small': |
|
| 494 | + $classes .= 'small '; |
|
| 495 | + break; |
|
| 496 | + case 'xsmall': |
|
| 497 | + $classes .= 'tiny '; |
|
| 498 | + break; |
|
| 499 | + case 'large': |
|
| 500 | + $classes .= 'large '; |
|
| 501 | + break; |
|
| 502 | + default: |
|
| 503 | + break; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + // Styles |
|
| 507 | + switch ($style) |
|
| 508 | + { |
|
| 509 | + case 'primary': |
|
| 510 | + $classes .= ''; |
|
| 511 | + break; |
|
| 512 | + case 'success': |
|
| 513 | + $classes .= 'success '; |
|
| 514 | + break; |
|
| 515 | + case 'info': |
|
| 516 | + $classes .= 'secondary '; |
|
| 517 | + break; |
|
| 518 | + case 'warning': |
|
| 519 | + $classes .= 'alert '; |
|
| 520 | + break; |
|
| 521 | + case 'danger': |
|
| 522 | + $classes .= 'alert '; |
|
| 523 | + break; |
|
| 524 | + case 'default': |
|
| 525 | + $classes .= 'secondary '; |
|
| 526 | + break; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 530 | + |
|
| 531 | + $tag = str_replace('{classes}', $classes, $tag); |
|
| 532 | + $tag = str_replace('{id}', $id, $tag); |
|
| 533 | + $tag = str_replace('{attributes}', $attributes, $tag); |
|
| 534 | + $tag = str_replace('{title}', $title, $tag); |
|
| 535 | + |
|
| 536 | + // If we're in a button group we need to wrap each item in li tags. |
|
| 537 | + if (isset($this->states['inButtonGroup'])) |
|
| 538 | + { |
|
| 539 | + $tag = '<li>'. $tag .'</li>'; |
|
| 540 | + } |
|
| 541 | + return $tag; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + //-------------------------------------------------------------------- |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Creates button groups wrapping HTML. |
|
| 548 | + * |
|
| 549 | + * @param $options |
|
| 550 | + * @param callable $c |
|
| 551 | + * @return mixed |
|
| 552 | + */ |
|
| 553 | + public function buttonGroup($options, \Closure $c) |
|
| 554 | + { |
|
| 555 | + $this->states['inButtonGroup'] = true; |
|
| 556 | + |
|
| 557 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-group', true); |
|
| 558 | + |
|
| 559 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 560 | + |
|
| 561 | + $output .= $this->runClosure($c); |
|
| 562 | + |
|
| 563 | + $output .= "</ul>\n"; |
|
| 564 | + |
|
| 565 | + unset($this->states['inButtonGroup']); |
|
| 566 | + |
|
| 567 | + return $output; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + //-------------------------------------------------------------------- |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Creates the button bar wrapping HTML. |
|
| 574 | + * |
|
| 575 | + * @param $options |
|
| 576 | + * @param callable $c |
|
| 577 | + * @return mixed |
|
| 578 | + */ |
|
| 579 | + public function buttonBar($options, \Closure $c) |
|
| 580 | + { |
|
| 581 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-bar', true); |
|
| 582 | + |
|
| 583 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 584 | + |
|
| 585 | + $output .= $this->runClosure($c); |
|
| 586 | + |
|
| 587 | + $output .= "</div>\n"; |
|
| 588 | + |
|
| 589 | + return $output; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + //-------------------------------------------------------------------- |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 596 | + * by some frameworks. |
|
| 597 | + * |
|
| 598 | + * @param $title |
|
| 599 | + * @param string $style |
|
| 600 | + * @param string $size |
|
| 601 | + * @param array $options |
|
| 602 | + * @param callable $c |
|
| 603 | + * @return mixed |
|
| 604 | + */ |
|
| 605 | + public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 606 | + { |
|
| 607 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button split', true); |
|
| 608 | + |
|
| 609 | + $output = "<a href='#' {$classes} {$id} {$attributes}>{$title} <span data-dropdown='drop'></span></a><br>\n |
|
| 610 | 610 | <ul id='drop' class='f-dropdown' data-dropdown-content>\n"; |
| 611 | 611 | |
| 612 | - $output .= $this->runClosure($c); |
|
| 613 | - |
|
| 614 | - $output .= "</ul>\n"; |
|
| 615 | - |
|
| 616 | - return $output; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - //-------------------------------------------------------------------- |
|
| 620 | - |
|
| 621 | - //-------------------------------------------------------------------- |
|
| 622 | - // Notices |
|
| 623 | - //-------------------------------------------------------------------- |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * Creates an 'alert-box' style of notice grid. |
|
| 627 | - * |
|
| 628 | - * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
| 629 | - * |
|
| 630 | - * @param $content |
|
| 631 | - * @param string $style |
|
| 632 | - * @param bool $closable |
|
| 633 | - * @return mixed |
|
| 634 | - */ |
|
| 635 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 636 | - { |
|
| 637 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert-box ', false); |
|
| 638 | - |
|
| 639 | - // Styles |
|
| 640 | - switch ($style) |
|
| 641 | - { |
|
| 642 | - case 'success': |
|
| 643 | - $classes .= ' success '; |
|
| 644 | - break; |
|
| 645 | - case 'info': |
|
| 646 | - $classes .= ' secondary '; |
|
| 647 | - break; |
|
| 648 | - case 'warning': |
|
| 649 | - $classes .= ' alert '; |
|
| 650 | - break; |
|
| 651 | - case 'danger': |
|
| 652 | - $classes .= ' alert '; |
|
| 653 | - break; |
|
| 654 | - case 'default': |
|
| 655 | - $classes .= ' secondary '; |
|
| 656 | - break; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - $output = "<div data-alert class='{$classes}'>\n"; |
|
| 660 | - |
|
| 661 | - $output .= "\t$content\n"; |
|
| 662 | - |
|
| 663 | - if ($closable) |
|
| 664 | - { |
|
| 665 | - $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - $output .= "</div>\n"; |
|
| 669 | - |
|
| 670 | - return $output; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - //-------------------------------------------------------------------- |
|
| 612 | + $output .= $this->runClosure($c); |
|
| 613 | + |
|
| 614 | + $output .= "</ul>\n"; |
|
| 615 | + |
|
| 616 | + return $output; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + //-------------------------------------------------------------------- |
|
| 620 | + |
|
| 621 | + //-------------------------------------------------------------------- |
|
| 622 | + // Notices |
|
| 623 | + //-------------------------------------------------------------------- |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * Creates an 'alert-box' style of notice grid. |
|
| 627 | + * |
|
| 628 | + * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
| 629 | + * |
|
| 630 | + * @param $content |
|
| 631 | + * @param string $style |
|
| 632 | + * @param bool $closable |
|
| 633 | + * @return mixed |
|
| 634 | + */ |
|
| 635 | + public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 636 | + { |
|
| 637 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert-box ', false); |
|
| 638 | + |
|
| 639 | + // Styles |
|
| 640 | + switch ($style) |
|
| 641 | + { |
|
| 642 | + case 'success': |
|
| 643 | + $classes .= ' success '; |
|
| 644 | + break; |
|
| 645 | + case 'info': |
|
| 646 | + $classes .= ' secondary '; |
|
| 647 | + break; |
|
| 648 | + case 'warning': |
|
| 649 | + $classes .= ' alert '; |
|
| 650 | + break; |
|
| 651 | + case 'danger': |
|
| 652 | + $classes .= ' alert '; |
|
| 653 | + break; |
|
| 654 | + case 'default': |
|
| 655 | + $classes .= ' secondary '; |
|
| 656 | + break; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + $output = "<div data-alert class='{$classes}'>\n"; |
|
| 660 | + |
|
| 661 | + $output .= "\t$content\n"; |
|
| 662 | + |
|
| 663 | + if ($closable) |
|
| 664 | + { |
|
| 665 | + $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + $output .= "</div>\n"; |
|
| 669 | + |
|
| 670 | + return $output; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + //-------------------------------------------------------------------- |
|
| 674 | 674 | |
| 675 | 675 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param array $options |
| 59 | 59 | * @return mixed |
| 60 | 60 | */ |
| 61 | - public function row($options=[], \Closure $c) |
|
| 61 | + public function row($options = [], \Closure $c) |
|
| 62 | 62 | { |
| 63 | 63 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
| 64 | 64 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param array $attributes |
| 91 | 91 | * @return mixed |
| 92 | 92 | */ |
| 93 | - public function column($options=[], \Closure $c) |
|
| 93 | + public function column($options = [], \Closure $c) |
|
| 94 | 94 | { |
| 95 | 95 | // Build our classes |
| 96 | 96 | $classes = ''; |
@@ -100,33 +100,33 @@ discard block |
||
| 100 | 100 | switch ($size) |
| 101 | 101 | { |
| 102 | 102 | case 's': |
| 103 | - $classes .= ' small-'. $value; |
|
| 103 | + $classes .= ' small-'.$value; |
|
| 104 | 104 | break; |
| 105 | 105 | case 'm': |
| 106 | - $classes .= ' medium-'. $value; |
|
| 106 | + $classes .= ' medium-'.$value; |
|
| 107 | 107 | break; |
| 108 | 108 | case 'l': |
| 109 | - $classes .= ' large-'. $value; |
|
| 109 | + $classes .= ' large-'.$value; |
|
| 110 | 110 | break; |
| 111 | 111 | case 'xl': |
| 112 | - $classes .= ' large-'. $value; |
|
| 112 | + $classes .= ' large-'.$value; |
|
| 113 | 113 | break; |
| 114 | 114 | case 's-offset': |
| 115 | - $classes .= ' small-offset-'. $value; |
|
| 115 | + $classes .= ' small-offset-'.$value; |
|
| 116 | 116 | break; |
| 117 | 117 | case 'm-offset': |
| 118 | - $classes .= ' medium-offset-'. $value; |
|
| 118 | + $classes .= ' medium-offset-'.$value; |
|
| 119 | 119 | break; |
| 120 | 120 | case 'l-offset': |
| 121 | - $classes .= ' large-offset-'. $value; |
|
| 121 | + $classes .= ' large-offset-'.$value; |
|
| 122 | 122 | break; |
| 123 | 123 | case 'xl-offset': |
| 124 | - $classes .= ' large-offset-'. $value; |
|
| 124 | + $classes .= ' large-offset-'.$value; |
|
| 125 | 125 | break; |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $classes = $this->buildClassString($classes .' columns', $options, true); |
|
| 129 | + $classes = $this->buildClassString($classes.' columns', $options, true); |
|
| 130 | 130 | |
| 131 | 131 | $id = $this->buildIdFromOptions($options); |
| 132 | 132 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param callable $c |
| 156 | 156 | * @return string |
| 157 | 157 | */ |
| 158 | - public function navbar($options=[], \Closure $c) |
|
| 158 | + public function navbar($options = [], \Closure $c) |
|
| 159 | 159 | { |
| 160 | 160 | $output = ''; |
| 161 | 161 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @param string $url |
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | - public function navbarTitle($title, $url='#') |
|
| 208 | + public function navbarTitle($title, $url = '#') |
|
| 209 | 209 | { |
| 210 | 210 | return "<ul class='title-area'> |
| 211 | 211 | <li class='name'> |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | * @param callable $c |
| 228 | 228 | * @return string |
| 229 | 229 | */ |
| 230 | - public function navbarRight($options=[], \Closure $c) |
|
| 230 | + public function navbarRight($options = [], \Closure $c) |
|
| 231 | 231 | { |
| 232 | 232 | $output = ''; |
| 233 | 233 | |
| 234 | - if (! isset($this->states['nav-section-open'])) |
|
| 234 | + if ( ! isset($this->states['nav-section-open'])) |
|
| 235 | 235 | { |
| 236 | 236 | $output .= "<section class='top-bar-section'>\n"; |
| 237 | 237 | $this->states['nav-section-open'] = true; |
@@ -266,11 +266,11 @@ discard block |
||
| 266 | 266 | * @param callable $c |
| 267 | 267 | * @return string |
| 268 | 268 | */ |
| 269 | - public function navbarLeft($options=[], \Closure $c) |
|
| 269 | + public function navbarLeft($options = [], \Closure $c) |
|
| 270 | 270 | { |
| 271 | 271 | $output = ''; |
| 272 | 272 | |
| 273 | - if (! isset($this->states['nav-section-open'])) |
|
| 273 | + if ( ! isset($this->states['nav-section-open'])) |
|
| 274 | 274 | { |
| 275 | 275 | $output .= "<section class='top-bar-section'>\n"; |
| 276 | 276 | $this->states['nav-section-open'] = true; |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @param array $options |
| 312 | 312 | * @return string |
| 313 | 313 | */ |
| 314 | - public function navItem($title, $url='#', $options=[], $active=false) |
|
| 314 | + public function navItem($title, $url = '#', $options = [], $active = false) |
|
| 315 | 315 | { |
| 316 | 316 | $options['active'] = $active; |
| 317 | 317 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * @param array $options |
| 334 | 334 | * @param callable $c |
| 335 | 335 | */ |
| 336 | - public function navDropdown($title,$options=[], \Closure $c) |
|
| 336 | + public function navDropdown($title, $options = [], \Closure $c) |
|
| 337 | 337 | { |
| 338 | 338 | $classes = $this->buildClassString('has-dropdown', $options, true); |
| 339 | 339 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | //-------------------------------------------------------------------- |
| 368 | 368 | |
| 369 | - public function sideNav($options=[], \Closure $c) |
|
| 369 | + public function sideNav($options = [], \Closure $c) |
|
| 370 | 370 | { |
| 371 | 371 | $classes = $this->buildClassString('side-nav', $options, true); |
| 372 | 372 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * @param callable $c |
| 393 | 393 | * @return mixed |
| 394 | 394 | */ |
| 395 | - public function breadcrumb($options=[], \Closure $c) |
|
| 395 | + public function breadcrumb($options = [], \Closure $c) |
|
| 396 | 396 | { |
| 397 | 397 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumbs', true); |
| 398 | 398 | |
@@ -433,9 +433,9 @@ discard block |
||
| 433 | 433 | * @param array $options |
| 434 | 434 | * @return mixed |
| 435 | 435 | */ |
| 436 | - public function button($title, $style='default', $size='default', $options=[]) |
|
| 436 | + public function button($title, $style = 'default', $size = 'default', $options = []) |
|
| 437 | 437 | { |
| 438 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 438 | + $tag = "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 439 | 439 | |
| 440 | 440 | return $this->renderButtonElement($title, $style, $size, $options, $tag); |
| 441 | 441 | } |
@@ -454,9 +454,9 @@ discard block |
||
| 454 | 454 | * @param array $options |
| 455 | 455 | * @return mixed |
| 456 | 456 | */ |
| 457 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 457 | + public function buttonLink($title, $url = '#', $style = 'default', $size = 'default', $options = []) |
|
| 458 | 458 | { |
| 459 | - $class = isset($options['class']) ? $options['class'] .' button' : 'button'; |
|
| 459 | + $class = isset($options['class']) ? $options['class'].' button' : 'button'; |
|
| 460 | 460 | $options['class'] = $class; |
| 461 | 461 | |
| 462 | 462 | $tag = "<a {classes} {id} {attributes} role='button'>{$title}</a>"; |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
| 480 | 480 | $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
| 481 | 481 | |
| 482 | - if (! in_array($style, $valid_styles)) |
|
| 482 | + if ( ! in_array($style, $valid_styles)) |
|
| 483 | 483 | { |
| 484 | 484 | $style = 'default'; |
| 485 | 485 | $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | $classes = 'btn '; |
| 489 | 489 | |
| 490 | 490 | // Sizes |
| 491 | - switch($size) |
|
| 491 | + switch ($size) |
|
| 492 | 492 | { |
| 493 | 493 | case 'small': |
| 494 | 494 | $classes .= 'small '; |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | // If we're in a button group we need to wrap each item in li tags. |
| 537 | 537 | if (isset($this->states['inButtonGroup'])) |
| 538 | 538 | { |
| 539 | - $tag = '<li>'. $tag .'</li>'; |
|
| 539 | + $tag = '<li>'.$tag.'</li>'; |
|
| 540 | 540 | } |
| 541 | 541 | return $tag; |
| 542 | 542 | } |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @param callable $c |
| 603 | 603 | * @return mixed |
| 604 | 604 | */ |
| 605 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 605 | + public function buttonDropdown($title, $style = 'default', $size = 'default', $options = [], \Closure $c) |
|
| 606 | 606 | { |
| 607 | 607 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button split', true); |
| 608 | 608 | |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | * @param bool $closable |
| 633 | 633 | * @return mixed |
| 634 | 634 | */ |
| 635 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 635 | + public function notice($content, $style = 'success', $closable = true, $options = []) |
|
| 636 | 636 | { |
| 637 | 637 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert-box ', false); |
| 638 | 638 | |