コード例 #1
0
ファイル: AkHasMany.php プロジェクト: joeymetal/v1
 public function &find()
 {
     $result = false;
     if (!$this->Owner->isNewRecord()) {
         $args = func_get_args();
         $num_args = func_num_args();
         if (!empty($args[$num_args - 1]) && is_array($args[$num_args - 1])) {
             $options_in_args = true;
             $options = $args[$num_args - 1];
         } else {
             $options_in_args = false;
             $options = array();
         }
         $this->constructSql(!empty($options['include']));
         $has_many_options = $this->getOptions($this->association_id);
         $Associated =& $this->getAssociatedModelInstance();
         if (empty($options['conditions'])) {
             $options['conditions'] = @$has_many_options['finder_sql'];
         } elseif (!empty($has_many_options['finder_sql']) && is_array($options['conditions']) && !strstr($options['conditions'][0], $has_many_options['finder_sql'])) {
             $options['conditions'][0] .= ' AND ' . $has_many_options['finder_sql'];
         } elseif (!empty($has_many_options['finder_sql']) && !strstr($options['conditions'], $has_many_options['finder_sql'])) {
             $options['conditions'] .= ' AND ' . $has_many_options['finder_sql'];
         }
         $options['bind'] = empty($options['bind']) ? @$has_many_options['bind'] : $options['bind'];
         $options['order'] = empty($options['order']) ? @$has_many_options['order'] : $options['order'];
         $options['group'] = empty($options['group']) ? @$has_many_options['group'] : $options['group'];
         $options['include'] = empty($options['include']) ? @$has_many_options['include'] : $options['include'];
         if (!empty($options['bind'])) {
             $options['bind'] = Ak::toArray($options['bind']);
             $options['bind'] = array_diff($options['bind'], array(''));
             $options['conditions'] = is_array($options['conditions']) ? $options['conditions'] : array($options['conditions']);
             $options['conditions'] = array_merge($options['conditions'], $options['bind']);
             unset($options['bind']);
         }
         if ($options_in_args) {
             $args[$num_args - 1] = $options;
         } else {
             $args = empty($args) ? array('all') : $args;
             array_push($args, $options);
         }
         $result =& Ak::call_user_func_array(array(&$Associated, 'find'), $args);
     }
     return $result;
 }
コード例 #2
0
ファイル: AkActiveRecord.php プロジェクト: joeymetal/v1
    /**
    * This method allows you to use finders in a more flexible way like:
    *
    *   findBy('username AND password', $username, $password);
    *   findBy('age > ? AND name:contains', 18, 'Joe');
    *   findBy('is_active = true AND session_id', session_id());
    *
    */
    function &findBy()
    {
        if(!isset($this->_activeRecordHasBeenInstantiated)){
            return Ak::handleStaticCall();
        }
        $args = func_get_args();
        $find_by_sql = array_shift($args);
        if($find_by_sql == 'all' || $find_by_sql == 'first'){
            $fetch = $find_by_sql;
            $find_by_sql = array_shift($args);
        }else{
            $fetch = 'all';
        }

        $options = $this->_extractOptionsFromArgs($args);

        $query_values = $args;
        $query_arguments_count = count($query_values);

        list($sql, $requested_args) = $this->_getFindBySqlAndColumns($find_by_sql, $query_values);

        if($query_arguments_count != count($requested_args)){
            trigger_error(Ak::t('Argument list did not match expected set. Requested arguments are:').join(', ',$requested_args),E_USER_ERROR);
            $false = false;
            return $false;
        }

        $true_bool_values = array(true,1,'true','True','TRUE','1','y','Y','yes','Yes','YES','s','Si','SI','V','v','T','t');

        foreach ($requested_args as $k=>$v){
            switch ($this->getColumnType($v)) {
                case 'boolean':
                    $query_values[$k] = in_array($query_values[$k],$true_bool_values) ? true : false;
                    break;

                case 'date':
                case 'datetime':
                    $query_values[$k] = str_replace('/','-', $this->castAttributeForDatabase($k,$query_values[$k],false));
                    break;

                default:
                    break;
            }
        }

        $conditions = array($sql);
        foreach ($query_values as $bind_value){
            $conditions[] = $bind_value;
        }
        /**
        * @todo merge_conditions
        */
        $options['conditions'] = $conditions;

        $result =& Ak::call_user_func_array(array(&$this,'find'), array($fetch,$options));
        return $result;
    }
