public function dashboard() { $this->SalesKeyword->recursive = -1; $daily = array(); $weekly = array(); $monthly = array(); $date = date('Y-m-d'); $today = date('d'); $today_int = settype($today, "integer"); $conds = array(); $conds['SalesKeyword.date BETWEEN ? AND ?'] = array(date('Y-m') . '-01', $date); $fields = array(); $fields = array('SalesKeyword.date'); $sales_keywords = $this->SalesKeyword->find('all', array('conditions' => $conds, 'fields' => $fields, 'group' => 'SalesKeyword.date', 'order' => 'SalesKeyword.date ASC')); $sales_date = Hash::extract($sales_keywords, '{n}.SalesKeyword.date'); $sales_keywords_daily = array(); $sum_sales_keyword = array(); for ($i = 0; $i < count($sales_date); $i++) { $sum_sales_keyword[$i] = $this->SalesKeyword->find('all', array('conditions' => array('SalesKeyword.date' => $sales_date[$i]), 'fields' => array('sum(SalesKeyword.sales) as total_sales', 'sum(SalesKeyword.cost) as total_cost', 'sum(SalesKeyword.profit) as total_profit', 'SalesKeyword.date'))); @($monthly['sales'] += @$sum_sales_keyword[$i][0][0]['total_sales']); @($monthly['cost'] += @$sum_sales_keyword[$i][0][0]['total_cost']); @($monthly['profit'] += @$sum_sales_keyword[$i][0][0]['total_profit']); } $daily = Hash::format($sum_sales_keyword, array('{n}.0.0.total_sales', '{n}.0.0.total_cost', '{n}.0.0.total_profit'), '%d, %d, %d'); // $weekly = array_slice($daily, $today_int - 8); /* WEEKLY */ $weekly = array(array(__('Day'), __('Sales'), __('Cost'), __('Profit'), __('Average'))); $week_tmp[] = array_slice($daily, 0, 7); $week_tmp[] = array_slice($daily, 7, 7); $week_tmp[] = array_slice($daily, 14, 7); $week_tmp[] = array_slice($daily, 21, 7); $week_tmp[] = array_slice($daily, 28, 7); foreach ($week_tmp as $w => $value_week) { $s_w = array(); $c_w = array(); $p_w = array(); $a_w = array(); foreach ($value_week as $v) { $s = explode(', ', $v); $s_w[] = $s[0]; $c_w[] = $s[1]; $p_w[] = $s[2]; $a_w[] = $s[0] / 7; } $weekly[$w + 1][] = 'Week ' . ($w + 1); $weekly[$w + 1][] = array_sum($s_w); $weekly[$w + 1][] = array_sum($c_w); $weekly[$w + 1][] = array_sum($p_w); $weekly[$w + 1][] = array_sum($a_w); } // goal seika monthly type = 1 $this->loadModel('SalesGoal'); $this->SalesGoal->recursive = 0; $goal = $this->SalesGoal->find('first', array('conditions' => array('SalesGoal.target' => date('Y-m')))); $this->set(compact('daily', 'weekly', 'monthly', 'goal')); }
/** * testFormattingNullValues method * * @return void */ public function testFormatNullValues() { $data = array(array('Person' => array('first_name' => 'Nate', 'last_name' => 'Abele', 'city' => 'Boston', 'state' => 'MA', 'something' => '42')), array('Person' => array('first_name' => 'Larry', 'last_name' => 'Masters', 'city' => 'Boondock', 'state' => 'TN', 'something' => null)), array('Person' => array('first_name' => 'Garrett', 'last_name' => 'Woodworth', 'city' => 'Venice Beach', 'state' => 'CA', 'something' => null))); $result = Hash::format($data, array('{n}.Person.something'), '%s'); $expected = array('42', '', ''); $this->assertEquals($expected, $result); $result = Hash::format($data, array('{n}.Person.city', '{n}.Person.something'), '%s, %s'); $expected = array('Boston, 42', 'Boondock, ', 'Venice Beach, '); $this->assertEquals($expected, $result); }
public function sentence($liked) { // Tu aimes ceci. // Eric Legois aime ceci. // Toi et Eric aimez ceci. // Eric Legois et Sarah Durieux aiment ceci. // Toi, Eric Legois et Sarah Durieux aimez ceci. // Michel Durand, Eric Legois et 3 autres bénévoles aiment ceci. // Toi, Michel Durand, Eric Legois et 3 autres bénévoles aimez ça. $sentence = ''; if ($liked['is_liked']) { if ($liked['total'] == 1) { $sentence = 'Tu '; } if ($liked['total'] == 2) { $sentence = 'Toi et '; } if ($liked['total'] > 2) { $sentence = 'Toi, '; } } if (count($liked['last_liked'])) { $likers = Hash::format($liked['last_liked'], array('{n}.User.first_name', '{n}.User.last_name'), '%s %s'); if (count($liked['last_liked']) == 1) { $sentence .= $likers[0]; } if (count($liked['last_liked']) == 2 && $liked['total'] == 2) { $sentence .= $likers[0] . ' et ' . $likers[1]; } if (count($liked['last_liked']) == 2 && $liked['total'] == 3 && $liked['is_liked']) { $sentence .= $likers[0] . ' et ' . $likers[1]; } if (count($liked['last_liked']) == 2 && $liked['total'] == 3 && !$liked['is_liked']) { $sentence .= $likers[0] . ', ' . $likers[1] . ' et ' . ($liked['total'] - 2) . ' bénévole' . ($liked['total'] - 3 > 1 ? 's' : ''); } if (count($liked['last_liked']) == 2 && $liked['total'] > 3 && $liked['is_liked']) { $sentence .= $likers[0] . ', ' . $likers[1] . ' et ' . ($liked['total'] - 3) . ' bénévole' . ($liked['total'] - 3 > 1 ? 's' : ''); } if (count($liked['last_liked']) == 2 && $liked['total'] > 3 && !$liked['is_liked']) { $sentence .= $likers[0] . ', ' . $likers[1] . ' et ' . ($liked['total'] - 2) . ' bénévole' . ($liked['total'] - 2 > 1 ? 's' : ''); } } if ($liked['is_liked']) { if ($liked['total'] == 1) { $sentence .= ' aimes '; } if ($liked['total'] > 1) { $sentence .= ' aimez '; } } else { if ($liked['total'] == 1) { $sentence .= ' aime '; } if ($liked['total'] > 1) { $sentence .= ' aiment '; } } if ($liked['total'] > 0) { $sentence .= 'ceci.'; } return $sentence; }