コード例 #1
0
ファイル: CompanyHelper.php プロジェクト: houzhenggang/cobalt
 public static function getSelectedColumnFilters()
 {
     //get the user session data
     $db = \Cobalt\Container::fetch('db');
     $query = $db->getQuery(true);
     $query->select("companies_columns");
     $query->from("#__users");
     $query->where("id=" . UsersHelper::getUserId());
     $db->setQuery($query);
     $results = $db->loadResult();
     //unserialize columns
     $columns = unserialize($results);
     if (is_array($columns)) {
         return $columns;
     } else {
         //if it is empty then load a default set
         return CompanyHelper::getDefaultColumnFilters();
     }
 }
コード例 #2
0
ファイル: User.php プロジェクト: houzhenggang/cobalt
 /**
  * Update a users database columns for displaying data on individual pages
  * @param string $loc    the column in the database to update
  * @param string $column the column in the serialized array that will be updated
  */
 public function updateColumns($loc, $column)
 {
     //get user id
     $user_id = UsersHelper::getUserId();
     $query = $this->db->getQuery(true);
     //get current array
     $query->select($loc . "_columns");
     $query->from("#__users");
     $query->where("id=" . $user_id);
     $this->db->setQuery($query);
     $result = unserialize($this->db->loadResult());
     //if we have no data assigned grab the defaults
     if (!is_array($result)) {
         switch ($loc) {
             case "deals":
                 $result = DealHelper::getDefaultColumnFilters();
                 break;
             case "people":
                 $result = PeopleHelper::getDefaultColumnFilters();
                 break;
             case "companies":
                 $result = CompanyHelper::getDefaultColumnFilters();
                 break;
         }
     }
     //if we do find the value in the array remove it
     if (in_array($column, $result)) {
         $key = array_search($column, $result);
         unset($result[$key]);
     } else {
         //if we dont find the value in the array add it
         $result[] = $column;
     }
     //serialize the new array
     $result = serialize($result);
     //update the database
     $query->update('#__users')->set($loc . "_columns='" . $result . "'")->where("id=" . $user_id);
     $this->db->setQuery($query);
     $this->db->execute();
 }