コード例 #3
0
 function find()
 {
     $result =& $GLOBALS['false'];
     if (!$this->Owner->isNewRecord()) {
         $this->constructSql();
         $has_and_belongs_to_many_options = $this->getOptions($this->association_id);
         $Associated =& $this->getAssociatedModelInstance();
         $args = func_get_args();
         $num_args = func_num_args();
         if (!empty($args[$num_args - 1]) && is_array($args[$num_args - 1])) {
             $options_in_args = true;
             $options = $args[$num_args - 1];
         } else {
             $options_in_args = false;
             $options = array();
         }
         $options['conditions'] = empty($options['conditions']) ? @$has_and_belongs_to_many_options['finder_sql'] : (empty($has_and_belongs_to_many_options['finder_sql']) || strstr($options['conditions'], $has_and_belongs_to_many_options['finder_sql']) ? $options['conditions'] : $options['conditions'] . ' AND ' . $has_and_belongs_to_many_options['finder_sql']);
         $options['order'] = empty($options['order']) ? @$has_and_belongs_to_many_options['order'] : $options['order'];
         $options['select_prefix'] = '';
         if ($options_in_args) {
             $args[$num_args - 1] = $options;
         } else {
             $args = empty($args) ? array('all') : $args;
             array_push($args, $options);
         }
         $result =& Ak::call_user_func_array(array(&$Associated, 'find'), $args);
     }
     return $result;
 }
コード例 #4
0
ファイル: AkActiveRecord.php プロジェクト: joeymetal/v1
 function &findAllBy()
 {
     if (!isset($this->_activeRecordHasBeenInstantiated)) {
         return Ak::handleStaticCall();
     }
     $args = func_get_args();
     if ($args[0] == 'first') {
         array_shift($args);
     }
     $result =& Ak::call_user_func_array(array(&$this, 'findBy'), $args);
     return $result;
 }
コード例 #5
0
ファイル: ActsAsVersioned.php プロジェクト: joeymetal/v1
    function &find()
    {
        $Versioned = false;
        $VersionedInstance =& $this->getInstance();
        $finder_sql = $this->options['foreign_key'].' = '.$this->_ActiveRecordInstance->quotedId();
        $finder_order = $this->options['version_column'].' ASC';

        $args = func_get_args();
        $args = $this->_getArgumentsForFinder($args, $finder_sql, $finder_order);

        $Versioned =& Ak::call_user_func_array(array(&$VersionedInstance,'find'), $args);

        if($Versioned){
            if(is_array($Versioned)){
                foreach (array_keys($Versioned) as $k){
                    $Versioned[$k]->VersionHandler =& $this;
                }
            }else{
                $Versioned->VersionHandler =& $this;
            }
        }

        return $Versioned;
    }
