Jump to content

Xtremer360

Members
  • Posts

    1,444
  • Joined

  • Last visited

Posts posted by Xtremer360

  1. Trying to figure out why I’m getting the following error in my code.

    Fatal error: Cannot use object of type stdClass as array in /home/xtremer/sites/dev.justmyfiles.me/public_html/application/models/dashboard_model.php on line 21

     

    public function get_menu()
    {
            $this->db->select('*');
            $this->db->from('dashboard_menu_categories');
            $query = $this->db->get();
            $dashboard_menu_categories = $query->result();
    
            foreach($dashboard_menu_categories as $category) {
                $links = $this->db->get_where('dashboard_menu_categories_items', array('category_id' => $category->category_id));
                if ($links->num_rows > 0) {
                    $category['links'] = $links->result();
                }
            }
            return $dashboard_menu_categories;
    }
    

     

  2. I'm trying to take my php output and using the HTML nav structure that is currently there turn it into dynamically generated menu using my result set. Any help on helping me figure out how to correct this.

     

    Here's my output.

    array(3) {
        [0]=> object(stdClass)#24 (3) {
            ["category_id"]=> string(1) "1"
            ["category_name"]=> string(9) "Dashboard"
            ["category_class"]=> string(9) "dashboard"
        }
        [1]=> object(stdClass)#24 (3) {
            ["category_id"]=> string(1) "2"
            ["category_name"]=> string(5) "Users"
            ["category_class"]=> string(5) "users"
        }
        [2]=> object(stdClass)#24 (3) {
            ["category_id"]=> string(1) "3"
            ["category_name"]=> string(5) "Pages"
            ["category_class"]=> string(5) "pages"
            ["links"]=> array(2) {
                [0]=> object(stdClass)#24 (2) {
                    ["item_id"]=> string(1) "1"
                    ["item_name"]=> string(5) "Admin Pages"
                [1]=> object(stdClass)#24 (2) {
                    ["item_id"]=> string(1) "2"
                    ["item_name"]=> string(5) "User Pages"
                }
            }
        }
    }
    

    I'm wanting to take my php output and using the HTML code below make a dynamic navigation.

    <li class="active"><a href="" class="glyphicons dashboard"><i></i><span>Dashboard</span></a></li>
    <li class="hasSubmenu">
        <a href="#menu_character" data-toggle="collapse" class="glyphicons page"><i></i><span>Pages</span><span class="icon-chevron-down"></span></a>
        <ul class="collapse" id="menu_character">
            <!-- Components Submenu Regular Items -->
            <li class=""><a href="">Item 1</a></li>
            <li class=""><a href="">Item 2</a></li>
            <!-- // Components Submenu Regular Items END -->
        </ul>
    </li>
    

    This is what I have so far.

    <?php 
    foreach ($dashboard_menu_categories AS $category)
    {
        echo '<li>';
         if (isset($category->links))
         {
             echo '<ul class="collapse" id="menu_'.$category->category_short_name.'">';
             /* Components Submenu Regular Items */
             foreach($category->links AS $item)
             {
                 echo '<li class=""><a href="">'.$item->item_name.'</a></li>';
             }
             /* Components Submenu Regular Items END */
             echo '</ul>';
        }
        echo '<a href="" class="glyphicons '.$category->category_class.'"><i></i><span>'.$category->category_name.'</span></a>';
        echo '</li>';
    }
    ?>
    
  3. Every time I try and submit my login form it takes past 25 seconds to submit and still never does I just stop it passed that. I'm wondering if there's something I'm missing somewhere. I'm wondering if its something like some returns somewhere or something. Any ideas?

     

    UNFLATTENED

     

    public function form_is_valid()
    {
    /* Set validation rules for post data */
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    $this->form_validation->set_rules('remember', 'Remember Me', 'trim|xss_clean|integer');
    
    /* Form validation passed */
    return $this->form_validation->run();
    }
    
    public function is_user_locked($user_data)
    {
    if ($user_data->lock_date !== '0000-00-00 00:00:00')
    {
    /* User is locked out */
    
    if (strtotime(gmdate('Y-m-d H:i:s', time())) < strtotime($user_data->lock_date))
    {
    /* User is still locked out */
    return TRUE;
    }
    else
    {
    /* User is no longer locked out */
    return FALSE;
    }
    
    }
    }
    
    public function check_user_status($user_data)
    {
    /* Match user status */
    switch ($user_data->user_status_id)
    {
    case 1:
    $this->output('Sorry you must verify your account before logging in!', 'Account Unverified', 'Error');
    break;
    case 3:
    $this->output('Your account has been suspended!', 'Account Suspended', 'Error');
    break;
    case 4:
    $this->output('Your account has been suspended!', 'Account Banned', 'Error');
    break;
    case 5:
    $this->output('Your account has been deleted!', 'Account Deleted', 'Error');
    break;
    default:
    return;
    }
    }
    
    public function output($message, $title, $status = 'Success')
    {
    switch ($status)
    {
    case 'Error':
    array('status' => 'Error');
    break;
    case 'Notice':
    array('status' => 'Notice');
    break;
    case 'Success':
    array('status' => 'Success');
    break;
    }
    echo json_encode($status, $title, $message);
    }
    
    public function start_user_session()
    {
    /* Start session with user id and clear previous failed login attempts */
    $this->session->set_userdata('uid', $user_data->user_id);
    $this->session->unset_userdata('failed_logins');
    $this->users_model->insert_session($user_data->user_id, gmdate('Y-m-d H:i:s', time()));
    return;
    }
    
    public function submit($post_username = NULL, $post_password = NULL)
    {
    if (!$this->form_is_valid())
    {
    echo 'test';
    die();
    $this->output('The form did not validate successfully!', 'Form Not Validated', 'Error');
    }
    
    /* Post values from login form */
    $post_username = $this->input->post('username');
    $post_password = $this->input->post('password');
    
    /* Test to see value of posted login form */
    //echo '<pre>';
    //var_dump($post_username);
    //var_dump($post_password);
    //echo '</pre>';
    //die();
    
    /* Get user data from post username value */
    $user_data = $this->users_model->get_by('username', $post_username);
    
    /* Test to see value of $user_data */
    //echo '<pre>';
    //var_dump($user_data);
    //echo '</pre>';
    //die();
    
    if (count($user_data) == 0)
    {
    /* User was not found in database */
    $this->output('The user was not found in the database!', 'User Not Found', 'Error');
    }
    
    /* User was found in database */
    
    if ($this->is_user_locked($user_data->lock_date))
    {
    /* User is locked from logging in from too many failed attempts */
    $this->output('This user account is currently locked!', 'Account Locked', 'Error');
    }
    else
    {
    /* User can be unlocked and form be resubmitted */
    $this->users_model->unlock_user($user_data->user_id);
    $this->submit($post_username, $post_password);
    return FALSE;
    }
    
    /* User is unlocked from logging in */
    
    if ($user_data->user_status_id != 2)
    {
    /* User has a status that is not allowed to proceed */
    $this->user_status_message($user_data->user_status_id);
    }
    
    /* User is registered and validated */
    
    $regenerated_post_password = $this->genfunc->reGenPassHash($post_password, $user_data->password_hash);
    
    $failed_logins = $this->session->userdata('failed_logins');
    
    if ($regenerated_post_password !== $user_data->password)
    {
    /* Password from login from does not match user stored password */
    
    if ($failed_logins == 0)
    {
    /* First time user has not entered username and password successfully */
    $this->session->set_userdata('failed_logins', 1);
    $this->users_model->increase_login_attempt($this->input->ip_address(), $post_username, gmdate('Y-m-d H:i:s', time()));
    $this->output('Incorrect username and password credentials!', 'Incorrect Login Credentials', 'Error');
    }
    
    /* User has atleast one failed login attempt for the current session */
    
    if ($failed_logins !== 4)
    {
    /* User has a few more chances to get password right */
    $failed_logins++;
    $this->session->set_userdata('failed_logins', $failed_logins);
    $this->users_model->increase_login_attempt($this->input->ip_address(), $post_username, gmdate('Y-m-d H:i:s', time()));
    $this->output('Incorrect username and password credentials!', 'Incorrect Login Credentials', 'Error');
    }
    
    $this->users_model->lock_out_user($user_data->user_id, gmdate('Y-m-d H:i:s', time()+(60*15)));
    //$this->functions_model->send_email('maximum_failed_login_attempts_exceeded', $user_data->email_address, $user_data)
    $this->output('Your account is currently locked, we apologize for the inconvienence. You must wait 15 minutes before you can log in again! An email was sent to the owner of this account! Forgotten your username or password? <a href="forgotusername">Forgot Username</a> or <a href="forgotpassword">Forgot Password</a>', 'Account Locked', 'Error');
    
    }
    
    /* Password from login form matches user stored password and user may login */
    
    $this->output('Successful login! Sending you to the dashboard!', 'Login Sucessful', 'Success');
    }
    


     

    UPDATE: This was the original submit function that completely works however the reason for my post was because I was having problems with how I was trying to flatten it.
     

    FLATTENED

    public function submit($post_username = NULL, $post_password = NULL)
    {
    /* Set variable defaults */
    $output_status = 'Notice';
    $output_title = 'Not Processed';
    $output_message = 'The request was unprocessed!';
    
    /* Number of error flags */
    $flags = 0;
    
    /* Set validation rules for post data */
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    $this->form_validation->set_rules('remember', 'Remember Me', 'trim|xss_clean|integer');
    
    if ($this->form_validation->run() == TRUE)
    {
    /* Form validation passed */
    
    /* Post values from login form */
    $post_username = $this->input->post('username');
    $post_password = $this->input->post('password');
    
    /* Test to see value of posted login form */
    //echo '<pre>';
    //var_dump($post_username);
    //var_dump($post_password);
    //echo '</pre>';
    //die();
    
    /* Get user data from post username value */
    $user_data = $this->users_model->get_by('username', $post_username);
    
     
    /* Test to see value of $user_data */
    //echo '<pre>';
    //var_dump($user_data);
    //echo '</pre>';
    //die();
    
    if (count($user_data) > 0)
    {
    /* User was found in database */
    
    if ($user_data->lock_date !== '0000-00-00 00:00:00')
    {
    /* User is locked out */
    
    if (strtotime(gmdate('Y-m-d H:i:s', time())) < strtotime($user_data->lock_date))
    {
    /* User is still locked out */
    $output_status = 'Error';
    $output_title = 'Account Locked';
    $output_message = 'This user account is currently locked!';
    $flags++;
    }
    else
    {
    /* User can be unlocked and form be resubmitted */
    $this->users_model->unlock_user($user_data->user_id);
    $this->submit($post_username, $post_password);
    return FALSE;
    }
    
    }
    
    if ($flags == 0)
    {
    /* User is not locked out and no error messages reported */
    
    /* Match user status */
    switch ($user_data->user_status_id)
    {
    case 1:
    $output_status = 'Error';
    $output_title = 'Account Unverified';
    $output_message = 'Sorry you must verify your account before logging in!';
    $flags++;
    break;
    case 3:
    $output_status = 'Error';
    $output_title = 'Account Suspended';
    $output_message = 'Your account has been suspended!';
    $flags++;
    break;
    case 4:
    $output_status = 'Error';
    $output_title = 'Account Banned';
    $output_message = 'Your account has been banned!';
    $flags++;
    break;
    case 5:
    $output_status = 'Error';
    $output_title = 'Account Deleted';
    $output_message = 'Your account has been deleted!';
    $flags++;
    break;
    }
    
    if ($flags == 0)
    {
    /* User is registered and validated and no error messages reported */
    $regenerated_post_password = $this->genfunc->reGenPassHash($post_password, $user_data->password_hash);
    
    $failed_logins = $this->session->userdata('failed_logins');
    
    if ($regenerated_post_password == $user_data->password)
    {
    /* Password from login form matches user stored password */
    
    /* Start session with user id and clear previous failed login attempts */
    $this->session->set_userdata('uid', $user_data->user_id);
    $this->session->unset_userdata('failed_logins');
    $this->users_model->insert_session($user_data->user_id, gmdate('Y-m-d H:i:s', time()));
    $output_status = 'Success';
    $output_title = 'Login Success';
    $output_message = 'Successful login! Sending you to the dashboard';
    }
    else
    {
    /* Password from login from does not match user stored password */
    if ($failed_logins > 0)
    {
    /* User has atleast one failed login attempt for the current session */
    if ($failed_logins == 4)
    {
    $this->users_model->lock_out_user($user_data->user_id, gmdate('Y-m-d H:i:s', time()+(60*15)));
    //$this->functions_model->send_email('maximum_failed_login_attempts_exceeded', $user_data->email_address, $user_data)
    $output_status = 'Error';
    $output_title = 'Account Locked';
    $output_message = 'Your account is currently locked, we apologize for the inconvienence. You must wait 15 minutes before you can log in again! An email was sent to the owner of this account! Forgotten your username or password? <a href="forgotusername">Forgot Username</a> or <a href="forgotpassword">Forgot Password</a>';
    }
    else
    {
    /* User has a few more chances to get password right */
    $failed_logins++;
    $this->session->set_userdata('failed_logins', $failed_logins);
    $output_status = 'Error';
    $output_title = 'Incorrect Login Credentials';
    $output_message = 'Incorrect username and password credentials!';
    }
    }
    else
    {
    /* First time user has not entered username and password successfully */
    $this->session->set_userdata('failed_logins', 1);
    $output_status = 'Error';
    $output_title = 'Incorrect Login Credentials';
    $output_message = 'Incorrect username and password credentials!';
    }
    
    $this->users_model->increase_login_attempt($this->input->ip_address(), $post_username, gmdate('Y-m-d H:i:s', time()));
    }
    }
    }
    }
    else
    {
    /* User was not found in database */
    $output_status = 'Error';
    $output_title = 'User Not Found';
    $output_message = 'The user was not found in the database!';
    }
    }
    else
    {
    
    /* Form validation failed */
    $output_status = 'Error';
    $output_title = 'Form Not Validated';
    $output_message = 'The form did not validate successfully!';
    }
    
    $output_array = array('output_status' => $output_status, 'output_title' => $output_title, 'output_message' => $output_message);
    
    echo json_encode($output_array);
    }
    

     

     

  4. Here's what I have so far...

     

    public function form_is_valid()
    {
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    return $this->form_validation->run();
    }
    
    public function submit()
    {
       $output_status = 'Notice';
       $output_title = 'Not Processed';
       $output_message = 'The request was unprocessed!';
    
     if ($this->form_is_valid())
     {
     $output_status = 'Success';
     $output_title = 'Form Submitted Successfully';
     $output_message = 'The form did validate successfully!';
     }
     else
     {
     $output_status = 'Error';
     $output_title = 'Form Not Validated';
     $output_message = 'The form did not validate successfully!';
     }
    
    echo json_encode(array('output_status' => $output_status, 'output_title' => $output_title, 'output_message' => $output_message, 'error_messages' => $this->form_validation->get_error_array()));
    }
    

  5. This is what I am currently using for my submit function but it is doing way to much and I'm wanting to work with it so that I can apply the Single Responsibility Principle as well as I can see my code is suffering from Arrow Anti-Pattern and was looking for some ideas on how this could be improved.

     

     

     

    /**
    * submit function.
    *
    * @access public
    * @param string $post_username
    * @param string $post_password
    * @return json data string
    */
    public function submit($post_username = NULL, $post_password = NULL)
    {
       // Set variable defaults
       $output_status = 'Notice';
       $output_title = 'Not Processed';
       $output_message = 'The request was unprocessed!';
       // Set validation rules for post data
       $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
       $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
       $this->form_validation->set_rules('remember', 'Remember Me', 'trim|xss_clean|integer');
       if ($this->form_validation->run() == TRUE)
       {
        // Form validation passed
        // Number of error flags
        $x = 0;
        // Post values from login form
        $post_username = $this->input->post('username');
        $post_password = $this->input->post('password');
        // Get user data from post username value
        $user_data = $this->users_model->get_users(array('usernames' => $post_username), 'row');
        //print_r($user_data);
        //die();
        if ($user_data !== NULL)
        {
    	    // User was found in database
    	    if ($user_data->lock_date !== '0000-00-00 00:00:00')
    	    {
    		    // User is locked out
    		    // Get the current GMT time
    		    $current_time = now();
    		    if (strtotime($user_data->lock_date) > $current_time)
    		    {
    			    // User is still locked out
    			    $output_status = 'Error';
    			    $output_title = 'Account Locked';
    			    $output_message = 'This user account is current locked!';
    			    $x++;
    		    }
    		    else
    		    {
    			    // User can be unlocked and form be resubmitted
    			    $this->users_model->unlock_user($user_data->user_id);
    			    $this->submit($post_username, $post_password);
    			    return FALSE;
    		    }
    	    }
    	    if ($x == 0)
    	    {
    		    // No error flags reported
    		    // User is not locked out
    		    if ($user_data->user_status_id == 1)
    		    {
    			    $output_status = 'Error';
    			    $output_title = 'Account Unverified';
    			    $output_message = 'Sorry you must verify your account before logging in!';
    			    $x++;
    		    }
    		    if ($user_data->user_status_id == 3)
    		    {
    			    $output_status = 'Error';
    			    $output_title = 'Account Suspended';
    			    $output_message = 'Your account has been suspended!';
    			    $x++;
    		    }
    		    if ($user_data->user_status_id == 4)
    		    {
    			    $output_status = 'Error';
    			    $output_title = 'Account Banned';
    			    $output_message = 'Your account has been banned!';
    			    $x++;
    		    }
    		    if ($user_data->user_status_id == 5)
    		    {
    			    $output_status = 'Error';
    			    $output_title = 'Account Deleted';
    			    $output_message = 'Your account has been deleted!';
    			    $x++;
    		    }
    		    if ($x == 0)
    		    {
    			    // No error flags reported
    			    // User is registered and verified
    			    $regenerated_post_password = $this->functions_model->regenerate_password_hash($post_password, $user_data->password_hash);
    			    /* Not sure if this is needed
    			    if ($this->session->userdata('failed_logins'))
    			    {
    				    // User has previous failed logins in session
    				    $failed_logins = $this->session->userdata('failed_logins');
    			    }
    			    */
    			    if ($regenerated_post_password == $user_data->password)
    			    {
    				    // Password from login form matches user stored password
    				    // Set session variable with user id and clear previous failed login attempts
    				    $this->session->set_userdata('xtr', $user_data->user_id);
    				    $this->session->unset_userdata('failed_logins');
    				    $output_status = 'Success';
    				    $output_title = 'Login Success';
    				    $output_message = 'Successful login! Sending you to the dashboard';
    			    }
    			    else
    			    {
    				    // Password from login from does not match user stored password
    				    if (is_integer($failed_logins))
    				    {
    					    // User has atleast one failed login attempt for the current session
    					    if ($failed_logins == 4)
    					    {
    						    $wait_time = 60 * 15;
    						    $lock_out_time = $current_time + $wait_time;
    						    /* Find out about if I can do this part differently.
    						    $lock_out_date = gmdate('Y-m-d H:i:s', $lock_out_time);
    						    */
    						    $this->users_model->lock_out_user($user_data->user_id, $lock_out_date);
    						    //$this->functions_model->send_email('maximum_failed_login_attempts_exceeded', $user_data->email_address, $user_data)
    						    $output_status = 'Error';
    						    $output_title = 'Account Locked';
    						    $output_message = 'Your account is currently locked, we apologize for the inconvienence. You must wait 15 minutes before you can log in again! An email was sent to the owner of this account! Forgotten your username or password? <a href="forgotusername">Forgot Username</a> or <a href="forgotpassword">Forgot Password</a>';
    					    }
    					    else
    					    {
    						    // User has a few more chances to get password right
    						    $failed_logins++;
    						    $this->session->set_userdata('failed_logins', $failed_logins);
    						    $output_status = 'Error';
    						    $output_title = 'Incorrect Login Credentials';
    						    $output_message = 'Incorrect username and password credentials!';
    					    }
    				    }
    				    else
    				    {
    					    // First time user has not entered username and password correctly
    					    $this->session->set_userdata('failed_logins', 1);
    					    $output_status = 'Error';
    					    $output_title = 'Incorrect Login Credentials';
    					    $output_message = 'Incorrect username and password credentials!';
    				    }
    				    $time_of_attempt = gmdate('Y-m-d H:i:s');
    				    $this->users_model->increase_login_attempt($this->input->ip_address(), $post_username, $time_of_attempt);
    			    }
    		    } // if ($x = 0) User is registered and verified
    	    } // if ($x = 0) User is not locked out
        }
        else
        {
    	    // User was not found in database
    	    $output_status = 'Error';
    	    $output_title = 'User Not Found';
    	    $output_message = 'The user was not found in the database!';
        }
       }
       else
       {
        // Form validation failed
        $output_status = 'Error';
        $output_title = 'Form Not Validated';
        $output_message = 'The form did not validate successfully!';
       }
       echo json_encode(array('output_status' => $output_status, 'output_title' => $output_title, 'output_message' => $output_message, 'error_messages' => $this->form_validation->error_array()));
    }
    

  6. I'm trying to figure out what the heck is going on here because I've never had this happen before. When I run this bit of code I receive ONE for the count but when it prints the array all it does is <pre></pre> as if there is nothing in it. I'm confused.

     

    <?php
    echo count($titles);
    echo '<pre>';
    print_r($titles);
    echo '</pre>';
    die();
    if (count($titles) > 0)
    {
    foreach ($titles AS $title)
    {
    }
    }
    ?>
    

  7. Basically the get_titles function will handle all kinds of situations but I'm going to try and do this one situation at a time. When the function is called with just one id (title_id) I want it to return data just about that title. When it gets the status_id I want it to take that value to the get_title_statuses function so it can get the name of that status.

     

    So the returned object should be this for a single row.

     

    stdClass Object
    (
       [title_id] => 1
       [title_name] => Undisputed Title
       [title_directory_name] => undisputed
       [title_status_name] => Active
       [title_sort_order] => 1
    )
    

  8. I'm trying to figure out how to have it not select the title_status_id but only use it to run the get_title_statuses function to get the name of the status without having it return it in the object print.

     

    $titles = $this->titles_model->get_titles(array('title_ids' =>1));
    
    echo '<pre>';
    print_r($titles);
    echo '</pre>';
    

     

    stdClass Object
    (
       [title_id] => 1
       [title_name] => Undisputed Title
       [title_directory_name] => undisputed
       [title_status_id] => 1
       [title_sort_order] => 1
    )
    
    

     

    <?php
    public function get_titles($params = array())
       {
           $this->db->select('titles.title_id');
           $this->db->select('titles.title_name');
           $this->db->select('titles.title_directory_name');
           $this->db->select('titles.title_status_id');
           $this->db->select('titles.title_sort_order');
    
           $this->db->from('titles');
    
           //checking to see if any $params are attempting to be passed
           if (count($params) > 0)
           {
               //start title specific selection
               if (isset($params['title_ids']))
               {
                   //if you only have one integer.
                   if (is_integer($params['title_ids']))
                   {
                       $this->db->where('titles.title_id', $params['title_ids']);
                       $query = $this->db->get();
                       if ($query->num_rows() > 0)
                       {
                           $title = $query->row();
                       }
                       else
                       {
                           return false;
                       }
                   }
               }
           }
       }
    ?>
    

  9. I have no idea how my post code showed up like that but thank you. Were you able to take a look at the controller code. Working with OOP is nice but here's a situation where with the class function and its possible parameters I need it to get a row value or a whole row or whole object and I'm not sure what I can do right now to account for that? And each situation is pretty much based on what parameters there are.

  10. The question I have is if you notice with the line below its supposed to get the status name of the title. However in the get_title_statuses function it returns an object so I’m trying to figure out how when I need only a certain value of one of the keys in the object I can just return the value.

     

    [color=#000000][color=#0000BB]$titles [/color][color=#007700]= [/color][color=#0000BB]$this[/color][color=#007700]->[/color][color=#0000BB]titles_model[/color][color=#007700]->[/color][color=#0000BB]get_titles[/color][color=#007700](array([/color][color=#DD0000]'title_status' [/color][color=#007700]=> array([/color][color=#0000BB]1[/color][color=#007700],[/color][color=#0000BB]2[/color][color=#007700],[/color][color=#0000BB]3[/color][color=#007700])));
    
    for([/color][color=#0000BB]$x [/color][color=#007700]= [/color][color=#0000BB]0[/color][color=#007700]; [/color][color=#0000BB]$x [/color][color=#007700]< [/color][color=#0000BB]count[/color][color=#007700]([/color][color=#0000BB]$titles[/color][color=#007700]); [/color][color=#0000BB]$x[/color][color=#007700]++)[/color]
    [color=#0000BB]{
    $titles[$x][/color][color=#007700]->[/color][color=#0000BB]title_status_name [/color][color=#007700]= [/color][color=#0000BB]$this[/color][color=#007700]->[/color][color=#0000BB]titles_model[/color][color=#007700]->[/color][color=#0000BB]get_title_statuses[/color][color=#007700](array([/color][color=#DD0000]'titles' [/color][color=#007700]=> [/color][color=#0000BB]$titles[$x][/color][color=#007700]->[/color][color=#0000BB]title_status_id[/color][color=#007700])); [/color]
    [color=#0000BB]} [/color] [/color] 
    

     

    Here's a link to what I have for my model functions. I had to include it in a separate place.

     

    http://pastebin.com/h6XZvr4s

  11. This is a reusable function that I’m going to be using elsewhere and I set it up so that it can take in a number of parameters. The question I have is for example how can I move the select clause that selects the title_id down to be not included if the $params[‘titles’] key is set because at that point I would already have that bit of data and want to prevent selecting it again. That way I can also adjust it if the other information is already known.

     

    public function get_titles($params = array())
    {
    $this->db->select('titles.title_id');
    $this->db->select('titles.title_name');
    $this->db->select('titles.title_directory_name');
    $this->db->select('titles.title_sort_order');
    $this->db->select('titles.title_status_id');
    $this->db->from('titles');
    
    //checking to see if any $params are attempting to be passed
    if(count($params) > 0)
    {
    //start title status type selection
    if (isset($params['title_status']))
    {
    //passed multiple status types.
    //eg $params['title_status'] = array(0, 2);
    if (is_array($params['title_status']))
    {
    $a = 0;
    foreach($params['title_status'] as $status_type)
    {
    if ($a == 0)
    {
    $this->db->where('titles.title_status_id', $status_type);
    }
    else
    {
    $this->db->or_where('titles.title_status_id', $status_type);
    }
    $a++;
    }
    }
    else
    {
    //if you only used a string with a single digit.
    if (is_numeric($params['title_status']))
    {
    $this->db->where('titles.title_status_id', $params['title_status']);
    }
    }
    }
    //end title status type selection
    
    //start titles sort_order specific selection
    if (isset($params['title_sort_order']))
    {
    if (is_array($params['title_sort_order']))
    {
    foreach ($params['title_sort_order'] as $title_sort_order)
    {
    $this->db->where('titles.title_sort_order', $title_sort_order);
    }
    }
    else
    {
    //if you only used a string with a single digit.
    if (is_numeric($params['title_sort_order']))
    {
    $this->db->where('titles.title_sort_order', $params['title_sort_order']);
    }
    }
    }
    //end titles sort_order specific selection
    
    //start titles specific selection
    if (isset($params['titles']))
    {
    if (is_array($params['titles']))
    {
    foreach ($params['titles'] as $title)
    {
    $this->db->where('titles.title_id', $title);
    }
    }
    else
    {
    //if you only used a string with a single digit.
    if (is_numeric($params['titles']))
    {
    $this->db->where('titles.title_id', $params['titles']);
    }
    }
    }
    //end titles specific selection
    }
    
    //if no params are found query will be made for all titles in the DB regardless it would be like
    // SELECT * FROM titles;
    
    $query = $this->db->get();
    if ($query->num_rows() > 0)
    {
    return $query->result();
    }
    else
    {
    return false;
    }
    }
    

  12. After thinking about it I came up with this and it worked.

     

    <?php
    foreach($title_statuses AS $status)
    {
    	if (isset($title_data))
    	{
    			$selected = $title_data->title_status_id === $status->title_status_id ? ' selected="selected"' : '';
    	}
    	echo '<option value="'.$status->title_status_id.'"';
    	if (isset($selected)) { echo $selected; } .
    	echo '>'.$status->title_status_name.'</option>';
    }
    ?>
    

  13. I'm trying to figure out why I am receiving a t_if error when my page loads?

     

    <?php
    foreach($title_statuses AS $status)
    {
    if (isset($title_data))
    {
    	$selected = $title_data->title_status_id === $status->title_status_id ? ' selected="selected"' : '';
    }
    echo '<option value="'.$status->title_status_id.'"'. if (isset($selected)) { echo $selected; } .'>'.$status->title_status_name.'</option>';
    }
    ?>
    

  14. I'm trying to figure out a way I can do this task with dealing with personal messages content on my site. As of right now I'm trying to put my functions together so that all my types of functions can work together to just run the get_messages function. ONly thing I'm having issues with is whte get_last_5_personal_messages function because this is the only one function that exists across my site. All others only appear when the personal messages box is accessed on the site.

     

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Personalmessages extends CI_Controller {
    
    public function __construct()
    {
    parent::__construct();
    }
    
    public function index()
    {
    redirect('kowmanager/personalmessages/inbox/');
    }
    
    public function inbox($display = NULL, $datetime_format = NULL)
    {
    $message_box_messages = array();
    $css_page_addons = '';
    $js_page_addons = '';
    $meta_tag_addons = '';
    $site_title = 'KOW Manager Personal Messages';
    
    $user_data = $this->users_model->is_logged_in($this->session->userdata('xtr'));
    
    if ($user_data === FALSE)
    {
    redirect('login', 'refresh');
    }
    else
    {
    $body_content = $this->config->item('themes_path').'/'.$this->config->item('default_theme').'/cpanel/view_messages';
    $body_type = 'full';
    $geo_data = $this->functions_model->geo_matching();
    
    /*
    * Gets the last 5 messages that were recieved.
    *
    @param integer $user_data->user_id User ID of the logged in user.
    @param integer or empty Represents the number of messages to retrieve. Empty represents getting all messages.
    @param integer $geo_data['zipz']['timezone'] The time offset of the user logged in based on his timezone.
    @param string inbox or outbox Tells the function which type of messages to retrieve.
    @param string d F Y g:i a Tells how to format the datetime_sent in the get_personal_messages functions.
    @param empty.
    */
    $last_5_personal_messages = $this->messages_model->get_personal_messages($user_data->user_id, 5, $geo_data['zipz']['timezone'], 'inbox', 'd F Y g:i a', '');
    
    /*
    * Grabs messages for the logged in user.
    *
    @param integer $user_data->user_id User ID of the logged in user.
    @param integer or empty Represents the number of messages to retrieve. Empty represents getting all messages.
    @param integer $geo_data['zipz']['timezone'] The time offset of the user logged in based on his timezone.
    @param string inbox or outbox Tells the function which type of messages to retrieve.
    @param string $datetime_format Tells how to format the datetime_sent in the get_personal_messages functions. Specified from the type function.
    @param array Sends a type of message(today, last_week, this_week, important) and a values to look for.
    */
    $personal_messages = $this->messages_model->get_personal_messages($user_data->user_id,'', $geo_data['zipz']['timezone'], 'inbox', $datetime_format, $display);
    }
    
    if (count($message_box_messages) !== 0)
    {
    $message_boxes = $this->functions_model->build_message_boxes_output(array('display' => 'show', 'message' => $message_box_messages));
    }
    else
    {
    $message_boxes = array('display' => 'none');
    }
    
    $meta_tags = $this->functions_model->meta_tags();
    
    if (isset($site_title) && (empty($site_title)))
    {
    $site_title = $this->functions_model->site_title();
    }
    
    $this->data['user_data'] = $user_data;
    $this->data['last_5_personal_messages'] = $last_5_personal_messages;
    $this->data['personal_messages'] = $personal_messages;
    $this->data['notifications'] = $this->site_model->get_notifications();
    $this->data['server_data'] = $this->server_model->get_server_data();
    $this->data['site_data'] = $this->site_model->get_site_data();
    $this->data['message_boxes'] = $message_boxes;
    $this->data['css_page_addons'] = $css_page_addons;
    $this->data['js_page_addons'] = $js_page_addons;
    $this->data['site_title'] = $site_title;
    $this->data['body_content'] = $body_content;
    $this->data['body_type'] = $body_type;
    $this->data['meta_tags'] = $meta_tags;
    $this->data['site_url'] = $this->functions_model->site_url();
    $this->load->view($this->config->item('themes_path').'/'.$this->config->item('default_theme').'/cpanel/template/index', $this->data);
    }
    
    public function today()
    {
    $today = date('Y-m-d', time());
    $start_range = $today.' 00:00:00';
    $end_range = $today. ' 23:59:59';
    $this->inbox(array('type' => 'today', 'values' => array('start_time' => $start_range, 'end_time' => $end_range)), 'H:s:i a');
    }
    
    public function thisweek()
    {
    
    $start_range = $today.' 00:00:00';
    $end_range = $today. ' 23:59:59';
    $this->inbox(array('type' => 'thisweek', 'values' => array('start_time' => $start_range, 'end_time' => $end_range)), 'M d');
    }
    
    public function lastweek()
    {
    $this->inbox(array('type' => 'lastweek', 'values' => array('start_time' => $start_range, 'end_time' => $end_range)), 'M d');
    }
    
    public function important()
    {
    $this->inbox(array('type' => 'important', 'values' => 0), '')
    }
    
    }
    
    /* End of file personalmessages.php */
    /* Location: ./application/controllers/personalmessages.php */
    

     

    Messags Model/get_personal_messages

     

    /**
    * Gets all or last $x number of personal messages of the specified user
    *
    * @param integer $user_id User ID of the user specified
    * @param integer $limit Limit of how many messages to retrieve
    * @param integer $timezone The timezone offset of the user's geo location
    * @param string $box Loading either the inbox or outbox of messages
    * @param string $date_format The format for which the date needs to be ouputted
    * @param array $display Tells what kind of messages to retrieve (important or specific datetime or datetime range)
    * @return object/NULL
    */
    public function get_personal_messages($user_id, $limit = NULL, $timezone, $box, $date_format, $display = NULL)
    {
    $this->db->select('personal_messages.message_id');
    $this->db->select('personal_messages.subject');
    $this->db->select('personal_messages.datetime_sent');
    $this->db->select('personal_messages.attachments');
    $this->db->select('personal_messages.priority');
    $this->db->select('personal_messages.message_content');
    if ($box == 'inbox')
    {
    $this->db->select('personal_messages.to_read AS message_read');
    }
    else
    {
    $this->db->select('personal_messages.from_read AS message_read');
    }
    if ($box == 'inbox')
    {
    $this->db->select('personal_messages.is_inbox_favorite AS is_favorite');
    }
    else
    {
    $this->db->select('personal_messages.is_outbox_favorite AS is_favorite');
    }
    $this->db->select('CONCAT(users.first_name, " ", users.last_name) AS sender_name', FALSE);
    $this->db->select('users.email_address AS sender_email_address');
    $this->db->select('user_profiles.user_avatar AS sender_avatar');
    $this->db->from('personal_messages');
    $this->db->join('users', 'users.user_id = personal_messages.from_user_id');
    $this->db->join('user_profiles', 'users.user_id = user_profiles.user_id');
    if ($display['type'] == 'today')
    {
    $this->db->where('datetime_sent >', $display['values']['start_time']);
    $this->db->where('datetime_sent <', $display['values']['end_time']);
    }
    elseif ($display['type'] == 'this_week')
    {
    
    }
    elseif ($display['type'] == 'last_week')
    {
    
    }
    if ($box == 'inbox')
    {
    $this->db->where('personal_messages.to_user_id', $user_id);
    }
    else
    {
    $this->db->where('personal_messages.from_user_id', $user_id);
    }
    if ($limit != NULL)
    {
    if (is_numeric($limit))
    {
    $this->db->limit($limit);
    }
    }
    $query = $this->db->get();
    $personal_messages = array();
    $personal_messages['messages'] = $query->result();
    if (count($personal_messages['messages']) > 0)
    {
    for ($x = 0; $x < count($personal_messages['messages']); $x++)
    {
    $attachments = $personal_messages['messages'][$x]->attachments;
    if ($this->functions_model->null_check($attachments) === FALSE)
    {
    $attachments = json_decode($attachments, TRUE);
    for ($i = 0; $i < count($attachments); $i++)
    {
    $file_name = $attachments[$i];
    $attachments[$i] = array();
    $attachments[$i]['file_name'] = $file_name;
    if ($this->functions_model->is_file('assets/downloads/'.$file_name, FALSE) === TRUE)
    {
    $attachments[$i]['is_file'] = TRUE;
    $file_size = $this->functions_model->bytes_to_size(filesize('assets/downloads/'.$file_name));
    $attachments[$i]['file_size'] = $file_size;
    $attachments[$i]['file_location'] = 'assets/downloads/'.$file_name;			
    }
    else
    {
    		 $attachments[$i]['is_file'] = FALSE;
    			 }
    		 }
    		 $personal_messages['messages'][$x]->attachments = $attachments;
    	 }
    $personal_messages['messages'][$x]->datetime_sent = $this->functions_model->actual_time('Y-m-d g:i:s', $timezone, strtotime($personal_messages['messages'][$x]->datetime_sent));
    echo $date_format;
    die();
    $personal_messages['messages'][$x]->datetime_sent = date($date_format, strtotime($personal_messages['messages'][$x]->datetime_sent));
    print_r($personal_messages);
    die();
    
    $personal_messages['messages'][$x]->datetime_sent = $this->functions_model->time_since(strtotime($personal_messages['messages'][$x]->datetime_sent));
    $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/avatar.jpg';
    if ($this->functions_model->null_check($personal_messages['messages'][$x]->sender_avatar) === FALSE)
    {
    if ($this->functions_model->is_file('assets/themes/supr/images/avatars/'.$personal_messages['messages'][$x]->sender_avatar, FALSE) === TRUE)
    {
    $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/'.$personal_messages['messages'][$x]->sender_avatar;
    }
    }
    $personal_messages['messages'][$x]->sender_avatar = $avatar;
    }
    $personal_messages['total_unread_messages'] = $this->get_users_unread_messages($user_id);
    }
    return $personal_messages;
    }
    
    

  15. If need be here's a commented out a few of the function calls from the code above.

     

    /*
               * Gets the last 5 messages that were recieved.
               *
               @param integer $user_data->user_id   User ID of the logged in user.
               @param integer or empty  Represents the number of messages to retrieve. Empty represents getting all messages.
               @param integer $geo_data['zipz']['timezone']   The time offset of the user logged in based on his timezone.
               @param string inbox or outbox Tells the function which type of messages to retrieve.
               @param string d F Y g:i a Tells how to format the datetime_sent in the get_personal_messages functions.
               @param empty.
               */
               $last_5_personal_messages = $this->messages_model->get_personal_messages($user_data->user_id, 5, $geo_data['zipz']['timezone'], 'inbox', 'd F Y g:i a', '');
    
               /*
               * Gets the last 5 messages that were recieved.
               *
               @param integer $user_data->user_id   User ID of the logged in user.
               @param integer or empty  Represents the number of messages to retrieve. Empty represents getting all messages.
               @param integer $geo_data['zipz']['timezone']   The time offset of the user logged in based on his timezone.
               @param string inbox or outbox Tells the function which type of messages to retrieve.
               @param string $datetime_format  Tells how to format the datetime_sent in the get_personal_messages functions. Specified from the type function.
               @param array Sends a type of message(today, last_week, this_week, important) and a values to look for.
               */
               $personal_messages = $this->messages_model->get_personal_messages($user_data->user_id,'', $geo_data['zipz']['timezone'], 'inbox', $datetime_format, $display);
    

  16. If you notice the second paramter of the today function says 'H:s:i a'. When it gets sent to the inbox function it shows the variable correctly when I echo it inside the inbox function however right before this call:

     

    $personal_messages = $this->messages_model->get_personal_messages($user_data->user_id,'', $geo_data['zipz']['timezone'], 'inbox', $datetime_format, $display);

     

    it then echos like this: 'd F Y g:i a'

     

    Any ideas as to why that is?

     

    
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Personalmessages extends CI_Controller {
    
           public function __construct()
           {
                   parent::__construct();
           }
    
           public function index()
           {
                   redirect('kowmanager/personalmessages/inbox/');
           }
    
           public function inbox($display = NULL, $datetime_format)
           {
                   $message_box_messages = array();
                   $css_page_addons = '';
                   $js_page_addons = '';
                   $meta_tag_addons = '';
                   $site_title = 'KOW Manager Personal Messages';
    
                   $user_data = $this->users_model->is_logged_in($this->session->userdata('xtr'));
    
                   if ($user_data === FALSE)
                   {
                           redirect('login', 'refresh');
                   }
                   else
                   {
                           $body_content = $this->config->item('themes_path').'/'.$this->config->item('default_theme').'/cpanel/view_messages';
                           $body_type = 'full';
                           $geo_data = $this->functions_model->geo_matching();
                           $last_5_personal_messages = $this->messages_model->get_personal_messages($user_data->user_id, 5, $geo_data['zipz']['timezone'], 'inbox', 'd F Y g:i a');
                           $personal_messages = $this->messages_model->get_personal_messages($user_data->user_id,'', $geo_data['zipz']['timezone'], 'inbox', $datetime_format, $display);
                   }
    
                   if (count($message_box_messages) !== 0)
                   {
                           $message_boxes = $this->functions_model->build_message_boxes_output(array('display' => 'show', 'message' => $message_box_messages));
                   }
                   else
                   {
                           $message_boxes = array('display' => 'none');
                   }
    
                   $meta_tags = $this->functions_model->meta_tags();
    
                   if (isset($site_title) && (empty($site_title)))
                   {
                           $site_title = $this->functions_model->site_title();
                   }
    
                   $this->data['user_data'] = $user_data;
                   $this->data['last_5_personal_messages'] = $last_5_personal_messages;
                   $this->data['personal_messages'] = $personal_messages;
                   $this->data['notifications'] = $this->site_model->get_notifications();
                   $this->data['server_data'] = $this->server_model->get_server_data();
                   $this->data['site_data'] = $this->site_model->get_site_data();
                   $this->data['message_boxes'] = $message_boxes;
                   $this->data['css_page_addons'] = $css_page_addons;
                   $this->data['js_page_addons'] = $js_page_addons;
                   $this->data['site_title'] = $site_title;
                   $this->data['body_content'] = $body_content;
                   $this->data['body_type'] = $body_type;
                   $this->data['meta_tags'] = $meta_tags;
                   $this->data['site_url'] = $this->functions_model->site_url();
                   $this->load->view($this->config->item('themes_path').'/'.$this->config->item('default_theme').'/cpanel/template/index', $this->data);
           }
    
           public function today()
           {
                   $today = date('Y-m-d', time());
                   $start_range = $today.' 00:00:00';
                   $end_range = $today. ' 23:59:59';
                   $this->inbox(array('type' => 'today', 'values' => array('start_time' => $start_range, 'end_time' => $end_range)), 'H:s:i a');
           }
    
           public function thisweek()
           {
    
           }
    
           public function lastweek()
           {
    
           }
    
           public function important()
           {
    
           }
    
    }
    
    /* End of file personalmessages.php */
    /* Location: ./application/controllers/personalmessages.php */
    

  17. I'm trying to figure out how to deal with the display variable. What it should do is be able to grab either todays messages, this weeks messages or last week messages or messages marked as important and not sure how to deal with the variable.

     

    /**
        * Gets all or last $x number of personal messages of the specified user
        *
        * @param integer $user_id   User ID of the user specified
        * @param integer $limit   Limit of how many messages to retrieve
        * @param integer $timezone   The timezone offset of the user's geo location
        * @param string  $box   Loading either the inbox or outbox of messages
        * @param string  $date_format   The format for which the date needs to be ouputted
        * @param array   $display  Tells what kind of messages to retrieve (important or specific datetime or datetime range)
        * @return object/NULL
        */
       public function get_personal_messages($user_id, $limit = NULL, $timezone, $box, $date_format, $display = NULL)
       {
           $this->db->select('personal_messages.message_id');
           $this->db->select('personal_messages.subject');
           $this->db->select('personal_messages.datetime_sent');
           $this->db->select('personal_messages.attachments');
           $this->db->select('personal_messages.priority');
           $this->db->select('personal_messages.message_content');
           if ($box == 'inbox')
           {
               $this->db->select('personal_messages.to_read AS message_read');
           }
           else
           {
               $this->db->select('personal_messages.from_read AS message_read');
           }
           if ($box == 'inbox')
           {
               $this->db->select('personal_messages.is_inbox_favorite AS is_favorite');
           }
           else
           {
               $this->db->select('personal_messages.is_outbox_favorite AS is_favorite');
           }
           $this->db->select('CONCAT(users.first_name, " ", users.last_name) AS sender_name', FALSE);
           $this->db->select('users.email_address AS sender_email_address');
           $this->db->select('user_profiles.user_avatar AS sender_avatar');
           $this->db->from('personal_messages');
           $this->db->join('users', 'users.user_id = personal_messages.from_user_id');
           $this->db->join('user_profiles', 'users.user_id = user_profiles.user_id');
           if ($box == 'inbox')
           {
               $this->db->where('personal_messages.to_user_id', $user_id);
           }
           else
           {
               $this->db->where('personal_messages.from_user_id', $user_id);
           }
           if ($display != NULL)
           {
               $this->db->where('personal_messages.to_user_id', $display);
           }
           if ($limit != NULL)
           {
               if (is_numeric($limit))
               {
                   $this->db->limit($limit);
               }
           }
           $query = $this->db->get();
           $personal_messages = array();
           $personal_messages['messages'] = $query->result();
           if (count($personal_messages['messages']) > 0)
           {
               for ($x = 0; $x < count($personal_messages['messages']); $x++)
               {
                   $attachments = $personal_messages['messages'][$x]->attachments;
                   if ($this->functions_model->null_check($attachments) === FALSE)
                   {
                       $attachments = json_decode($attachments, TRUE);
                       for ($i = 0; $i < count($attachments); $i++)
                       {
                           $file_name = $attachments[$i];
                           $attachments[$i] = array();
                           $attachments[$i]['file_name'] = $file_name;
                           if ($this->functions_model->is_file('assets/downloads/'.$file_name, FALSE) === TRUE)
                           {
                               $attachments[$i]['is_file'] = TRUE;    
                               $file_size =  $this->functions_model->bytes_to_size(filesize('assets/downloads/'.$file_name));
                               $attachments[$i]['file_size'] = $file_size;   
                               $attachments[$i]['file_location'] = 'assets/downloads/'.$file_name;			    
                           }
                           else
                           {
          			         $attachments[$i]['is_file'] = FALSE;    
          				 }
          			 }
          			 $personal_messages['messages'][$x]->attachments = $attachments;
          		 }
                   $personal_messages['messages'][$x]->datetime_sent = $this->functions_model->actual_time('Y-m-d g:i:s', $timezone, strtotime($personal_messages['messages'][$x]->datetime_sent));
                   $personal_messages['messages'][$x]->datetime_sent = date($date_format, strtotime($personal_messages['messages'][$x]->datetime_sent));
                   $personal_messages['messages'][$x]->datetime_sent = $this->functions_model->time_since(strtotime($personal_messages['messages'][$x]->datetime_sent));
                   $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/avatar.jpg';
                   if ($this->functions_model->null_check($personal_messages['messages'][$x]->sender_avatar) === FALSE)
                   {
                       if ($this->functions_model->is_file('assets/themes/supr/images/avatars/'.$personal_messages['messages'][$x]->sender_avatar, FALSE) === TRUE)
                       {
                           $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/'.$personal_messages['messages'][$x]->sender_avatar;
                       }
                   }
                   $personal_messages['messages'][$x]->sender_avatar = $avatar;
               }
               $personal_messages['total_unread_messages'] = $this->get_users_unread_messages($user_id);
           }
           return $personal_messages;
       }
    

  18. I have a better question that deals with this sort of issue. I'm getting an error that consists of...

     

     

    A PHP Error was encountered

     

    Severity: Notice

    Message: Undefined property: stdClass::$datetime_sent

    Filename: models/messages_model.php

    Line Number: 72

     

    A PHP Error was encountered

     

    Severity: Notice

    Message: Undefined property: stdClass::$sender_avatar

    Filename: models/messages_model.php

    Line Number: 74

     

    There's a var_dump of an array at the bottom of my code. This is also included next.

     

    array(4) {

    [0]=>

    object(stdClass)#29 (8) {

    ["message_id"]=>

    string(1) "1"

    ["subject"]=>

    string(12) "Test Message"

    ["datetime_sent"]=>

    string(6) "1 week"

    ["attachments"]=>

    NULL

    ["message_content"]=>

    string(446) "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

    ["sender_name"]=>

    string(16) "Jeffrey Davidson"

    ["sender_email_address"]=>

    string(20) "xtremer360@yahoo.com"

    ["sender_avatar"]=>

    string(82) "http://dev.kansasoutlawwrestling.com/assets/themes/supr/images/avatars/avatar5.jpg"

    }

    [1]=>

    object(stdClass)#30 (8) {

    ["message_id"]=>

    string(1) "2"

    ["subject"]=>

    string(18) "Testing PM Message"

    ["datetime_sent"]=>

    string(19) "2012-09-22 18:27:25"

    ["attachments"]=>

    string(37) "["file1.jpg","file2.jpg","file3.jpg"]"

    ["message_content"]=>

    string(51) "This is jsut a test of the personal message system!"

    ["sender_name"]=>

    string(11) "Frank Scott"

    ["sender_email_address"]=>

    string(24) "frankscott@testemail.com"

    ["sender_avatar"]=>

    NULL

    }

    [2]=>

    object(stdClass)#31 (8) {

    ["message_id"]=>

    string(1) "3"

    ["subject"]=>

    string(16) "Testing Whatever"

    ["datetime_sent"]=>

    string(19) "2012-10-04 05:03:09"

    ["attachments"]=>

    NULL

    ["message_content"]=>

    string(11) "dak;fdaf;ld"

    ["sender_name"]=>

    string(11) "Frank Scott"

    ["sender_email_address"]=>

    string(24) "frankscott@testemail.com"

    ["sender_avatar"]=>

    NULL

    }

    [3]=>

    object(stdClass)#32 (3) {

    ["attachments"]=>

    array(3) {

    [0]=>

    array(2) {

    ["file_name"]=>

    string(9) "file1.jpg"

    ["is_file"]=>

    bool(false)

    }

    [1]=>

    array(2) {

    ["file_name"]=>

    string(9) "file2.jpg"

    ["is_file"]=>

    bool(false)

    }

    [2]=>

    array(2) {

    ["file_name"]=>

    string(9) "file3.jpg"

    ["is_file"]=>

    bool(false)

    }

    }

    ["datetime_sent"]=>

    string(8) "42 years"

    ["sender_avatar"]=>

    string(81) "http://dev.kansasoutlawwrestling.com/assets/themes/supr/images/avatars/avatar.jpg"

    }

    }

     

     

    /**
        * Gets all or last $x number of personal messages of the specified user
        *
        * @param integer $user_id User ID of the user specified
        * @param integer $limit Limit of how many messages to retrieve
        * @return object/NULL
        */
       public function get_personal_messages($user_id, $limit = NULL, $timezone)
       {
           $this->db->select('personal_messages.message_id');
           $this->db->select('personal_messages.subject');
           $this->db->select('personal_messages.datetime_sent');
           $this->db->select('personal_messages.attachments');
           $this->db->select('personal_messages.message_content');
           $this->db->select('CONCAT(users.first_name, " ", users.last_name) AS sender_name', FALSE);
           $this->db->select('users.email_address AS sender_email_address');
           $this->db->select('user_profiles.user_avatar AS sender_avatar');
           $this->db->from('personal_messages');
           $this->db->join('users', 'users.user_id = personal_messages.from_user_id');
           $this->db->join('user_profiles', 'users.user_id = user_profiles.user_id');
           $this->db->where('personal_messages.to_user_id', $user_id);
           if ($limit != NULL)
           {
               if (is_numeric($limit))
               {
                   $this->db->limit($limit);
               }
           }
           $query = $this->db->get();
           $personal_messages = $query->result();
           if (count($personal_messages) > 0)
           {
               for ($x = 0; $x < count($personal_messages); $x++)
               {
                   $attachments = $personal_messages[$x]->attachments;
                   if ($this->functions_model->null_check($attachments) === FALSE)
                   {
                       $attachments = json_decode($attachments, TRUE);
                       for ($x = 0; $x < count($attachments); $x++)
                       {
                           $file_name = $attachments[$x];
                           if ($this->functions_model->is_file('assets/downloads/'.$file_name, FALSE) === TRUE)
                           {
                               $attachments[$x] = array('file_name' => $file_name, 'is_file' => TRUE);   				     
                           }
                           else
                           {
          			         $attachments[$x] = array('file_name' => $file_name, 'is_file' => FALSE);    
          				 }
          			 }
          			 $personal_messages[$x]->attachments = $attachments;
          		 }
                   $personal_messages[$x]->datetime_sent = $this->functions_model->actual_time('d F Y g:i a', $timezone, strtotime($personal_messages[$x]->datetime_sent));
                   $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/avatar.jpg';
                   if ($this->functions_model->null_check($personal_messages[$x]->sender_avatar) === FALSE)
                   {
                       if ($this->functions_model->is_file('assets/themes/supr/images/avatars/'.$personal_messages[$x]->sender_avatar, FALSE) === TRUE)
                       {
                           $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/'.$personal_messages[$x]->sender_avatar;
                       }
                   }
                   $personal_messages[$x]->datetime_sent = $this->functions_model->time_since(strtotime($personal_messages[$x]->datetime_sent));
                   $personal_messages[$x]->sender_avatar = $avatar;
               }
           }
           echo '<pre>';
           var_dump($personal_messages);
           echo '</pre>';
           die();
           return $personal_messages;
       }
    

  19. I've also tried this however its not adding the second key is_file regardless of if its TRUE or FALSE

    $attachments = json_decode($attachments, TRUE);
                   for ($x = 0; $x < count($attachments); $x++)
                   {
                       $file_name = $attachments[$x];
                       if ($this->functions_model->is_file('assets/downloads/'.$file_name, FALSE) === TRUE)
                       {
                           $attachments[$x]['is_file'] = TRUE;
                       }
                       else
                       {
                           $attachments[$x]['is_file'] = FALSE;
                       }
                   }

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.