createQuery('job') ->addWhere('profile_id = ?', $profile->getId()) ->orderBy('created_at DESC'); } /** * * @return Doctrine_Query */ public static function getOfferJobsQuery() { return Doctrine::getTable('Job')->createQuery('job') ->addWhere('type_id = ?', JobType::OFFER) ->orderBy('created_at DESC'); } /** * * @return Doctrine_Query */ public static function getDemandJobsQuery() { return Doctrine::getTable('Job')->createQuery('job') ->addWhere('type_id = ?', JobType::DEMAND) ->orderBy('created_at DESC'); } /** * * @param Doctrine_Query $query * @return Doctrine_Query */ public static function getPreExpirationQuery(Doctrine_Query $query = null) { if(is_null($query)) { $query = Doctrine::getTable('Job')->createQuery(); } return $query->addWhere('valid_to > ?', date('Y-m-d H:i:s', time()+sfConfig::get('app_preexpiration_time'))); } /** * * @param Doctrine_Query $query * @return Doctrine_Query */ public static function getNonExpirationQuery(Doctrine_Query $query = null) { if(is_null($query)) { $query = Doctrine::getTable('Job')->createQuery(); } return $query->addWhere('valid_to >= ?', date('Y-m-d H:i:s')); } /** * * @param Doctrine_Query $query * @return Doctrine_Query */ public static function getExpirationQuery(Doctrine_Query $query = null) { if(is_null($query)) { $query = Doctrine::getTable('Job')->createQuery(); } return $query->addWhere('valid_to < ?', date('Y-m-d H:i:s')); } /** * Aktuálně platné * * @param Doctrine_Query $query * @return Doctrine_Query */ public static function getValidTimeQuery(Doctrine_Query $query = null) { if(is_null($query)) { $query = Doctrine::getTable('Job')->createQuery(); } return $query->addWhere('valid_from <= ? AND valid_to >= ?', array(date('Y-m-d H:i:s'), date('Y-m-d'))); } /** * Aktuálně neplatné * * @param Doctrine_Query $query * @return Doctrine_Query */ public static function getUnvalidTimeQuery(Doctrine_Query $query = null) { if(is_null($query)) { $query = Doctrine::getTable('Job')->createQuery(); } return $query->addWhere('valid_from > ? OR valid_to < ?', array(date('Y-m-d H:i:s'), date('Y-m-d H:i:s'))); } public static function getRowsCount($chars_count) { return floor($chars_count / (sfConfig::get('app_row_chars') + 1)) + 1; // + 2; // if($chars_count == 0) // { // return 2; // } // +2 => jeden za pozici a jeden za název instituce+město. Je to proto, že v tisku jsou toto dva řádky nadpisu inzerátu //return floor($chars_count / (sfConfig::get('app_row_chars') + 1)) + 1 + 2; } /** * Zjisti koli se bude fakturovat * * @param type $chars_count * @param JobStyle $style * @param int $months platnost v mesicich * @param Profile $profile * @return int */ public static function getRowsCountForInvoice($chars_count, JobStyle $style, $months = 1, Profile $profile = null) { if(!is_null($profile) && $profile->getPrepaymentTypeId() == PrepaymentType::TYPE_COUNT && $profile->isPrepaymentValid($style)) { $fulls = $months - $profile->getPrepaymentCount($style); $fulls = $fulls < 0 ? 0 : $fulls; $halfs = (($count = (self::getRowsCount($chars_count)) - sfConfig::get('app_prepayment_job_rows'))) > 0 ? $count : 0; $halfs *= $profile->getPrepaymentDiscount($style); return $halfs + (self::getRowsCount($chars_count) * $fulls); } elseif(!is_null($profile) && $profile->getPrepaymentTypeId() == PrepaymentType::TYPE_ROW && $profile->isPrepaymentValid($style)) { $credits = (self::getRowsCount($chars_count) * $months); $pay = $credits - self::getUsePrepaymentRows($chars_count, $style, $months, $profile); $pay *= $profile->getPrepaymentRowsDiscount($style); return $pay; } else { return self::getRowsCount($chars_count) * $months; } } public static function getUsePrepaymentRows($chars_count, JobStyle $style, $months, Profile $profile) { $credits = (self::getRowsCount($chars_count) * $months); $pay = $credits - $profile->getPrepaymentRows($style); $pay = $pay > 0 ? $pay : 0; return $credits - $pay; } public static function getPrice(JobStyle $style, Country $country, $chars_count, $months = 1, Profile $profile = null) { // $pr = $style->getPriceRelation($country); // $row_price = $pr ? $pr->getRowPrice() : 0; // // return self::getRowsCountForInvoice($chars_count, $style, $months, $profile) * $row_price; // return round($chars_count * $months * self::getCharPrice($style, $country), 2); // nově pevná cena za inzerát: switch($style->getId()) { case JobStyle::STANDARD: return $months * 50; case JobStyle::HIGHLIGHT: return $months * 150; case JobStyle::TOP: return $months * 300; } } public static function getCharPrice(JobStyle $style, Country $country) { return 0; // switch($style->getId()) // { // case JobStyle::STANDARD: // return 0.16; // case JobStyle::HIGHLIGHT: // return 0.20; // case JobStyle::TOP: // return 0.24; // } // if($country->getId() == 1) // { // switch($style->getId()) // { // case JobStyle::STANDARD: // return 4.20; // case JobStyle::HIGHLIGHT: // return 5.60; // case JobStyle::TOP: // return 7.00; // } // } // else // { // switch($style->getId()) // { // case JobStyle::STANDARD: // return 0.25; // case JobStyle::HIGHLIGHT: // return 0.31; // case JobStyle::TOP: // return 0.40; // } // } } }