/** * 'on_row' callback for TIP_Data_View * * Adds the following calculated fields to every data row: * - 'TOTAL': the sum of all votes * - 'PERCENT1': percentual (rounded to integer) of 'votes1' * - 'PERCENT2': percentual (rounded to integer) of 'votes2' * - 'PERCENT3': percentual (rounded to integer) of 'votes3' * - 'PERCENT4': percentual (rounded to integer) of 'votes4' * - 'PERCENT5': percentual (rounded to integer) of 'votes5' * - 'PERCENT6': percentual (rounded to integer) of 'votes6' * * @param array &$row The row as generated by TIP_Data_View * @return bool always true */ public function _onDataRow(&$row) { $total = $row['votes1'] + $row['votes2'] + $row['votes3'] + $row['votes4'] + $row['votes5'] + $row['votes6']; $row['TOTAL'] = $total; // Avoid division per 0 $total > 0 || ($total = 1); $row['PERCENT1'] = round($row['votes1'] * 100 / $total); $row['PERCENT2'] = round($row['votes2'] * 100 / $total); $row['PERCENT3'] = round($row['votes3'] * 100 / $total); $row['PERCENT4'] = round($row['votes4'] * 100 / $total); $row['PERCENT5'] = round($row['votes5'] * 100 / $total); $row['PERCENT6'] = round($row['votes6'] * 100 / $total); // Chain-up the parent callback return parent::_onDataRow($row); }
/** * 'on_row' callback for TIP_Data_View * * Adds the following calculated fields to every data row: * - 'COUNT': the difference between counts and submitted counts * - 'HITS': the difference between hits and submitted hits * * @param array &$row The row as generated by TIP_Data_View * @return bool always true */ public function _onDataRow(&$row) { $row['COUNT'] = $row[$this->count_field] - $row[$this->counted_field]; $row['HITS'] = $row[$this->hits_field] - $row[$this->hitted_field]; // Chain-up the parent callback return parent::_onDataRow($row); }
/** * 'on_row' callback for TIP_Data_View * * Adds the following calculated fields to every data row: * - 'MESSAGE': a reference to the proper localized message * * @param array &$row The row as generated by TIP_Data_View * @return bool always true */ public function _onDataRow(&$row) { $row['MESSAGE'] = $row[$this->locale]; // Chain-up the parent callback return parent::_onDataRow($row); }
/** * 'on_row' callback for TIP_Data_View * * Adds the following calculated fields to every data row: * - 'OA': 'a' if 'sex' is female or 'o' otherwise * * In this content, the 'IS_OWNER' calculated field has no meaning, * so the parent callback is not chained. * * @param array &$row The row as generated by TIP_Data_View * @return bool always true */ public function _onDataRow(&$row) { array_key_exists('sex', $row) && ($row['OA'] = $row['sex'] == 'female' ? 'a' : 'o'); return parent::_onDataRow($row); }
/** * 'on_row' callback for TIP_Data_View * * Adds the following calculated fields to every data row: * - 'EXPIRED': true if the row has expired * * @param array &$row The row as generated by TIP_Data_View * @return bool always true */ public function _onDataRow(&$row) { $row['EXPIRED'] = TIP::getTimestamp($row[$this->expiration_field], 'sql') < time(); return parent::_onDataRow($row); }