コード例 #6
0
    function &find()
    {
        $result = false;
        if(!$this->Owner->isNewRecord()){
            $this->constructSql();
            $has_and_belongs_to_many_options = $this->getOptions($this->association_id);
            $Associated =& $this->getAssociatedModelInstance();

            $args = func_get_args();
            $num_args = func_num_args();

            if(!empty($args[$num_args-1]) && is_array($args[$num_args-1])){
                $options_in_args = true;
                $options = $args[$num_args-1];
            }else{
                $options_in_args = false;
                $options = array();
            }
            /**if (isset($args[0]) && is_int($args[0])) {
                $findId = $args[0];
                $args[0] = 'first';
                if (!isset($args[1])) {
                    $args[1] = array();
                } else if (!isset($args[1]['conditions'])) {
                    $args[1]['conditions'] = array();
                } else if (!is_arraY($args[1]['conditions'])) {
                    $args[1]['conditions'] = array($args[1]['conditions']);
                }
                if (!isset($args[1]['conditions'][1])) {
                    $args[1]['conditions'][1] = array();
                } else if (!is_array($args[1]['conditions'][1])) {
                    $args[1]['conditions'][1] = array($args[1]['conditions'][1]);
                }
                $args[1]['conditions'][1][]=$findId;
            }*/
            /**
             * Buggy Part
             */
            /**$options['conditions'] = empty($options['conditions']) ? @$has_and_belongs_to_many_options['finder_sql'] :
            (empty($has_and_belongs_to_many_options['finder_sql'])  || strstr($options['conditions'], $has_and_belongs_to_many_options['finder_sql'])
            ? $options['conditions'] : $options['conditions'].' AND '.$has_and_belongs_to_many_options['finder_sql']);
            */
            if(empty($options['conditions'])) {
                $options['conditions'] = @$has_and_belongs_to_many_options['finder_sql'];
            } else if (empty($has_and_belongs_to_many_options['finder_sql'])  || (!is_array($options['conditions']) && strstr($options['conditions'], $has_and_belongs_to_many_options['finder_sql']))) {
                $options['conditions'] = $options['conditions'];
            } else {
                if (stristr($has_and_belongs_to_many_options['finder_sql'],' WHERE ')) {
                    $wherePos = stripos($has_and_belongs_to_many_options['finder_sql'],'WHERE');
                    $oldConditions = substr($has_and_belongs_to_many_options['finder_sql'],$wherePos+5);
                    if(is_array($options['conditions'])) {
                        
                        $newConditions = array_shift($options['conditions']);
                        $bind =  $options['conditions'];
                    } else {
                        $newConditions = $options['conditions'];
                        $bind = array();
                    }

                    $newConditions = $this->Owner->_addTableAliasesToAssociatedSql($has_and_belongs_to_many_options['table_name'],$newConditions);
                    $options['conditions'] = trim(substr($has_and_belongs_to_many_options['finder_sql'],0, $wherePos)).' WHERE ('.trim($newConditions).') AND ('.trim($oldConditions).')';
                    if (!empty($bind)) {
                        $options['conditions'] = array_merge(array($options['conditions']),$bind);
                    }
                } else {
                    $options['conditions'] = '('.$options['conditions'].') AND ('.$has_and_belongs_to_many_options['finder_sql'].')';
                }
            }
            $options['include'] = empty($options['include']) ? @$has_and_belongs_to_many_options['include'] : $options['include'];
            $options['bind'] = empty($options['bind']) ? @$has_and_belongs_to_many_options['bind'] : $options['bind'];
            $options['order'] = empty($options['order']) ? @$has_and_belongs_to_many_options['order'] : $options['order'];
            $options['group'] = empty($options['group']) ? @$has_and_belongs_to_many_options['group'] : $options['group'];
            
            $options['select_prefix'] = '';

            if (!empty($options['bind'])) {
                $options['bind'] = Ak::toArray($options['bind']);
                $options['bind'] = array_diff($options['bind'],array(''));
                $options['conditions'] = is_array($options['conditions'])?$options['conditions']:array($options['conditions']);
                $options['conditions'] = array_merge($options['conditions'],$options['bind']);
                unset($options['bind']);
            }
            if (is_array($options['conditions'])) {
                $options['conditions'][0]=trim($Associated->_addTableAliasesToAssociatedSql($has_and_belongs_to_many_options['table_name'],$options['conditions'][0]));
            } else {
                empty($options['conditions']) ?null:$options['conditions']=trim($Associated->_addTableAliasesToAssociatedSql($has_and_belongs_to_many_options['table_name'],$options['conditions']));
            
            }
            empty($options['order']) ?null:$options['order']=trim($Associated->_addTableAliasesToAssociatedSql($has_and_belongs_to_many_options['table_name'],$options['order']));
            empty($options['group']) ?null:$options['group']=trim($Associated->_addTableAliasesToAssociatedSql($has_and_belongs_to_many_options['table_name'],$options['group']));
            
            
            if($options_in_args){
                $args[$num_args-1] = $options;
            }else{
                $args = empty($args) ? array('all') : $args;
                array_push($args, $options);
            }
            $result =& Ak::call_user_func_array(array(&$Associated,'find'), $args);
        }

        return $result;
    }